[tip:x86/apic] x86/idt: Unify gate_struct handling for 32/64-bit kernels

2017-08-29 Thread tip-bot for Thomas Gleixner
Commit-ID:  64b163fab684e3de47aa8db6cc08ae7d2e194373
Gitweb: http://git.kernel.org/tip/64b163fab684e3de47aa8db6cc08ae7d2e194373
Author: Thomas Gleixner 
AuthorDate: Mon, 28 Aug 2017 08:47:37 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 29 Aug 2017 12:07:24 +0200

x86/idt: Unify gate_struct handling for 32/64-bit kernels

The first 32 bits of gate struct are the same for 32 and 64 bit kernels.

The 32-bit version uses desc_struct and no designated data structure,
so we need different accessors for 32 and 64 bit kernels.

Aside of that the macros which are necessary to build the 32-bit
gate descriptor are horrible to read.

Unify the gate structs and switch all code fiddling with it over.

Signed-off-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Link: http://lkml.kernel.org/r/20170828064957.861974...@linutronix.de
Signed-off-by: Ingo Molnar 
---
 arch/x86/boot/compressed/eboot.c |  8 +++---
 arch/x86/include/asm/desc.h  | 45 ++-
 arch/x86/include/asm/desc_defs.h | 57 ++--
 arch/x86/kvm/vmx.c   |  2 +-
 arch/x86/xen/enlighten_pv.c  | 12 -
 5 files changed, 67 insertions(+), 57 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index c3e869e..65f0b24 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -1058,7 +1058,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = DESC_TYPE_CODE_DATA;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0xf;
+   desc->limit1 = 0xf;
desc->avl = 0;
desc->l = 0;
desc->d = SEG_OP_SIZE_32BIT;
@@ -1078,7 +1078,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = DESC_TYPE_CODE_DATA;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0xf;
+   desc->limit1 = 0xf;
desc->avl = 0;
if (IS_ENABLED(CONFIG_X86_64)) {
desc->l = 1;
@@ -1099,7 +1099,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = DESC_TYPE_CODE_DATA;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0xf;
+   desc->limit1 = 0xf;
desc->avl = 0;
desc->l = 0;
desc->d = SEG_OP_SIZE_32BIT;
@@ -1116,7 +1116,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = 0;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0x0;
+   desc->limit1 = 0x0;
desc->avl = 0;
desc->l = 0;
desc->d = 0;
diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
index d18a604..0731064 100644
--- a/arch/x86/include/asm/desc.h
+++ b/arch/x86/include/asm/desc.h
@@ -84,33 +84,25 @@ static inline phys_addr_t get_cpu_gdt_paddr(unsigned int 
cpu)
return per_cpu_ptr_to_phys(get_cpu_gdt_rw(cpu));
 }
 
-#ifdef CONFIG_X86_64
-
 static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long 
func,
 unsigned dpl, unsigned ist, unsigned seg)
 {
-   gate->offset_low= PTR_LOW(func);
+   gate->offset_low= (u16) func;
+   gate->bits.p= 1;
+   gate->bits.dpl  = dpl;
+   gate->bits.zero = 0;
+   gate->bits.type = type;
+   gate->offset_middle = (u16) (func >> 16);
+#ifdef CONFIG_X86_64
gate->segment   = __KERNEL_CS;
-   gate->ist   = ist;
-   gate->p = 1;
-   gate->dpl   = dpl;
-   gate->zero0 = 0;
-   gate->zero1 = 0;
-   gate->type  = type;
-   gate->offset_middle = PTR_MIDDLE(func);
-   gate->offset_high   = PTR_HIGH(func);
-}
-
+   gate->bits.ist  = ist;
+   gate->reserved  = 0;
+   gate->offset_high   = (u32) (func >> 32);
 #else
-static inline void pack_gate(gate_desc *gate, unsigned char type,
-unsigned long base, unsigned dpl, unsigned flags,
-unsigned short seg)
-{
-   gate->a = (seg << 16) | (base & 0x);
-   gate->b = (base & 0x) | (((0x80 | type | (dpl << 5)) & 0xff) << 
8);
-}
-
+   gate->segment   = seg;
+   gate->bits.ist  = 0;
 #endif
