aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@SteelEye.com>2006-02-24 16:04:14 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-02-24 17:31:38 -0500
commit2b932f6cf052920fb3a6281499e08209b08f5086 (patch)
treec2710e09dd40ee9733bcd77234d6373acec741d2
parent1e275d406bf6b88e4de6925cf594b64bb2ec49bc (diff)
[PATCH] x86: fix broken SMP boot sequence
Recent GDT changes broke the SMP boot sequence if the booting CPU is numbered anything other than zero. There's also a subtle source of error in that the boot time CPU now uses cpu_gdt_table (which is actually the GDT for booting CPUs in head.S). This patch fixes both problems by making GDT descriptors themselves allocated from a per_cpu area and switching to them in cpu_init(), which now means that cpu_gdt_table is exclusively used for booting CPUs again. Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com> Cc: Zachary Amsden <zach@vmware.com> Cc: Matt Tolentino <metolent@snoqualmie.dp.intel.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--arch/i386/kernel/cpu/common.c32
-rw-r--r--arch/i386/kernel/efi.c12
-rw-r--r--arch/i386/kernel/head.S2
-rw-r--r--arch/i386/kernel/i386_ksyms.c2
-rw-r--r--arch/i386/kernel/smpboot.c6
-rw-r--r--include/asm-i386/desc.h6
6 files changed, 39 insertions, 21 deletions
diff --git a/arch/i386/kernel/cpu/common.c b/arch/i386/kernel/cpu/common.c
index 7eb9213734a..4ecd4b326de 100644
--- a/arch/i386/kernel/cpu/common.c
+++ b/arch/i386/kernel/cpu/common.c
@@ -4,6 +4,7 @@
4#include <linux/smp.h> 4#include <linux/smp.h>
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/percpu.h> 6#include <linux/percpu.h>
7#include <linux/bootmem.h>
7#include <asm/semaphore.h> 8#include <asm/semaphore.h>
8#include <asm/processor.h> 9#include <asm/processor.h>
9#include <asm/i387.h> 10#include <asm/i387.h>
@@ -18,6 +19,9 @@
18 19
19#include "cpu.h" 20#include "cpu.h"
20 21
22DEFINE_PER_CPU(struct Xgt_desc_struct, cpu_gdt_descr);
23EXPORT_PER_CPU_SYMBOL(cpu_gdt_descr);
24
21DEFINE_PER_CPU(unsigned char, cpu_16bit_stack[CPU_16BIT_STACK_SIZE]); 25DEFINE_PER_CPU(unsigned char, cpu_16bit_stack[CPU_16BIT_STACK_SIZE]);
22EXPORT_PER_CPU_SYMBOL(cpu_16bit_stack); 26EXPORT_PER_CPU_SYMBOL(cpu_16bit_stack);
23 27
@@ -571,8 +575,9 @@ void __devinit cpu_init(void)
571 int cpu = smp_processor_id(); 575 int cpu = smp_processor_id();
572 struct tss_struct * t = &per_cpu(init_tss, cpu); 576 struct tss_struct * t = &per_cpu(init_tss, cpu);
573 struct thread_struct *thread = &current->thread; 577 struct thread_struct *thread = &current->thread;
574 struct desc_struct *gdt = get_cpu_gdt_table(cpu); 578 struct desc_struct *gdt;
575 __u32 stk16_off = (__u32)&per_cpu(cpu_16bit_stack, cpu); 579 __u32 stk16_off = (__u32)&per_cpu(cpu_16bit_stack, cpu);
580 struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, cpu);
576 581
577 if (cpu_test_and_set(cpu, cpu_initialized)) { 582 if (cpu_test_and_set(cpu, cpu_initialized)) {
578 printk(KERN_WARNING "CPU#%d already initialized!\n", cpu); 583 printk(KERN_WARNING "CPU#%d already initialized!\n", cpu);
@@ -590,6 +595,25 @@ void __devinit cpu_init(void)
590 } 595 }
591 596
592 /* 597 /*
598 * This is a horrible hack to allocate the GDT. The problem
599 * is that cpu_init() is called really early for the boot CPU
600 * (and hence needs bootmem) but much later for the secondary
601 * CPUs, when bootmem will have gone away
602 */
603 if (NODE_DATA(0)->bdata->node_bootmem_map) {
604 gdt = (struct desc_struct *)alloc_bootmem_pages(PAGE_SIZE);
605 /* alloc_bootmem_pages panics on failure, so no check */
606 memset(gdt, 0, PAGE_SIZE);
607 } else {
608 gdt = (struct desc_struct *)get_zeroed_page(GFP_KERNEL);
609 if (unlikely(!gdt)) {
610 printk(KERN_CRIT "CPU%d failed to allocate GDT\n", cpu);
611 for (;;)
612 local_irq_enable();
613 }
614 }
615
616 /*
593 * Initialize the per-CPU GDT with the boot GDT, 617 * Initialize the per-CPU GDT with the boot GDT,
594 * and set up the GDT descriptor: 618 * and set up the GDT descriptor:
595 */ 619 */
@@ -601,10 +625,10 @@ void __devinit cpu_init(void)
601 ((((__u64)stk16_off) << 32) & 0xff00000000000000ULL) | 625 ((((__u64)stk16_off) << 32) & 0xff00000000000000ULL) |
602 (CPU_16BIT_STACK_SIZE - 1); 626 (CPU_16BIT_STACK_SIZE - 1);
603 627
604 cpu_gdt_descr[cpu].size = GDT_SIZE - 1; 628 cpu_gdt_descr->size = GDT_SIZE - 1;
605 cpu_gdt_descr[cpu].address = (unsigned long)gdt; 629 cpu_gdt_descr->address = (unsigned long)gdt;
606 630
607 load_gdt(&cpu_gdt_descr[cpu]); 631 load_gdt(cpu_gdt_descr);
608 load_idt(&idt_descr); 632 load_idt(&idt_descr);
609 633
610 /* 634 /*
diff --git a/arch/i386/kernel/efi.c b/arch/i386/kernel/efi.c
index ecad519fd39..e3e42fd6240 100644
--- a/arch/i386/kernel/efi.c
+++ b/arch/i386/kernel/efi.c
@@ -103,17 +103,19 @@ static void efi_call_phys_prelog(void)
103 */ 103 */
104 local_flush_tlb(); 104 local_flush_tlb();
105 105
106 cpu_gdt_descr[0].address = __pa(cpu_gdt_descr[0].address); 106 per_cpu(cpu_gdt_descr, 0).address =
107 load_gdt((struct Xgt_desc_struct *) __pa(&cpu_gdt_descr[0])); 107 __pa(per_cpu(cpu_gdt_descr, 0).address);
108 load_gdt((struct Xgt_desc_struct *)__pa(&per_cpu(cpu_gdt_descr, 0)));
108} 109}
109 110
110static void efi_call_phys_epilog(void) 111static void efi_call_phys_epilog(void)
111{ 112{
112 unsigned long cr4; 113 unsigned long cr4;
113 114
114 cpu_gdt_descr[0].address = 115 per_cpu(cpu_gdt_descr, 0).address =
115 (unsigned long) __va(cpu_gdt_descr[0].address); 116 (unsigned long)__va(per_cpu(cpu_gdt_descr, 0).address);
116 load_gdt(&cpu_gdt_descr[0]); 117 load_gdt((struct Xgt_desc_struct *)__va(&per_cpu(cpu_gdt_descr, 0)));
118
117 cr4 = read_cr4(); 119 cr4 = read_cr4();
118 120
119 if (cr4 & X86_CR4_PSE) { 121 if (cr4 & X86_CR4_PSE) {
diff --git a/arch/i386/kernel/head.S b/arch/i386/kernel/head.S
index 2bee6499edd..e0b7c632efb 100644
--- a/arch/i386/kernel/head.S
+++ b/arch/i386/kernel/head.S
@@ -534,5 +534,3 @@ ENTRY(cpu_gdt_table)
534 .quad 0x0000000000000000 /* 0xf0 - unused */ 534 .quad 0x0000000000000000 /* 0xf0 - unused */
535 .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */ 535 .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
536 536
537 /* Be sure this is zeroed to avoid false validations in Xen */
538 .fill PAGE_SIZE_asm / 8 - GDT_ENTRIES,8,0
diff --git a/arch/i386/kernel/i386_ksyms.c b/arch/i386/kernel/i386_ksyms.c
index 3999bec50c3..055325056a7 100644
--- a/arch/i386/kernel/i386_ksyms.c
+++ b/arch/i386/kernel/i386_ksyms.c
@@ -3,8 +3,6 @@
3#include <asm/checksum.h> 3#include <asm/checksum.h>
4#include <asm/desc.h> 4#include <asm/desc.h>
5 5
6EXPORT_SYMBOL_GPL(cpu_gdt_descr);
7
8EXPORT_SYMBOL(__down_failed); 6EXPORT_SYMBOL(__down_failed);
9EXPORT_SYMBOL(__down_failed_interruptible); 7EXPORT_SYMBOL(__down_failed_interruptible);
10EXPORT_SYMBOL(__down_failed_trylock); 8EXPORT_SYMBOL(__down_failed_trylock);
diff --git a/arch/i386/kernel/smpboot.c b/arch/i386/kernel/smpboot.c
index fb00ab7b761..eba7f53f8b4 100644
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -898,12 +898,6 @@ static int __devinit do_boot_cpu(int apicid, int cpu)
898 unsigned long start_eip; 898 unsigned long start_eip;
899 unsigned short nmi_high = 0, nmi_low = 0; 899 unsigned short nmi_high = 0, nmi_low = 0;
900 900
901 if (!cpu_gdt_descr[cpu].address &&
902 !(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) {
903 printk("Failed to allocate GDT for CPU %d\n", cpu);
904 return 1;
905 }
906
907 ++cpucount; 901 ++cpucount;
908 902
909 /* 903 /*
diff --git a/include/asm-i386/desc.h b/include/asm-i386/desc.h
index 494e73bca09..89b8b82c82b 100644
--- a/include/asm-i386/desc.h
+++ b/include/asm-i386/desc.h
@@ -24,11 +24,13 @@ struct Xgt_desc_struct {
24 unsigned short pad; 24 unsigned short pad;
25} __attribute__ ((packed)); 25} __attribute__ ((packed));
26 26
27extern struct Xgt_desc_struct idt_descr, cpu_gdt_descr[NR_CPUS]; 27extern struct Xgt_desc_struct idt_descr;
28DECLARE_PER_CPU(struct Xgt_desc_struct, cpu_gdt_descr);
29
28 30
29static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu) 31static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
30{ 32{
31 return ((struct desc_struct *)cpu_gdt_descr[cpu].address); 33 return (struct desc_struct *)per_cpu(cpu_gdt_descr, cpu).address;
32} 34}
33 35
34#define load_TR_desc() __asm__ __volatile__("ltr %w0"::"q" (GDT_ENTRY_TSS*8)) 36#define load_TR_desc() __asm__ __volatile__("ltr %w0"::"q" (GDT_ENTRY_TSS*8))