aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/kernel/paravirt_32.c2
-rw-r--r--arch/x86/kernel/smpcommon_32.c7
-rw-r--r--arch/x86/kernel/vmi_32.c21
-rw-r--r--arch/x86/lguest/boot.c6
-rw-r--r--arch/x86/xen/enlighten.c11
-rw-r--r--include/asm-x86/desc_32.h34
-rw-r--r--include/asm-x86/paravirt.h9
7 files changed, 56 insertions, 34 deletions
diff --git a/arch/x86/kernel/paravirt_32.c b/arch/x86/kernel/paravirt_32.c
index 13bbc99b639b..77602c1252d7 100644
--- a/arch/x86/kernel/paravirt_32.c
+++ b/arch/x86/kernel/paravirt_32.c
@@ -380,7 +380,7 @@ struct pv_cpu_ops pv_cpu_ops = {
380 .store_tr = native_store_tr, 380 .store_tr = native_store_tr,
381 .load_tls = native_load_tls, 381 .load_tls = native_load_tls,
382 .write_ldt_entry = write_dt_entry, 382 .write_ldt_entry = write_dt_entry,
383 .write_gdt_entry = write_dt_entry, 383 .write_gdt_entry = native_write_gdt_entry,
384 .write_idt_entry = native_write_idt_entry, 384 .write_idt_entry = native_write_idt_entry,
385 .load_sp0 = native_load_sp0, 385 .load_sp0 = native_load_sp0,
386 386
diff --git a/arch/x86/kernel/smpcommon_32.c b/arch/x86/kernel/smpcommon_32.c
index bbfe85a0f699..8bc38af29aef 100644
--- a/arch/x86/kernel/smpcommon_32.c
+++ b/arch/x86/kernel/smpcommon_32.c
@@ -14,10 +14,11 @@ __cpuinit void init_gdt(int cpu)
14{ 14{
15 struct desc_struct *gdt = get_cpu_gdt_table(cpu); 15 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16 16
17 pack_descriptor((u32 *)&gdt[GDT_ENTRY_PERCPU].a, 17 pack_descriptor(&gdt[GDT_ENTRY_PERCPU],
18 (u32 *)&gdt[GDT_ENTRY_PERCPU].b,
19 __per_cpu_offset[cpu], 0xFFFFF, 18 __per_cpu_offset[cpu], 0xFFFFF,
20 0x80 | DESCTYPE_S | 0x2, 0x8); 19 0x2 | DESCTYPE_S, 0x8);
20
21 gdt[GDT_ENTRY_PERCPU].s = 1;
21 22
22 per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu]; 23 per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
23 per_cpu(cpu_number, cpu) = cpu; 24 per_cpu(cpu_number, cpu) = cpu;
diff --git a/arch/x86/kernel/vmi_32.c b/arch/x86/kernel/vmi_32.c
index a635b22de25f..21edd0d6eae5 100644
--- a/arch/x86/kernel/vmi_32.c
+++ b/arch/x86/kernel/vmi_32.c
@@ -63,6 +63,7 @@ static struct {
63 void (*_set_ldt)(u32 selector); 63 void (*_set_ldt)(u32 selector);
64 void (*set_tr)(u32 selector); 64 void (*set_tr)(u32 selector);
65 void (*write_idt_entry)(struct desc_struct *, int, u32, u32); 65 void (*write_idt_entry)(struct desc_struct *, int, u32, u32);
66 void (*write_gdt_entry)(struct desc_struct *, int, u32, u32);
66 void (*set_kernel_stack)(u32 selector, u32 sp0); 67 void (*set_kernel_stack)(u32 selector, u32 sp0);
67 void (*allocate_page)(u32, u32, u32, u32, u32); 68 void (*allocate_page)(u32, u32, u32, u32, u32);
68 void (*release_page)(u32, u32); 69 void (*release_page)(u32, u32);
@@ -187,7 +188,7 @@ static void vmi_cpuid(unsigned int *ax, unsigned int *bx,
187static inline void vmi_maybe_load_tls(struct desc_struct *gdt, int nr, struct desc_struct *new) 188static inline void vmi_maybe_load_tls(struct desc_struct *gdt, int nr, struct desc_struct *new)
188{ 189{
189 if (gdt[nr].a != new->a || gdt[nr].b != new->b) 190 if (gdt[nr].a != new->a || gdt[nr].b != new->b)
190 write_gdt_entry(gdt, nr, new->a, new->b); 191 write_gdt_entry(gdt, nr, new, 0);
191} 192}
192 193
193static void vmi_load_tls(struct thread_struct *t, unsigned int cpu) 194static void vmi_load_tls(struct thread_struct *t, unsigned int cpu)
@@ -201,12 +202,12 @@ static void vmi_load_tls(struct thread_struct *t, unsigned int cpu)
201static void vmi_set_ldt(const void *addr, unsigned entries) 202static void vmi_set_ldt(const void *addr, unsigned entries)
202{ 203{
203 unsigned cpu = smp_processor_id(); 204 unsigned cpu = smp_processor_id();
204 u32 low, high; 205 struct desc_struct desc;
205 206
206 pack_descriptor(&low, &high, (unsigned long)addr, 207 pack_descriptor(&desc, (unsigned long)addr,
207 entries * sizeof(struct desc_struct) - 1, 208 entries * sizeof(struct desc_struct) - 1,
208 DESCTYPE_LDT, 0); 209 DESC_LDT, 0);
209 write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_LDT, low, high); 210 write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_LDT, &desc, DESC_LDT);
210 vmi_ops._set_ldt(entries ? GDT_ENTRY_LDT*sizeof(struct desc_struct) : 0); 211 vmi_ops._set_ldt(entries ? GDT_ENTRY_LDT*sizeof(struct desc_struct) : 0);
211} 212}
212 213
@@ -221,6 +222,13 @@ static void vmi_write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
221 vmi_ops.write_idt_entry(dt, entry, idt_entry[0], idt_entry[2]); 222 vmi_ops.write_idt_entry(dt, entry, idt_entry[0], idt_entry[2]);
222} 223}
223 224
225static void vmi_write_gdt_entry(struct desc_struct *dt, int entry,
226 const void *desc, int type)
227{
228 u32 *gdt_entry = (u32 *)desc;
229 vmi_ops.write_gdt_entry(dt, entry, gdt_entry[0], gdt_entry[2]);
230}
231
224static void vmi_load_sp0(struct tss_struct *tss, 232static void vmi_load_sp0(struct tss_struct *tss,
225 struct thread_struct *thread) 233 struct thread_struct *thread)
226{ 234{
@@ -798,7 +806,8 @@ static inline int __init activate_vmi(void)
798 para_fill(pv_cpu_ops.store_tr, GetTR); 806 para_fill(pv_cpu_ops.store_tr, GetTR);
799 pv_cpu_ops.load_tls = vmi_load_tls; 807 pv_cpu_ops.load_tls = vmi_load_tls;
800 para_fill(pv_cpu_ops.write_ldt_entry, WriteLDTEntry); 808 para_fill(pv_cpu_ops.write_ldt_entry, WriteLDTEntry);
801 para_fill(pv_cpu_ops.write_gdt_entry, WriteGDTEntry); 809 para_wrap(pv_cpu_ops.write_gdt_entry, vmi_write_gdt_entry,
810 write_gdt_entry, WriteGDTEntry);
802 para_wrap(pv_cpu_ops.write_idt_entry, vmi_write_idt_entry, 811 para_wrap(pv_cpu_ops.write_idt_entry, vmi_write_idt_entry,
803 write_idt_entry, WriteIDTEntry); 812 write_idt_entry, WriteIDTEntry);
804 para_wrap(pv_cpu_ops.load_sp0, vmi_load_sp0, set_kernel_stack, UpdateKernelStack); 813 para_wrap(pv_cpu_ops.load_sp0, vmi_load_sp0, set_kernel_stack, UpdateKernelStack);
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index b50c8ad25ab4..a63373759f08 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -262,10 +262,10 @@ static void lguest_load_gdt(const struct desc_ptr *desc)
262/* For a single GDT entry which changes, we do the lazy thing: alter our GDT, 262/* For a single GDT entry which changes, we do the lazy thing: alter our GDT,
263 * then tell the Host to reload the entire thing. This operation is so rare 263 * then tell the Host to reload the entire thing. This operation is so rare
264 * that this naive implementation is reasonable. */ 264 * that this naive implementation is reasonable. */
265static void lguest_write_gdt_entry(struct desc_struct *dt, 265static void lguest_write_gdt_entry(struct desc_struct *dt, int entrynum,
266 int entrynum, u32 low, u32 high) 266 const void *desc, int type)
267{ 267{
268 write_dt_entry(dt, entrynum, low, high); 268 native_write_gdt_entry(dt, entrynum, desc, type);
269 hcall(LHCALL_LOAD_GDT, __pa(dt), GDT_ENTRIES, 0); 269 hcall(LHCALL_LOAD_GDT, __pa(dt), GDT_ENTRIES, 0);
270} 270}
271 271
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index b7b7346d8cdc..7f98c63f6381 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -475,22 +475,21 @@ static void xen_load_idt(const struct desc_ptr *desc)
475/* Write a GDT descriptor entry. Ignore LDT descriptors, since 475/* Write a GDT descriptor entry. Ignore LDT descriptors, since
476 they're handled differently. */ 476 they're handled differently. */
477static void xen_write_gdt_entry(struct desc_struct *dt, int entry, 477static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
478 u32 low, u32 high) 478 const void *desc, int type)
479{ 479{
480 preempt_disable(); 480 preempt_disable();
481 481
482 switch ((high >> 8) & 0xff) { 482 switch (type) {
483 case DESCTYPE_LDT: 483 case DESC_LDT:
484 case DESCTYPE_TSS: 484 case DESC_TSS:
485 /* ignore */ 485 /* ignore */
486 break; 486 break;
487 487
488 default: { 488 default: {
489 xmaddr_t maddr = virt_to_machine(&dt[entry]); 489 xmaddr_t maddr = virt_to_machine(&dt[entry]);
490 u64 desc = (u64)high << 32 | low;
491 490
492 xen_mc_flush(); 491 xen_mc_flush();
493 if (HYPERVISOR_update_descriptor(maddr.maddr, desc)) 492 if (HYPERVISOR_update_descriptor(maddr.maddr, *(u64 *)desc))
494 BUG(); 493 BUG();
495 } 494 }
496 495
diff --git a/include/asm-x86/desc_32.h b/include/asm-x86/desc_32.h
index 03700991c5db..41d8214c6173 100644
--- a/include/asm-x86/desc_32.h
+++ b/include/asm-x86/desc_32.h
@@ -28,12 +28,13 @@ extern struct desc_ptr idt_descr;
28extern gate_desc idt_table[]; 28extern gate_desc idt_table[];
29extern void set_intr_gate(unsigned int irq, void * addr); 29extern void set_intr_gate(unsigned int irq, void * addr);
30 30
31static inline void pack_descriptor(__u32 *a, __u32 *b, 31static inline void pack_descriptor(struct desc_struct *desc,
32 unsigned long base, unsigned long limit, unsigned char type, unsigned char flags) 32 unsigned long base, unsigned long limit, unsigned char type, unsigned char flags)
33{ 33{
34 *a = ((base & 0xffff) << 16) | (limit & 0xffff); 34 desc->a = ((base & 0xffff) << 16) | (limit & 0xffff);
35 *b = (base & 0xff000000) | ((base & 0xff0000) >> 16) | 35 desc->b = (base & 0xff000000) | ((base & 0xff0000) >> 16) |
36 (limit & 0x000f0000) | ((type & 0xff) << 8) | ((flags & 0xf) << 20); 36 (limit & 0x000f0000) | ((type & 0xff) << 8) | ((flags & 0xf) << 20);
37 desc->p = 1;
37} 38}
38 39
39static inline void pack_gate(gate_desc *gate, 40static inline void pack_gate(gate_desc *gate,
@@ -69,7 +70,8 @@ static inline void pack_gate(gate_desc *gate,
69#define set_ldt native_set_ldt 70#define set_ldt native_set_ldt
70 71
71#define write_ldt_entry(dt, entry, a, b) write_dt_entry(dt, entry, a, b) 72#define write_ldt_entry(dt, entry, a, b) write_dt_entry(dt, entry, a, b)
72#define write_gdt_entry(dt, entry, a, b) write_dt_entry(dt, entry, a, b) 73#define write_gdt_entry(dt, entry, desc, type) \
74 native_write_gdt_entry(dt, entry, desc, type)
73#define write_idt_entry(dt, entry, g) native_write_idt_entry(dt, entry, g) 75#define write_idt_entry(dt, entry, g) native_write_idt_entry(dt, entry, g)
74#endif 76#endif
75 77
@@ -79,6 +81,12 @@ static inline void native_write_idt_entry(gate_desc *idt, int entry,
79 memcpy(&idt[entry], gate, sizeof(*gate)); 81 memcpy(&idt[entry], gate, sizeof(*gate));
80} 82}
81 83
84static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
85 const void *desc, int type)
86{
87 memcpy(&gdt[entry], desc, sizeof(struct desc_struct));
88}
89
82static inline void write_dt_entry(struct desc_struct *dt, 90static inline void write_dt_entry(struct desc_struct *dt,
83 int entry, u32 entry_low, u32 entry_high) 91 int entry, u32 entry_low, u32 entry_high)
84{ 92{
@@ -86,18 +94,20 @@ static inline void write_dt_entry(struct desc_struct *dt,
86 dt[entry].b = entry_high; 94 dt[entry].b = entry_high;
87} 95}
88 96
97
89static inline void native_set_ldt(const void *addr, unsigned int entries) 98static inline void native_set_ldt(const void *addr, unsigned int entries)
90{ 99{
91 if (likely(entries == 0)) 100 if (likely(entries == 0))
92 __asm__ __volatile__("lldt %w0"::"q" (0)); 101 __asm__ __volatile__("lldt %w0"::"q" (0));
93 else { 102 else {
94 unsigned cpu = smp_processor_id(); 103 unsigned cpu = smp_processor_id();
95 __u32 a, b; 104 ldt_desc ldt;
96 105
97 pack_descriptor(&a, &b, (unsigned long)addr, 106 pack_descriptor(&ldt, (unsigned long)addr,
98 entries * sizeof(struct desc_struct) - 1, 107 entries * sizeof(struct desc_struct) - 1,
99 DESCTYPE_LDT, 0); 108 DESC_LDT, 0);
100 write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_LDT, a, b); 109 write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_LDT,
110 &ldt, DESC_LDT);
101 __asm__ __volatile__("lldt %w0"::"q" (GDT_ENTRY_LDT*8)); 111 __asm__ __volatile__("lldt %w0"::"q" (GDT_ENTRY_LDT*8));
102 } 112 }
103} 113}
@@ -153,11 +163,11 @@ static inline void _set_gate(int gate, unsigned int type, void *addr, unsigned s
153 163
154static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, const void *addr) 164static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, const void *addr)
155{ 165{
156 __u32 a, b; 166 tss_desc tss;
157 pack_descriptor(&a, &b, (unsigned long)addr, 167 pack_descriptor(&tss, (unsigned long)addr,
158 offsetof(struct tss_struct, __cacheline_filler) - 1, 168 offsetof(struct tss_struct, __cacheline_filler) - 1,
159 DESCTYPE_TSS, 0); 169 DESC_TSS, 0);
160 write_gdt_entry(get_cpu_gdt_table(cpu), entry, a, b); 170 write_gdt_entry(get_cpu_gdt_table(cpu), entry, &tss, DESC_TSS);
161} 171}
162 172
163 173
diff --git a/include/asm-x86/paravirt.h b/include/asm-x86/paravirt.h
index 86a9d7b0920f..3f2abf295e2a 100644
--- a/include/asm-x86/paravirt.h
+++ b/include/asm-x86/paravirt.h
@@ -99,7 +99,7 @@ struct pv_cpu_ops {
99 void (*write_ldt_entry)(struct desc_struct *, 99 void (*write_ldt_entry)(struct desc_struct *,
100 int entrynum, u32 low, u32 high); 100 int entrynum, u32 low, u32 high);
101 void (*write_gdt_entry)(struct desc_struct *, 101 void (*write_gdt_entry)(struct desc_struct *,
102 int entrynum, u32 low, u32 high); 102 int entrynum, const void *desc, int size);
103 void (*write_idt_entry)(gate_desc *, 103 void (*write_idt_entry)(gate_desc *,
104 int entrynum, const gate_desc *gate); 104 int entrynum, const gate_desc *gate);
105 void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t); 105 void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t);
@@ -664,10 +664,13 @@ static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
664{ 664{
665 PVOP_VCALL4(pv_cpu_ops.write_ldt_entry, dt, entry, low, high); 665 PVOP_VCALL4(pv_cpu_ops.write_ldt_entry, dt, entry, low, high);
666} 666}
667static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high) 667
668static inline void write_gdt_entry(struct desc_struct *dt, int entry,
669 void *desc, int type)
668{ 670{
669 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, low, high); 671 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
670} 672}
673
671static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g) 674static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
672{ 675{
673 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g); 676 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);