linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386.
@ 2007-07-18  7:22 Rusty Russell
  2007-07-18  7:23 ` [PATCH 2/3] i386: use x86_64's desc_def.h Rusty Russell
  2007-07-18  9:03 ` [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386 Andi Kleen
  0 siblings, 2 replies; 11+ messages in thread
From: Rusty Russell @ 2007-07-18  7:22 UTC (permalink / raw)
  To: lkml - Kernel Mailing List; +Cc: Andi Kleen, kvm-devel, Andrew Morton

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.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r ef94811a10d5 arch/x86_64/ia32/tls32.c
--- a/arch/x86_64/ia32/tls32.c	Wed Jul 18 14:46:15 2007 +1000
+++ b/arch/x86_64/ia32/tls32.c	Wed Jul 18 15:59:01 2007 +1000
@@ -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_str
 int 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_str
 	if (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 == &current->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_str
 	if (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(st
 
 int 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 *p
 	if (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;
 }
diff -r ef94811a10d5 arch/x86_64/kernel/process.c
--- a/arch/x86_64/kernel/process.c	Wed Jul 18 14:46:15 2007 +1000
+++ b/arch/x86_64/kernel/process.c	Wed Jul 18 15:59:01 2007 +1000
@@ -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);
 }
 
 /*
diff -r ef94811a10d5 arch/x86_64/kernel/suspend.c
--- a/arch/x86_64/kernel/suspend.c	Wed Jul 18 14:46:15 2007 +1000
+++ b/arch/x86_64/kernel/suspend.c	Wed Jul 18 15:59:01 2007 +1000
@@ -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 */
diff -r ef94811a10d5 include/asm-x86_64/desc.h
--- a/include/asm-x86_64/desc.h	Wed Jul 18 14:46:15 2007 +1000
+++ b/include/asm-x86_64/desc.h	Wed Jul 18 15:59:01 2007 +1000
@@ -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_descriptor
 static 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 threa
 static 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];
diff -r ef94811a10d5 include/asm-x86_64/desc_defs.h
--- a/include/asm-x86_64/desc_defs.h	Wed Jul 18 14:46:15 2007 +1000
+++ b/include/asm-x86_64/desc_defs.h	Wed Jul 18 16:20:57 2007 +1000
@@ -11,16 +11,43 @@
 
 #include <linux/types.h>
 
-// 8 byte segment descriptor
-struct desc_struct {
+// 8 byte segment descriptor (GDT/LDT)
+struct segment_desc {
 	u16 limit0;
 	u16 base0;
 	unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1;
 	unsigned limit : 4, avl : 1, l : 1, d : 1, g : 1, base2 : 8;
 } __attribute__((packed));
 
-struct n_desc_struct {
+static inline u32 get_seg_desc_base(const struct segment_desc *seg)
+{
+	return seg->base0 | ((u32)seg->base1 << 16) | ((u32)seg->base2 << 24);
+}
+
+static inline u32 get_seg_desc_limit(const struct segment_desc *seg)
+{
+	return seg->limit0 | ((u32)seg->limit << 16);
+}
+
+// 8 byte interrupt/trap descriptor (i386 IDT)
+struct gate_struct_32 {
+	u16 offset_low;
+	u16 segment;
+	unsigned zero0 : 8, type : 5, dpl : 2, p : 1;
+	u16 offset_middle;
+};
+
+struct raw_desc {
 	unsigned int a,b;
+};
+
+struct desc_struct {
+	union {
+		u64 raw;
+		struct segment_desc seg;
+		struct gate_struct_32 gate;
+		struct raw_desc raw32;
+	};
 };
 
 enum {
@@ -29,8 +56,8 @@ enum {
 	GATE_CALL = 0xC,
 };
 
-// 16byte gate
-struct gate_struct {
+// 16byte gate (x86_64 only)
+struct gate_struct_64 {
 	u16 offset_low;
 	u16 segment;
 	unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
@@ -48,8 +75,8 @@ enum {
 	DESC_LDT = 0x2,
 };
 
-// LDT or TSS descriptor in the GDT. 16 bytes.
-struct ldttss_desc {
+// LDT or TSS descriptor in the GDT (x86_64 only). 16 bytes.
+struct ldttss_desc_64 {
 	u16 limit0;
 	u16 base0;
 	unsigned base1 : 8, type : 5, dpl : 2, p : 1;
diff -r ef94811a10d5 include/asm-x86_64/processor.h
--- a/include/asm-x86_64/processor.h	Wed Jul 18 14:46:15 2007 +1000
+++ b/include/asm-x86_64/processor.h	Wed Jul 18 15:59:01 2007 +1000
@@ -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  { \



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/3] i386: use x86_64's desc_def.h
  2007-07-18  7:22 [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386 Rusty Russell
@ 2007-07-18  7:23 ` Rusty Russell
  2007-07-18  7:30   ` [PATCH 3/3] i386: Replace struct Xgt_desc_struct with struct desc_ptr Rusty Russell
  2007-07-18 16:19   ` [PATCH 2/3] i386: use x86_64's desc_def.h Zachary Amsden
  2007-07-18  9:03 ` [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386 Andi Kleen
  1 sibling, 2 replies; 11+ messages in thread
From: Rusty Russell @ 2007-07-18  7:23 UTC (permalink / raw)
  To: lkml - Kernel Mailing List
  Cc: Andi Kleen, kvm-devel, Andrew Morton, Zachary Amsden

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".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r 656f3ff2c9ce arch/i386/kernel/cpu/common.c
--- a/arch/i386/kernel/cpu/common.c	Wed Jul 18 16:21:04 2007 +1000
+++ b/arch/i386/kernel/cpu/common.c	Wed Jul 18 16:29:06 2007 +1000
@@ -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);
 
diff -r 656f3ff2c9ce arch/i386/kernel/process.c
--- a/arch/i386/kernel/process.c	Wed Jul 18 16:21:04 2007 +1000
+++ b/arch/i386/kernel/process.c	Wed Jul 18 16:21:06 2007 +1000
@@ -466,8 +466,8 @@ int copy_thread(int nr, unsigned long cl
 			goto out;
 
 		desc = p->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
-		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);
 	}
 
 	err = 0;
@@ -863,11 +863,11 @@ asmlinkage int sys_set_thread_area(struc
 	cpu = get_cpu();
 
 	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);
 	}
 	load_TLS(t, cpu);
 
@@ -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)
 
 asmlinkage int sys_get_thread_area(struct user_desc __user *u_info)
 {
@@ -912,14 +899,14 @@ asmlinkage int sys_get_thread_area(struc
 	desc = current->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(u_info, &info, sizeof(info)))
 		return -EFAULT;
diff -r 656f3ff2c9ce arch/i386/kernel/ptrace.c
--- a/arch/i386/kernel/ptrace.c	Wed Jul 18 16:21:04 2007 +1000
+++ b/arch/i386/kernel/ptrace.c	Wed Jul 18 16:21:06 2007 +1000
@@ -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;
diff -r 656f3ff2c9ce arch/i386/kernel/smpcommon.c
--- a/arch/i386/kernel/smpcommon.c	Wed Jul 18 16:21:04 2007 +1000
+++ b/arch/i386/kernel/smpcommon.c	Wed Jul 18 16:29:59 2007 +1000
@@ -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);
 
diff -r 656f3ff2c9ce arch/i386/kernel/traps.c
--- a/arch/i386/kernel/traps.c	Wed Jul 18 16:21:04 2007 +1000
+++ b/arch/i386/kernel/traps.c	Wed Jul 18 16:21:06 2007 +1000
@@ -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);
diff -r 656f3ff2c9ce arch/i386/kernel/vmi.c
--- a/arch/i386/kernel/vmi.c	Wed Jul 18 16:21:04 2007 +1000
+++ b/arch/i386/kernel/vmi.c	Wed Jul 18 16:31:00 2007 +1000
@@ -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)
diff -r 656f3ff2c9ce include/asm-i386/desc.h
--- a/include/asm-i386/desc.h	Wed Jul 18 16:21:04 2007 +1000
+++ b/include/asm-i386/desc.h	Wed Jul 18 16:21:06 2007 +1000
@@ -81,8 +81,8 @@ static inline void write_dt_entry(struct
 static 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)
diff -r 656f3ff2c9ce include/asm-i386/processor.h
--- a/include/asm-i386/processor.h	Wed Jul 18 16:21:04 2007 +1000
+++ b/include/asm-i386/processor.h	Wed Jul 18 16:21:06 2007 +1000
@@ -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").



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/3] i386: Replace struct Xgt_desc_struct with struct desc_ptr
  2007-07-18  7:23 ` [PATCH 2/3] i386: use x86_64's desc_def.h Rusty Russell
@ 2007-07-18  7:30   ` Rusty Russell
  2007-07-21  1:33     ` Chris Wright
  2007-07-18 16:19   ` [PATCH 2/3] i386: use x86_64's desc_def.h Zachary Amsden
  1 sibling, 1 reply; 11+ messages in thread
From: Rusty Russell @ 2007-07-18  7:30 UTC (permalink / raw)
  To: lkml - Kernel Mailing List
  Cc: Andi Kleen, kvm-devel, Andrew Morton, Jeremy Fitzhardinge,
	Zachary Amsden, Chris Wright

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.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r 0b03f449c0b3 arch/i386/kernel/asm-offsets.c
--- a/arch/i386/kernel/asm-offsets.c	Wed Jul 18 16:34:04 2007 +1000
+++ b/arch/i386/kernel/asm-offsets.c	Wed Jul 18 16:55:36 2007 +1000
@@ -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);
diff -r 0b03f449c0b3 arch/i386/kernel/cpu/common.c
--- a/arch/i386/kernel/cpu/common.c	Wed Jul 18 16:34:04 2007 +1000
+++ b/arch/i386/kernel/cpu/common.c	Wed Jul 18 16:56:08 2007 +1000
@@ -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;
diff -r 0b03f449c0b3 arch/i386/kernel/doublefault.c
--- a/arch/i386/kernel/doublefault.c	Wed Jul 18 16:34:04 2007 +1000
+++ b/arch/i386/kernel/doublefault.c	Wed Jul 18 16:56:34 2007 +1000
@@ -17,7 +17,7 @@ static unsigned long doublefault_stack[D
 
 static 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);
diff -r 0b03f449c0b3 arch/i386/kernel/efi.c
--- a/arch/i386/kernel/efi.c	Wed Jul 18 16:34:04 2007 +1000
+++ b/arch/i386/kernel/efi.c	Wed Jul 18 16:56:43 2007 +1000
@@ -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;
diff -r 0b03f449c0b3 arch/i386/kernel/machine_kexec.c
--- a/arch/i386/kernel/machine_kexec.c	Wed Jul 18 16:34:04 2007 +1000
+++ b/arch/i386/kernel/machine_kexec.c	Wed Jul 18 16:56:54 2007 +1000
@@ -31,7 +31,7 @@ static u32 kexec_pte1[1024] PAGE_ALIGNED
 
 static 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, __u16 
 
 static void set_gdt(void *newgdt, __u16 limit)
 {
-	struct Xgt_desc_struct curgdt;
+	struct desc_ptr curgdt;
 
 	/* ia32 supports unaligned loads & stores */
 	curgdt.size    = limit;
diff -r 0b03f449c0b3 arch/i386/kernel/reboot.c
--- a/arch/i386/kernel/reboot.c	Wed Jul 18 16:34:04 2007 +1000
+++ b/arch/i386/kernel/reboot.c	Wed Jul 18 16:56:59 2007 +1000
@@ -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 };
diff -r 0b03f449c0b3 drivers/kvm/svm.c
--- a/drivers/kvm/svm.c	Wed Jul 18 16:34:04 2007 +1000
+++ b/drivers/kvm/svm.c	Wed Jul 18 17:10:13 2007 +1000
@@ -290,11 +290,7 @@ static void svm_hardware_enable(void *ga
 
 	struct 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();
 
diff -r 0b03f449c0b3 include/asm-i386/desc.h
--- a/include/asm-i386/desc.h	Wed Jul 18 16:34:04 2007 +1000
+++ b/include/asm-i386/desc.h	Wed Jul 18 16:47:34 2007 +1000
@@ -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_cp
 	return 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
 	asm volatile("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)
 {
 	asm volatile("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)
 {
 	asm volatile("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));
 }
diff -r 0b03f449c0b3 include/asm-i386/paravirt.h
--- a/include/asm-i386/paravirt.h	Wed Jul 18 16:34:04 2007 +1000
+++ b/include/asm-i386/paravirt.h	Wed Jul 18 16:49:02 2007 +1000
@@ -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);
 }
diff -r 0b03f449c0b3 include/asm-i386/processor.h
--- a/include/asm-i386/processor.h	Wed Jul 18 16:34:04 2007 +1000
+++ b/include/asm-i386/processor.h	Wed Jul 18 16:49:14 2007 +1000
@@ -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);
diff -r 0b03f449c0b3 include/asm-i386/suspend.h
--- a/include/asm-i386/suspend.h	Wed Jul 18 16:34:04 2007 +1000
+++ b/include/asm-i386/suspend.h	Wed Jul 18 16:49:20 2007 +1000
@@ -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;



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386.
  2007-07-18  7:22 [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386 Rusty Russell
  2007-07-18  7:23 ` [PATCH 2/3] i386: use x86_64's desc_def.h Rusty Russell
@ 2007-07-18  9:03 ` Andi Kleen
  2007-07-18 11:44   ` Rusty Russell
  1 sibling, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2007-07-18  9:03 UTC (permalink / raw)
  To: Rusty Russell; +Cc: lkml - Kernel Mailing List, kvm-devel, Andrew Morton

On Wed, Jul 18, 2007 at 05:22:34PM +1000, Rusty Russell wrote:
> However, the currently (i386-derived) x86-64 ones are suboptimal.  The

In what way are they suboptimal? 

They seem to work just fine.

-Andi


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386.
  2007-07-18  9:03 ` [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386 Andi Kleen
@ 2007-07-18 11:44   ` Rusty Russell
  0 siblings, 0 replies; 11+ messages in thread
From: Rusty Russell @ 2007-07-18 11:44 UTC (permalink / raw)
  To: Andi Kleen; +Cc: lkml - Kernel Mailing List, kvm-devel, Andrew Morton

On Wed, 2007-07-18 at 11:03 +0200, Andi Kleen wrote:
> On Wed, Jul 18, 2007 at 05:22:34PM +1000, Rusty Russell wrote:
> > 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.

> 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.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] i386: use x86_64's desc_def.h
  2007-07-18  7:23 ` [PATCH 2/3] i386: use x86_64's desc_def.h Rusty Russell
  2007-07-18  7:30   ` [PATCH 3/3] i386: Replace struct Xgt_desc_struct with struct desc_ptr Rusty Russell
@ 2007-07-18 16:19   ` Zachary Amsden
  2007-07-18 23:27     ` Rusty Russell
  1 sibling, 1 reply; 11+ messages in thread
From: Zachary Amsden @ 2007-07-18 16:19 UTC (permalink / raw)
  To: Rusty Russell
  Cc: lkml - Kernel Mailing List, Andi Kleen, kvm-devel, Andrew Morton

Rusty Russell wrote:
> 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.

>  
> diff -r 656f3ff2c9ce arch/i386/kernel/process.c
> @@ -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 656f3ff2c9ce arch/i386/kernel/ptrace.c
> --- a/arch/i386/kernel/ptrace.c	Wed Jul 18 16:21:04 2007 +1000
> +++ b/arch/i386/kernel/ptrace.c	Wed Jul 18 16:21:06 2007 +1000
> @@ -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)
>   

You got rid of the duplicate definitions here, but then added new 
duplicates (GET_CONTENTS / WRITABLE).  Can you stick them in desc.h?

Zach

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] i386: use x86_64's desc_def.h
  2007-07-18 16:19   ` [PATCH 2/3] i386: use x86_64's desc_def.h Zachary Amsden
@ 2007-07-18 23:27     ` Rusty Russell
  2007-07-18 23:29       ` Rusty Russell
  2007-07-19  0:00       ` Andi Kleen
  0 siblings, 2 replies; 11+ messages in thread
From: Rusty Russell @ 2007-07-18 23:27 UTC (permalink / raw)
  To: Zachary Amsden
  Cc: lkml - Kernel Mailing List, Andi Kleen, kvm-devel, Andrew Morton

On Wed, 2007-07-18 at 09:19 -0700, Zachary Amsden wrote:
> > +#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?

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.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r ef94811a10d5 arch/x86_64/ia32/tls32.c
--- a/arch/x86_64/ia32/tls32.c	Wed Jul 18 14:46:15 2007 +1000
+++ b/arch/x86_64/ia32/tls32.c	Thu Jul 19 09:09:02 2007 +1000
@@ -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_str
 int 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_str
 	if (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 == &current->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_str
 	if (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(st
 
 int 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 *p
 	if (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;
 }
diff -r ef94811a10d5 arch/x86_64/kernel/process.c
--- a/arch/x86_64/kernel/process.c	Wed Jul 18 14:46:15 2007 +1000
+++ b/arch/x86_64/kernel/process.c	Wed Jul 18 16:34:03 2007 +1000
@@ -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);
 }
 
 /*
diff -r ef94811a10d5 arch/x86_64/kernel/suspend.c
--- a/arch/x86_64/kernel/suspend.c	Wed Jul 18 14:46:15 2007 +1000
+++ b/arch/x86_64/kernel/suspend.c	Wed Jul 18 16:34:03 2007 +1000
@@ -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 */
diff -r ef94811a10d5 include/asm-x86_64/desc.h
--- a/include/asm-x86_64/desc.h	Wed Jul 18 14:46:15 2007 +1000
+++ b/include/asm-x86_64/desc.h	Thu Jul 19 08:57:00 2007 +1000
@@ -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_descriptor
 static 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 threa
 static 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];
diff -r ef94811a10d5 include/asm-x86_64/desc_defs.h
--- a/include/asm-x86_64/desc_defs.h	Wed Jul 18 14:46:15 2007 +1000
+++ b/include/asm-x86_64/desc_defs.h	Thu Jul 19 09:08:03 2007 +1000
@@ -11,16 +11,54 @@
 
 #include <linux/types.h>
 
-// 8 byte segment descriptor
-struct desc_struct {
+// 8 byte segment descriptor (GDT/LDT)
+struct segment_desc {
 	u16 limit0;
 	u16 base0;
 	unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1;
 	unsigned limit : 4, avl : 1, l : 1, d : 1, g : 1, base2 : 8;
 } __attribute__((packed));
 
-struct n_desc_struct {
+static inline u32 get_seg_desc_base(const struct segment_desc *seg)
+{
+	return seg->base0 | ((u32)seg->base1 << 16) | ((u32)seg->base2 << 24);
+}
+
+static inline u32 get_seg_desc_limit(const struct segment_desc *seg)
+{
+	return seg->limit0 | ((u32)seg->limit << 16);
+}
+
+/* Bottom two type bits are Writable and Accessed flags respectively. */
+static inline unsigned get_seg_desc_contents(const struct segment_desc *seg)
+{
+	return seg->type >> 2;
+}
+
+static inline unsigned get_seg_desc_writable(const struct segment_desc *seg)
+{
+	return (seg->type >> 1) & 1;
+}
+
+// 8 byte interrupt/trap descriptor (i386 IDT)
+struct gate_struct_32 {
+	u16 offset_low;
+	u16 segment;
+	unsigned zero0 : 8, type : 5, dpl : 2, p : 1;
+	u16 offset_middle;
+};
+
+struct raw_desc {
 	unsigned int a,b;
+};
+
+struct desc_struct {
+	union {
+		u64 raw;
+		struct segment_desc seg;
+		struct gate_struct_32 gate;
+		struct raw_desc raw32;
+	};
 };
 
 enum {
@@ -29,8 +67,8 @@ enum {
 	GATE_CALL = 0xC,
 };
 
-// 16byte gate
-struct gate_struct {
+// 16byte gate (x86_64 only)
+struct gate_struct_64 {
 	u16 offset_low;
 	u16 segment;
 	unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
@@ -48,8 +86,8 @@ enum {
 	DESC_LDT = 0x2,
 };
 
-// LDT or TSS descriptor in the GDT. 16 bytes.
-struct ldttss_desc {
+// LDT or TSS descriptor in the GDT (x86_64 only). 16 bytes.
+struct ldttss_desc_64 {
 	u16 limit0;
 	u16 base0;
 	unsigned base1 : 8, type : 5, dpl : 2, p : 1;
@@ -63,7 +101,6 @@ struct desc_ptr {
 	unsigned long address;
 } __attribute__((packed)) ;
 
-
 #endif /* !__ASSEMBLY__ */
 
 #endif
diff -r ef94811a10d5 include/asm-x86_64/processor.h
--- a/include/asm-x86_64/processor.h	Wed Jul 18 14:46:15 2007 +1000
+++ b/include/asm-x86_64/processor.h	Wed Jul 18 16:34:03 2007 +1000
@@ -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  { \



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] i386: use x86_64's desc_def.h
  2007-07-18 23:27     ` Rusty Russell
@ 2007-07-18 23:29       ` Rusty Russell
  2007-07-21  1:32         ` Chris Wright
  2007-07-19  0:00       ` Andi Kleen
  1 sibling, 1 reply; 11+ messages in thread
From: Rusty Russell @ 2007-07-18 23:29 UTC (permalink / raw)
  To: Zachary Amsden
  Cc: lkml - Kernel Mailing List, Andi Kleen, kvm-devel, Andrew Morton

On Thu, 2007-07-19 at 09:27 +1000, Rusty Russell wrote:
> On Wed, 2007-07-18 at 09:19 -0700, Zachary Amsden wrote:
> > > +#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?
> 
> 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".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r e80364496ab1 arch/i386/kernel/cpu/common.c
--- a/arch/i386/kernel/cpu/common.c	Thu Jul 19 09:09:28 2007 +1000
+++ b/arch/i386/kernel/cpu/common.c	Thu Jul 19 09:12:33 2007 +1000
@@ -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);
 
diff -r e80364496ab1 arch/i386/kernel/process.c
--- a/arch/i386/kernel/process.c	Thu Jul 19 09:09:28 2007 +1000
+++ b/arch/i386/kernel/process.c	Thu Jul 19 09:13:33 2007 +1000
@@ -466,8 +466,8 @@ int copy_thread(int nr, unsigned long cl
 			goto out;
 
 		desc = p->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
-		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);
 	}
 
 	err = 0;
@@ -863,11 +863,11 @@ asmlinkage int sys_set_thread_area(struc
 	cpu = get_cpu();
 
 	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);
 	}
 	load_TLS(t, cpu);
 
@@ -879,23 +879,6 @@ 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)
-
 asmlinkage int sys_get_thread_area(struct user_desc __user *u_info)
 {
 	struct user_desc info;
@@ -912,14 +895,14 @@ asmlinkage int sys_get_thread_area(struc
 	desc = current->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.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.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;
 
 	if (copy_to_user(u_info, &info, sizeof(info)))
 		return -EFAULT;
diff -r e80364496ab1 arch/i386/kernel/ptrace.c
--- a/arch/i386/kernel/ptrace.c	Thu Jul 19 09:09:28 2007 +1000
+++ b/arch/i386/kernel/ptrace.c	Thu Jul 19 09:14:22 2007 +1000
@@ -283,37 +283,20 @@ 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)
-
 	if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
 		return -EINVAL;
 
 	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.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.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;
 
 	if (copy_to_user(user_desc, &info, sizeof(info)))
 		return -EFAULT;
@@ -339,11 +322,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;
diff -r e80364496ab1 arch/i386/kernel/smpcommon.c
--- a/arch/i386/kernel/smpcommon.c	Thu Jul 19 09:09:28 2007 +1000
+++ b/arch/i386/kernel/smpcommon.c	Thu Jul 19 09:12:33 2007 +1000
@@ -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);
 
diff -r e80364496ab1 arch/i386/kernel/traps.c
--- a/arch/i386/kernel/traps.c	Thu Jul 19 09:09:28 2007 +1000
+++ b/arch/i386/kernel/traps.c	Thu Jul 19 09:12:33 2007 +1000
@@ -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);
diff -r e80364496ab1 arch/i386/kernel/vmi.c
--- a/arch/i386/kernel/vmi.c	Thu Jul 19 09:09:28 2007 +1000
+++ b/arch/i386/kernel/vmi.c	Thu Jul 19 09:12:33 2007 +1000
@@ -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)
diff -r e80364496ab1 include/asm-i386/desc.h
--- a/include/asm-i386/desc.h	Thu Jul 19 09:09:28 2007 +1000
+++ b/include/asm-i386/desc.h	Thu Jul 19 09:12:33 2007 +1000
@@ -81,8 +81,8 @@ static inline void write_dt_entry(struct
 static 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)
diff -r e80364496ab1 include/asm-i386/processor.h
--- a/include/asm-i386/processor.h	Thu Jul 19 09:09:28 2007 +1000
+++ b/include/asm-i386/processor.h	Thu Jul 19 09:12:33 2007 +1000
@@ -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").



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] i386: use x86_64's desc_def.h
  2007-07-18 23:27     ` Rusty Russell
  2007-07-18 23:29       ` Rusty Russell
@ 2007-07-19  0:00       ` Andi Kleen
  1 sibling, 0 replies; 11+ messages in thread
From: Andi Kleen @ 2007-07-19  0:00 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Zachary Amsden, lkml - Kernel Mailing List, kvm-devel, Andrew Morton

On Thu, Jul 19, 2007 at 09:27:41AM +1000, Rusty Russell wrote:
> On Wed, 2007-07-18 at 09:19 -0700, Zachary Amsden wrote:
> > > +#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?
> 
> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] i386: use x86_64's desc_def.h
  2007-07-18 23:29       ` Rusty Russell
@ 2007-07-21  1:32         ` Chris Wright
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wright @ 2007-07-21  1:32 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Zachary Amsden, lkml - Kernel Mailing List, Andi Kleen,
	kvm-devel, Andrew Morton

* Rusty Russell (rusty@rustcorp.com.au) wrote:
> On Thu, 2007-07-19 at 09:27 +1000, Rusty Russell wrote:
> > On Wed, 2007-07-18 at 09:19 -0700, Zachary Amsden wrote:
> > > > +#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?
> > 
> > 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

plus this needed as well now

Index: linus-2.6/include/asm-i386/xen/hypercall.h
===================================================================
--- linus-2.6.orig/include/asm-i386/xen/hypercall.h
+++ linus-2.6/include/asm-i386/xen/hypercall.h
@@ -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
Index: linus-2.6/drivers/lguest/interrupts_and_traps.c
===================================================================
--- linus-2.6.orig/drivers/lguest/interrupts_and_traps.c
+++ linus-2.6/drivers/lguest/interrupts_and_traps.c
@@ -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 lgue
 		return 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 des
 	if (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,
Index: linus-2.6/drivers/lguest/lg.h
===================================================================
--- linus-2.6.orig/drivers/lguest/lg.h
+++ linus-2.6/drivers/lguest/lg.h
@@ -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
 {
Index: linus-2.6/drivers/lguest/lguest.c
===================================================================
--- linus-2.6.orig/drivers/lguest/lguest.c
+++ linus-2.6/drivers/lguest/lguest.c
@@ -173,7 +173,7 @@ static void lguest_load_idt(const struct
 	struct 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)
Index: linus-2.6/drivers/lguest/segments.c
===================================================================
--- linus-2.6.orig/drivers/lguest/segments.c
+++ linus-2.6/drivers/lguest/segments.c
@@ -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 lgues
 			kill_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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/3] i386: Replace struct Xgt_desc_struct with struct desc_ptr
  2007-07-18  7:30   ` [PATCH 3/3] i386: Replace struct Xgt_desc_struct with struct desc_ptr Rusty Russell
@ 2007-07-21  1:33     ` Chris Wright
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wright @ 2007-07-21  1:33 UTC (permalink / raw)
  To: Rusty Russell
  Cc: lkml - Kernel Mailing List, Andi Kleen, kvm-devel, Andrew Morton,
	Jeremy Fitzhardinge, Zachary Amsden, Chris Wright

* Rusty Russell (rusty@rustcorp.com.au) wrote:
> Remove i386's Xgt_desc_struct definition and use desc_def.h's desc_ptr.

plus this is needed now


Index: linus-2.6/drivers/lguest/lg.h
===================================================================
--- linus-2.6.orig/drivers/lguest/lg.h
+++ linus-2.6/drivers/lguest/lg.h
@@ -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];
Index: linus-2.6/arch/i386/xen/enlighten.c
===================================================================
--- linus-2.6.orig/arch/i386/xen/enlighten.c
+++ linus-2.6/arch/i386/xen/enlighten.c
@@ -301,7 +301,7 @@ static void xen_set_ldt(const void *addr
 	xen_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 d
 	preempt_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(const 
 
 void 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];
Index: linus-2.6/drivers/lguest/lguest.c
===================================================================
--- linus-2.6.orig/drivers/lguest/lguest.c
+++ linus-2.6/drivers/lguest/lguest.c
@@ -167,7 +167,7 @@ static void lguest_write_idt_entry(struc
 	hcall(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 struct
 		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)
+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);

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-07-21  1:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-18  7:22 [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386 Rusty Russell
2007-07-18  7:23 ` [PATCH 2/3] i386: use x86_64's desc_def.h Rusty Russell
2007-07-18  7:30   ` [PATCH 3/3] i386: Replace struct Xgt_desc_struct with struct desc_ptr Rusty Russell
2007-07-21  1:33     ` Chris Wright
2007-07-18 16:19   ` [PATCH 2/3] i386: use x86_64's desc_def.h Zachary Amsden
2007-07-18 23:27     ` Rusty Russell
2007-07-18 23:29       ` Rusty Russell
2007-07-21  1:32         ` Chris Wright
2007-07-19  0:00       ` Andi Kleen
2007-07-18  9:03 ` [PATCH 1/3] Standardize x86_64's desc_defs.h in preparation for exposure to i386 Andi Kleen
2007-07-18 11:44   ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).