From: Steven Rostedt <rostedt@goodmis.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Kees Cook <kees@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Randy Dunlap <rdunlap@infradead.org>,
Alexei Starovoitov <ast@kernel.org>,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] seq_buf: avoid clang section mismatch from seq_buf_terminate optimization
Date: Tue, 1 Dec 2026 10:13:14 -0500 [thread overview]
Message-ID: <20261201101314.233335f6@gandalf.local.home> (raw)
In-Reply-To: <20261201090627.699022-1-arnd@kernel.org>
On Tue, 1 Dec 2026 10:06:16 +0100
Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> I observed clang-21 create a specialized version of seq_buf_terminate()
The above line denotes what kind of bug this is. Clang is creating a
"specialized version"!
> 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:
It's definitely a bug in clang. If it created a specialized version of a
function and that version is now causing section mismatches, that's a bug
in the compiler. The kernel did nothing wrong.
>
> - 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")
This doesn't fix that commit. It is a workaround to a clang bug.
I really don't think this should be fixed in the kernel.
-- Steve
> 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;
next prev parent reply other threads:[~2026-12-01 15:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:06 Arnd Bergmann
2026-12-01 15:13 ` Steven Rostedt [this message]
2026-12-01 21:53 ` Arnd Bergmann
2026-12-01 22:05 ` Nick Desaulniers
2026-12-01 22:17 ` Steven Rostedt
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=20261201101314.233335f6@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=ast@kernel.org \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=rdunlap@infradead.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®