aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-06-17 19:12:40 -0400
committerTejun Heo <tj@kernel.org>2014-06-17 19:12:40 -0400
commit6fbc07bbe2b5a898532f970c5a397f8789ace0d5 (patch)
treec9b615d1c4e48b35d13bdfdef786875b45c605d9
parenteba117889ac444bea6e8270049cbaeed48169889 (diff)
percpu: invoke __verify_pcpu_ptr() from the generic part of accessors and operations
__verify_pcpu_ptr() is used to verify that a specified parameter is actually an percpu pointer by percpu accessor and operation implementations. Currently, where it's called isn't clearly defined and we just ensure that it's invoked at least once for all accessors and operations. The lack of clarity on when it should be called isn't nice and given that this is a completely generic issue, there's no reason to make archs worry about it. This patch updates __verify_pcpu_ptr() invocations such that it's always invoked from the final generic wrapper once per access or operation. As this is already the case for {raw|this}_cpu_*() definitions through __pcpu_size_*(), only the {raw|per|this}_cpu_ptr() accessors need to be updated. This change makes it unnecessary for archs to worry about __verify_pcpu_ptr(). x86's arch_raw_cpu_ptr() is updated accordingly. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Christoph Lameter <cl@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com>
-rw-r--r--arch/x86/include/asm/percpu.h1
-rw-r--r--include/linux/percpu-defs.h29
2 files changed, 21 insertions, 9 deletions
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 9bc23f18a6fa..fd472181a1d0 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -55,7 +55,6 @@
55#define arch_raw_cpu_ptr(ptr) \ 55#define arch_raw_cpu_ptr(ptr) \
56({ \ 56({ \
57 unsigned long tcp_ptr__; \ 57 unsigned long tcp_ptr__; \
58 __verify_pcpu_ptr(ptr); \
59 asm volatile("add " __percpu_arg(1) ", %0" \ 58 asm volatile("add " __percpu_arg(1) ", %0" \
60 : "=r" (tcp_ptr__) \ 59 : "=r" (tcp_ptr__) \
61 : "m" (this_cpu_off), "0" (ptr)); \ 60 : "m" (this_cpu_off), "0" (ptr)); \
diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h
index d8bb6e001c6a..c93fff16776c 100644
--- a/include/linux/percpu-defs.h
+++ b/include/linux/percpu-defs.h
@@ -191,9 +191,12 @@
191#ifndef __ASSEMBLY__ 191#ifndef __ASSEMBLY__
192 192
193/* 193/*
194 * Macro which verifies @ptr is a percpu pointer without evaluating 194 * __verify_pcpu_ptr() verifies @ptr is a percpu pointer without evaluating
195 * @ptr. This is to be used in percpu accessors to verify that the 195 * @ptr and is invoked once before a percpu area is accessed by all
196 * input parameter is a percpu pointer. 196 * accessors and operations. This is performed in the generic part of
197 * percpu and arch overrides don't need to worry about it; however, if an
198 * arch wants to implement an arch-specific percpu accessor or operation,
199 * it may use __verify_pcpu_ptr() to verify the parameters.
197 * 200 *
198 * + 0 is required in order to convert the pointer type from a 201 * + 0 is required in order to convert the pointer type from a
199 * potential array type to a pointer to a single item of the array. 202 * potential array type to a pointer to a single item of the array.
@@ -212,16 +215,26 @@ do { \
212 * pointer value. The weird cast keeps both GCC and sparse happy. 215 * pointer value. The weird cast keeps both GCC and sparse happy.
213 */ 216 */
214#define SHIFT_PERCPU_PTR(__p, __offset) \ 217#define SHIFT_PERCPU_PTR(__p, __offset) \
218 RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
219
220#define per_cpu_ptr(ptr, cpu) \
215({ \ 221({ \
216 __verify_pcpu_ptr(__p); \ 222 __verify_pcpu_ptr(ptr); \
217 RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset)); \ 223 SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu))); \
218}) 224})
219 225
220#define per_cpu_ptr(ptr, cpu) SHIFT_PERCPU_PTR(ptr, per_cpu_offset(cpu)) 226#define raw_cpu_ptr(ptr) \
221#define raw_cpu_ptr(ptr) arch_raw_cpu_ptr(ptr) 227({ \
228 __verify_pcpu_ptr(ptr); \
229 arch_raw_cpu_ptr(ptr); \
230})
222 231
223#ifdef CONFIG_DEBUG_PREEMPT 232#ifdef CONFIG_DEBUG_PREEMPT
224#define this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, my_cpu_offset) 233#define this_cpu_ptr(ptr) \
234({ \
235 __verify_pcpu_ptr(ptr); \
236 SHIFT_PERCPU_PTR(ptr, my_cpu_offset); \
237})
225#else 238#else
226#define this_cpu_ptr(ptr) raw_cpu_ptr(ptr) 239#define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
227#endif 240#endif