The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] seq_buf: avoid clang section mismatch from seq_buf_terminate optimization
@ 2026-12-01  9:06 Arnd Bergmann
  0 siblings, 0 replies; only message in thread
From: Arnd Bergmann @ 2026-12-01  9:06 UTC (permalink / raw)
  To: Kees Cook, Nathan Chancellor, Steven Rostedt
  Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Andy Shevchenko, Randy Dunlap, Alexei Starovoitov, linux-kernel,
	llvm

From: Arnd Bergmann <arnd@arndb.de>

I observed clang-21 create a specialized version of seq_buf_terminate()
that hardcodes the 'bootup_event_seq' argument since all callers pass
the same one. Since seq_buf_terminate is not marked __init, it does
not get inlined into the caller if that is __init, but the __initdata
argument does get referenced from the specialized version, causing a
section mismatch warning:

WARNING: modpost: vmlinux: section mismatch in reference: __seq_buf_terminate+0x13 (section: .text) -> bootup_event_seq (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: seq_buf_terminate+0xda (section: .text) -> bootup_event_seq (section: .init.data)
ERROR: modpost: Section mismatches detected.
Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.

I'm unsure whether this should be considered a bug in clang or the
kernel, or what the best workaround is. The two options I considered
are:

 - mark bootup_event_seq as non-__initdata to avoid this one instance,
   slightly pessimizing this the runtime memory usage and possibly having
   the same situation elsewhere

 - mark all three functions in the call chain as __always_inline, forcing
   an inlining decision that the compiler would perhaps not make, but
   preventing other instances of this issue as well.

This is the second option.

Fixes: 7b8cd26b6aab ("seq_buf: Mark a seq_buf overflowed when terminating it loses a byte")
Link: https://lore.kernel.org/all/20261118171346.FH6VoALE-lkp@intel.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/seq_buf.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index 6b915c67d235..43bc067c82cf 100644
--- a/include/linux/seq_buf.h
+++ b/include/linux/seq_buf.h
@@ -74,7 +74,7 @@ seq_buf_has_overflowed(struct seq_buf *s)
  * seq_buf_str() terminates it, so clear whatever was not written: a writer
  * sets len to how much it filled, and anything past that was never adopted.
  */
-static inline void
+static __always_inline void
 seq_buf_set_overflow(struct seq_buf *s)
 {
 	if (s->len < s->size)
@@ -134,7 +134,7 @@ static inline unsigned int seq_buf_used(struct seq_buf *s)
  *
  * Returns: the offset of the NUL.
  */
-static inline size_t __seq_buf_terminate(struct seq_buf *s)
+static __always_inline size_t __seq_buf_terminate(struct seq_buf *s)
 {
 	size_t end;
 
@@ -240,7 +240,7 @@ static inline size_t seq_buf_strlen(struct seq_buf *s)
  * After this function is called, s->buffer is safe to use
  * in string operations.
  */
-static inline void seq_buf_terminate(struct seq_buf *s)
+static __always_inline void seq_buf_terminate(struct seq_buf *s)
 {
 	if (s->size == 0)
 		return;
-- 
2.53.0


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

only message in thread, other threads:[~2026-12-01  9:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  9:06 [PATCH] seq_buf: avoid clang section mismatch from seq_buf_terminate optimization Arnd Bergmann

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