Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: hwprobe: Register unaligned probes before usermode
@ 2026-07-21 15:05 Rui Qi
  2026-07-22  7:52 ` Nam Cao
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Rui Qi @ 2026-07-21 15:05 UTC (permalink / raw)
  To: linux-riscv
  Cc: Rui Qi, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Nam Cao, Kees Cook, Jingwei Wang, open list

The hwprobe vDSO data is populated by the first riscv_hwprobe syscall.
Some values, such as MISALIGNED_VECTOR_PERF, may depend on the async
vector unaligned access speed probe registered by
check_unaligned_access_all_cpus().

That initcall currently runs at late_initcall level. However,
rootfs_initcall enables usermode helpers before late initcalls run, so an
early helper can execute userspace and call riscv_hwprobe first.

In that case complete_hwprobe_vdso_data() consumes the initial
pending_boot_probes reference, populates the vDSO cache, and marks it
ready before the later async probe is registered. The eventual probe
result then cannot update the already-ready cache.

Move check_unaligned_access_all_cpus() to fs_initcall_sync. This still
runs after clocksource_done_booting(), so the ktime_get_mono_fast_ns()
benchmark uses a stable clocksource, but it runs before rootfs_initcall
enables usermode helpers.

Any async hwprobe probe is therefore registered before userspace can
trigger the one-time vDSO cache population.

Fixes: 6455c6c11827 ("riscv: Clean up & optimize unaligned scalar access probe")
Signed-off-by: Rui Qi <qirui.001@bytedance.com>
---
 arch/riscv/kernel/unaligned_access_speed.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/unaligned_access_speed.c b/arch/riscv/kernel/unaligned_access_speed.c
index bb57eb5d19df..ee2ac9972510 100644
--- a/arch/riscv/kernel/unaligned_access_speed.c
+++ b/arch/riscv/kernel/unaligned_access_speed.c
@@ -411,4 +411,10 @@ static int __init check_unaligned_access_all_cpus(void)
 	return 0;
 }
 
-late_initcall(check_unaligned_access_all_cpus);
+/*
+ * 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.
+ */
+fs_initcall_sync(check_unaligned_access_all_cpus);
-- 
2.20.1

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: hwprobe: Register unaligned probes before usermode
  2026-07-21 15:05 [PATCH] riscv: hwprobe: Register unaligned probes before usermode Rui Qi
@ 2026-07-22  7:52 ` Nam Cao
  2026-07-28  3:57 ` Rui Qi
  2026-08-06 18:50 ` Paul Walmsley
  2 siblings, 0 replies; 6+ messages in thread
From: Nam Cao @ 2026-07-22  7:52 UTC (permalink / raw)
  To: Rui Qi, linux-riscv
  Cc: Rui Qi, Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Kees Cook, Jingwei Wang, open list

"Rui Qi" <qirui.001@bytedance.com> writes:
> The hwprobe vDSO data is populated by the first riscv_hwprobe syscall.
> Some values, such as MISALIGNED_VECTOR_PERF, may depend on the async
> vector unaligned access speed probe registered by
> check_unaligned_access_all_cpus().
>
> That initcall currently runs at late_initcall level. However,
> rootfs_initcall enables usermode helpers before late initcalls run, so an
> early helper can execute userspace and call riscv_hwprobe first.
>
> In that case complete_hwprobe_vdso_data() consumes the initial
> pending_boot_probes reference, populates the vDSO cache, and marks it
> ready before the later async probe is registered. The eventual probe
> result then cannot update the already-ready cache.
>
> Move check_unaligned_access_all_cpus() to fs_initcall_sync. This still
> runs after clocksource_done_booting(), so the ktime_get_mono_fast_ns()
> benchmark uses a stable clocksource, but it runs before rootfs_initcall
> enables usermode helpers.
>
> Any async hwprobe probe is therefore registered before userspace can
> trigger the one-time vDSO cache population.
>
> Fixes: 6455c6c11827 ("riscv: Clean up & optimize unaligned scalar access probe")
> Signed-off-by: Rui Qi <qirui.001@bytedance.com>

Sounds reasonable.

