mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] asm-generic: cmpxchg: always inline __generic_cmpxchg_local()
@ 2026-10-09  8:22 Karl Mehltretter
  0 siblings, 0 replies; only message in thread
From: Karl Mehltretter @ 2026-10-09  8:22 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Karl Mehltretter, Gary Guo, linux-arch, linux-kernel

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
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---

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/asg-nSs2cg7O-znd@gmail.com/

 include/asm-generic/cmpxchg-local.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/cmpxchg-local.h b/include/asm-generic/cmpxchg-local.h
index f27d66fdc00a..083f6688f137 100644
--- a/include/asm-generic/cmpxchg-local.h
+++ b/include/asm-generic/cmpxchg-local.h
@@ -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
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-09  8:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09  8:22 [PATCH] asm-generic: cmpxchg: always inline __generic_cmpxchg_local() Karl Mehltretter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®