[PATCH] riscv: cfi: parse riscv_nousercfi before riscv_fill_hwcap()
Guodong Xu
guodong.xu at oss.qualcomm.com
Sun Nov 8 01:42:01 PST 2026
ISA bitmaps don't honour riscv_nousercfi because the ISA bitmaps are
composed during setup_arch(), while riscv_nousercfi is a __setup()
parameter, and those are parsed from start_kernel() after setup_arch()
has returned.
As a consequence, the riscv_nousercfi test in riscv_cfilp_validate() and
riscv_cfiss_validate() always sees zero, and Zicfilp and Zicfiss stay in
the ISA bitmaps even when user CFI is disabled on the kernel command
line.
Register the option with early_param() instead. The handler now returns
0 on success, as early_param() expects. Also in this patch, reject a
bare "riscv_nousercfi" without a value, which early_param() passes in as
a NULL string.
Fixes: c9b859c4d8f5 ("riscv: add kernel command line option to opt out of user CFI")
Signed-off-by: Guodong Xu <guodong.xu at oss.qualcomm.com>
---
Tested on QEMU (rva23s64 with zicfilp and zicfiss, 4 harts).
qemu-system-riscv64 -M virt -smp 4 -cpu rva23s64,zicfilp=true,zicfiss=true
Without the patch, with 'riscv_nousercfi=all', cpuinfo and hwprobe keep
reporting the disabled extensions.
---
Documentation/admin-guide/kernel-parameters.txt | 2 +-
arch/riscv/kernel/usercfi.c | 7 +++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 0b3c140babd9..b8d9db39497e 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6714,7 +6714,7 @@ Kernel parameters
replacement properties are not found. See the Kconfig
entry for RISCV_ISA_FALLBACK.
- riscv_nousercfi=
+ riscv_nousercfi= [RISCV,EARLY]
all Disable user CFI ABI to userspace even if cpu extension
are available.
bcfi Disable user backward CFI ABI to userspace even if
diff --git a/arch/riscv/kernel/usercfi.c b/arch/riscv/kernel/usercfi.c
index 86141e5bab82..a3446d706cf1 100644
--- a/arch/riscv/kernel/usercfi.c
+++ b/arch/riscv/kernel/usercfi.c
@@ -508,6 +508,9 @@ bool is_user_lpad_enabled(void)
static int __init setup_global_riscv_enable(char *str)
{
+ if (!str)
+ return -EINVAL;
+
if (strcmp(str, "all") == 0)
riscv_nousercfi = CMDLINE_DISABLE_RISCV_USERCFI;
@@ -522,7 +525,7 @@ static int __init setup_global_riscv_enable(char *str)
str_disabled_enabled(riscv_nousercfi & CMDLINE_DISABLE_RISCV_USERCFI_BCFI),
str_disabled_enabled(riscv_nousercfi & CMDLINE_DISABLE_RISCV_USERCFI_FCFI));
- return 1;
+ return 0;
}
-__setup("riscv_nousercfi=", setup_global_riscv_enable);
+early_param("riscv_nousercfi", setup_global_riscv_enable);
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261108-nousercfi-early-param-c48f7d54c168
Best regards,
--
Guodong Xu <guodong.xu at oss.qualcomm.com>
More information about the linux-riscv
mailing list