Linux Trace Kernel
 help / color / mirror / Atom feed
From: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
To: "Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Will Deacon" <will@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Chao-ying Fu" <chao-ying.fu@globalfoundries.com>,
	"Conor Dooley" <conor.dooley@microchip.com>,
	torvalds@linux-foundation.org, olof@lixom.net,
	aleksa.paunovic@htecgroup.com, arikalo@gmail.com,
	"Boqun Feng" <boqun@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Luke Nelson" <luke.r.nels@gmail.com>,
	"Xi Wang" <xi.wang@gmail.com>, "Björn Töpel" <bjorn@kernel.org>,
	"Pu Lehui" <pulehui@huawei.com>,
	"Puranjay Mohan" <puranjay@kernel.org>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Andrew Jones" <ajones@ventanamicro.com>,
	"Boqun Feng" <boqun@kernel.org>
Cc: Jisheng Zhang <jszhang@kernel.org>,
	linux-riscv@lists.infradead.org,  linux-kernel@vger.kernel.org,
	Vladimir.Kondratiev@mobileye.com,  bpf@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,  linux-doc@vger.kernel.org,
	Jonathan Corbet <corbet@lwn.net>,
	 Charlie Jenkins <thecharlesjenkins@gmail.com>,
	 Nam Cao <namcao@linutronix.de>,
	rust-for-linux@vger.kernel.org,
	 Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
Subject: [PATCH v7 5/6] riscv: hwprobe: update the vDSO data after the boot-time speed probes
Date: Wed, 18 Nov 2026 18:24:01 +0200	[thread overview]
Message-ID: <20261118-lrsc-only-v7-5-602dcf4c1921@mobileye.com> (raw)
In-Reply-To: <20261118-lrsc-only-v7-0-602dcf4c1921@mobileye.com>

init_hwprobe_vdso_data() fills the vDSO copy of the hwprobe answers at
arch_initcall_sync. The misaligned access speed probes run later, at
fs_initcall_sync, so the vDSO keeps RISCV_HWPROBE_MISALIGNED_*_UNKNOWN
for RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF and _VECTOR_PERF, and
every hwprobe() call that the vDSO answers itself, which is the common
"all CPUs" case, returns UNKNOWN where the syscall would return the
measured value.

This was handled by filling the vDSO data lazily on the first syscall,
which commit 7e14e42edfaa ("Revert "riscv: hwprobe: Fix stale vDSO
data for late-initialized keys at boot"") removed once the probes
became synchronous; the ordering between the two initcalls was left
as it was.

Split the filling out of the initcall into
riscv_hwprobe_update_vdso_data() and call it again at the end of
check_unaligned_access_all_cpus(). That still runs before
rootfs_initcall() enables usermode helpers, so no userspace can read
the vDSO data before it is complete.

Fixes: 7e14e42edfaa ("Revert "riscv: hwprobe: Fix stale vDSO data for late-initialized keys at boot"")
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 arch/riscv/include/asm/hwprobe.h           |  6 ++++++
 arch/riscv/kernel/sys_hwprobe.c            | 16 +++++++++++-----
 arch/riscv/kernel/unaligned_access_speed.c |  8 +++++---
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hwprobe.h
index 9b04377c0f98..1cc83cecbc05 100644
--- a/arch/riscv/include/asm/hwprobe.h
+++ b/arch/riscv/include/asm/hwprobe.h
@@ -43,4 +43,10 @@ static inline bool riscv_hwprobe_pair_cmp(struct riscv_hwprobe *pair,
 	return pair->value == other_pair->value;
 }
 
+#ifdef CONFIG_MMU
+void riscv_hwprobe_update_vdso_data(void);
+#else
+static inline void riscv_hwprobe_update_vdso_data(void) {}
+#endif
+
 #endif
diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c
index 52c4c2085d0a..2c64a13c5155 100644
--- a/arch/riscv/kernel/sys_hwprobe.c
+++ b/arch/riscv/kernel/sys_hwprobe.c
@@ -534,17 +534,18 @@ static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
 
 #ifdef CONFIG_MMU
 
