Standardize x86_64's desc_defs.h in preparation for exposure to i386.
Subsystems (3)
PATCH 1/3 Standardize x86_64's desc_defs.h in preparation for exposure to i386.
KVM has independent definitions of these structures, which is bad. However, the currently (i386-derived) x86-64 ones are suboptimal. The first step is to clean them up, especially by making desc_struct a union.
Additional changes:
1) s/ldttss_desc/ldttss_desc_64/ to clearly indicate it's x86-64 only.
2) Changed the type of the tls_array in struct thread_struct:
there seems little point to all these casts.
3) s/gate_struct/gate_struct_64/ to differentiate from new gate_struct_32.
4) New base/limit extraction convenience functions in desc_defs.h.
arch/x86_64/ia32/tls32.c +21 -36
@@ -19,7 +19,7 @@ static int get_free_idx(void)int idx;for (idx =0 ; idx <GDT_ENTRY_TLS_ENTRIES ; idx++) -if (desc_empty ((struct n_desc_struct *)(t->tls_array) + idx)) +if (desc_empty (t->tls_array + idx))return idx +GDT_ENTRY_TLS_MIN ;return -ESRCH ; }
@@ -31,7 +31,7 @@ int do_set_thread_area(struct thread_strint do_set_thread_area (struct thread_struct *t,struct user_desc __user *u_info) {struct user_desc info; -struct n_desc_struct *desc; +struct desc_struct *desc;int cpu, idx;if (copy_from_user (&info, u_info,sizeof (info)))
@@ -54,7 +54,7 @@ int do_set_thread_area(struct thread_strif (idx <GDT_ENTRY_TLS_MIN || idx >GDT_ENTRY_TLS_MAX )return -EINVAL ; - desc = ((struct n_desc_struct *)t->tls_array) + idx -GDT_ENTRY_TLS_MIN ; + desc = t->tls_array + idx -GDT_ENTRY_TLS_MIN ;/* * We must not get preempted while modifying the TLS.
@@ -62,11 +62,10 @@ int do_set_thread_area(struct thread_str cpu =get_cpu ();if (LDT_empty (&info)) { - desc->a =0 ; - desc->b =0 ; + desc->raw =0 ; }else { - desc->a =LDT_entry_a (&info); - desc->b =LDT_entry_b (&info); + desc->raw32.a =LDT_entry_a (&info); + desc->raw32.b =LDT_entry_b (&info); }if (t == ¤t->thread)load_TLS (t, cpu);
@@ -85,27 +85,13 @@ asmlinkage long sys32_set_thread_area(st* Get the current Thread-Local Storage area: */ -#define GET_BASE (desc) ( \ - (((desc)->a >> 16) & 0x0000ffff) | \ - (((desc)->b << 16) & 0x00ff0000) | \ - ( (desc)->b & 0xff000000) ) - -#define GET_LIMIT (desc) ( \ - ((desc)->a & 0x0ffff) | \ - ((desc)->b & 0xf0000) ) - -#define GET_32BIT (desc) (((desc)->b >> 22) & 1) -#define GET_CONTENTS (desc) (((desc)->b >> 10) & 3) -#define GET_WRITABLE (desc) (((desc)->b >> 9) & 1) -#define GET_LIMIT_PAGES (desc) (((desc)->b >> 23) & 1) -#define GET_PRESENT (desc) (((desc)->b >> 15) & 1) -#define GET_USEABLE (desc) (((desc)->b >> 20) & 1) -#define GET_LONGMODE (desc) (((desc)->b >> 21) & 1) +#define GET_CONTENTS (desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE (desc) (((desc)->raw32.b >> 9) & 1)int do_get_thread_area (struct thread_struct *t,struct user_desc __user *u_info) {struct user_desc info; -struct n_desc_struct *desc; +struct desc_struct *desc;int idx;if (get_user (idx, &u_info->entry_number))
@@ -113,19 +99,19 @@ int do_get_thread_area(struct thread_strif (idx <GDT_ENTRY_TLS_MIN || idx >GDT_ENTRY_TLS_MAX )return -EINVAL ; - desc = ((struct n_desc_struct *)t->tls_array) + idx -GDT_ENTRY_TLS_MIN ; + desc = t->tls_array + idx -GDT_ENTRY_TLS_MIN ;memset (&info,0 ,sizeof (struct user_desc )); info.entry_number = idx; - info.base_addr =GET_BASE (desc); - info.limit =GET_LIMIT (desc); - info.seg_32bit =GET_32BIT (desc); + info.base_addr =get_seg_desc_base (&desc->seg); + info.limit =get_seg_desc_limit (&desc->seg); + info.seg_32bit = desc->seg.d; info.contents =GET_CONTENTS (desc); info.read_exec_only = !GET_WRITABLE (desc); - info.limit_in_pages =GET_LIMIT_PAGES (desc); - info.seg_not_present = !GET_PRESENT (desc); - info.useable =GET_USEABLE (desc); - info.lm =GET_LONGMODE (desc); + info.limit_in_pages = desc->seg.g; + info.seg_not_present = !desc->seg.p; + info.useable = desc->seg.avl; + info.lm = desc->seg.l;if (copy_to_user (u_info, &info,sizeof (info)))return -EFAULT ;
@@ -140,7 +126,7 @@ asmlinkage long sys32_get_thread_area(stint ia32_child_tls (struct task_struct *p,struct pt_regs *childregs) { -struct n_desc_struct *desc; +struct desc_struct *desc;struct user_desc info;struct user_desc __user *cp;int idx;
@@ -155,9 +141,9 @@ int ia32_child_tls(struct task_struct *pif (idx <GDT_ENTRY_TLS_MIN || idx >GDT_ENTRY_TLS_MAX )return -EINVAL ; - desc = (struct n_desc_struct *)(p->thread.tls_array) + idx -GDT_ENTRY_TLS_MIN ; - desc->a =LDT_entry_a (&info); - desc->b =LDT_entry_b (&info); + desc = p->thread.tls_array + idx -GDT_ENTRY_TLS_MIN ; + desc->raw32.a =LDT_entry_a (&info); + desc->raw32.b =LDT_entry_b (&info);return 0 ; }
arch/x86_64/kernel/process.c +3 -9
@@ -432,19 +432,13 @@ static inline void set_32bit_tls(struct .limit_in_pages = 1, .useable = 1, }; -struct n_desc_struct *desc = (void *)t->thread.tls_array; - desc += tls; - desc->a =LDT_entry_a (&ud); - desc->b =LDT_entry_b (&ud); + t->thread.tls_array[tls].raw32.a =LDT_entry_a (&ud); + t->thread.tls_array[tls].raw32.b =LDT_entry_b (&ud); }static inline u32 read_32bit_tls (struct task_struct *t,int tls) { -struct desc_struct *desc = (void *)t->thread.tls_array; - desc += tls; -return desc->base0 | - (((u32 )desc->base1) <<16 ) | - (((u32 )desc->base2) <<24 ); +return get_seg_desc_base (&t->thread.tls_array[tls].seg); }/*
arch/x86_64/kernel/suspend.c +1 -1
@@ -125,7 +125,7 @@ void fix_processor_context(void)set_tss_desc (cpu,t);/* This just modifies memory; should not be neccessary. But... This is neccessary, because 386 hardware has concept of busy TSS or some similar stupidity. */ -cpu_gdt (cpu)[GDT_ENTRY_TSS ].type =9 ; +cpu_gdt (cpu)[GDT_ENTRY_TSS ].seg.type =DESC_TSS ;syscall_init ();/* This sets MSR_*STAR and related */ load_TR_desc ();/* This does ltr */
include/asm-x86_64/desc.h +4 -4
@@ -25,7 +25,7 @@ extern struct desc_struct cpu_gdt_table[* something other than this. */ extern struct desc_struct default_ldt[]; -extern struct gate_struct idt_table[]; +extern struct gate_struct_64 idt_table[];extern struct desc_ptr cpu_gdt_descr[];/* the cpu gdt accessor */
@@ -33,7 +33,7 @@ extern struct desc_ptr cpu_gdt_descr[];static inline void _set_gate (void *adr,unsigned type,unsigned long func,unsigned dpl,unsigned ist) { -struct gate_struct s; +struct gate_struct_64 s; s.offset_low =PTR_LOW (func); s.segment = __KERNEL_CS; s.ist = ist;
@@ -74,7 +74,7 @@ static inline void set_tssldt_descriptorstatic inline void set_tssldt_descriptor (void *ptr,unsigned long tss,unsigned type,unsigned size) { -struct ldttss_desc d; +struct ldttss_desc_64 d;memset (&d,0 ,sizeof (d)); d.limit0 = size &0xFFFF ; d.base0 =PTR_LOW (tss);
@@ -138,7 +138,7 @@ static inline void load_TLS(struct threastatic inline void load_TLS (struct thread_struct *t,unsigned int cpu) {unsigned int i; -u64 *gdt = (u64 *)(cpu_gdt (cpu) +GDT_ENTRY_TLS_MIN ); +struct desc_struct *gdt =cpu_gdt (cpu) +GDT_ENTRY_TLS_MIN ;for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) gdt[i] = t->tls_array[i];
include/asm-x86_64/desc_defs.h +34 -7
66 lines not on this page · raw message
include/asm-x86_64/processor.h +12 -6
@@ -21,6 +21,7 @@#include <linux/personality.h> #include <linux/cpumask.h> #include <asm/processor-flags.h> +#include <asm/desc_defs.h> #define TF_MASK 0x00000100#define IF_MASK 0x00000200
@@ -32,11 +33,16 @@#define VIP_MASK 0x00100000/* virtual interrupt pending */ #define ID_MASK 0x00200000 -#define desc_empty (desc) \ - (!((desc)->a | (desc)->b)) - -#define desc_equal (desc1, desc2) \ - (((desc1)->a == (desc2)->a) && ((desc1)->b == (desc2)->b)) +static inline bool desc_empty (const struct desc_struct *desc) +{ +return !desc->raw; +} + +static inline bool desc_equal (const struct desc_struct *d1, +const struct desc_struct *d2) +{ +return d1->raw == d2->raw; +}/* * Default implementation of macro that returns current
@@ -238,7 +244,7 @@ struct thread_struct {unsigned long *io_bitmap_ptr;unsigned io_bitmap_max;/* cached TLS descriptors. */ -u64 tls_array[GDT_ENTRY_TLS_ENTRIES ]; +struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES ]; } __attribute__((aligned(16)));#define INIT_THREAD { \
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 2/3 i386: use x86_64's desc_def.h
The main effect is to change the definition of "struct desc_struct" to a union of more complex types.
I kept the old 32-bit comparisons, but many could be changed to use the 64-bit "desc->raw".
arch/i386/kernel/cpu/common.c +15 -15
@@ -22,31 +22,31 @@#include "cpu.h" DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = { - [GDT_ENTRY_KERNEL_CS ] = {0x0000ffff ,0x00cf9a00 }, - [GDT_ENTRY_KERNEL_DS ] = {0x0000ffff ,0x00cf9200 }, - [GDT_ENTRY_DEFAULT_USER_CS ] = {0x0000ffff ,0x00cffa00 }, - [GDT_ENTRY_DEFAULT_USER_DS ] = {0x0000ffff ,0x00cff200 }, + [GDT_ENTRY_KERNEL_CS ] = { {0x00cf9a000000ffffULL } }, + [GDT_ENTRY_KERNEL_DS ] = { {0x00cf92000000ffffULL } }, + [GDT_ENTRY_DEFAULT_USER_CS ] = { {0x00cffa000000ffffULL } }, + [GDT_ENTRY_DEFAULT_USER_DS ] = { {0x00cff2000000ffffULL } },/* * Segments used for calling PnP BIOS have byte granularity. * They code segments and data segments have fixed 64k limits, * the transfer segment sizes are set at run time. */ - [GDT_ENTRY_PNPBIOS_CS32 ] = {0x0000ffff ,0x00409a00 },/* 32-bit code */ - [GDT_ENTRY_PNPBIOS_CS16 ] = {0x0000ffff ,0x00009a00 },/* 16-bit code */ - [GDT_ENTRY_PNPBIOS_DS ] = {0x0000ffff ,0x00009200 },/* 16-bit data */ - [GDT_ENTRY_PNPBIOS_TS1 ] = {0x00000000 ,0x00009200 },/* 16-bit data */ - [GDT_ENTRY_PNPBIOS_TS2 ] = {0x00000000 ,0x00009200 },/* 16-bit data */ + [GDT_ENTRY_PNPBIOS_CS32 ] = { {0x00409a000000ffffULL } },/* 32-bit code */ + [GDT_ENTRY_PNPBIOS_CS16 ] = { {0x00009a000000ffffULL } },/* 16-bit code */ + [GDT_ENTRY_PNPBIOS_DS ] = { {0x000092000000ffffULL } },/* 16-bit data */ + [GDT_ENTRY_PNPBIOS_TS1 ] = { {0x0000920000000000ULL } },/* 16-bit data */ + [GDT_ENTRY_PNPBIOS_TS2 ] = { {0x0000920000000000ULL } },/* 16-bit data */ /* * The APM segments have byte granularity and their bases * are set at run time. All have 64k limits. */ - [GDT_ENTRY_APMBIOS_BASE ] = {0x0000ffff ,0x00409a00 },/* 32-bit code */ + [GDT_ENTRY_APMBIOS_BASE ] = { {0x00409a000000ffffULL } },/* 32-bit code */ /* 16-bit code */ - [GDT_ENTRY_APMBIOS_BASE +1 ] = {0x0000ffff ,0x00009a00 }, - [GDT_ENTRY_APMBIOS_BASE +2 ] = {0x0000ffff ,0x00409200 },/* data */ - - [GDT_ENTRY_ESPFIX_SS ] = {0x00000000 ,0x00c09200 }, - [GDT_ENTRY_PERCPU ] = {0x00000000 ,0x00000000 }, + [GDT_ENTRY_APMBIOS_BASE +1 ] = { {0x00009a000000ffffULL } }, + [GDT_ENTRY_APMBIOS_BASE +2 ] = { {0x004092000000ffffULL } },/* data */ + + [GDT_ENTRY_ESPFIX_SS ] = { {0x00c0920000000000ULL } }, + [GDT_ENTRY_PERCPU ] = { {0x0000000000000000ULL } }, } };EXPORT_PER_CPU_SYMBOL_GPL (gdt_page);
arch/i386/kernel/process.c +14 -27
68 lines not on this page · raw message
arch/i386/kernel/ptrace.c +12 -26
@@ -283,22 +283,8 @@ ptrace_get_thread_area(struct task_struc/* * Get the current Thread-Local Storage area: */ - -#define GET_BASE (desc) ( \ - (((desc)->a >> 16) & 0x0000ffff) | \ - (((desc)->b << 16) & 0x00ff0000) | \ - ( (desc)->b & 0xff000000) ) - -#define GET_LIMIT (desc) ( \ - ((desc)->a & 0x0ffff) | \ - ((desc)->b & 0xf0000) ) - -#define GET_32BIT (desc) (((desc)->b >> 22) & 1) -#define GET_CONTENTS (desc) (((desc)->b >> 10) & 3) -#define GET_WRITABLE (desc) (((desc)->b >> 9) & 1) -#define GET_LIMIT_PAGES (desc) (((desc)->b >> 23) & 1) -#define GET_PRESENT (desc) (((desc)->b >> 15) & 1) -#define GET_USEABLE (desc) (((desc)->b >> 20) & 1) +#define GET_CONTENTS (desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE (desc) (((desc)->raw32.b >> 9) & 1)if (idx <GDT_ENTRY_TLS_MIN || idx >GDT_ENTRY_TLS_MAX )return -EINVAL ;
@@ -306,14 +292,14 @@ ptrace_get_thread_area(struct task_struc desc = child->thread.tls_array + idx -GDT_ENTRY_TLS_MIN ; info.entry_number = idx; - info.base_addr =GET_BASE (desc); - info.limit =GET_LIMIT (desc); - info.seg_32bit =GET_32BIT (desc); + info.base_addr =get_seg_desc_base (&desc->seg); + info.limit =get_seg_desc_limit (&desc->seg); + info.seg_32bit = desc->seg.d; info.contents =GET_CONTENTS (desc); info.read_exec_only = !GET_WRITABLE (desc); - info.limit_in_pages =GET_LIMIT_PAGES (desc); - info.seg_not_present = !GET_PRESENT (desc); - info.useable =GET_USEABLE (desc); + info.limit_in_pages = desc->seg.g; + info.seg_not_present = !desc->seg.p; + info.useable = desc->seg.avl;if (copy_to_user (user_desc, &info,sizeof (info)))return -EFAULT ;
@@ -339,11 +325,11 @@ ptrace_set_thread_area(struct task_struc desc = child->thread.tls_array + idx -GDT_ENTRY_TLS_MIN ;if (LDT_empty (&info)) { - desc->a =0 ; - desc->b =0 ; + desc->raw32.a =0 ; + desc->raw32.b =0 ; }else { - desc->a =LDT_entry_a (&info); - desc->b =LDT_entry_b (&info); + desc->raw32.a =LDT_entry_a (&info); + desc->raw32.b =LDT_entry_b (&info); }return 0 ;
arch/i386/kernel/smpcommon.c +2 -2
@@ -14,8 +14,8 @@ __cpuinit void init_gdt(int cpu) {struct desc_struct *gdt =get_cpu_gdt_table (cpu); -pack_descriptor ((u32 *)&gdt[GDT_ENTRY_PERCPU ].a, - (u32 *)&gdt[GDT_ENTRY_PERCPU ].b, +pack_descriptor (&gdt[GDT_ENTRY_PERCPU ].raw32.a, + &gdt[GDT_ENTRY_PERCPU ].raw32.b, __per_cpu_offset[cpu],0xFFFFF ,0x80 |DESCTYPE_S |0x2 ,0x8 );
arch/i386/kernel/traps.c +1 -1
@@ -71,7 +71,7 @@ char ignore_fpu_irq = 0;* F0 0F bug workaround.. We have a special link segment * for this. */ -struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, }; +struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))); asmlinkage void divide_error(void); asmlinkage void debug(void);
arch/i386/kernel/vmi.c +2 -2
@@ -178,8 +178,8 @@ static void vmi_cpuid(unsigned int *eax,static inline void vmi_maybe_load_tls (struct desc_struct *gdt,int nr,struct desc_struct *new) { -if (gdt[nr].a != new->a || gdt[nr].b != new->b) -write_gdt_entry (gdt, nr, new->a, new->b); +if (gdt[nr].raw32.a != new->raw32.a || gdt[nr].raw32.b != new->raw32.b) +write_gdt_entry (gdt, nr, new->raw32.a, new->raw32.b); }static void vmi_load_tls (struct thread_struct *t,unsigned int cpu)
include/asm-i386/desc.h +2 -2
@@ -81,8 +81,8 @@ static inline void write_dt_entry(structstatic inline void write_dt_entry (struct desc_struct *dt,int entry,u32 entry_low,u32 entry_high) { - dt[entry].a = entry_low; - dt[entry].b = entry_high; + dt[entry].raw32.a = entry_low; + dt[entry].raw32.b = entry_high; }static inline void native_set_ldt (const void *addr,unsigned int entries)
include/asm-i386/processor.h +6 -8
@@ -22,19 +22,17 @@#include <linux/cpumask.h> #include <linux/init.h> #include <asm/processor-flags.h> +#include <asm-x86_64/desc_defs.h> /* flag for disabling the tsc */ extern int tsc_disable; -struct desc_struct { -unsigned long a,b; -}; -#define desc_empty (desc) \ - (!((desc)->a | (desc)->b)) - -#define desc_equal (desc1, desc2) \ - (((desc1)->a == (desc2)->a) && ((desc1)->b == (desc2)->b)) + (!((desc)->raw32.a | (desc)->raw32.b)) + +#define desc_equal (desc1, desc2) \ + (((desc1)->raw32.a == (desc2)->raw32.a) && \ + ((desc1)->raw32.b == (desc2)->raw32.b))/* * Default implementation of macro that returns current * instruction pointer ("program counter").
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
PATCH 3/3 i386: Replace struct Xgt_desc_struct with struct desc_ptr
Remove i386's Xgt_desc_struct definition and use desc_def.h's desc_ptr.
The offsets in asm-offsets.c do not seem to be used anywhere, so I simply removed them.
arch/i386/kernel/asm-offsets.c +0 -5
@@ -61,11 +61,6 @@ void foo(void)OFFSET (TI_sysenter_return, thread_info, sysenter_return);BLANK (); -OFFSET (GDS_size, Xgt_desc_struct, size); -OFFSET (GDS_address, Xgt_desc_struct, address); -OFFSET (GDS_pad, Xgt_desc_struct, pad); -BLANK (); -OFFSET (PT_EBX , pt_regs, ebx);OFFSET (PT_ECX , pt_regs, ecx);OFFSET (PT_EDX , pt_regs, edx);
arch/i386/kernel/cpu/common.c +1 -1
@@ -642,7 +642,7 @@ struct pt_regs * __devinit idle_regs(str* it's on the real one. */ void switch_to_new_gdt (void ) { -struct Xgt_desc_struct gdt_descr; +struct desc_ptr gdt_descr; gdt_descr.address = (long )get_cpu_gdt_table (smp_processor_id ()); gdt_descr.size =GDT_SIZE -1 ;
arch/i386/kernel/doublefault.c +1 -1
@@ -17,7 +17,7 @@ static unsigned long doublefault_stack[Dstatic void doublefault_fn (void ) { -struct Xgt_desc_struct gdt_desc = {0 ,0 }; +struct desc_ptr gdt_desc = {0 ,0 };unsigned long gdt, tss;store_gdt (&gdt_desc);
arch/i386/kernel/efi.c +2 -2
@@ -69,7 +69,7 @@ static void efi_call_phys_prelog(void) _ {unsigned long cr4;unsigned long temp; -struct Xgt_desc_struct gdt_descr; +struct desc_ptr gdt_descr;spin_lock (&efi_rt_lock);local_irq_save (efi_rt_eflags);
@@ -111,7 +111,7 @@ static void efi_call_phys_epilog(void) _static void efi_call_phys_epilog (void )__releases (efi_rt_lock) {unsigned long cr4; -struct Xgt_desc_struct gdt_descr; +struct desc_ptr gdt_descr; gdt_descr.address = (unsigned long )get_cpu_gdt_table (0 ); gdt_descr.size =GDT_SIZE -1 ;
arch/i386/kernel/machine_kexec.c +2 -2
@@ -31,7 +31,7 @@ static u32 kexec_pte1[1024] PAGE_ALIGNEDstatic void set_idt (void *newidt,__u16 limit) { -struct Xgt_desc_struct curidt; +struct desc_ptr curidt;/* ia32 supports unaliged loads & stores */ curidt.size = limit;
@@ -43,7 +43,7 @@ static void set_idt(void *newidt, __u16static void set_gdt (void *newgdt,__u16 limit) { -struct Xgt_desc_struct curgdt; +struct desc_ptr curgdt;/* ia32 supports unaligned loads & stores */ curgdt.size = limit;
arch/i386/kernel/reboot.c +1 -1
@@ -155,7 +155,7 @@ real_mode_gdt_entries [3] = 0x000092000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */ }; -static struct Xgt_desc_struct +static struct desc_ptr real_mode_gdt = {sizeof (real_mode_gdt_entries) -1 , (long )real_mode_gdt_entries }, real_mode_idt = {0x3ff ,0 }, no_idt = {0 ,0 };
drivers/kvm/svm.c +0 -4
@@ -290,11 +290,7 @@ static void svm_hardware_enable(void *gastruct svm_cpu_data *svm_data;uint64_t efer; -#ifdef CONFIG_X86_64 struct desc_ptr gdt_descr; -#else -struct Xgt_desc_struct gdt_descr; -#endif struct desc_struct *gdt;int me =raw_smp_processor_id ();
include/asm-i386/desc.h +5 -11
@@ -12,12 +12,6 @@#include <asm/mmu.h> -struct Xgt_desc_struct { -unsigned short size; -unsigned long address __attribute__((packed)); -unsigned short pad; -} __attribute__ ((packed)); -struct gdt_page {struct desc_struct gdt[GDT_ENTRIES ];
@@ -29,7 +23,7 @@ static inline struct desc_struct *get_cpreturn per_cpu (gdt_page, cpu).gdt; } -extern struct Xgt_desc_struct idt_descr; +extern struct desc_ptr idt_descr;extern struct desc_struct idt_table[];extern void set_intr_gate (unsigned int irq,void * addr);
@@ -107,22 +101,22 @@ static inline void native_load_tr_desc(v asmvolatile ("ltr %w0" ::"q" (GDT_ENTRY_TSS *8 )); } -static inline void native_load_gdt (const struct Xgt_desc_struct *dtr) +static inline void native_load_gdt (const struct desc_ptr *dtr) { asmvolatile ("lgdt %0" ::"m" (*dtr)); } -static inline void native_load_idt (const struct Xgt_desc_struct *dtr) +static inline void native_load_idt (const struct desc_ptr *dtr) { asmvolatile ("lidt %0" ::"m" (*dtr)); } -static inline void native_store_gdt (struct Xgt_desc_struct *dtr) +static inline void native_store_gdt (struct desc_ptr *dtr) { asm ("sgdt %0" :"=m" (*dtr)); } -static inline void native_store_idt (struct Xgt_desc_struct *dtr) +static inline void native_store_idt (struct desc_ptr *dtr) { asm ("sidt %0" :"=m" (*dtr)); }
include/asm-i386/paravirt.h +9 -9
@@ -20,7 +20,7 @@struct page ;struct thread_struct ; -struct Xgt_desc_struct ; +struct desc_ptr ;struct tss_struct ;struct mm_struct ;struct desc_struct ;
@@ -121,10 +121,10 @@ struct paravirt_ops/* Segment descriptor handling */ void (*load_tr_desc)(void ); -void (*load_gdt)(const struct Xgt_desc_struct *); -void (*load_idt)(const struct Xgt_desc_struct *); -void (*store_gdt)(struct Xgt_desc_struct *); -void (*store_idt)(struct Xgt_desc_struct *); +void (*load_gdt)(const struct desc_ptr *); +void (*load_idt)(const struct desc_ptr *); +void (*store_gdt)(struct desc_ptr *); +void (*store_idt)(struct desc_ptr *);void (*set_ldt)(const void *desc,unsigned entries);unsigned long (*store_tr)(void );void (*load_tls)(struct thread_struct *t,unsigned int cpu);
@@ -583,11 +583,11 @@ static inline void load_TR_desc(void) {PVOP_VCALL0 (load_tr_desc); } -static inline void load_gdt (const struct Xgt_desc_struct *dtr) +static inline void load_gdt (const struct desc_ptr *dtr) {PVOP_VCALL1 (load_gdt, dtr); } -static inline void load_idt (const struct Xgt_desc_struct *dtr) +static inline void load_idt (const struct desc_ptr *dtr) {PVOP_VCALL1 (load_idt, dtr); }
@@ -595,11 +595,11 @@ static inline void set_ldt(const void *a {PVOP_VCALL2 (set_ldt, addr, entries); } -static inline void store_gdt (struct Xgt_desc_struct *dtr) +static inline void store_gdt (struct desc_ptr *dtr) {PVOP_VCALL1 (store_gdt, dtr); } -static inline void store_idt (struct Xgt_desc_struct *dtr) +static inline void store_idt (struct desc_ptr *dtr) {PVOP_VCALL1 (store_idt, dtr); }
include/asm-i386/processor.h +1 -1
@@ -748,7 +748,7 @@ extern int sysenter_setup(void);extern int sysenter_setup (void );/* Defined in head.S */ -extern struct Xgt_desc_struct early_gdt_descr; +extern struct desc_ptr early_gdt_descr;extern void cpu_set_gdt (int );extern void switch_to_new_gdt (void );
include/asm-i386/suspend.h +2 -2
@@ -12,8 +12,8 @@ struct saved_context {struct saved_context {u16 es, fs, gs, ss;unsigned long cr0, cr2, cr3, cr4; -struct Xgt_desc_struct gdt; -struct Xgt_desc_struct idt; +struct desc_ptr gdt; +struct desc_ptr idt;u16 ldt;u16 tss;unsigned long tr;
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Re: [PATCH 3/3] i386: Replace struct Xgt_desc_struct with struct desc_ptr
Quoted 1 line · * Rusty Russell (rusty-8n+1lVoiYb80n/[email protected]) wrote:
Remove i386's
Xgt_desc_structdefinition and use desc_def.h'sdesc_ptr.
plus this is needed now
drivers/lguest/lg.h +4 -4
@@ -91,13 +91,13 @@ struct lguest_ro_state {/* Host information we need to restore when we switch back. */ u32 host_cr3; -struct Xgt_desc_struct host_idt_desc; -struct Xgt_desc_struct host_gdt_desc; +struct desc_ptr host_idt_desc; +struct desc_ptr host_gdt_desc;u32 host_sp;/* Fields which are used when guest is running. */ -struct Xgt_desc_struct guest_idt_desc; -struct Xgt_desc_struct guest_gdt_desc; +struct desc_ptr guest_idt_desc; +struct desc_ptr guest_gdt_desc;struct i386_hw_tss guest_tss;struct desc_struct guest_idt[IDT_ENTRIES ];struct desc_struct guest_gdt[GDT_ENTRIES ];
arch/i386/xen/enlighten.c +5 -5
@@ -301,7 +301,7 @@ static void xen_set_ldt(const void *addrxen_mc_issue (PARAVIRT_LAZY_CPU ); } -static void xen_load_gdt (const struct Xgt_desc_struct *dtr) +static void xen_load_gdt (const struct desc_ptr *dtr) {unsigned long *frames;unsigned long va = dtr->address;
@@ -401,7 +401,7 @@ static int cvt_gate_to_trap(int vector, }/* Locations of each CPU's IDT */ -static DEFINE_PER_CPU(struct Xgt_desc_struct, idt_desc); +static DEFINE_PER_CPU(struct desc_ptr, idt_desc);/* Set an IDT entry. If the entry is part of the current IDT, then also update Xen. */
@@ -433,7 +433,7 @@ static void xen_write_idt_entry(struct dpreempt_enable (); } -static void xen_convert_trap_info (const struct Xgt_desc_struct *desc, +static void xen_convert_trap_info (const struct desc_ptr *desc,struct trap_info *traps) {unsigned in, out, count;
@@ -452,7 +452,7 @@ static void xen_convert_trap_info(constvoid xen_copy_trap_info (struct trap_info *traps) { -const struct Xgt_desc_struct *desc = &__get_cpu_var (idt_desc); +const struct desc_ptr *desc = &__get_cpu_var (idt_desc);xen_convert_trap_info (desc, traps); }
@@ -460,7 +460,7 @@ void xen_copy_trap_info(struct trap_info/* Load a new IDT into Xen. In principle this can be per-CPU, so we hold a spinlock to protect the static traps[] array (static because it avoids allocation, and saves stack space). */ -static void xen_load_idt (const struct Xgt_desc_struct *desc) +static void xen_load_idt (const struct desc_ptr *desc) {static DEFINE_SPINLOCK (lock);static struct trap_info traps[257 ];
drivers/lguest/lguest.c +2 -2
@@ -167,7 +167,7 @@ static void lguest_write_idt_entry(struchcall (LHCALL_LOAD_IDT_ENTRY , entrynum, low, high); } -static void lguest_load_idt (const struct Xgt_desc_struct *desc) +static void lguest_load_idt (const struct desc_ptr *desc) {unsigned int i;struct desc_struct *idt = (void *)desc->address;
@@ -176,7 +176,7 @@ static void lguest_load_idt(const structhcall (LHCALL_LOAD_IDT_ENTRY , i, idt[i].raw32.a, idt[i].raw32.b); } -static void lguest_load_gdt (const struct Xgt_desc_struct *desc) +static void lguest_load_gdt (const struct desc_ptr *desc) {BUG_ON ((desc->size+1 )/8 !=GDT_ENTRIES );hcall (LHCALL_LOAD_GDT ,__pa (desc->address),GDT_ENTRIES ,0 );
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [PATCH 2/3] i386: use x86_64's desc_def.h
In reply to Rusty RussellQuoted 3 lines · Rusty Russell
The main effect is to change the definition of "struct
desc_struct" to a union of more complex types.
Yay! Someone finally killed it. Every time I tried to kill it, I ended up off in the weeds chasing some bug.
Quoted 40 lines
diff -r
656f3ff2c9cearch/i386/kernel/process.carch/i386/kernel/process.c +2
-15@@ -880,21 +880,8 @@ asmlinkage int sys_set_thread_area(struc* Get the current Thread-Local Storage area: */ -#define GET_BASE (desc) ( \ - (((desc)->a >> 16) & 0x0000ffff) | \ - (((desc)->b << 16) & 0x00ff0000) | \ - ( (desc)->b & 0xff000000) ) - -#define GET_LIMIT (desc) ( \ - ((desc)->a & 0x0ffff) | \ - ((desc)->b & 0xf0000) ) - -#define GET_32BIT (desc) (((desc)->b >> 22) & 1) -#define GET_CONTENTS (desc) (((desc)->b >> 10) & 3) -#define GET_WRITABLE (desc) (((desc)->b >> 9) & 1) -#define GET_LIMIT_PAGES (desc) (((desc)->b >> 23) & 1) -#define GET_PRESENT (desc) (((desc)->b >> 15) & 1) -#define GET_USEABLE (desc) (((desc)->b >> 20) & 1) +#define GET_CONTENTS (desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE (desc) (((desc)->raw32.b >> 9) & 1)diff -r
656f3ff2c9cearch/i386/kernel/ptrace.carch/i386/kernel/ptrace.c +0
-9@@ -283,22 +283,8 @@ ptrace_get_thread_area(struct task_struc/* * Get the current Thread-Local Storage area: */ - -#define GET_BASE (desc) ( \ - (((desc)->a >> 16) & 0x0000ffff) | \ - (((desc)->b << 16) & 0x00ff0000) | \ - ( (desc)->b & 0xff000000) ) - -#define GET_LIMIT (desc) ( \ - ((desc)->a & 0x0ffff) | \ - ((desc)->b & 0xf0000) )
arch/i386/kernel/ptrace.c ptrace_get_thread_area(struct task_struc · line 288
Quoted 10 lines
arch/i386/kernel/ptrace.c +2
-7- -#define GET_32BIT (desc) (((desc)->b >> 22) & 1) -#define GET_CONTENTS (desc) (((desc)->b >> 10) & 3) -#define GET_WRITABLE (desc) (((desc)->b >> 9) & 1) -#define GET_LIMIT_PAGES (desc) (((desc)->b >> 23) & 1) -#define GET_PRESENT (desc) (((desc)->b >> 15) & 1) -#define GET_USEABLE (desc) (((desc)->b >> 20) & 1) +#define GET_CONTENTS (desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE (desc) (((desc)->raw32.b >> 9) & 1)
You got rid of the duplicate definitions here, but then added new duplicates (GET_CONTENTS / WRITABLE). Can you stick them in desc.h?
Zach
Re: [PATCH 2/3] i386: use x86_64's desc_def.h
Quoted 5 lines · Zachary Amsden
Review
Quoted 2 lines
(quoted diff) +2
-0+#define GET_CONTENTS(desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE(desc) (((desc)->raw32.b >> 9) & 1)You got rid of the duplicate definitions here, but then added new duplicates (
GET_CONTENTS/ WRITABLE). Can you stick them indesc.h?
To be honest, I got sick of counting bits at this point, and didn't want to introduce bugs.
Here's the updated version of PATCH 1/3:
===
Standardize x86_64's desc_defs.h in preparation for exposure to i386.
KVM has independent definitions of these structures, which is bad. However, the currently (i386-derived) x86-64 ones are suboptimal. The first step is to clean them up, especially by making desc_struct a union.
Additional changes:
1) s/ldttss_desc/ldttss_desc_64/ to clearly indicate it's x86-64 only.
2) Changed the type of the tls_array in struct thread_struct:
there seems little point to all these casts.
3) s/gate_struct/gate_struct_64/ to differentiate from new gate_struct_32.
4) New base/limit extraction convenience functions in desc_defs.h.
arch/x86_64/ia32/tls32.c +21 -40
@@ -19,7 +19,7 @@ static int get_free_idx(void)int idx;for (idx =0 ; idx <GDT_ENTRY_TLS_ENTRIES ; idx++) -if (desc_empty ((struct n_desc_struct *)(t->tls_array) + idx)) +if (desc_empty (t->tls_array + idx))return idx +GDT_ENTRY_TLS_MIN ;return -ESRCH ; }
@@ -31,7 +31,7 @@ int do_set_thread_area(struct thread_strint do_set_thread_area (struct thread_struct *t,struct user_desc __user *u_info) {struct user_desc info; -struct n_desc_struct *desc; +struct desc_struct *desc;int cpu, idx;if (copy_from_user (&info, u_info,sizeof (info)))
@@ -54,7 +54,7 @@ int do_set_thread_area(struct thread_strif (idx <GDT_ENTRY_TLS_MIN || idx >GDT_ENTRY_TLS_MAX )return -EINVAL ; - desc = ((struct n_desc_struct *)t->tls_array) + idx -GDT_ENTRY_TLS_MIN ; + desc = t->tls_array + idx -GDT_ENTRY_TLS_MIN ;/* * We must not get preempted while modifying the TLS.
@@ -62,11 +62,10 @@ int do_set_thread_area(struct thread_str cpu =get_cpu ();if (LDT_empty (&info)) { - desc->a =0 ; - desc->b =0 ; + desc->raw =0 ; }else { - desc->a =LDT_entry_a (&info); - desc->b =LDT_entry_b (&info); + desc->raw32.a =LDT_entry_a (&info); + desc->raw32.b =LDT_entry_b (&info); }if (t == ¤t->thread)load_TLS (t, cpu);
@@ -84,28 +83,10 @@ asmlinkage long sys32_set_thread_area(st/* * Get the current Thread-Local Storage area: */ - -#define GET_BASE (desc) ( \ - (((desc)->a >> 16) & 0x0000ffff) | \ - (((desc)->b << 16) & 0x00ff0000) | \ - ( (desc)->b & 0xff000000) ) - -#define GET_LIMIT (desc) ( \ - ((desc)->a & 0x0ffff) | \ - ((desc)->b & 0xf0000) ) - -#define GET_32BIT (desc) (((desc)->b >> 22) & 1) -#define GET_CONTENTS (desc) (((desc)->b >> 10) & 3) -#define GET_WRITABLE (desc) (((desc)->b >> 9) & 1) -#define GET_LIMIT_PAGES (desc) (((desc)->b >> 23) & 1) -#define GET_PRESENT (desc) (((desc)->b >> 15) & 1) -#define GET_USEABLE (desc) (((desc)->b >> 20) & 1) -#define GET_LONGMODE (desc) (((desc)->b >> 21) & 1) -int do_get_thread_area (struct thread_struct *t,struct user_desc __user *u_info) {struct user_desc info; -struct n_desc_struct *desc; +struct desc_struct *desc;int idx;if (get_user (idx, &u_info->entry_number))
@@ -113,19 +94,19 @@ int do_get_thread_area(struct thread_strif (idx <GDT_ENTRY_TLS_MIN || idx >GDT_ENTRY_TLS_MAX )return -EINVAL ; - desc = ((struct n_desc_struct *)t->tls_array) + idx -GDT_ENTRY_TLS_MIN ; + desc = t->tls_array + idx -GDT_ENTRY_TLS_MIN ;memset (&info,0 ,sizeof (struct user_desc )); info.entry_number = idx; - info.base_addr =GET_BASE (desc); - info.limit =GET_LIMIT (desc); - info.seg_32bit =GET_32BIT (desc); - info.contents =GET_CONTENTS (desc); - info.read_exec_only = !GET_WRITABLE (desc); - info.limit_in_pages =GET_LIMIT_PAGES (desc); - info.seg_not_present = !GET_PRESENT (desc); - info.useable =GET_USEABLE (desc); - info.lm =GET_LONGMODE (desc); + info.base_addr =get_seg_desc_base (&desc->seg); + info.limit =get_seg_desc_limit (&desc->seg); + info.seg_32bit = desc->seg.d; + info.contents =get_seg_desc_contents (&desc->seg); + info.read_exec_only = !get_seg_desc_writable (&desc->seg); + info.limit_in_pages = desc->seg.g; + info.seg_not_present = !desc->seg.p; + info.useable = desc->seg.avl; + info.lm = desc->seg.l;if (copy_to_user (u_info, &info,sizeof (info)))return -EFAULT ;
@@ -140,7 +121,7 @@ asmlinkage long sys32_get_thread_area(stint ia32_child_tls (struct task_struct *p,struct pt_regs *childregs) { -struct n_desc_struct *desc; +struct desc_struct *desc;struct user_desc info;struct user_desc __user *cp;int idx;
@@ -155,9 +136,9 @@ int ia32_child_tls(struct task_struct *pif (idx <GDT_ENTRY_TLS_MIN || idx >GDT_ENTRY_TLS_MAX )return -EINVAL ; - desc = (struct n_desc_struct *)(p->thread.tls_array) + idx -GDT_ENTRY_TLS_MIN ; - desc->a =LDT_entry_a (&info); - desc->b =LDT_entry_b (&info); + desc = p->thread.tls_array + idx -GDT_ENTRY_TLS_MIN ; + desc->raw32.a =LDT_entry_a (&info); + desc->raw32.b =LDT_entry_b (&info);return 0 ; }
arch/x86_64/kernel/process.c +3 -9
@@ -432,19 +432,13 @@ static inline void set_32bit_tls(struct .limit_in_pages = 1, .useable = 1, }; -struct n_desc_struct *desc = (void *)t->thread.tls_array; - desc += tls; - desc->a =LDT_entry_a (&ud); - desc->b =LDT_entry_b (&ud); + t->thread.tls_array[tls].raw32.a =LDT_entry_a (&ud); + t->thread.tls_array[tls].raw32.b =LDT_entry_b (&ud); }static inline u32 read_32bit_tls (struct task_struct *t,int tls) { -struct desc_struct *desc = (void *)t->thread.tls_array; - desc += tls; -return desc->base0 | - (((u32 )desc->base1) <<16 ) | - (((u32 )desc->base2) <<24 ); +return get_seg_desc_base (&t->thread.tls_array[tls].seg); }/*
arch/x86_64/kernel/suspend.c +1 -1
@@ -125,7 +125,7 @@ void fix_processor_context(void)set_tss_desc (cpu,t);/* This just modifies memory; should not be neccessary. But... This is neccessary, because 386 hardware has concept of busy TSS or some similar stupidity. */ -cpu_gdt (cpu)[GDT_ENTRY_TSS ].type =9 ; +cpu_gdt (cpu)[GDT_ENTRY_TSS ].seg.type =DESC_TSS ;syscall_init ();/* This sets MSR_*STAR and related */ load_TR_desc ();/* This does ltr */
include/asm-x86_64/desc.h +4 -4
@@ -25,7 +25,7 @@ extern struct desc_struct cpu_gdt_table[* something other than this. */ extern struct desc_struct default_ldt[]; -extern struct gate_struct idt_table[]; +extern struct gate_struct_64 idt_table[];extern struct desc_ptr cpu_gdt_descr[];/* the cpu gdt accessor */
@@ -33,7 +33,7 @@ extern struct desc_ptr cpu_gdt_descr[];static inline void _set_gate (void *adr,unsigned type,unsigned long func,unsigned dpl,unsigned ist) { -struct gate_struct s; +struct gate_struct_64 s; s.offset_low =PTR_LOW (func); s.segment = __KERNEL_CS; s.ist = ist;
@@ -74,7 +74,7 @@ static inline void set_tssldt_descriptorstatic inline void set_tssldt_descriptor (void *ptr,unsigned long tss,unsigned type,unsigned size) { -struct ldttss_desc d; +struct ldttss_desc_64 d;memset (&d,0 ,sizeof (d)); d.limit0 = size &0xFFFF ; d.base0 =PTR_LOW (tss);
@@ -138,7 +138,7 @@ static inline void load_TLS(struct threastatic inline void load_TLS (struct thread_struct *t,unsigned int cpu) {unsigned int i; -u64 *gdt = (u64 *)(cpu_gdt (cpu) +GDT_ENTRY_TLS_MIN ); +struct desc_struct *gdt =cpu_gdt (cpu) +GDT_ENTRY_TLS_MIN ;for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) gdt[i] = t->tls_array[i];
include/asm-x86_64/desc_defs.h +45 -8
84 lines not on this page · raw message
include/asm-x86_64/processor.h +12 -6
@@ -21,6 +21,7 @@#include <linux/personality.h> #include <linux/cpumask.h> #include <asm/processor-flags.h> +#include <asm/desc_defs.h> #define TF_MASK 0x00000100#define IF_MASK 0x00000200
@@ -32,11 +33,16 @@#define VIP_MASK 0x00100000/* virtual interrupt pending */ #define ID_MASK 0x00200000 -#define desc_empty (desc) \ - (!((desc)->a | (desc)->b)) - -#define desc_equal (desc1, desc2) \ - (((desc1)->a == (desc2)->a) && ((desc1)->b == (desc2)->b)) +static inline bool desc_empty (const struct desc_struct *desc) +{ +return !desc->raw; +} + +static inline bool desc_equal (const struct desc_struct *d1, +const struct desc_struct *d2) +{ +return d1->raw == d2->raw; +}/* * Default implementation of macro that returns current
@@ -238,7 +244,7 @@ struct thread_struct {unsigned long *io_bitmap_ptr;unsigned io_bitmap_max;/* cached TLS descriptors. */ -u64 tls_array[GDT_ENTRY_TLS_ENTRIES ]; +struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES ]; } __attribute__((aligned(16)));#define INIT_THREAD { \
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Re: [PATCH 2/3] i386: use x86_64's desc_def.h
Quoted 11 lines · Rusty Russell
Quoted 5 lines · Zachary Amsden
Review
Quoted 2 lines
(quoted diff) +2
-0+#define GET_CONTENTS(desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE(desc) (((desc)->raw32.b >> 9) & 1)You got rid of the duplicate definitions here, but then added new duplicates (
GET_CONTENTS/ WRITABLE). Can you stick them indesc.h?To be honest, I got sick of counting bits at this point, and didn't want to introduce bugs.
Here's the updated version of PATCH 1/3:
And 2/3:
===
i386: use x86_64's desc_def.h
The main effect is to change the definition of "struct desc_struct" to a union of more complex types.
I kept the old 32-bit comparisons, but many could be changed to use the 64-bit "desc->raw".
arch/i386/kernel/cpu/common.c +15 -15
@@ -22,31 +22,31 @@#include "cpu.h" DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = { - [GDT_ENTRY_KERNEL_CS ] = {0x0000ffff ,0x00cf9a00 }, - [GDT_ENTRY_KERNEL_DS ] = {0x0000ffff ,0x00cf9200 }, - [GDT_ENTRY_DEFAULT_USER_CS ] = {0x0000ffff ,0x00cffa00 }, - [GDT_ENTRY_DEFAULT_USER_DS ] = {0x0000ffff ,0x00cff200 }, + [GDT_ENTRY_KERNEL_CS ] = { {0x00cf9a000000ffffULL } }, + [GDT_ENTRY_KERNEL_DS ] = { {0x00cf92000000ffffULL } }, + [GDT_ENTRY_DEFAULT_USER_CS ] = { {0x00cffa000000ffffULL } }, + [GDT_ENTRY_DEFAULT_USER_DS ] = { {0x00cff2000000ffffULL } },/* * Segments used for calling PnP BIOS have byte granularity. * They code segments and data segments have fixed 64k limits, * the transfer segment sizes are set at run time. */ - [GDT_ENTRY_PNPBIOS_CS32 ] = {0x0000ffff ,0x00409a00 },/* 32-bit code */ - [GDT_ENTRY_PNPBIOS_CS16 ] = {0x0000ffff ,0x00009a00 },/* 16-bit code */ - [GDT_ENTRY_PNPBIOS_DS ] = {0x0000ffff ,0x00009200 },/* 16-bit data */ - [GDT_ENTRY_PNPBIOS_TS1 ] = {0x00000000 ,0x00009200 },/* 16-bit data */ - [GDT_ENTRY_PNPBIOS_TS2 ] = {0x00000000 ,0x00009200 },/* 16-bit data */ + [GDT_ENTRY_PNPBIOS_CS32 ] = { {0x00409a000000ffffULL } },/* 32-bit code */ + [GDT_ENTRY_PNPBIOS_CS16 ] = { {0x00009a000000ffffULL } },/* 16-bit code */ + [GDT_ENTRY_PNPBIOS_DS ] = { {0x000092000000ffffULL } },/* 16-bit data */ + [GDT_ENTRY_PNPBIOS_TS1 ] = { {0x0000920000000000ULL } },/* 16-bit data */ + [GDT_ENTRY_PNPBIOS_TS2 ] = { {0x0000920000000000ULL } },/* 16-bit data */ /* * The APM segments have byte granularity and their bases * are set at run time. All have 64k limits. */ - [GDT_ENTRY_APMBIOS_BASE ] = {0x0000ffff ,0x00409a00 },/* 32-bit code */ + [GDT_ENTRY_APMBIOS_BASE ] = { {0x00409a000000ffffULL } },/* 32-bit code */ /* 16-bit code */ - [GDT_ENTRY_APMBIOS_BASE +1 ] = {0x0000ffff ,0x00009a00 }, - [GDT_ENTRY_APMBIOS_BASE +2 ] = {0x0000ffff ,0x00409200 },/* data */ - - [GDT_ENTRY_ESPFIX_SS ] = {0x00000000 ,0x00c09200 }, - [GDT_ENTRY_PERCPU ] = {0x00000000 ,0x00000000 }, + [GDT_ENTRY_APMBIOS_BASE +1 ] = { {0x00009a000000ffffULL } }, + [GDT_ENTRY_APMBIOS_BASE +2 ] = { {0x004092000000ffffULL } },/* data */ + + [GDT_ENTRY_ESPFIX_SS ] = { {0x00c0920000000000ULL } }, + [GDT_ENTRY_PERCPU ] = { {0x0000000000000000ULL } }, } };EXPORT_PER_CPU_SYMBOL_GPL (gdt_page);
arch/i386/kernel/process.c +14 -31
70 lines not on this page · raw message
arch/i386/kernel/ptrace.c +12 -29
60 lines not on this page · raw message
arch/i386/kernel/smpcommon.c +2 -2
@@ -14,8 +14,8 @@ __cpuinit void init_gdt(int cpu) {struct desc_struct *gdt =get_cpu_gdt_table (cpu); -pack_descriptor ((u32 *)&gdt[GDT_ENTRY_PERCPU ].a, - (u32 *)&gdt[GDT_ENTRY_PERCPU ].b, +pack_descriptor (&gdt[GDT_ENTRY_PERCPU ].raw32.a, + &gdt[GDT_ENTRY_PERCPU ].raw32.b, __per_cpu_offset[cpu],0xFFFFF ,0x80 |DESCTYPE_S |0x2 ,0x8 );
arch/i386/kernel/traps.c +1 -1
@@ -71,7 +71,7 @@ char ignore_fpu_irq = 0;* F0 0F bug workaround.. We have a special link segment * for this. */ -struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, }; +struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))); asmlinkage void divide_error(void); asmlinkage void debug(void);
arch/i386/kernel/vmi.c +2 -2
@@ -178,8 +178,8 @@ static void vmi_cpuid(unsigned int *eax,static inline void vmi_maybe_load_tls (struct desc_struct *gdt,int nr,struct desc_struct *new) { -if (gdt[nr].a != new->a || gdt[nr].b != new->b) -write_gdt_entry (gdt, nr, new->a, new->b); +if (gdt[nr].raw32.a != new->raw32.a || gdt[nr].raw32.b != new->raw32.b) +write_gdt_entry (gdt, nr, new->raw32.a, new->raw32.b); }static void vmi_load_tls (struct thread_struct *t,unsigned int cpu)
include/asm-i386/desc.h +2 -2
@@ -81,8 +81,8 @@ static inline void write_dt_entry(structstatic inline void write_dt_entry (struct desc_struct *dt,int entry,u32 entry_low,u32 entry_high) { - dt[entry].a = entry_low; - dt[entry].b = entry_high; + dt[entry].raw32.a = entry_low; + dt[entry].raw32.b = entry_high; }static inline void native_set_ldt (const void *addr,unsigned int entries)
include/asm-i386/processor.h +6 -8
@@ -22,19 +22,17 @@#include <linux/cpumask.h> #include <linux/init.h> #include <asm/processor-flags.h> +#include <asm-x86_64/desc_defs.h> /* flag for disabling the tsc */ extern int tsc_disable; -struct desc_struct { -unsigned long a,b; -}; -#define desc_empty (desc) \ - (!((desc)->a | (desc)->b)) - -#define desc_equal (desc1, desc2) \ - (((desc1)->a == (desc2)->a) && ((desc1)->b == (desc2)->b)) + (!((desc)->raw32.a | (desc)->raw32.b)) + +#define desc_equal (desc1, desc2) \ + (((desc1)->raw32.a == (desc2)->raw32.a) && \ + ((desc1)->raw32.b == (desc2)->raw32.b))/* * Default implementation of macro that returns current * instruction pointer ("program counter").
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Re: [PATCH 2/3] i386: use x86_64's desc_def.h
Quoted 8 lines · * Rusty Russell (rusty-8n+1lVoiYb80n/[email protected]) wrote:
Quoted 7 lines · Rusty Russell
Quoted 5 lines · Zachary Amsden
Review
Quoted 2 lines
(quoted diff) +2
-0+#define GET_CONTENTS(desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE(desc) (((desc)->raw32.b >> 9) & 1)You got rid of the duplicate definitions here, but then added new duplicates (
GET_CONTENTS/ WRITABLE). Can you stick them indesc.h?
Quoted 8 lines
Quoted 4 lines
To be honest, I got sick of counting bits at this point, and didn't want to introduce bugs.
Here's the updated version of PATCH 1/3:
And 2/3:
===
i386: use x86_64'sdesc_def.h
plus this needed as well now
include/asm-i386/xen/hypercall.h +2 -2
@@ -359,8 +359,8 @@ MULTI_update_descriptor(struct multicall mcl->op = __HYPERVISOR_update_descriptor; mcl->args[0 ] = maddr; mcl->args[1 ] = maddr >>32 ; - mcl->args[2 ] = desc.a; - mcl->args[3 ] = desc.b; + mcl->args[2 ] = desc.raw32.a; + mcl->args[3 ] = desc.raw32.b; } static inline void
drivers/lguest/interrupts_and_traps.c +9 -9
@@ -103,9 +103,9 @@ void maybe_do_interrupt(struct lguest *l } idt = &lg->idt[FIRST_EXTERNAL_VECTOR +irq]; -if (idt_present (idt->a, idt->b)) { +if (idt_present (idt->raw32.a, idt->raw32.b)) {clear_bit (irq, lg->irqs_pending); -set_guest_interrupt (lg, idt->a, idt->b,0 ); +set_guest_interrupt (lg, idt->raw32.a, idt->raw32.b,0 ); } }
@@ -116,7 +116,7 @@ static int has_err(unsigned int trap)int deliver_trap (struct lguest *lg,unsigned int num) { -u32 lo = lg->idt[num].a, hi = lg->idt[num].b; +u32 lo = lg->idt[num].raw32.a, hi = lg->idt[num].raw32.b;if (!idt_present (lo, hi))return 0 ;
@@ -139,7 +139,7 @@ static int direct_trap(const struct lguereturn 0 ;/* Interrupt gates (0xE) or not present (0x0) can't go direct. */ -return idt_type (trap->a, trap->b) ==0xF ; +return idt_type (trap->raw32.a, trap->raw32.b) ==0xF ; }void pin_stack_pages (struct lguest *lg)
@@ -170,15 +170,15 @@ static void set_trap(struct lguest *lg,u8 type =idt_type (lo, hi);if (!idt_present (lo, hi)) { - trap->a = trap->b =0 ; + trap->raw32.a = trap->raw32.b =0 ;return ; }if (type !=0xE && type !=0xF )kill_guest (lg,"bad IDT type %i" , type); - trap->a = ((__KERNEL_CS|GUEST_PL )<<16 ) | (lo&0x0000FFFF ); - trap->b = (hi&0xFFFFEF00 ); + trap->raw32.a = ((__KERNEL_CS|GUEST_PL )<<16 ) | (lo&0x0000FFFF ); + trap->raw32.b = (hi&0xFFFFEF00 ); }void load_guest_idt_entry (struct lguest *lg,unsigned int num,u32 lo,u32 hi)
@@ -204,8 +204,8 @@ static void default_idt_entry(struct desif (trap ==LGUEST_TRAP_ENTRY ) flags |= (GUEST_PL <<13 ); - idt->a = (LGUEST_CS <<16 ) | (handler&0x0000FFFF ); - idt->b = (handler&0xFFFF0000 ) | flags; + idt->raw32.a = (LGUEST_CS <<16 ) | (handler&0x0000FFFF ); + idt->raw32.b = (handler&0xFFFF0000 ) | flags; } void setup_default_idt_entries(struct lguest_ro_state *state,
drivers/lguest/lg.h +2 -2
@@ -44,8 +44,8 @@ void free_pagetables(void);int init_pagetables (struct page **switcher_page,unsigned int pages);/* Full 4G segment descriptors, suitable for CS and DS. */ -#define FULL_EXEC_SEGMENT ((struct desc_struct){0x0000ffff, 0x00cf9b00}) -#define FULL_SEGMENT ((struct desc_struct){0x0000ffff, 0x00cf9300}) +#define FULL_EXEC_SEGMENT ((struct desc_struct){ {0x00cf9b000000ffffULL} }) +#define FULL_SEGMENT ((struct desc_struct){ {0x00cf93000000ffffULL} })struct lguest_dma_info {
drivers/lguest/lguest.c +1 -1
@@ -173,7 +173,7 @@ static void lguest_load_idt(const structstruct desc_struct *idt = (void *)desc->address;for (i =0 ; i < (desc->size+1 )/8 ; i++) -hcall (LHCALL_LOAD_IDT_ENTRY , i, idt[i].a, idt[i].b); +hcall (LHCALL_LOAD_IDT_ENTRY , i, idt[i].raw32.a, idt[i].raw32.b); }static void lguest_load_gdt (const struct Xgt_desc_struct *desc)
drivers/lguest/segments.c +9 -9
@@ -3,12 +3,12 @@static int desc_ok (const struct desc_struct *gdt) {/* MBZ=0, P=1, DT=1 */ -return ((gdt->b &0x00209000 ) ==0x00009000 ); +return ((gdt->raw32.b &0x00209000 ) ==0x00009000 ); }static int segment_present (const struct desc_struct *gdt) { -return gdt->b &0x8000 ; +return gdt->raw32.b &0x8000 ; }static int ignored_gdt (unsigned int num)
@@ -54,11 +54,11 @@ static void fixup_gdt_table(struct lgueskill_guest (lg,"Bad GDT descriptor %i" , i);/* DPL 0 presumably means "for use by guest". */ -if ((lg->gdt[i].b &0x00006000 ) ==0 ) - lg->gdt[i].b |= (GUEST_PL <<13 ); +if ((lg->gdt[i].raw32.b &0x00006000 ) ==0 ) + lg->gdt[i].raw32.b |= (GUEST_PL <<13 );/* Set accessed bit, since gdt isn't writable. */ - lg->gdt[i].b |=0x00000100 ; + lg->gdt[i].raw32.b |=0x00000100 ; } }
@@ -73,8 +73,8 @@ void setup_default_gdt_entries(struct lg/* This is the one which we *cannot* copy from guest, since tss is depended on this lguest_ro_state, ie. this cpu. */ - gdt[GDT_ENTRY_TSS ].a =0x00000067 | (tss <<16 ); - gdt[GDT_ENTRY_TSS ].b =0x00008900 | (tss &0xFF000000 ) + gdt[GDT_ENTRY_TSS ].raw32.a =0x00000067 | (tss <<16 ); + gdt[GDT_ENTRY_TSS ].raw32.b =0x00008900 | (tss &0xFF000000 ) | ((tss >>16 ) &0x000000FF ); }
@@ -82,8 +82,8 @@ void setup_guest_gdt(struct lguest *lg) { lg->gdt[GDT_ENTRY_KERNEL_CS ] =FULL_EXEC_SEGMENT ; lg->gdt[GDT_ENTRY_KERNEL_DS ] =FULL_SEGMENT ; - lg->gdt[GDT_ENTRY_KERNEL_CS ].b |= (GUEST_PL <<13 ); - lg->gdt[GDT_ENTRY_KERNEL_DS ].b |= (GUEST_PL <<13 ); + lg->gdt[GDT_ENTRY_KERNEL_CS ].raw32.b |= (GUEST_PL <<13 ); + lg->gdt[GDT_ENTRY_KERNEL_DS ].raw32.b |= (GUEST_PL <<13 ); }/* This is a fast version for the common case where only the three TLS entries
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Re: [PATCH 2/3] i386: use x86_64's desc_def.h
In reply to Rusty RussellQuoted 9 lines · Rusty Russell
Quoted 5 lines · Zachary Amsden
Review
Quoted 2 lines
(quoted diff) +2
-0+#define GET_CONTENTS(desc) (((desc)->raw32.b >> 10) & 3) +#define GET_WRITABLE(desc) (((desc)->raw32.b >> 9) & 1)You got rid of the duplicate definitions here, but then added new duplicates (
GET_CONTENTS/ WRITABLE). Can you stick them indesc.h?To be honest, I got sick of counting bits at this point, and didn't want to introduce bugs.
Where is 1/ and 3/ ?
I got an older version of this patch queued now
-Andi
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Quoted 1 line · Rusty Russell
However, the currently (i386-derived) x86-64 ones are suboptimal. The
In what way are they suboptimal?
They seem to work just fine.
-Andi
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Quoted 4 lines · Andi Kleen
Quoted 1 line · Rusty Russell
However, the currently (i386-derived) x86-64 ones are suboptimal. The
In what way are they suboptimal?
This was badly worded. They're "suboptimal" for use by i386 (ie. they clash with the i386 declaration and they'd need lots of casts to convert the code).
Of course, treating them as 2 32-bit values on x86-64 *is* suboptimal, and this patch helps that, but that wasn't what I was talking about.
Quoted 1 line
They seem to work just fine.
Yep. But my first attempt was to simply #include
<asm-x86_64/desc_defs.h> from asm-i386, and that doesn't work fine 8(
Thanks,
Rusty.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/