All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: cfi: disable function merging if CFI is enabled
@ 2026-08-20 13:57 Gary Guo
  2026-08-20 15:58 ` Gary Guo
  0 siblings, 1 reply; 2+ messages in thread
From: Gary Guo @ 2026-08-20 13:57 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan,
	Nick Desaulniers, Bill Wendling, Justin Stitt
  Cc: kernel test robot, linux-kbuild, linux-kernel, rust-for-linux,
	llvm

From: Gary Guo <gary@garyguo.net>

In Rust doc tests, there is a dummy `__module_firmware_test_init` function
generated by the example in `module_firmware!`'s documentation, which just
returns zero. Many other documentation generates function that produces
zero. LKP test robot reports a `Flags::zeroed` instance; my local
reproduction has a `Bounded::new::<0>`.

LLVM's MergeFunctionsPass incorrectly merge functions with the same KCFI
type, causing `__module_firmware_test_init` being merged into one of the
zero-returning function. As module init is invoked via indirect function
call, KCFI is checked and this produces a KCFI failure.

I've reported this bug to upstream LLVM [1]; in the mean time, disable
function merging if CFI is enabled. No separate treatment is needed for
CONFIG_RUST_INLINE_HELPERS, as Clang does not enable function merging by
default.

Reported-by: kernel test robot <yi1.lai@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202608201017.100a4511-lkp@intel.com
Link: https://github.com/llvm/llvm-project/issues/217629 [1]
Signed-off-by: Gary Guo <gary@garyguo.net>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 4fee5ee9e9f4..0dd9a6eda739 100644
--- a/Makefile
+++ b/Makefile
@@ -1118,7 +1118,8 @@ endif
 ifdef CONFIG_RUST
 	# Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects
 	# CONFIG_CFI_ICALL_NORMALIZE_INTEGERS.
-	RUSTC_FLAGS_CFI   := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
+	# Disable function merging as LLVM incorrectly merge functions with the same KCFI type.
+	RUSTC_FLAGS_CFI   := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zmerge-functions=disabled
 	KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_CFI)
 	export RUSTC_FLAGS_CFI
 endif

base-commit: e6664f2b33db9b6811eb4cec109f06cb2b4f458d
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rust: cfi: disable function merging if CFI is enabled
  2026-08-20 13:57 [PATCH] rust: cfi: disable function merging if CFI is enabled Gary Guo
@ 2026-08-20 15:58 ` Gary Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Gary Guo @ 2026-08-20 15:58 UTC (permalink / raw)
  To: Gary Guo, Nathan Chancellor, Nicolas Schier, Miguel Ojeda,
	Boqun Feng, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan,
	Nick Desaulniers, Bill Wendling, Justin Stitt
  Cc: kernel test robot, linux-kbuild, linux-kernel, rust-for-linux,
	llvm

On Thu Aug 20, 2026 at 2:57 PM BST, Gary Guo wrote:
> From: Gary Guo <gary@garyguo.net>
>
> In Rust doc tests, there is a dummy `__module_firmware_test_init` function
> generated by the example in `module_firmware!`'s documentation, which just
> returns zero. Many other documentation generates function that produces
> zero. LKP test robot reports a `Flags::zeroed` instance; my local
> reproduction has a `Bounded::new::<0>`.
>
> LLVM's MergeFunctionsPass incorrectly merge functions with the same KCFI

This should read "with different KCFI type" (obviously).

Best,
Gary

> type, causing `__module_firmware_test_init` being merged into one of the
> zero-returning function. As module init is invoked via indirect function
> call, KCFI is checked and this produces a KCFI failure.
>
> I've reported this bug to upstream LLVM [1]; in the mean time, disable
> function merging if CFI is enabled. No separate treatment is needed for
> CONFIG_RUST_INLINE_HELPERS, as Clang does not enable function merging by
> default.
>
> Reported-by: kernel test robot <yi1.lai@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202608201017.100a4511-lkp@intel.com
> Link: https://github.com/llvm/llvm-project/issues/217629 [1]
> Signed-off-by: Gary Guo <gary@garyguo.net>
> ---
>  Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index 4fee5ee9e9f4..0dd9a6eda739 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1118,7 +1118,8 @@ endif
>  ifdef CONFIG_RUST
>  	# Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects
>  	# CONFIG_CFI_ICALL_NORMALIZE_INTEGERS.
> -	RUSTC_FLAGS_CFI   := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
> +	# Disable function merging as LLVM incorrectly merge functions with the same KCFI type.
> +	RUSTC_FLAGS_CFI   := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zmerge-functions=disabled
>  	KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_CFI)
>  	export RUSTC_FLAGS_CFI
>  endif
>
> base-commit: e6664f2b33db9b6811eb4cec109f06cb2b4f458d



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-20 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20 13:57 [PATCH] rust: cfi: disable function merging if CFI is enabled Gary Guo
2026-08-20 15:58 ` Gary Guo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.