[PATCH v2 0/2] riscv: hwprobe: report per-process extension availability

Andy Chiu posted 2 patches an hour ago
Only 0 patches received!
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               |  36 ++++--
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, 281 insertions(+), 33 deletions(-)
create mode 100644 tools/testing/selftests/riscv/hwprobe/ext-enabled.c
create mode 100644 tools/testing/selftests/riscv/hwprobe/ext-enabled_nolibc.c
[PATCH v2 0/2] riscv: hwprobe: report per-process extension availability
Posted by Andy Chiu an hour ago
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: 1
 - Unchanged patch: 2
 - New patch: none

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 (2):
  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               |  36 ++++--
 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, 281 insertions(+), 33 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