[PATCH RFC 8/8] arm64: ftrace: Allow CALL_OPS on kCFI kernels built with Rust
From: Jose Fernandez (Anthropic)
Date: Thu Sep 03 2026 - 21:20:56 EST
Pass -Zpatchable-function-entry=M,M,.discard.patchable_function_entries
to rustc when CFI and CALL_OPS are both enabled, so Rust functions get
the same prefix NOPs as C functions. The section argument needs
Rust 1.98 [1]. Probe for it, and let ARM64_CFI_PERMITS_CALL_OPS
accept RUST=y when the probe passes.
[1] https://github.com/rust-lang/rust/pull/157445
Suggested-by: Ben Cressey <ben@xxxxxxxxxxx>
Reviewed-by: Ben Cressey <ben@xxxxxxxxxxx>
Reviewed-by: Florent Revest (Anthropic) <florent.revest@xxxxxxxxx>
Assisted-by: LLM
Signed-off-by: Jose Fernandez (Anthropic) <jose.fernandez@xxxxxxxxx>
---
arch/arm64/Kconfig | 7 ++++++-
arch/arm64/Makefile | 3 +++
rust/Makefile | 5 ++++-
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index afa566e0fa86c..cad2bdf3456ff 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -282,11 +282,16 @@ config CC_HAS_PATCHABLE_FUNCTION_ENTRY_SECTION
# https://github.com/llvm/llvm-project/pull/131230
def_bool $(cc-option,-fpatchable-function-entry=1$(comma)1$(comma).discard.patchable_function_entries)
+config RUSTC_HAS_PATCHABLE_FUNCTION_ENTRY_SECTION
+ # The section argument needs Rust 1.98.0 or later:
+ # https://github.com/rust-lang/rust/pull/157445
+ def_bool $(rustc-option,-Zpatchable-function-entry=1$(comma)1$(comma).discard.patchable_function_entries)
+
config ARM64_CFI_PERMITS_CALL_OPS
def_bool y
depends on CFI
depends on CC_HAS_PATCHABLE_FUNCTION_ENTRY_SECTION
- depends on !RUST
+ depends on !RUST || RUSTC_HAS_PATCHABLE_FUNCTION_ENTRY_SECTION
config ARM64_FUNCTION_PREFIX_NOPS
int
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 653c1ed6ef38f..b23430e2b8567 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -152,6 +152,9 @@ ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y)
-DCC_USING_PATCHABLE_FUNCTION_PREFIX=$(prefix_nops)
KBUILD_CFLAGS += $(CFI_PREFIX_CFLAGS)
export CFI_PREFIX_CFLAGS
+ # Rust functions are not patched by ftrace, but they are called indirectly
+ # from C and make indirect calls themselves, so they need the same prefix.
+ KBUILD_RUSTFLAGS += -Zpatchable-function-entry=$(prefix_nops),$(prefix_nops),.discard.patchable_function_entries
endif
else ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y)
KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
diff --git a/rust/Makefile b/rust/Makefile
index da1a7409d9845..0036cefbed76f 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -432,7 +432,10 @@ rusttest-macros: $(src)/macros/lib.rs \
+$(call if_changed,rustdoc_test)
ifdef CONFIG_CC_IS_CLANG
-bindgen_c_flags = $(c_flags)
+# bindgen generates no code, and its libclang may predate the section
+# argument of -fpatchable-function-entry that a kCFI kernel with CALL_OPS
+# passes on arm64.
+bindgen_c_flags = $(filter-out -fpatchable-function-entry=%,$(c_flags))
else
# bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC
# plugin backend and/or the Clang driver would be perfectly compatible with GCC.
--
2.52.0