aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarkko Sakkinen <jarkko.sakkinen@intel.com>2012-05-08 14:22:28 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2012-05-08 14:41:51 -0400
commit48927bbb97c7d4cf343c05827ab9ac30c60678cb (patch)
tree715b2efa48c5678ada3d02a73f87e1538fe8c9b2
parent5a8c9aebe04a78b069828d364798d5f24c5a42bd (diff)
x86, realmode: Move SMP trampoline to unified realmode code
Migrated SMP trampoline code to the real mode blob. SMP trampoline code is not yet removed from .x86_trampoline because it is needed by the wakeup code. [ hpa: always enable compiling startup_32_smp in head_32.S... it is only a few instructions which go into .init on UP builds, and it makes the rest of the code less #ifdef ugly. ] Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@intel.com> Link: http://lkml.kernel.org/r/1336501366-28617-6-git-send-email-jarkko.sakkinen@intel.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--arch/x86/include/asm/realmode.h18
-rw-r--r--arch/x86/kernel/head_32.S5
-rw-r--r--arch/x86/kernel/head_64.S4
-rw-r--r--arch/x86/kernel/realmode.c14
-rw-r--r--arch/x86/kernel/smpboot.c18
-rw-r--r--arch/x86/realmode/rm/Makefile1
-rw-r--r--arch/x86/realmode/rm/header.S11
-rw-r--r--arch/x86/realmode/rm/trampoline_32.S86
-rw-r--r--arch/x86/realmode/rm/trampoline_64.S175
9 files changed, 316 insertions, 16 deletions
diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
index bf26b0681931..9b4a5da5e22e 100644
--- a/arch/x86/include/asm/realmode.h
+++ b/arch/x86/include/asm/realmode.h
@@ -13,6 +13,17 @@ struct real_mode_header {
13#ifdef CONFIG_X86_32 13#ifdef CONFIG_X86_32
14 u32 machine_real_restart_asm; 14 u32 machine_real_restart_asm;
15#endif 15#endif
16 /* SMP trampoline */
17 u32 trampoline_data;
18 u32 trampoline_status;
19#ifdef CONFIG_X86_32
20 u32 startup_32_smp;
21 u32 boot_gdt;
22#else
23 u32 startup_64_smp;
24 u32 level3_ident_pgt;
25 u32 level3_kernel_pgt;
26#endif
16} __attribute__((__packed__)); 27} __attribute__((__packed__));
17 28
18extern struct real_mode_header real_mode_header; 29extern struct real_mode_header real_mode_header;
@@ -25,6 +36,13 @@ extern unsigned long initial_gs;
25extern unsigned char real_mode_blob[]; 36extern unsigned char real_mode_blob[];
26extern unsigned char real_mode_relocs[]; 37extern unsigned char real_mode_relocs[];
27 38
39#ifdef CONFIG_X86_32
40extern unsigned char startup_32_smp[];
41extern unsigned char boot_gdt[];
42#else
43extern unsigned char secondary_startup_64[];
44#endif
45
28extern void __init setup_real_mode(void); 46extern void __init setup_real_mode(void);
29 47
30#endif /* _ARCH_X86_REALMODE_H */ 48#endif /* _ARCH_X86_REALMODE_H */
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index ce0be7cd085e..a3c2b4ffebc6 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -273,10 +273,7 @@ num_subarch_entries = (. - subarch_entries) / 4
273 * If cpu hotplug is not supported then this code can go in init section 273 * If cpu hotplug is not supported then this code can go in init section
274 * which will be freed later 274 * which will be freed later
275 */ 275 */
276
277__CPUINIT 276__CPUINIT
278
279#ifdef CONFIG_SMP
280ENTRY(startup_32_smp) 277ENTRY(startup_32_smp)
281 cld 278 cld
282 movl $(__BOOT_DS),%eax 279 movl $(__BOOT_DS),%eax
@@ -287,7 +284,7 @@ ENTRY(startup_32_smp)
287 movl pa(stack_start),%ecx 284 movl pa(stack_start),%ecx
288 movl %eax,%ss 285 movl %eax,%ss
289 leal -__PAGE_OFFSET(%ecx),%esp 286 leal -__PAGE_OFFSET(%ecx),%esp
290#endif /* CONFIG_SMP */ 287
291default_entry: 288default_entry:
292 289
293/* 290/*
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 40f4eb3766d1..d70bc2eb202b 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -136,10 +136,6 @@ ident_complete:
136 /* Fixup phys_base */ 136 /* Fixup phys_base */
137 addq %rbp, phys_base(%rip) 137 addq %rbp, phys_base(%rip)
138 138
139 /* Fixup trampoline */
140 addq %rbp, trampoline_level4_pgt + 0(%rip)
141 addq %rbp, trampoline_level4_pgt + (511*8)(%rip)
142
143 /* Due to ENTRY(), sometimes the empty space gets filled with 139 /* Due to ENTRY(), sometimes the empty space gets filled with
144 * zeros. Better take a jmp than relying on empty space being 140 * zeros. Better take a jmp than relying on empty space being
145 * filled with 0x90 (nop) 141 * filled with 0x90 (nop)
diff --git a/arch/x86/kernel/realmode.c b/arch/x86/kernel/realmode.c
index 7415c42547ac..a465775b32f2 100644
--- a/arch/x86/kernel/realmode.c
+++ b/arch/x86/kernel/realmode.c
@@ -58,6 +58,20 @@ void __init setup_real_mode(void)
58 /* Copied header will contain relocated physical addresses. */ 58 /* Copied header will contain relocated physical addresses. */
59 memcpy(&real_mode_header, real_mode_base, 59 memcpy(&real_mode_header, real_mode_base,
60 sizeof(struct real_mode_header)); 60 sizeof(struct real_mode_header));
61
62#ifdef CONFIG_X86_32
63 *((u32 *)__va(real_mode_header.startup_32_smp)) = __pa(startup_32_smp);
64 *((u32 *)__va(real_mode_header.boot_gdt)) = __pa(boot_gdt);
65#else
66 *((u64 *) __va(real_mode_header.startup_64_smp)) =
67 (u64) __pa(secondary_startup_64);
68
69 *((u64 *) __va(real_mode_header.level3_ident_pgt)) =
70 __pa(level3_ident_pgt) + _KERNPG_TABLE;
71
72 *((u64 *) __va(real_mode_header.level3_kernel_pgt)) =
73 __pa(level3_kernel_pgt) + _KERNPG_TABLE;
74#endif
61} 75}
62 76
63/* 77/*
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 6e1e406038c2..c7971ea74bd0 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -57,7 +57,7 @@
57#include <asm/nmi.h> 57#include <asm/nmi.h>
58#include <asm/irq.h> 58#include <asm/irq.h>
59#include <asm/idle.h> 59#include <asm/idle.h>
60#include <asm/trampoline.h> 60#include <asm/realmode.h>
61#include <asm/cpu.h> 61#include <asm/cpu.h>
62#include <asm/numa.h> 62#include <asm/numa.h>
63#include <asm/pgtable.h> 63#include <asm/pgtable.h>
@@ -73,6 +73,8 @@
73#include <asm/smpboot_hooks.h> 73#include <asm/smpboot_hooks.h>
74#include <asm/i8259.h> 74#include <asm/i8259.h>
75 75
76#include <asm/realmode.h>
77
76/* State of each CPU */ 78/* State of each CPU */
77DEFINE_PER_CPU(int, cpu_state) = { 0 }; 79DEFINE_PER_CPU(int, cpu_state) = { 0 };
78 80
@@ -662,8 +664,12 @@ static void __cpuinit announce_cpu(int cpu, int apicid)
662 */ 664 */
663static int __cpuinit do_boot_cpu(int apicid, int cpu) 665static int __cpuinit do_boot_cpu(int apicid, int cpu)
664{ 666{
667 volatile u32 *trampoline_status =
668 (volatile u32 *) __va(real_mode_header.trampoline_status);
669 /* start_ip had better be page-aligned! */
670 unsigned long start_ip = real_mode_header.trampoline_data;
671
665 unsigned long boot_error = 0; 672 unsigned long boot_error = 0;
666 unsigned long start_ip;
667 int timeout; 673 int timeout;
668 struct create_idle c_idle = { 674 struct create_idle c_idle = {
669 .cpu = cpu, 675 .cpu = cpu,
@@ -713,9 +719,6 @@ do_rest:
713 initial_code = (unsigned long)start_secondary; 719 initial_code = (unsigned long)start_secondary;
714 stack_start = c_idle.idle->thread.sp; 720 stack_start = c_idle.idle->thread.sp;
715 721
716 /* start_ip had better be page-aligned! */
717 start_ip = trampoline_address();
718
719 /* So we see what's up */ 722 /* So we see what's up */
720 announce_cpu(cpu, apicid); 723 announce_cpu(cpu, apicid);
721 724
@@ -778,8 +781,7 @@ do_rest:
778 pr_debug("CPU%d: has booted.\n", cpu); 781 pr_debug("CPU%d: has booted.\n", cpu);
779 } else { 782 } else {
780 boot_error = 1; 783 boot_error = 1;
781 if (*(volatile u32 *)TRAMPOLINE_SYM(trampoline_status) 784 if (*trampoline_status == 0xA5A5A5A5)
782 == 0xA5A5A5A5)
783 /* trampoline started but...? */ 785 /* trampoline started but...? */
784 pr_err("CPU%d: Stuck ??\n", cpu); 786 pr_err("CPU%d: Stuck ??\n", cpu);
785 else 787 else
@@ -805,7 +807,7 @@ do_rest:
805 } 807 }
806 808
807 /* mark "stuck" area as not stuck */ 809 /* mark "stuck" area as not stuck */
808 *(volatile u32 *)TRAMPOLINE_SYM(trampoline_status) = 0; 810 *trampoline_status = 0;
809 811
810 if (get_uv_system_type() != UV_NON_UNIQUE_APIC) { 812 if (get_uv_system_type() != UV_NON_UNIQUE_APIC) {
811 /* 813 /*
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index 3f851c488593..56ec64f94e69 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -13,6 +13,7 @@ always := realmode.bin
13 13
14realmode-y += header.o 14realmode-y += header.o
15realmode-$(CONFIG_X86_32) += reboot_32.o 15realmode-$(CONFIG_X86_32) += reboot_32.o
16realmode-y += trampoline_$(BITS).o
16 17
17targets += $(realmode-y) 18targets += $(realmode-y)
18 19
diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
index db21401c0c57..a97900409c61 100644
--- a/arch/x86/realmode/rm/header.S
+++ b/arch/x86/realmode/rm/header.S
@@ -16,4 +16,15 @@ ENTRY(real_mode_header)
16#ifdef CONFIG_X86_32 16#ifdef CONFIG_X86_32
17 .long pa_machine_real_restart_asm 17 .long pa_machine_real_restart_asm
18#endif 18#endif
19 /* SMP trampoline */
20 .long pa_trampoline_data
21 .long pa_trampoline_status
22#ifdef CONFIG_X86_32
23 .long pa_startup_32_smp
24 .long pa_boot_gdt
25#else
26 .long pa_startup_64_smp
27 .long pa_level3_ident_pgt
28 .long pa_level3_kernel_pgt
29#endif
19END(real_mode_header) 30END(real_mode_header)
diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
new file mode 100644
index 000000000000..18cb7fc9fad4
--- /dev/null
+++ b/arch/x86/realmode/rm/trampoline_32.S
@@ -0,0 +1,86 @@
1/*
2 *
3 * Trampoline.S Derived from Setup.S by Linus Torvalds
4 *
5 * 4 Jan 1997 Michael Chastain: changed to gnu as.
6 *
7 * This is only used for booting secondary CPUs in SMP machine
8 *
9 * Entry: CS:IP point to the start of our code, we are
10 * in real mode with no stack, but the rest of the
11 * trampoline page to make our stack and everything else
12 * is a mystery.
13 *
14 * We jump into arch/x86/kernel/head_32.S.
15 *
16 * On entry to trampoline_data, the processor is in real mode
17 * with 16-bit addressing and 16-bit data. CS has some value
18 * and IP is zero. Thus, we load CS to the physical segment
19 * of the real mode code before doing anything further.
20 *
21 * The structure real_mode_header includes entries that need
22 * to be set up before executing this code:
23 *
24 * startup_32_smp
25 * boot_gdt
26 */
27
28#include <linux/linkage.h>
29#include <linux/init.h>
30#include <asm/segment.h>
31#include <asm/page_types.h>
32
33 .text
34 .code16
35 .globl trampoline_data
36
37 .balign PAGE_SIZE
38trampoline_data:
39 wbinvd # Needed for NUMA-Q should be harmless for others
40
41 .byte 0xea # ljmpw
42 .word 1f # Offset
43 .word real_mode_seg # Segment
441:
45 mov %cs, %ax # Code and data in the same place
46 mov %ax, %ds
47
48 cli # We should be safe anyway
49
50 movl $0xA5A5A5A5, trampoline_status
51 # write marker for master knows we're running
52
53 /* GDT tables in non default location kernel can be beyond 16MB and
54 * lgdt will not be able to load the address as in real mode default
55 * operand size is 16bit. Use lgdtl instead to force operand size
56 * to 32 bit.
57 */
58
59 lidtl boot_idt_descr # load idt with 0, 0
60 lgdtl boot_gdt_descr # load gdt with whatever is appropriate
61
62 xor %ax, %ax
63 inc %ax # protected mode (PE) bit
64 lmsw %ax # into protected mode
65
66 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
67 ljmpl *(startup_32_smp)
68
69 .data
70 .globl startup_32_smp, boot_gdt, trampoline_status
71
72boot_gdt_descr:
73 .word __BOOT_DS + 7 # gdt limit
74boot_gdt:
75 .long 0 # gdt base
76
77boot_idt_descr:
78 .word 0 # idt limit = 0
79 .long 0 # idt base = 0L
80
81trampoline_status:
82 .long 0
83
84startup_32_smp:
85 .long 0x00000000
86 .word __BOOT_CS, 0
diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
new file mode 100644
index 000000000000..063da008d520
--- /dev/null
+++ b/arch/x86/realmode/rm/trampoline_64.S
@@ -0,0 +1,175 @@
1/*
2 *
3 * Trampoline.S Derived from Setup.S by Linus Torvalds
4 *
5 * 4 Jan 1997 Michael Chastain: changed to gnu as.
6 * 15 Sept 2005 Eric Biederman: 64bit PIC support
7 *
8 * Entry: CS:IP point to the start of our code, we are
9 * in real mode with no stack, but the rest of the
10 * trampoline page to make our stack and everything else
11 * is a mystery.
12 *
13 * On entry to trampoline_data, the processor is in real mode
14 * with 16-bit addressing and 16-bit data. CS has some value
15 * and IP is zero. Thus, data addresses need to be absolute
16 * (no relocation) and are taken with regard to r_base.
17 *
18 * With the addition of trampoline_level4_pgt this code can
19 * now enter a 64bit kernel that lives at arbitrary 64bit
20 * physical addresses.
21 *
22 * If you work on this file, check the object module with objdump
23 * --full-contents --reloc to make sure there are no relocation
24 * entries.
25 */
26
27#include <linux/linkage.h>
28#include <linux/init.h>
29#include <asm/pgtable_types.h>
30#include <asm/page_types.h>
31#include <asm/msr.h>
32#include <asm/segment.h>
33#include <asm/processor-flags.h>
34
35 .text
36 .balign PAGE_SIZE
37 .code16
38
39ENTRY(trampoline_data)
40 cli # We should be safe anyway
41 wbinvd
42
43 .byte 0xea # ljmpw
44 .word 1f # Offset
45 .word real_mode_seg # Segment
461:
47 mov %cs, %ax # Code and data in the same place
48 mov %ax, %ds
49 mov %ax, %es
50 mov %ax, %ss
51
52 movl $0xA5A5A5A5, trampoline_status
53 # write marker for master knows we're running
54
55 # Setup stack
56 movw $trampoline_stack_end, %sp
57
58 call verify_cpu # Verify the cpu supports long mode
59 testl %eax, %eax # Check for return code
60 jnz no_longmode
61
62 /*
63 * GDT tables in non default location kernel can be beyond 16MB and
64 * lgdt will not be able to load the address as in real mode default
65 * operand size is 16bit. Use lgdtl instead to force operand size
66 * to 32 bit.
67 */
68
69 lidtl tidt # load idt with 0, 0
70 lgdtl tgdt # load gdt with whatever is appropriate
71
72 mov $X86_CR0_PE, %ax # protected mode (PE) bit
73 lmsw %ax # into protected mode
74
75 # flush prefetch and jump to startup_32
76 ljmpl *(startup_32_vector)
77
78no_longmode:
79 hlt
80 jmp no_longmode
81#include "../kernel/verify_cpu.S"
82
83 .code32
84 .balign 4
85ENTRY(startup_32)
86 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
87 movl %eax, %ds
88
89 movl $X86_CR4_PAE, %eax
90 movl %eax, %cr4 # Enable PAE mode
91
92 movl pa_startup_64_smp, %esi
93 movl pa_startup_64_smp_high, %edi
94
95 # Setup trampoline 4 level pagetables
96 leal pa_trampoline_level4_pgt, %eax
97 movl %eax, %cr3
98
99 movl $MSR_EFER, %ecx
100 movl $(1 << _EFER_LME), %eax # Enable Long Mode
101 xorl %edx, %edx
102 wrmsr
103
104 # Enable paging and in turn activate Long Mode
105 # Enable protected mode
106 movl $(X86_CR0_PG | X86_CR0_PE), %eax
107 movl %eax, %cr0
108
109 /*
110 * At this point we're in long mode but in 32bit compatibility mode
111 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
112 * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we use
113 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
114 */
115 ljmpl *(pa_startup_64_vector)
116
117 .code64
118 .balign 4
119ENTRY(startup_64)
120 # Now jump into the kernel using virtual addresses
121 movl %edi, %eax
122 shlq $32, %rax
123 addl %esi, %eax
124 jmp *%rax
125
126 # Careful these need to be in the same 64K segment as the above;
127tidt:
128 .word 0 # idt limit = 0
129 .word 0, 0 # idt base = 0L
130
131 # Duplicate the global descriptor table
132 # so the kernel can live anywhere
133 .balign 4
134 .globl tgdt
135tgdt:
136 .short tgdt_end - tgdt # gdt limit
137 .long pa_tgdt
138 .short 0
139 .quad 0x00cf9b000000ffff # __KERNEL32_CS
140 .quad 0x00af9b000000ffff # __KERNEL_CS
141 .quad 0x00cf93000000ffff # __KERNEL_DS
142tgdt_end:
143
144 .balign 4
145startup_32_vector:
146 .long pa_startup_32
147 .word __KERNEL32_CS, 0
148
149 .balign 4
150 .globl startup_64_vector
151startup_64_vector:
152 .long pa_startup_64
153 .word __KERNEL_CS, 0
154
155 .data
156
157 .balign 4
158ENTRY(trampoline_status)
159 .long 0
160
161trampoline_stack:
162 .org 0x1000
163trampoline_stack_end:
164
165 .globl level3_ident_pgt
166 .globl level3_kernel_pgt
167ENTRY(trampoline_level4_pgt)
168 level3_ident_pgt: .quad 0
169 .fill 510,8,0
170 level3_kernel_pgt: .quad 0
171
172 .globl startup_64_smp
173 .globl startup_64_smp_high
174startup_64_smp: .long 0
175startup_64_smp_high: .long 0