Reviewed-by: Nam Cao <namcao@linutronix.de>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: hwprobe: Register unaligned probes before usermode
  2026-07-21 15:05 [PATCH] riscv: hwprobe: Register unaligned probes before usermode Rui Qi
  2026-07-22  7:52 ` Nam Cao
@ 2026-07-28  3:57 ` Rui Qi
  2026-08-06 18:50 ` Paul Walmsley
  2 siblings, 0 replies; 6+ messages in thread
From: Rui Qi @ 2026-07-28  3:57 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: Alexandre Ghiti, Nam Cao, Kees Cook, Jingwei Wang, linux-riscv,
	linux-kernel

Hi Palmer, Alexandre,

Gentle ping on this patch [1]. Nam has reviewed and given his
Reviewed-by. Is there anything else needed before this can be picked
up?

Thanks,
Rui

[1] https://lore.kernel.org/all/20260721150511.1607105-1-qirui.001@bytedance.com/

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: hwprobe: Register unaligned probes before usermode
  2026-07-21 15:05 [PATCH] riscv: hwprobe: Register unaligned probes before usermode Rui Qi
  2026-07-22  7:52 ` Nam Cao
  2026-07-28  3:57 ` Rui Qi
@ 2026-08-06 18:50 ` Paul Walmsley
  2026-08-07  6:07   ` Nam Cao
  2 siblings, 1 reply; 6+ messages in thread
From: Paul Walmsley @ 2026-08-06 18:50 UTC (permalink / raw)
  To: Rui Qi
  Cc: linux-riscv, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Nam Cao, Kees Cook, Jingwei Wang, open list

Hi, 

On Tue, 21 Jul 2026, Rui Qi wrote:

> The hwprobe vDSO data is populated by the first riscv_hwprobe syscall.
> Some values, such as MISALIGNED_VECTOR_PERF, may depend on the async
> vector unaligned access speed probe registered by
> check_unaligned_access_all_cpus().
> 
> That initcall currently runs at late_initcall level. However,
> rootfs_initcall enables usermode helpers before late initcalls run, so an
> early helper can execute userspace and call riscv_hwprobe first.
> 
> In that case complete_hwprobe_vdso_data() consumes the initial
> pending_boot_probes reference, populates the vDSO cache, and marks it
> ready before the later async probe is registered. The eventual probe
> result then cannot update the already-ready cache.
> 
> Move check_unaligned_access_all_cpus() to fs_initcall_sync. This still
> runs after clocksource_done_booting(), so the ktime_get_mono_fast_ns()
> benchmark uses a stable clocksource, but it runs before rootfs_initcall
> enables usermode helpers.
> 
> Any async hwprobe probe is therefore registered before userspace can
> trigger the one-time vDSO cache population.
> 
> Fixes: 6455c6c11827 ("riscv: Clean up & optimize unaligned scalar access probe")
> Signed-off-by: Rui Qi <qirui.001@bytedance.com>

Now that we've queued a patch to get rid of the async hwprobe 
infrastructure, is this patch still needed?


- Paul

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: hwprobe: Register unaligned probes before usermode
  2026-08-06 18:50 ` Paul Walmsley
@ 2026-08-07  6:07   ` Nam Cao
  2026-08-07 23:29     ` Paul Walmsley
  0 siblings, 1 reply; 6+ messages in thread
From: Nam Cao @ 2026-08-07  6:07 UTC (permalink / raw)
  To: Paul Walmsley, Rui Qi
  Cc: linux-riscv, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Kees Cook, Jingwei Wang, open list

Paul Walmsley <pjw@kernel.org> writes:
> Now that we've queued a patch to get rid of the async hwprobe 
> infrastructure, is this patch still needed?

Yes. Removing async probe only ensures probe is finished before the
kernel is done booting.

But there are usermode helpers which run while the kernel is still booting.
This patch ensures probe is done before that.

Nam

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] riscv: hwprobe: Register unaligned probes before usermode
  2026-08-07  6:07   ` Nam Cao
@ 2026-08-07 23:29     ` Paul Walmsley
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Walmsley @ 2026-08-07 23:29 UTC (permalink / raw)
  To: Nam Cao
  Cc: Paul Walmsley, Rui Qi, linux-riscv, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Kees Cook, Jingwei Wang, open list

On Fri, 7 Aug 2026, Nam Cao wrote:

> Paul Walmsley <pjw@kernel.org> writes:
> > Now that we've queued a patch to get rid of the async hwprobe 
> > infrastructure, is this patch still needed?
> 
> Yes. Removing async probe only ensures probe is finished before the
> kernel is done booting.
> 
> But there are usermode helpers which run while the kernel is still booting.
> This patch ensures probe is done before that.

Okay, thanks for taking a look.  

Thanks Rui Qi for the patch; queued for v7.2-rc with a cc: to stable.


- Paul

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-08-07 23:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-21 15:05 [PATCH] riscv: hwprobe: Register unaligned probes before usermode Rui Qi
2026-07-22  7:52 ` Nam Cao
2026-07-28  3:57 ` Rui Qi
2026-08-06 18:50 ` Paul Walmsley
2026-08-07  6:07   ` Nam Cao
2026-08-07 23:29     ` Paul Walmsley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox