Skip to content

Commit b90169b

Browse files
ubizjakIngo Molnar
authored andcommitted
x86/percpu: Do not use this_cpu_read_stable_8() for 32-bit targets
this_cpu_read_stable() macro uses __pcpu_size_call_return() that unconditionally calls this_cpu_read_stable_8() also for 32-bit targets. This usage is ivalid as it will result in the generation of 64-bit MOVQ instruction on 32-bit targets via percpu_stable_op() macro. Since there is no generic support for this_cpu_read_stable_8() for 32-bit targets, the patch defines this_cpu_read_stable_8() to BUILD_BUG() when CONFIG_X86_64 is not defined. This way, we are sure that this_cpu_read_stable_8() won't actually be used for 32-bit targets, but it is still defined to prevent build failure. Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4e5b0e8 commit b90169b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

arch/x86/include/asm/percpu.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,6 @@ do { \
423423
* actually per-thread variables implemented as per-CPU variables and
424424
* thus stable for the duration of the respective task.
425425
*/
426-
#define this_cpu_read_stable_1(pcp) percpu_stable_op(1, "mov", pcp)
427-
#define this_cpu_read_stable_2(pcp) percpu_stable_op(2, "mov", pcp)
428-
#define this_cpu_read_stable_4(pcp) percpu_stable_op(4, "mov", pcp)
429-
#define this_cpu_read_stable_8(pcp) percpu_stable_op(8, "mov", pcp)
430426
#define this_cpu_read_stable(pcp) __pcpu_size_call_return(this_cpu_read_stable_, pcp)
431427

432428
#ifdef CONFIG_USE_X86_SEG_SUPPORT
@@ -495,6 +491,10 @@ do { \
495491
#define this_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
496492
#endif /* CONFIG_USE_X86_SEG_SUPPORT */
497493

494+
#define this_cpu_read_stable_1(pcp) percpu_stable_op(1, "mov", pcp)
495+
#define this_cpu_read_stable_2(pcp) percpu_stable_op(2, "mov", pcp)
496+
#define this_cpu_read_stable_4(pcp) percpu_stable_op(4, "mov", pcp)
497+
498498
#define raw_cpu_add_1(pcp, val) percpu_add_op(1, , (pcp), val)
499499
#define raw_cpu_add_2(pcp, val) percpu_add_op(2, , (pcp), val)
500500
#define raw_cpu_add_4(pcp, val) percpu_add_op(4, , (pcp), val)
@@ -546,6 +546,8 @@ do { \
546546
* 32 bit must fall back to generic operations.
547547
*/
548548
#ifdef CONFIG_X86_64
549+
#define this_cpu_read_stable_8(pcp) percpu_stable_op(8, "mov", pcp)
550+
549551
#define raw_cpu_add_8(pcp, val) percpu_add_op(8, , (pcp), val)
550552
#define raw_cpu_and_8(pcp, val) percpu_to_op(8, , "and", (pcp), val)
551553
#define raw_cpu_or_8(pcp, val) percpu_to_op(8, , "or", (pcp), val)
@@ -561,6 +563,9 @@ do { \
561563
#define this_cpu_xchg_8(pcp, nval) this_percpu_xchg_op(pcp, nval)
562564
#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval)
563565
#define this_cpu_try_cmpxchg_8(pcp, ovalp, nval) percpu_try_cmpxchg_op(8, volatile, pcp, ovalp, nval)
566+
#else
567+
/* There is no generic 64 bit read stable operation for 32 bit targets. */
568+
#define this_cpu_read_stable_8(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
564569
#endif
565570

566571
static __always_inline bool x86_this_cpu_constant_test_bit(unsigned int nr,

0 commit comments

Comments
 (0)