mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Karl Mehltretter <kmehltretter@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
	Gary Guo <gary@garyguo.net>,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] asm-generic: cmpxchg: always inline __generic_cmpxchg_local()
Date: Fri,  9 Oct 2026 10:22:23 +0200	[thread overview]
Message-ID: <20261009082223.40760-1-kmehltretter@gmail.com> (raw)

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)


                 reply	other threads:[~2026-10-09  8:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261009082223.40760-1-kmehltretter@gmail.com \
    --to=kmehltretter@gmail.com \
    --cc=arnd@arndb.de \
    --cc=gary@garyguo.net \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®