All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] riscv: hwprobe: report per-process extension availability
@ 2026-07-25  0:15 ` Andy Chiu
  0 siblings, 0 replies; 14+ messages in thread
From: Andy Chiu @ 2026-07-25  0:15 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Samuel Holland, linux-riscv
  Cc: bergner, kito.cheng, Andy Chiu, dfustini, greentime.hu,
	linux-kernel, olof

hwprobe reports whether an extension is present in hardware, not whether it
is usable by the calling process. Vector can be disabled per-process via
prctl(PR_RISCV_V_SET_CONTROL, PR_RISCV_V_VSTATE_CTRL_OFF), yet
RISCV_HWPROBE_KEY_IMA_EXT_0 still reports it. An IFUNC resolver that
dispatches to a vector routine on that basis then takes a SIGILL.

This series adds RISCV_HWPROBE_KEY_EXT_ENABLED, a positional modifier:
within one request, keys before it report present-in-hardware, keys after
it report present-and-enabled for the calling process. Both views come back
in a single call:

      [ {IMA_EXT_0}, {EXT_ENABLED}, {IMA_EXT_0} ]
          present       modifier       enabled

When V is disabled for the process, V and its V-dependent sub-extensions are
cleared from a following RISCV_HWPROBE_KEY_IMA_EXT_0, and XTHEADVECTOR is
cleared from a following RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0. The enabled
view is per-process, so requests carrying the modifier are deferred from the
vDSO to the syscall. Old kernels report the key as -1, so support is
detectable and existing users are unaffected.

The earlier documentation patch [1] clarified that userspace should discover
non-standard Vector extensions through hwprobe(2) and then use
prctl(PR_RISCV_V_GET_CONTROL) to check whether the process is actually
allowed to execute them. Requiring that separate prctl step is awkward for
the IFUNC-resolver environment, where a resolver wants to decide from the
single hwprobe query it already issues. This series folds the availability
check into hwprobe itself, so a resolver obtains present-and-enabled state
in one call.

Tested under QEMU (rv64, V enabled); the selftest passes. The disabled-V
case runs in a forked child that sets the NEXT control to off and execs a
nolibc worker, since V cannot be disabled in-place (-EPERM) and a
vector-using libc cannot run with V off. That check assumes
/proc/sys/abi/riscv_v_default_allow == 1 and skips otherwise.

[1] https://lore.kernel.org/all/20260107000609.63892-1-andybnac@gmail.com/
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220795

Patch summary:
 - Modify patch: none
 - Unchanged patch: 2, 3
 - New patch: 1

Changelog v3:
 - add a patch to fix hwprobe value leaking for vendor extensions on
   vdso (Sashiko)
 - Link to v2: https://lore.kernel.org/all/20260724183646.2363114-1-tchiu@tenstorrent.com/

Changelog v2:
 - Rebase on top of the latest riscv for-next branch (patchwork ci)
 - Hook test_avail into sifive's vendor vector extensions (Sashiko)
 - Link to v1: https://lore.kernel.org/all/20260723222109.2229089-3-tchiu@tenstorrent.com/

Andy Chiu (3):
  riscv: hwprobe: initialize pair->value in hwprobe_one_pair()
  riscv: hwprobe: export the availability of vector to user
  selftests: riscv: hwprobe: test the RISCV_HWPROBE_KEY_EXT_ENABLED
    modifier

 Documentation/arch/riscv/hwprobe.rst          |  27 +++++
 arch/riscv/include/asm/hwprobe.h              |   2 +-
 .../asm/vendor_extensions/sifive_hwprobe.h    |   6 +-
 .../asm/vendor_extensions/thead_hwprobe.h     |   6 +-
 arch/riscv/include/uapi/asm/hwprobe.h         |   2 +
 arch/riscv/kernel/sys_hwprobe.c               |  41 ++++---
 arch/riscv/kernel/vdso/hwprobe.c              |  25 +++-
 .../kernel/vendor_extensions/sifive_hwprobe.c |  16 ++-
 .../kernel/vendor_extensions/thead_hwprobe.c  |   9 +-
 .../selftests/riscv/hwprobe/.gitignore        |   2 +
 .../testing/selftests/riscv/hwprobe/Makefile  |  14 ++-
 .../selftests/riscv/hwprobe/ext-enabled.c     | 111 ++++++++++++++++++
 .../riscv/hwprobe/ext-enabled_nolibc.c        |  58 +++++++++
 13 files changed, 283 insertions(+), 36 deletions(-)
 create mode 100644 tools/testing/selftests/riscv/hwprobe/ext-enabled.c
 create mode 100644 tools/testing/selftests/riscv/hwprobe/ext-enabled_nolibc.c


base-commit: 76e885f2b89d9e88291c1864e5f89a6b180768da
prerequisite-patch-id: ecac88d39cfd235fd3bd3be495124f8156f45c5f
-- 
2.43.0


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

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

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

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25  0:15 [PATCH v3 0/3] riscv: hwprobe: report per-process extension availability Andy Chiu
2026-07-25  0:15 ` Andy Chiu
2026-07-25  0:15 ` [PATCH v3 1/3] riscv: hwprobe: initialize pair->value in hwprobe_one_pair() Andy Chiu
2026-08-05 16:56   ` Jesse Taube
2026-07-25  0:15 ` [PATCH v3 2/3] riscv: hwprobe: export the availability of vector to user Andy Chiu
2026-07-25  0:15   ` Andy Chiu
2026-08-05 17:38   ` Jesse Taube
2026-08-05 17:38     ` Jesse Taube
2026-08-13 23:38   ` Mark Harris
2026-08-13 23:38     ` Mark Harris
2026-07-25  0:15 ` [PATCH v3 3/3] selftests: riscv: hwprobe: test the RISCV_HWPROBE_KEY_EXT_ENABLED modifier Andy Chiu
2026-07-25  0:15   ` Andy Chiu
2026-08-05 19:20   ` Jesse Taube
2026-08-05 19:20     ` Jesse Taube

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.