From: "Arnd Bergmann" <arnd@arndb.de>
To: "Kees Cook" <kees@kernel.org>
Cc: "Thomas Gleixner" <tglx@linutronix.de>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Mike Rapoport" <rppt@kernel.org>,
"Ard Biesheuvel" <ardb@kernel.org>,
"Vitaly Kuznetsov" <vkuznets@redhat.com>,
"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Rafael J . Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"Michal Wilczynski" <michal.wilczynski@intel.com>,
"Juergen Gross" <jgross@suse.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
"Roger Pau Monne" <roger.pau@citrix.com>,
"David Woodhouse" <dwmw@amazon.co.uk>,
"Usama Arif" <usama.arif@bytedance.com>,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
"Thomas Huth" <thuth@redhat.com>,
"Brian Gerst" <brgerst@gmail.com>,
kvm@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net,
platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, linux-efi@vger.kernel.org,
linux-mm@kvack.org, "Will Deacon" <will@kernel.org>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
"Gavin Shan" <gshan@redhat.com>,
"Russell King" <rmk+kernel@armlinux.org.uk>,
"James Morse" <james.morse@arm.com>,
"Oza Pawandeep" <quic_poza@quicinc.com>,
"Anshuman Khandual" <anshuman.khandual@arm.com>,
"Hans de Goede" <hansg@kernel.org>,
"Kirill A. Shutemov" <kas@kernel.org>,
"Marco Elver" <elver@google.com>,
"Andrey Konovalov" <andreyknvl@gmail.com>,
"Andrey Ryabinin" <ryabinin.a.a@gmail.com>,
"Hou Wenlong" <houwenlong.hwl@antgroup.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Masahiro Yamada" <masahiroy@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nicolas Schier" <nicolas.schier@linux.dev>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"Andy Lutomirski" <luto@kernel.org>,
"Baoquan He" <bhe@redhat.com>, "Alexander Graf" <graf@amazon.com>,
"Changyuan Lyu" <changyuanl@google.com>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Nick Desaulniers" <nick.desaulniers+lkml@gmail.com>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Bibo Mao" <maobibo@loongson.cn>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kasan-dev@googlegroups.com,
linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org,
kexec@lists.infradead.org, linux-security-module@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH v4 2/4] x86: Handle KCOV __init vs inline mismatches
Date: Tue, 29 Jul 2025 11:34:57 +0200 [thread overview]
Message-ID: <f8bcf5ce-8b8b-4555-a210-14e1974eac92@app.fastmail.com> (raw)
In-Reply-To: <20250724055029.3623499-2-kees@kernel.org>
On Thu, Jul 24, 2025, at 07:50, Kees Cook wrote:
> GCC appears to have kind of fragile inlining heuristics, in the
> sense that it can change whether or not it inlines something based on
> optimizations. It looks like the kcov instrumentation being added (or in
> this case, removed) from a function changes the optimization results,
> and some functions marked "inline" are _not_ inlined. In that case,
> we end up with __init code calling a function not marked __init, and we
> get the build warnings I'm trying to eliminate in the coming patch that
> adds __no_sanitize_coverage to __init functions:
>
> WARNING: modpost: vmlinux: section mismatch in reference: xbc_exit+0x8
> (section: .text.unlikely) -> _xbc_exit (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference:
> real_mode_size_needed+0x15 (section: .text.unlikely) ->
> real_mode_blob_end (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference:
> __set_percpu_decrypted+0x16 (section: .text.unlikely) ->
> early_set_memory_decrypted (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference:
> memblock_alloc_from+0x26 (section: .text.unlikely) ->
> memblock_alloc_try_nid (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference:
> acpi_arch_set_root_pointer+0xc (section: .text.unlikely) -> x86_init
> (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference:
> acpi_arch_get_root_pointer+0x8 (section: .text.unlikely) -> x86_init
> (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference:
> efi_config_table_is_usable+0x16 (section: .text.unlikely) ->
> xen_efi_config_table_is_usable (section: .init.text)
>
> This problem is somewhat fragile (though using either __always_inline
> or __init will deterministically solve it), but we've tripped over
> this before with GCC and the solution has usually been to just use
> __always_inline and move on.
>
> For x86 this means forcing several functions to be inline with
> __always_inline.
>
> Signed-off-by: Kees Cook <kees@kernel.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
In my randconfig tests, I got these ones as well:
WARNING: modpost: vmlinux: section mismatch in reference: early_page_ext_enabled+0x14 (section: .text.unlikely) -> early_
page_ext (section: .init.data)
x86_64-linux-ld: lm75.c:(.text+0xd25): undefined reference to `i3c_device_do_priv_xfers'
And one more with a private patch of mine.
These are the fixups that make it build for arm/arm64/x86
randconfigs for me, so you could fold them as well in
as well. I have already sent the i3c patch for upstream
but not the page_ext.h patch.
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -57,7 +57,7 @@ extern bool early_page_ext;
extern unsigned long page_ext_size;
extern void pgdat_page_ext_init(struct pglist_data *pgdat);
-static inline bool early_page_ext_enabled(void)
+static __always_inline bool early_page_ext_enabled(void)
{
return early_page_ext;
}
@@ -189,7 +189,7 @@ static inline struct page_ext *page_ext_iter_get(const struct page_ext_iter *ite
#else /* !CONFIG_PAGE_EXTENSION */
struct page_ext;
-static inline bool early_page_ext_enabled(void)
+static __always_inline bool early_page_ext_enabled(void)
{
return false;
}
--- a/include/linux/i3c/device.h
+++ b/include/linux/i3c/device.h
@@ -245,7 +245,7 @@ void i3c_driver_unregister(struct i3c_driver *drv);
*
* Return: 0 if both registrations succeeds, a negative error code otherwise.
*/
-static inline int i3c_i2c_driver_register(struct i3c_driver *i3cdrv,
+static __always_inline int i3c_i2c_driver_register(struct i3c_driver *i3cdrv,
struct i2c_driver *i2cdrv)
{
int ret;
@@ -270,7 +270,7 @@ static inline int i3c_i2c_driver_register(struct i3c_driver *i3cdrv,
* Note that when CONFIG_I3C is not enabled, this function only unregisters the
* @i2cdrv.
*/
-static inline void i3c_i2c_driver_unregister(struct i3c_driver *i3cdrv,
+static __always_inline void i3c_i2c_driver_unregister(struct i3c_driver *i3cdrv,
struct i2c_driver *i2cdrv)
{
if (IS_ENABLED(CONFIG_I3C))
As I understand, the underlying problem is less gcc inlining
being fragile, but more that gcc does not inline functions
when they have different __no_sanitize_coverage attributes.
Arnd
next prev parent reply other threads:[~2025-07-29 9:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 5:50 [PATCH v4 0/4] stackleak: Support Clang stack depth tracking Kees Cook
2025-07-24 5:50 ` [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches Kees Cook
2025-07-29 8:10 ` Will Deacon
2025-07-24 5:50 ` [PATCH v4 2/4] x86: " Kees Cook
2025-07-29 8:28 ` Mike Rapoport
2025-07-29 9:34 ` Arnd Bergmann [this message]
2025-07-24 5:50 ` [PATCH v4 3/4] init.h: Disable sanitizer coverage for __init and __head Kees Cook
2025-07-24 5:50 ` [PATCH v4 4/4] kstack_erase: Support Clang stack depth tracking Kees Cook
2025-07-24 13:08 ` Nicolas Schier
2025-07-26 0:43 ` [PATCH v4 0/4] stackleak: " Nathan Chancellor
2025-07-26 6:27 ` Kees Cook
2025-07-26 21:47 ` Kees Cook
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=f8bcf5ce-8b8b-4555-a210-14e1974eac92@app.fastmail.com \
--to=arnd@arndb.de \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=bhe@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=changyuanl@google.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw@amazon.co.uk \
--cc=elver@google.com \
--cc=gpiccoli@igalia.com \
--cc=graf@amazon.com \
--cc=gshan@redhat.com \
--cc=gustavoars@kernel.org \
--cc=hansg@kernel.org \
--cc=hdegoede@redhat.com \
--cc=hmh@hmh.eng.br \
--cc=houwenlong.hwl@antgroup.com \
--cc=hpa@zytor.com \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=james.morse@arm.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=jmorris@namei.org \
--cc=justinstitt@google.com \
--cc=kas@kernel.org \
--cc=kasan-dev@googlegroups.com \
--cc=kees@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=luto@kernel.org \
--cc=maobibo@loongson.cn \
--cc=masahiroy@kernel.org \
--cc=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=michal.wilczynski@intel.com \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=nicolas.schier@linux.dev \
--cc=paul@paul-moore.com \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=quic_poza@quicinc.com \
--cc=rafael@kernel.org \
--cc=rmk+kernel@armlinux.org.uk \
--cc=roger.pau@citrix.com \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=samitolvanen@google.com \
--cc=serge@hallyn.com \
--cc=tglx@linutronix.de \
--cc=thuth@redhat.com \
--cc=usama.arif@bytedance.com \
--cc=viresh.kumar@linaro.org \
--cc=vkuznets@redhat.com \
--cc=will@kernel.org \
--cc=x86@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