Skip to contentSkip to conversation

asm-generic: cmpxchg: always inline __generic_cmpxchg_local()

PATCH New Karl Mehltretter 1 participant 1 message Oct 9 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 asm-generic: cmpxchg: always inline __generic_cmpxchg_local()

With gcc 8.1.0 and CC_OPTIMIZE_FOR_SIZE, an ARMv5 test module with 24 cmpxchg_local() callers for 1-, 2- and 4-byte values fails at modpost with an undefined wrong_size_cmpxchg.

__generic_cmpxchg_local() uses that undefined symbol to reject unsupported sizes. ARM used to force inlining of functions marked inline. With compiler-controlled inlining, gcc can emit an out-of-line copy that retains the call even for valid callers.

Mark it __always_inline so the compiler can fold each caller's constant size and remove the unsupported-size path.

Fixes 9012d011660e ("compiler: allow all arches to enable CONFIG_OPTIMIZE_INLINING")
Assisted-by LLM

---

Notes:
Sashiko noted that the generic helper still used plain inline while reviewing the cmpxchg inlining fix in my Rust ARM support series [1]. This is a separate fix against v7.3-rc1. No in-tree build failure is known.

With gcc 8.1.0, versatile_defconfig and CC_OPTIMIZE_FOR_SIZE, zImage and modules build without warnings before and after.

External test modules built through Kbuild:

before after
12 valid callers builds builds
24 or 96 valid callers fails builds
Invalid 8-byte caller fails fails

Valid callers use 1-, 2- and 4-byte values. The failures are modpost errors for undefined wrong_size_cmpxchg. The modules were built, not run.

With clang 22.1.8 and CC_OPTIMIZE_FOR_SIZE, the patched versatile_defconfig kernel builds without warnings and boots to the initramfs shell in QEMU versatilepb (ARM926EJ-S).

[1] https://lore.kernel.org/rust-for-linux/[email protected]/

 include/asm-generic/cmpxchg-local.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
include/asm-generic/cmpxchg-local.h +3 -2
index f27d66fdc00a..083f6688f137 100644
@@ -12,8 +12,9 @@ extern unsigned long wrong_size_cmpxchg(volatile void *ptr)
  * Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned
  * long parameter, supporting various types of architectures.
  */
-static inline unsigned long __generic_cmpxchg_local(volatile void *ptr,
-		unsigned long old, unsigned long new, int size)
+static __always_inline unsigned long
+__generic_cmpxchg_local(volatile void *ptr, unsigned long old,
+			unsigned long new, int size)
 {
 	unsigned long flags, prev;
 

base-commit: cee9395acd8043be0644b25c34bfa86623f2b935

Signature · 1 line
2.39.5 (Apple Git-154)