+}
 
 static inline int desc_empty(const void *ptr)
 {
@@ -186,7 +178,8 @@ static inline void pack_descriptor(struct desc_struct 
*desc, unsigned long 

[tip:x86/apic] x86/idt: Unify gate_struct handling for 32/64-bit kernels

2017-08-29 Thread tip-bot for Thomas Gleixner
Commit-ID:  64b163fab684e3de47aa8db6cc08ae7d2e194373
Gitweb: http://git.kernel.org/tip/64b163fab684e3de47aa8db6cc08ae7d2e194373
Author: Thomas Gleixner 
AuthorDate: Mon, 28 Aug 2017 08:47:37 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 29 Aug 2017 12:07:24 +0200

x86/idt: Unify gate_struct handling for 32/64-bit kernels

The first 32 bits of gate struct are the same for 32 and 64 bit kernels.

The 32-bit version uses desc_struct and no designated data structure,
so we need different accessors for 32 and 64 bit kernels.

Aside of that the macros which are necessary to build the 32-bit
gate descriptor are horrible to read.

Unify the gate structs and switch all code fiddling with it over.

Signed-off-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Link: http://lkml.kernel.org/r/20170828064957.861974...@linutronix.de
Signed-off-by: Ingo Molnar 
---
 arch/x86/boot/compressed/eboot.c |  8 +++---
 arch/x86/include/asm/desc.h  | 45 ++-
 arch/x86/include/asm/desc_defs.h | 57 ++--
 arch/x86/kvm/vmx.c   |  2 +-
 arch/x86/xen/enlighten_pv.c  | 12 -
 5 files changed, 67 insertions(+), 57 deletions(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index c3e869e..65f0b24 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -1058,7 +1058,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = DESC_TYPE_CODE_DATA;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0xf;
+   desc->limit1 = 0xf;
desc->avl = 0;
desc->l = 0;
desc->d = SEG_OP_SIZE_32BIT;
@@ -1078,7 +1078,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = DESC_TYPE_CODE_DATA;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0xf;
+   desc->limit1 = 0xf;
desc->avl = 0;
if (IS_ENABLED(CONFIG_X86_64)) {
desc->l = 1;
@@ -1099,7 +1099,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = DESC_TYPE_CODE_DATA;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0xf;
+   desc->limit1 = 0xf;
desc->avl = 0;
desc->l = 0;
desc->d = SEG_OP_SIZE_32BIT;
@@ -1116,7 +1116,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->s = 0;
desc->dpl = 0;
desc->p = 1;
-   desc->limit = 0x0;
+   desc->limit1 = 0x0;
desc->avl = 0;
desc->l = 0;
desc->d = 0;
diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
index d18a604..0731064 100644
--- a/arch/x86/include/asm/desc.h
+++ b/arch/x86/include/asm/desc.h
@@ -84,33 +84,25 @@ static inline phys_addr_t get_cpu_gdt_paddr(unsigned int 
cpu)
return per_cpu_ptr_to_phys(get_cpu_gdt_rw(cpu));
 }
 
-#ifdef CONFIG_X86_64
-
 static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long 
func,
 unsigned dpl, unsigned ist, unsigned seg)
 {
-   gate->offset_low= PTR_LOW(func);
+   gate->offset_low= (u16) func;
+   gate->bits.p= 1;
+   gate->bits.dpl  = dpl;
+   gate->bits.zero = 0;
+   gate->bits.type = type;
+   gate->offset_middle = (u16) (func >> 16);
+#ifdef CONFIG_X86_64
gate->segment   = __KERNEL_CS;
-   gate->ist   = ist;
-   gate->p = 1;
-   gate->dpl   = dpl;
-   gate->zero0 = 0;
-   gate->zero1 = 0;
-   gate->type  = type;
-   gate->offset_middle = PTR_MIDDLE(func);
-   gate->offset_high   = PTR_HIGH(func);
-}
-
+   gate->bits.ist  = ist;
+   gate->reserved  = 0;
+   gate->offset_high   = (u32) (func >> 32);
 #else
-static inline void pack_gate(gate_desc *gate, unsigned char type,
-unsigned long base, unsigned dpl, unsigned flags,
-unsigned short seg)
-{
-   gate->a = (seg << 16) | (base & 0x);
-   gate->b = (base & 0x) | (((0x80 | type | (dpl << 5)) & 0xff) << 
8);
-}
-
+   gate->segment   = seg;
+   gate->bits.ist  = 0;
 #endif
+}
 
 static inline int desc_empty(const void *ptr)
 {
@@ -186,7 +178,8 @@ static inline void pack_descriptor(struct desc_struct 
*desc, unsigned long base,
 }
 
 
-static inline void set_tssldt_descriptor(void *d, unsigned long addr, unsigned 
type, unsigned size)
+static inline void set_tssldt_descriptor(void *d, unsigned long addr,
+unsigned type, unsigned size)
 {