Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 0/2] RISC-V: KVM: Add PMU event filter support
@ 2026-08-07  3:50 Yuhang.chen
  2026-08-07  3:50 ` [PATCH 1/2] " Yuhang.chen
  2026-08-07  3:50 ` [PATCH 2/2] RISC-V: KVM: selftests: Add PMU event filter test Yuhang.chen
  0 siblings, 2 replies; 4+ messages in thread
From: Yuhang.chen @ 2026-08-07  3:50 UTC (permalink / raw)
  To: anup
  Cc: atish.patra, palmer, pjw, aou, alex, pbonzini, shuah, kvm,
	kvm-riscv, linux-riscv, linux-kernel, linux-kselftest, zhouquan,
	Yuhang.chen

This series adds PMU event filter support to RISC-V KVM, allowing a
userspace VMM to restrict which SBI PMU events a guest is permitted to
program.

The KVM_SET_PMU_EVENT_FILTER ioctl and KVM_CAP_PMU_EVENT_FILTER already
exist as generic KVM uAPI (include/uapi/linux/kvm.h); RISC-V KVM does
not yet implement them.  Wiring them up lets a VMM limit a guest's PMU
event access, which is useful for sandboxing and for withholding host
PMU events the host does not intend to expose.

Patch 1 implements the kernel side: the uapi struct, the ioctl handler
with an SRCU-protected filter, enforcement in
kvm_riscv_vcpu_pmu_ctr_cfg_match() (a disallowed event fails with
SBI_ERR_NOT_SUPPORTED), and advertisement of KVM_CAP_PMU_EVENT_FILTER.

Patch 2 adds a selftest that covers the ALLOW/DENY semantics with the
event in and out of the list, filter clearing, and ioctl argument
rejection (EINVAL/E2BIG).

Testing: built and run under QEMU TCG with nested KVM (an L1 KVM host
running an L2 guest).  The selftest (patch 2) passes - all ALLOW/DENY
and argument-validation cases behave as expected - and dmesg stays
clean throughout the run.

Based on v7.2-rc2 (a635d6748234).

Assisted-by: YuanSheng:deepseek-v4-pro
Co-developed-by: Quan Zhou <zhouquan@iscas.ac.cn>
Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
Signed-off-by: Yuhang.chen <yhchen312@gmail.com>

Yuhang.chen (2):
  RISC-V: KVM: Add PMU event filter support
  RISC-V: KVM: selftests: Add PMU event filter test

 arch/riscv/include/asm/kvm_host.h             |   3 +
 arch/riscv/include/uapi/asm/kvm.h             |  20 ++
 arch/riscv/kvm/vcpu_pmu.c                     |  28 +++
 arch/riscv/kvm/vm.c                           |  66 +++++-
 tools/testing/selftests/kvm/Makefile.kvm      |   1 +
 .../kvm/riscv/pmu_event_filter_test.c         | 199 ++++++++++++++++++
 6 files changed, 316 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/kvm/riscv/pmu_event_filter_test.c

-- 
2.34.1


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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07  3:50 [PATCH 0/2] RISC-V: KVM: Add PMU event filter support Yuhang.chen
2026-08-07  3:50 ` [PATCH 1/2] " Yuhang.chen
2026-08-07  4:12   ` sashiko-bot
2026-08-07  3:50 ` [PATCH 2/2] RISC-V: KVM: selftests: Add PMU event filter test Yuhang.chen

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