diff options
-rw-r--r-- | arch/x86/include/asm/pda.h | 3 | ||||
-rw-r--r-- | arch/x86/include/asm/percpu.h | 127 | ||||
-rw-r--r-- | arch/x86/kernel/asm-offsets_64.c | 1 | ||||
-rw-r--r-- | arch/x86/kernel/entry_64.S | 7 | ||||
-rw-r--r-- | arch/x86/kernel/head64.c | 2 | ||||
-rw-r--r-- | arch/x86/kernel/setup_percpu.c | 15 | ||||
-rw-r--r-- | arch/x86/kernel/smpcommon.c | 3 | ||||
-rw-r--r-- | arch/x86/mach-voyager/voyager_smp.c | 2 |
8 files changed, 55 insertions, 105 deletions
diff --git a/arch/x86/include/asm/pda.h b/arch/x86/include/asm/pda.h index 2d5b49c3248e..e91558e37850 100644 --- a/arch/x86/include/asm/pda.h +++ b/arch/x86/include/asm/pda.h | |||
@@ -11,8 +11,7 @@ | |||
11 | /* Per processor datastructure. %gs points to it while the kernel runs */ | 11 | /* Per processor datastructure. %gs points to it while the kernel runs */ |
12 | struct x8664_pda { | 12 | struct x8664_pda { |
13 | struct task_struct *pcurrent; /* 0 Current process */ | 13 | struct task_struct *pcurrent; /* 0 Current process */ |
14 | unsigned long data_offset; /* 8 Per cpu data offset from linker | 14 | unsigned long dummy; |
15 | address */ | ||
16 | unsigned long kernelstack; /* 16 top of kernel stack for current */ | 15 | unsigned long kernelstack; /* 16 top of kernel stack for current */ |
17 | unsigned long oldrsp; /* 24 user rsp for system call */ | 16 | unsigned long oldrsp; /* 24 user rsp for system call */ |
18 | int irqcount; /* 32 Irq nesting counter. Starts -1 */ | 17 | int irqcount; /* 32 Irq nesting counter. Starts -1 */ |
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 0ed77cf33f76..556f84b9ea96 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h | |||
@@ -1,62 +1,13 @@ | |||
1 | #ifndef _ASM_X86_PERCPU_H | 1 | #ifndef _ASM_X86_PERCPU_H |
2 | #define _ASM_X86_PERCPU_H | 2 | #define _ASM_X86_PERCPU_H |
3 | 3 | ||
4 | #ifndef __ASSEMBLY__ | ||
5 | #ifdef CONFIG_X86_64 | 4 | #ifdef CONFIG_X86_64 |
6 | extern void load_pda_offset(int cpu); | 5 | #define __percpu_seg gs |
6 | #define __percpu_mov_op movq | ||
7 | #else | 7 | #else |
8 | static inline void load_pda_offset(int cpu) { } | 8 | #define __percpu_seg fs |
9 | #endif | 9 | #define __percpu_mov_op movl |
10 | #endif | ||
11 | |||
12 | #ifdef CONFIG_X86_64 | ||
13 | #include <linux/compiler.h> | ||
14 | |||
15 | /* Same as asm-generic/percpu.h, except that we store the per cpu offset | ||
16 | in the PDA. Longer term the PDA and every per cpu variable | ||
17 | should be just put into a single section and referenced directly | ||
18 | from %gs */ | ||
19 | |||
20 | #ifdef CONFIG_SMP | ||
21 | #include <asm/pda.h> | ||
22 | |||
23 | #define __per_cpu_offset(cpu) (cpu_pda(cpu)->data_offset) | ||
24 | #define __my_cpu_offset read_pda(data_offset) | ||
25 | |||
26 | #define per_cpu_offset(x) (__per_cpu_offset(x)) | ||
27 | |||
28 | #endif | 10 | #endif |
29 | #include <asm-generic/percpu.h> | ||
30 | |||
31 | DECLARE_PER_CPU(struct x8664_pda, pda); | ||
32 | |||
33 | /* | ||
34 | * These are supposed to be implemented as a single instruction which | ||
35 | * operates on the per-cpu data base segment. x86-64 doesn't have | ||
36 | * that yet, so this is a fairly inefficient workaround for the | ||
37 | * meantime. The single instruction is atomic with respect to | ||
38 | * preemption and interrupts, so we need to explicitly disable | ||
39 | * interrupts here to achieve the same effect. However, because it | ||
40 | * can be used from within interrupt-disable/enable, we can't actually | ||
41 | * disable interrupts; disabling preemption is enough. | ||
42 | */ | ||
43 | #define x86_read_percpu(var) \ | ||
44 | ({ \ | ||
45 | typeof(per_cpu_var(var)) __tmp; \ | ||
46 | preempt_disable(); \ | ||
47 | __tmp = __get_cpu_var(var); \ | ||
48 | preempt_enable(); \ | ||
49 | __tmp; \ | ||
50 | }) | ||
51 | |||
52 | #define x86_write_percpu(var, val) \ | ||
53 | do { \ | ||
54 | preempt_disable(); \ | ||
55 | __get_cpu_var(var) = (val); \ | ||
56 | preempt_enable(); \ | ||
57 | } while(0) | ||
58 | |||
59 | #else /* CONFIG_X86_64 */ | ||
60 | 11 | ||
61 | #ifdef __ASSEMBLY__ | 12 | #ifdef __ASSEMBLY__ |
62 | 13 | ||
@@ -73,42 +24,26 @@ DECLARE_PER_CPU(struct x8664_pda, pda); | |||
73 | * PER_CPU(cpu_gdt_descr, %ebx) | 24 | * PER_CPU(cpu_gdt_descr, %ebx) |
74 | */ | 25 | */ |
75 | #ifdef CONFIG_SMP | 26 | #ifdef CONFIG_SMP |
76 | #define PER_CPU(var, reg) \ | 27 | #define PER_CPU(var, reg) \ |
77 | movl %fs:per_cpu__##this_cpu_off, reg; \ | 28 | __percpu_mov_op %__percpu_seg:per_cpu__this_cpu_off, reg; \ |
78 | lea per_cpu__##var(reg), reg | 29 | lea per_cpu__##var(reg), reg |
79 | #define PER_CPU_VAR(var) %fs:per_cpu__##var | 30 | #define PER_CPU_VAR(var) %__percpu_seg:per_cpu__##var |
80 | #else /* ! SMP */ | 31 | #else /* ! SMP */ |
81 | #define PER_CPU(var, reg) \ | 32 | #define PER_CPU(var, reg) \ |
82 | movl $per_cpu__##var, reg | 33 | __percpu_mov_op $per_cpu__##var, reg |
83 | #define PER_CPU_VAR(var) per_cpu__##var | 34 | #define PER_CPU_VAR(var) per_cpu__##var |
84 | #endif /* SMP */ | 35 | #endif /* SMP */ |
85 | 36 | ||
86 | #else /* ...!ASSEMBLY */ | 37 | #else /* ...!ASSEMBLY */ |
87 | 38 | ||
88 | /* | 39 | #include <linux/stringify.h> |
89 | * PER_CPU finds an address of a per-cpu variable. | ||
90 | * | ||
91 | * Args: | ||
92 | * var - variable name | ||
93 | * cpu - 32bit register containing the current CPU number | ||
94 | * | ||
95 | * The resulting address is stored in the "cpu" argument. | ||
96 | * | ||
97 | * Example: | ||
98 | * PER_CPU(cpu_gdt_descr, %ebx) | ||
99 | */ | ||
100 | #ifdef CONFIG_SMP | ||
101 | |||
102 | #define __my_cpu_offset x86_read_percpu(this_cpu_off) | ||
103 | |||
104 | /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */ | ||
105 | #define __percpu_seg "%%fs:" | ||
106 | 40 | ||
107 | #else /* !SMP */ | 41 | #ifdef CONFIG_SMP |
108 | 42 | #define __percpu_seg_str "%%"__stringify(__percpu_seg)":" | |
109 | #define __percpu_seg "" | 43 | #define __my_cpu_offset x86_read_percpu(this_cpu_off) |
110 | 44 | #else | |
111 | #endif /* SMP */ | 45 | #define __percpu_seg_str |
46 | #endif | ||
112 | 47 | ||
113 | #include <asm-generic/percpu.h> | 48 | #include <asm-generic/percpu.h> |
114 | 49 | ||
@@ -128,20 +63,25 @@ do { \ | |||
128 | } \ | 63 | } \ |
129 | switch (sizeof(var)) { \ | 64 | switch (sizeof(var)) { \ |
130 | case 1: \ | 65 | case 1: \ |
131 | asm(op "b %1,"__percpu_seg"%0" \ | 66 | asm(op "b %1,"__percpu_seg_str"%0" \ |
132 | : "+m" (var) \ | 67 | : "+m" (var) \ |
133 | : "ri" ((T__)val)); \ | 68 | : "ri" ((T__)val)); \ |
134 | break; \ | 69 | break; \ |
135 | case 2: \ | 70 | case 2: \ |
136 | asm(op "w %1,"__percpu_seg"%0" \ | 71 | asm(op "w %1,"__percpu_seg_str"%0" \ |
137 | : "+m" (var) \ | 72 | : "+m" (var) \ |
138 | : "ri" ((T__)val)); \ | 73 | : "ri" ((T__)val)); \ |
139 | break; \ | 74 | break; \ |
140 | case 4: \ | 75 | case 4: \ |
141 | asm(op "l %1,"__percpu_seg"%0" \ | 76 | asm(op "l %1,"__percpu_seg_str"%0" \ |
142 | : "+m" (var) \ | 77 | : "+m" (var) \ |
143 | : "ri" ((T__)val)); \ | 78 | : "ri" ((T__)val)); \ |
144 | break; \ | 79 | break; \ |
80 | case 8: \ | ||
81 | asm(op "q %1,"__percpu_seg_str"%0" \ | ||
82 | : "+m" (var) \ | ||
83 | : "r" ((T__)val)); \ | ||
84 | break; \ | ||
145 | default: __bad_percpu_size(); \ | 85 | default: __bad_percpu_size(); \ |
146 | } \ | 86 | } \ |
147 | } while (0) | 87 | } while (0) |
@@ -151,17 +91,22 @@ do { \ | |||
151 | typeof(var) ret__; \ | 91 | typeof(var) ret__; \ |
152 | switch (sizeof(var)) { \ | 92 | switch (sizeof(var)) { \ |
153 | case 1: \ | 93 | case 1: \ |
154 | asm(op "b "__percpu_seg"%1,%0" \ | 94 | asm(op "b "__percpu_seg_str"%1,%0" \ |
155 | : "=r" (ret__) \ | 95 | : "=r" (ret__) \ |
156 | : "m" (var)); \ | 96 | : "m" (var)); \ |
157 | break; \ | 97 | break; \ |
158 | case 2: \ | 98 | case 2: \ |
159 | asm(op "w "__percpu_seg"%1,%0" \ | 99 | asm(op "w "__percpu_seg_str"%1,%0" \ |
160 | : "=r" (ret__) \ | 100 | : "=r" (ret__) \ |
161 | : "m" (var)); \ | 101 | : "m" (var)); \ |
162 | break; \ | 102 | break; \ |
163 | case 4: \ | 103 | case 4: \ |
164 | asm(op "l "__percpu_seg"%1,%0" \ | 104 | asm(op "l "__percpu_seg_str"%1,%0" \ |
105 | : "=r" (ret__) \ | ||
106 | : "m" (var)); \ | ||
107 | break; \ | ||
108 | case 8: \ | ||
109 | asm(op "q "__percpu_seg_str"%1,%0" \ | ||
165 | : "=r" (ret__) \ | 110 | : "=r" (ret__) \ |
166 | : "m" (var)); \ | 111 | : "m" (var)); \ |
167 | break; \ | 112 | break; \ |
@@ -175,8 +120,14 @@ do { \ | |||
175 | #define x86_add_percpu(var, val) percpu_to_op("add", per_cpu__##var, val) | 120 | #define x86_add_percpu(var, val) percpu_to_op("add", per_cpu__##var, val) |
176 | #define x86_sub_percpu(var, val) percpu_to_op("sub", per_cpu__##var, val) | 121 | #define x86_sub_percpu(var, val) percpu_to_op("sub", per_cpu__##var, val) |
177 | #define x86_or_percpu(var, val) percpu_to_op("or", per_cpu__##var, val) | 122 | #define x86_or_percpu(var, val) percpu_to_op("or", per_cpu__##var, val) |
123 | |||
124 | #ifdef CONFIG_X86_64 | ||
125 | extern void load_pda_offset(int cpu); | ||
126 | #else | ||
127 | static inline void load_pda_offset(int cpu) { } | ||
128 | #endif | ||
129 | |||
178 | #endif /* !__ASSEMBLY__ */ | 130 | #endif /* !__ASSEMBLY__ */ |
179 | #endif /* !CONFIG_X86_64 */ | ||
180 | 131 | ||
181 | #ifdef CONFIG_SMP | 132 | #ifdef CONFIG_SMP |
182 | 133 | ||
diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c index f8d1b047ef4f..f4cc81bfbf89 100644 --- a/arch/x86/kernel/asm-offsets_64.c +++ b/arch/x86/kernel/asm-offsets_64.c | |||
@@ -55,7 +55,6 @@ int main(void) | |||
55 | ENTRY(irqcount); | 55 | ENTRY(irqcount); |
56 | ENTRY(cpunumber); | 56 | ENTRY(cpunumber); |
57 | ENTRY(irqstackptr); | 57 | ENTRY(irqstackptr); |
58 | ENTRY(data_offset); | ||
59 | DEFINE(pda_size, sizeof(struct x8664_pda)); | 58 | DEFINE(pda_size, sizeof(struct x8664_pda)); |
60 | BLANK(); | 59 | BLANK(); |
61 | #undef ENTRY | 60 | #undef ENTRY |
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S index e28c7a987793..4833f3a19650 100644 --- a/arch/x86/kernel/entry_64.S +++ b/arch/x86/kernel/entry_64.S | |||
@@ -52,6 +52,7 @@ | |||
52 | #include <asm/irqflags.h> | 52 | #include <asm/irqflags.h> |
53 | #include <asm/paravirt.h> | 53 | #include <asm/paravirt.h> |
54 | #include <asm/ftrace.h> | 54 | #include <asm/ftrace.h> |
55 | #include <asm/percpu.h> | ||
55 | 56 | ||
56 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ | 57 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
57 | #include <linux/elf-em.h> | 58 | #include <linux/elf-em.h> |
@@ -1072,10 +1073,10 @@ ENTRY(\sym) | |||
1072 | TRACE_IRQS_OFF | 1073 | TRACE_IRQS_OFF |
1073 | movq %rsp,%rdi /* pt_regs pointer */ | 1074 | movq %rsp,%rdi /* pt_regs pointer */ |
1074 | xorl %esi,%esi /* no error code */ | 1075 | xorl %esi,%esi /* no error code */ |
1075 | movq %gs:pda_data_offset, %rbp | 1076 | PER_CPU(init_tss, %rbp) |
1076 | subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | 1077 | subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp) |
1077 | call \do_sym | 1078 | call \do_sym |
1078 | addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) | 1079 | addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp) |
1079 | jmp paranoid_exit /* %ebx: no swapgs flag */ | 1080 | jmp paranoid_exit /* %ebx: no swapgs flag */ |
1080 | CFI_ENDPROC | 1081 | CFI_ENDPROC |
1081 | END(\sym) | 1082 | END(\sym) |
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 1a311293f733..e99b661a97f4 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c | |||
@@ -38,8 +38,6 @@ void __init x86_64_init_pda(void) | |||
38 | #else | 38 | #else |
39 | cpu_pda(0) = &_boot_cpu_pda; | 39 | cpu_pda(0) = &_boot_cpu_pda; |
40 | #endif | 40 | #endif |
41 | cpu_pda(0)->data_offset = | ||
42 | (unsigned long)(__per_cpu_load - __per_cpu_start); | ||
43 | pda_init(0); | 41 | pda_init(0); |
44 | } | 42 | } |
45 | 43 | ||
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c index 63d462802272..be1ff34db112 100644 --- a/arch/x86/kernel/setup_percpu.c +++ b/arch/x86/kernel/setup_percpu.c | |||
@@ -125,14 +125,14 @@ static void __init setup_per_cpu_maps(void) | |||
125 | #endif | 125 | #endif |
126 | } | 126 | } |
127 | 127 | ||
128 | #ifdef CONFIG_X86_32 | 128 | #ifdef CONFIG_X86_64 |
129 | /* | 129 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = { |
130 | * Great future not-so-futuristic plan: make i386 and x86_64 do it | 130 | [0] = (unsigned long)__per_cpu_load, |
131 | * the same way | 131 | }; |
132 | */ | 132 | #else |
133 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; | 133 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
134 | EXPORT_SYMBOL(__per_cpu_offset); | ||
135 | #endif | 134 | #endif |
135 | EXPORT_SYMBOL(__per_cpu_offset); | ||
136 | 136 | ||
137 | /* | 137 | /* |
138 | * Great future plan: | 138 | * Great future plan: |
@@ -178,6 +178,7 @@ void __init setup_per_cpu_areas(void) | |||
178 | #endif | 178 | #endif |
179 | 179 | ||
180 | memcpy(ptr, __per_cpu_load, __per_cpu_end - __per_cpu_start); | 180 | memcpy(ptr, __per_cpu_load, __per_cpu_end - __per_cpu_start); |
181 | per_cpu_offset(cpu) = ptr - __per_cpu_start; | ||
181 | #ifdef CONFIG_X86_64 | 182 | #ifdef CONFIG_X86_64 |
182 | cpu_pda(cpu) = (void *)ptr; | 183 | cpu_pda(cpu) = (void *)ptr; |
183 | 184 | ||
@@ -190,7 +191,7 @@ void __init setup_per_cpu_areas(void) | |||
190 | else | 191 | else |
191 | memset(cpu_pda(cpu), 0, sizeof(*cpu_pda(cpu))); | 192 | memset(cpu_pda(cpu), 0, sizeof(*cpu_pda(cpu))); |
192 | #endif | 193 | #endif |
193 | per_cpu_offset(cpu) = ptr - __per_cpu_start; | 194 | per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu); |
194 | 195 | ||
195 | DBG("PERCPU: cpu %4d %p\n", cpu, ptr); | 196 | DBG("PERCPU: cpu %4d %p\n", cpu, ptr); |
196 | } | 197 | } |
diff --git a/arch/x86/kernel/smpcommon.c b/arch/x86/kernel/smpcommon.c index 397e309839dd..84395fabc410 100644 --- a/arch/x86/kernel/smpcommon.c +++ b/arch/x86/kernel/smpcommon.c | |||
@@ -4,10 +4,10 @@ | |||
4 | #include <linux/module.h> | 4 | #include <linux/module.h> |
5 | #include <asm/smp.h> | 5 | #include <asm/smp.h> |
6 | 6 | ||
7 | #ifdef CONFIG_X86_32 | ||
8 | DEFINE_PER_CPU(unsigned long, this_cpu_off); | 7 | DEFINE_PER_CPU(unsigned long, this_cpu_off); |
9 | EXPORT_PER_CPU_SYMBOL(this_cpu_off); | 8 | EXPORT_PER_CPU_SYMBOL(this_cpu_off); |
10 | 9 | ||
10 | #ifdef CONFIG_X86_32 | ||
11 | /* | 11 | /* |
12 | * Initialize the CPU's GDT. This is either the boot CPU doing itself | 12 | * Initialize the CPU's GDT. This is either the boot CPU doing itself |
13 | * (still using the master per-cpu area), or a CPU doing it for a | 13 | * (still using the master per-cpu area), or a CPU doing it for a |
@@ -24,7 +24,6 @@ __cpuinit void init_gdt(int cpu) | |||
24 | write_gdt_entry(get_cpu_gdt_table(cpu), | 24 | write_gdt_entry(get_cpu_gdt_table(cpu), |
25 | GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S); | 25 | GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S); |
26 | 26 | ||
27 | per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu]; | ||
28 | per_cpu(cpu_number, cpu) = cpu; | 27 | per_cpu(cpu_number, cpu) = cpu; |
29 | } | 28 | } |
30 | #endif | 29 | #endif |
diff --git a/arch/x86/mach-voyager/voyager_smp.c b/arch/x86/mach-voyager/voyager_smp.c index 9840b7ec749a..1a48368acb09 100644 --- a/arch/x86/mach-voyager/voyager_smp.c +++ b/arch/x86/mach-voyager/voyager_smp.c | |||
@@ -531,6 +531,7 @@ static void __init do_boot_cpu(__u8 cpu) | |||
531 | stack_start.sp = (void *)idle->thread.sp; | 531 | stack_start.sp = (void *)idle->thread.sp; |
532 | 532 | ||
533 | init_gdt(cpu); | 533 | init_gdt(cpu); |
534 | per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu]; | ||
534 | per_cpu(current_task, cpu) = idle; | 535 | per_cpu(current_task, cpu) = idle; |
535 | early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); | 536 | early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); |
536 | irq_ctx_init(cpu); | 537 | irq_ctx_init(cpu); |
@@ -1748,6 +1749,7 @@ static void __init voyager_smp_prepare_cpus(unsigned int max_cpus) | |||
1748 | static void __cpuinit voyager_smp_prepare_boot_cpu(void) | 1749 | static void __cpuinit voyager_smp_prepare_boot_cpu(void) |
1749 | { | 1750 | { |
1750 | init_gdt(smp_processor_id()); | 1751 | init_gdt(smp_processor_id()); |
1752 | per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu]; | ||
1751 | switch_to_new_gdt(); | 1753 | switch_to_new_gdt(); |
1752 | 1754 | ||
1753 | cpu_set(smp_processor_id(), cpu_online_map); | 1755 | cpu_set(smp_processor_id(), cpu_online_map); |