[PATCH v7 5/6] riscv: hwprobe: update the vDSO data after the boot-time speed probes
From: Vladimir Kondratiev
Date: Wed Nov 18 2026 - 11:24:41 EST
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@xxxxxxxxxxxx>
---
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