mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guodong Xu <guodong.xu@oss.qualcomm.com>
To: Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	Deepak Gupta <debug@rivosinc.com>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-riscv@lists.infradead.org,
	Radim Krcmar <radim.krcmar@oss.qualcomm.com>,
	Conor Dooley <conor@kernel.org>,
	Charlie Jenkins <thecharlesjenkins@gmail.com>,
	Andy Chiu <tchiu@tenstorrent.com>,
	Anup Patel <anup@brainfault.org>,
	kvm-riscv@lists.infradead.org,
	Guodong Xu <guodong.xu@oss.qualcomm.com>
Subject: [PATCH] riscv: cfi: parse riscv_nousercfi before riscv_fill_hwcap()
Date: Sun, 08 Nov 2026 04:42:01 -0500	[thread overview]
Message-ID: <20261108-nousercfi-early-param-v1-1-ea22d3a60683@oss.qualcomm.com> (raw)

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@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@oss.qualcomm.com>


             reply	other threads:[~2026-11-08  9:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08  9:42 Guodong Xu [this message]
2026-11-18 20:09 ` Radim Krčmář

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=20261108-nousercfi-early-param-v1-1-ea22d3a60683@oss.qualcomm.com \
    --to=guodong.xu@oss.qualcomm.com \
    --cc=alex@ghiti.fr \
    --cc=anup@brainfault.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor@kernel.org \
    --cc=corbet@lwn.net \
    --cc=debug@rivosinc.com \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=radim.krcmar@oss.qualcomm.com \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tchiu@tenstorrent.com \
    --cc=thecharlesjenkins@gmail.com \
    /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®