-static int __init init_hwprobe_vdso_data(void)
+/*
+ * Fill the vDSO data with the answers for the "all CPUs" case, to save a
+ * syscall in the common case. Called once the ISA is known, and again by
+ * the boot-time probes whose results feed some of the keys.
+ */
+void __init riscv_hwprobe_update_vdso_data(void)
 {
 	struct vdso_arch_data *avd = vdso_k_arch_data;
 	u64 id_bitsmash = 0;
 	struct riscv_hwprobe pair;
 	int key;
 
-	/*
-	 * Initialize vDSO data with the answers for the "all CPUs" case, to
-	 * save a syscall in the common case.
-	 */
 	for (key = 0; key <= RISCV_HWPROBE_MAX_KEY; key++) {
 		pair.key = key;
 		hwprobe_one_pair(&pair, cpu_online_mask);
@@ -568,6 +569,11 @@ static int __init init_hwprobe_vdso_data(void)
 	 * vDSO should defer to the kernel for exotic cpu masks.
 	 */
 	avd->homogeneous_cpus = id_bitsmash != 0 && id_bitsmash != -1;
+}
+
+static int __init init_hwprobe_vdso_data(void)
+{
+	riscv_hwprobe_update_vdso_data();
 	return 0;
 }
 
diff --git a/arch/riscv/kernel/unaligned_access_speed.c b/arch/riscv/kernel/unaligned_access_speed.c
index 67f1a0371659..3a6f85e3f94c 100644
--- a/arch/riscv/kernel/unaligned_access_speed.c
+++ b/arch/riscv/kernel/unaligned_access_speed.c
@@ -393,13 +393,15 @@ static int __init check_unaligned_access_all_cpus(void)
 	modify_unaligned_access_branches(cpu_online_mask);
 	cpus_read_unlock();
 
+	/* The vDSO was filled before the probes ran; give it the results. */
+	riscv_hwprobe_update_vdso_data();
+
 	return 0;
 }
 
 /*
  * Run after clocksource_done_booting() so measure_cycles() uses a stable
- * clocksource, but before rootfs_initcall() enables usermode helpers. Those
- * helpers can reach hwprobe and populate the vDSO cache, so async hwprobe
- * probes must be registered first.
+ * clocksource, but before rootfs_initcall() enables usermode helpers, which
+ * can reach hwprobe and must see the results in the vDSO data.
  */
 fs_initcall_sync(check_unaligned_access_all_cpus);

-- 
2.43.0


  parent reply	other threads:[~2026-11-18 16:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 16:23 [PATCH v7 0/6] riscv: restrict the ISA used for atomics to avoid unsupported or slow AMO Vladimir Kondratiev
2026-11-18 16:23 ` [PATCH v7 1/6] riscv: build kernel atomics from LR/SC when Zaamo is disabled Vladimir Kondratiev
2026-11-18 16:23 ` [PATCH v7 2/6] riscv: accept the atomic extensions this kernel was built with Vladimir Kondratiev
2026-11-18 16:23 ` [PATCH v7 3/6] riscv: report the A extension when Zaamo and Zalrsc are both present Vladimir Kondratiev
2026-11-18 16:24 ` [PATCH v7 4/6] riscv, bpf: emit LR/SC loops when Zaamo is disabled Vladimir Kondratiev
2026-11-18 16:24 ` Vladimir Kondratiev [this message]
2026-11-18 16:24 ` [PATCH v7 6/6] riscv: hwprobe: report whether AMO is faster than LR/SC Vladimir Kondratiev

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=20261118-lrsc-only-v7-5-602dcf4c1921@mobileye.com \
    --to=vladimir.kondratiev@mobileye.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=ajones@ventanamicro.com \
    --cc=aleksa.paunovic@htecgroup.com \
    --cc=alex@ghiti.fr \
    --cc=aliceryhl@google.com \
    --cc=andrii@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=arikalo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn3_gh@protonmail.com \
    --cc=bjorn@kernel.org \
    --cc=boqun@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chao-ying.fu@globalfoundries.com \
    --cc=conor.dooley@microchip.com \
    --cc=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=gary@garyguo.net \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=jszhang@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=lossin@kernel.org \
    --cc=luke.r.nels@gmail.com \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=namcao@linutronix.de \
    --cc=ojeda@kernel.org \
    --cc=oleg@redhat.com \
    --cc=olof@lixom.net \
    --cc=palmer@dabbelt.com \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=pulehui@huawei.com \
    --cc=puranjay@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=song@kernel.org \
    --cc=tamird@kernel.org \
    --cc=thecharlesjenkins@gmail.com \
    --cc=tmgross@umich.edu \
    --cc=torvalds@linux-foundation.org \
    --cc=will@kernel.org \
    --cc=work@onurozkan.dev \
    --cc=xi.wang@gmail.com \
    --cc=yonghong.song@linux.dev \
    --cc=yury.norov@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