diff options
author | Brian Gerst <brgerst@gmail.com> | 2009-01-18 10:38:58 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2009-01-18 10:38:58 -0500 |
commit | 9af45651f1f7c89942e016a1a00a7ebddfa727f8 (patch) | |
tree | a22617474a2a62bc816b97c9156c5a2fc9a566b3 /arch/x86 | |
parent | c6f5e0acd5d12ee23f701f15889872e67b47caa6 (diff) |
x86-64: Move kernelstack from PDA to per-cpu.
Also clean up PER_CPU_VAR usage in xen-asm_64.S
tj: * remove now unused stack_thread_info()
* s/kernelstack/kernel_stack/
* added FIXME comment in xen-asm_64.S
Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/ia32/ia32entry.S | 8 | ||||
-rw-r--r-- | arch/x86/include/asm/pda.h | 4 | ||||
-rw-r--r-- | arch/x86/include/asm/thread_info.h | 20 | ||||
-rw-r--r-- | arch/x86/kernel/asm-offsets_64.c | 1 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/common.c | 6 | ||||
-rw-r--r-- | arch/x86/kernel/entry_64.S | 4 | ||||
-rw-r--r-- | arch/x86/kernel/process_64.c | 4 | ||||
-rw-r--r-- | arch/x86/kernel/smpboot.c | 3 | ||||
-rw-r--r-- | arch/x86/xen/xen-asm_64.S | 23 |
9 files changed, 35 insertions, 38 deletions
diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S index 256b00b61892..9c79b2477008 100644 --- a/arch/x86/ia32/ia32entry.S +++ b/arch/x86/ia32/ia32entry.S | |||
@@ -112,8 +112,8 @@ ENTRY(ia32_sysenter_target) | |||
112 | CFI_DEF_CFA rsp,0 | 112 | CFI_DEF_CFA rsp,0 |
113 | CFI_REGISTER rsp,rbp | 113 | CFI_REGISTER rsp,rbp |
114 | SWAPGS_UNSAFE_STACK | 114 | SWAPGS_UNSAFE_STACK |
115 | movq %gs:pda_kernelstack, %rsp | 115 | movq PER_CPU_VAR(kernel_stack), %rsp |
116 | addq $(PDA_STACKOFFSET),%rsp | 116 | addq $(KERNEL_STACK_OFFSET),%rsp |
117 | /* | 117 | /* |
118 | * No need to follow this irqs on/off section: the syscall | 118 | * No need to follow this irqs on/off section: the syscall |
119 | * disabled irqs, here we enable it straight after entry: | 119 | * disabled irqs, here we enable it straight after entry: |
@@ -273,13 +273,13 @@ ENDPROC(ia32_sysenter_target) | |||
273 | ENTRY(ia32_cstar_target) | 273 | ENTRY(ia32_cstar_target) |
274 | CFI_STARTPROC32 simple | 274 | CFI_STARTPROC32 simple |
275 | CFI_SIGNAL_FRAME | 275 | CFI_SIGNAL_FRAME |
276 | CFI_DEF_CFA rsp,PDA_STACKOFFSET | 276 | CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET |
277 | CFI_REGISTER rip,rcx | 277 | CFI_REGISTER rip,rcx |
278 | /*CFI_REGISTER rflags,r11*/ | 278 | /*CFI_REGISTER rflags,r11*/ |
279 | SWAPGS_UNSAFE_STACK | 279 | SWAPGS_UNSAFE_STACK |
280 | movl %esp,%r8d | 280 | movl %esp,%r8d |
281 | CFI_REGISTER rsp,r8 | 281 | CFI_REGISTER rsp,r8 |
282 | movq %gs:pda_kernelstack,%rsp | 282 | movq PER_CPU_VAR(kernel_stack),%rsp |
283 | /* | 283 | /* |
284 | * No need to follow this irqs on/off section: the syscall | 284 | * No need to follow this irqs on/off section: the syscall |
285 | * disabled irqs and here we enable it straight after entry: | 285 | * disabled irqs and here we enable it straight after entry: |
diff --git a/arch/x86/include/asm/pda.h b/arch/x86/include/asm/pda.h index 7209302d9227..4d28ffba6e1b 100644 --- a/arch/x86/include/asm/pda.h +++ b/arch/x86/include/asm/pda.h | |||
@@ -13,7 +13,7 @@ | |||
13 | struct x8664_pda { | 13 | struct x8664_pda { |
14 | unsigned long unused1; | 14 | unsigned long unused1; |
15 | unsigned long unused2; | 15 | unsigned long unused2; |
16 | unsigned long kernelstack; /* 16 top of kernel stack for current */ | 16 | unsigned long unused3; |
17 | unsigned long oldrsp; /* 24 user rsp for system call */ | 17 | unsigned long oldrsp; /* 24 user rsp for system call */ |
18 | int irqcount; /* 32 Irq nesting counter. Starts -1 */ | 18 | int irqcount; /* 32 Irq nesting counter. Starts -1 */ |
19 | unsigned int unused6; /* 36 was cpunumber */ | 19 | unsigned int unused6; /* 36 was cpunumber */ |
@@ -44,6 +44,4 @@ extern void pda_init(int); | |||
44 | 44 | ||
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #define PDA_STACKOFFSET (5*8) | ||
48 | |||
49 | #endif /* _ASM_X86_PDA_H */ | 47 | #endif /* _ASM_X86_PDA_H */ |
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index 98789647baa9..b46f8ca007b5 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h | |||
@@ -194,25 +194,21 @@ static inline struct thread_info *current_thread_info(void) | |||
194 | 194 | ||
195 | #else /* X86_32 */ | 195 | #else /* X86_32 */ |
196 | 196 | ||
197 | #include <asm/pda.h> | 197 | #include <asm/percpu.h> |
198 | #define KERNEL_STACK_OFFSET (5*8) | ||
198 | 199 | ||
199 | /* | 200 | /* |
200 | * macros/functions for gaining access to the thread information structure | 201 | * macros/functions for gaining access to the thread information structure |
201 | * preempt_count needs to be 1 initially, until the scheduler is functional. | 202 | * preempt_count needs to be 1 initially, until the scheduler is functional. |
202 | */ | 203 | */ |
203 | #ifndef __ASSEMBLY__ | 204 | #ifndef __ASSEMBLY__ |
204 | static inline struct thread_info *current_thread_info(void) | 205 | DECLARE_PER_CPU(unsigned long, kernel_stack); |
205 | { | ||
206 | struct thread_info *ti; | ||
207 | ti = (void *)(read_pda(kernelstack) + PDA_STACKOFFSET - THREAD_SIZE); | ||
208 | return ti; | ||
209 | } | ||
210 | 206 | ||
211 | /* do not use in interrupt context */ | 207 | static inline struct thread_info *current_thread_info(void) |
212 | static inline struct thread_info *stack_thread_info(void) | ||
213 | { | 208 | { |
214 | struct thread_info *ti; | 209 | struct thread_info *ti; |
215 | asm("andq %%rsp,%0; " : "=r" (ti) : "0" (~(THREAD_SIZE - 1))); | 210 | ti = (void *)(percpu_read(kernel_stack) + |
211 | KERNEL_STACK_OFFSET - THREAD_SIZE); | ||
216 | return ti; | 212 | return ti; |
217 | } | 213 | } |
218 | 214 | ||
@@ -220,8 +216,8 @@ static inline struct thread_info *stack_thread_info(void) | |||
220 | 216 | ||
221 | /* how to get the thread information struct from ASM */ | 217 | /* how to get the thread information struct from ASM */ |
222 | #define GET_THREAD_INFO(reg) \ | 218 | #define GET_THREAD_INFO(reg) \ |
223 | movq %gs:pda_kernelstack,reg ; \ | 219 | movq PER_CPU_VAR(kernel_stack),reg ; \ |
224 | subq $(THREAD_SIZE-PDA_STACKOFFSET),reg | 220 | subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg |
225 | 221 | ||
226 | #endif | 222 | #endif |
227 | 223 | ||
diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c index 4f7a210e1e58..cafff5f4a031 100644 --- a/arch/x86/kernel/asm-offsets_64.c +++ b/arch/x86/kernel/asm-offsets_64.c | |||
@@ -49,7 +49,6 @@ int main(void) | |||
49 | BLANK(); | 49 | BLANK(); |
50 | #undef ENTRY | 50 | #undef ENTRY |
51 | #define ENTRY(entry) DEFINE(pda_ ## entry, offsetof(struct x8664_pda, entry)) | 51 | #define ENTRY(entry) DEFINE(pda_ ## entry, offsetof(struct x8664_pda, entry)) |
52 | ENTRY(kernelstack); | ||
53 | ENTRY(oldrsp); | 52 | ENTRY(oldrsp); |
54 | ENTRY(irqcount); | 53 | ENTRY(irqcount); |
55 | DEFINE(pda_size, sizeof(struct x8664_pda)); | 54 | DEFINE(pda_size, sizeof(struct x8664_pda)); |
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index b50e38d16888..06b6290088f4 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -889,6 +889,10 @@ DEFINE_PER_CPU(char *, irq_stack_ptr) = | |||
889 | per_cpu_var(irq_stack) + IRQ_STACK_SIZE - 64; | 889 | per_cpu_var(irq_stack) + IRQ_STACK_SIZE - 64; |
890 | #endif | 890 | #endif |
891 | 891 | ||
892 | DEFINE_PER_CPU(unsigned long, kernel_stack) = | ||
893 | (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE; | ||
894 | EXPORT_PER_CPU_SYMBOL(kernel_stack); | ||
895 | |||
892 | void __cpuinit pda_init(int cpu) | 896 | void __cpuinit pda_init(int cpu) |
893 | { | 897 | { |
894 | struct x8664_pda *pda = cpu_pda(cpu); | 898 | struct x8664_pda *pda = cpu_pda(cpu); |
@@ -900,8 +904,6 @@ void __cpuinit pda_init(int cpu) | |||
900 | load_pda_offset(cpu); | 904 | load_pda_offset(cpu); |
901 | 905 | ||
902 | pda->irqcount = -1; | 906 | pda->irqcount = -1; |
903 | pda->kernelstack = (unsigned long)stack_thread_info() - | ||
904 | PDA_STACKOFFSET + THREAD_SIZE; | ||
905 | 907 | ||
906 | if (cpu != 0) { | 908 | if (cpu != 0) { |
907 | if (pda->nodenumber == 0 && cpu_to_node(cpu) != NUMA_NO_NODE) | 909 | if (pda->nodenumber == 0 && cpu_to_node(cpu) != NUMA_NO_NODE) |
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S index d22677a66438..0dd45859a7a8 100644 --- a/arch/x86/kernel/entry_64.S +++ b/arch/x86/kernel/entry_64.S | |||
@@ -468,7 +468,7 @@ END(ret_from_fork) | |||
468 | ENTRY(system_call) | 468 | ENTRY(system_call) |
469 | CFI_STARTPROC simple | 469 | CFI_STARTPROC simple |
470 | CFI_SIGNAL_FRAME | 470 | CFI_SIGNAL_FRAME |
471 | CFI_DEF_CFA rsp,PDA_STACKOFFSET | 471 | CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET |
472 | CFI_REGISTER rip,rcx | 472 | CFI_REGISTER rip,rcx |
473 | /*CFI_REGISTER rflags,r11*/ | 473 | /*CFI_REGISTER rflags,r11*/ |
474 | SWAPGS_UNSAFE_STACK | 474 | SWAPGS_UNSAFE_STACK |
@@ -480,7 +480,7 @@ ENTRY(system_call) | |||
480 | ENTRY(system_call_after_swapgs) | 480 | ENTRY(system_call_after_swapgs) |
481 | 481 | ||
482 | movq %rsp,%gs:pda_oldrsp | 482 | movq %rsp,%gs:pda_oldrsp |
483 | movq %gs:pda_kernelstack,%rsp | 483 | movq PER_CPU_VAR(kernel_stack),%rsp |
484 | /* | 484 | /* |
485 | * No need to follow this irqs off/on section - it's straight | 485 | * No need to follow this irqs off/on section - it's straight |
486 | * and short: | 486 | * and short: |
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index e00c31a4b3c0..6c5f57602108 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c | |||
@@ -620,9 +620,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) | |||
620 | write_pda(oldrsp, next->usersp); | 620 | write_pda(oldrsp, next->usersp); |
621 | percpu_write(current_task, next_p); | 621 | percpu_write(current_task, next_p); |
622 | 622 | ||
623 | write_pda(kernelstack, | 623 | percpu_write(kernel_stack, |
624 | (unsigned long)task_stack_page(next_p) + | 624 | (unsigned long)task_stack_page(next_p) + |
625 | THREAD_SIZE - PDA_STACKOFFSET); | 625 | THREAD_SIZE - KERNEL_STACK_OFFSET); |
626 | #ifdef CONFIG_CC_STACKPROTECTOR | 626 | #ifdef CONFIG_CC_STACKPROTECTOR |
627 | write_pda(stack_canary, next_p->stack_canary); | 627 | write_pda(stack_canary, next_p->stack_canary); |
628 | /* | 628 | /* |
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 5854be0fb804..869b98840fd0 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c | |||
@@ -798,6 +798,9 @@ do_rest: | |||
798 | #else | 798 | #else |
799 | clear_tsk_thread_flag(c_idle.idle, TIF_FORK); | 799 | clear_tsk_thread_flag(c_idle.idle, TIF_FORK); |
800 | initial_gs = per_cpu_offset(cpu); | 800 | initial_gs = per_cpu_offset(cpu); |
801 | per_cpu(kernel_stack, cpu) = | ||
802 | (unsigned long)task_stack_page(c_idle.idle) - | ||
803 | KERNEL_STACK_OFFSET + THREAD_SIZE; | ||
801 | #endif | 804 | #endif |
802 | early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); | 805 | early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); |
803 | initial_code = (unsigned long)start_secondary; | 806 | initial_code = (unsigned long)start_secondary; |
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S index 05794c566e87..5a23e8993678 100644 --- a/arch/x86/xen/xen-asm_64.S +++ b/arch/x86/xen/xen-asm_64.S | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <asm/processor-flags.h> | 17 | #include <asm/processor-flags.h> |
18 | #include <asm/errno.h> | 18 | #include <asm/errno.h> |
19 | #include <asm/segment.h> | 19 | #include <asm/segment.h> |
20 | #include <asm/percpu.h> | ||
20 | 21 | ||
21 | #include <xen/interface/xen.h> | 22 | #include <xen/interface/xen.h> |
22 | 23 | ||
@@ -28,12 +29,10 @@ | |||
28 | 29 | ||
29 | #if 1 | 30 | #if 1 |
30 | /* | 31 | /* |
31 | x86-64 does not yet support direct access to percpu variables | 32 | FIXME: x86_64 now can support direct access to percpu variables |
32 | via a segment override, so we just need to make sure this code | 33 | via a segment override. Update xen accordingly. |
33 | never gets used | ||
34 | */ | 34 | */ |
35 | #define BUG ud2a | 35 | #define BUG ud2a |
36 | #define PER_CPU_VAR(var, off) 0xdeadbeef | ||
37 | #endif | 36 | #endif |
38 | 37 | ||
39 | /* | 38 | /* |
@@ -45,14 +44,14 @@ ENTRY(xen_irq_enable_direct) | |||
45 | BUG | 44 | BUG |
46 | 45 | ||
47 | /* Unmask events */ | 46 | /* Unmask events */ |
48 | movb $0, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) | 47 | movb $0, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask |
49 | 48 | ||
50 | /* Preempt here doesn't matter because that will deal with | 49 | /* Preempt here doesn't matter because that will deal with |
51 | any pending interrupts. The pending check may end up being | 50 | any pending interrupts. The pending check may end up being |
52 | run on the wrong CPU, but that doesn't hurt. */ | 51 | run on the wrong CPU, but that doesn't hurt. */ |
53 | 52 | ||
54 | /* Test for pending */ | 53 | /* Test for pending */ |
55 | testb $0xff, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_pending) | 54 | testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending |
56 | jz 1f | 55 | jz 1f |
57 | 56 | ||
58 | 2: call check_events | 57 | 2: call check_events |
@@ -69,7 +68,7 @@ ENDPATCH(xen_irq_enable_direct) | |||
69 | ENTRY(xen_irq_disable_direct) | 68 | ENTRY(xen_irq_disable_direct) |
70 | BUG | 69 | BUG |
71 | 70 | ||
72 | movb $1, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) | 71 | movb $1, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask |
73 | ENDPATCH(xen_irq_disable_direct) | 72 | ENDPATCH(xen_irq_disable_direct) |
74 | ret | 73 | ret |
75 | ENDPROC(xen_irq_disable_direct) | 74 | ENDPROC(xen_irq_disable_direct) |
@@ -87,7 +86,7 @@ ENDPATCH(xen_irq_disable_direct) | |||
87 | ENTRY(xen_save_fl_direct) | 86 | ENTRY(xen_save_fl_direct) |
88 | BUG | 87 | BUG |
89 | 88 | ||
90 | testb $0xff, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) | 89 | testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask |
91 | setz %ah | 90 | setz %ah |
92 | addb %ah,%ah | 91 | addb %ah,%ah |
93 | ENDPATCH(xen_save_fl_direct) | 92 | ENDPATCH(xen_save_fl_direct) |
@@ -107,13 +106,13 @@ ENTRY(xen_restore_fl_direct) | |||
107 | BUG | 106 | BUG |
108 | 107 | ||
109 | testb $X86_EFLAGS_IF>>8, %ah | 108 | testb $X86_EFLAGS_IF>>8, %ah |
110 | setz PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_mask) | 109 | setz PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask |
111 | /* Preempt here doesn't matter because that will deal with | 110 | /* Preempt here doesn't matter because that will deal with |
112 | any pending interrupts. The pending check may end up being | 111 | any pending interrupts. The pending check may end up being |
113 | run on the wrong CPU, but that doesn't hurt. */ | 112 | run on the wrong CPU, but that doesn't hurt. */ |
114 | 113 | ||
115 | /* check for unmasked and pending */ | 114 | /* check for unmasked and pending */ |
116 | cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info, XEN_vcpu_info_pending) | 115 | cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending |
117 | jz 1f | 116 | jz 1f |
118 | 2: call check_events | 117 | 2: call check_events |
119 | 1: | 118 | 1: |
@@ -196,7 +195,7 @@ ENTRY(xen_sysret64) | |||
196 | /* We're already on the usermode stack at this point, but still | 195 | /* We're already on the usermode stack at this point, but still |
197 | with the kernel gs, so we can easily switch back */ | 196 | with the kernel gs, so we can easily switch back */ |
198 | movq %rsp, %gs:pda_oldrsp | 197 | movq %rsp, %gs:pda_oldrsp |
199 | movq %gs:pda_kernelstack,%rsp | 198 | movq PER_CPU_VAR(kernel_stack),%rsp |
200 | 199 | ||
201 | pushq $__USER_DS | 200 | pushq $__USER_DS |
202 | pushq %gs:pda_oldrsp | 201 | pushq %gs:pda_oldrsp |
@@ -213,7 +212,7 @@ ENTRY(xen_sysret32) | |||
213 | /* We're already on the usermode stack at this point, but still | 212 | /* We're already on the usermode stack at this point, but still |
214 | with the kernel gs, so we can easily switch back */ | 213 | with the kernel gs, so we can easily switch back */ |
215 | movq %rsp, %gs:pda_oldrsp | 214 | movq %rsp, %gs:pda_oldrsp |
216 | movq %gs:pda_kernelstack, %rsp | 215 | movq PER_CPU_VAR(kernel_stack), %rsp |
217 | 216 | ||
218 | pushq $__USER32_DS | 217 | pushq $__USER32_DS |
219 | pushq %gs:pda_oldrsp | 218 | pushq %gs:pda_oldrsp |