]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
RISC-V: KVM: Allow legacy PMU access from guest
authorAtish Patra <atishp@rivosinc.com>
Fri, 16 Aug 2024 07:08:08 +0000 (00:08 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:28:51 +0000 (16:28 +0200)
commit3c39f253e2c989e4d4aee58d0e33d6f79317bf33
tree265e6a7a8acb61e02132ac78364489186ee34e90
parenta72a99da7a8f63b3d845e702ae553bae3b7888e2
RISC-V: KVM: Allow legacy PMU access from guest

[ Upstream commit 7d1ffc8b087e97dbe1985912c7a2d00e53cea169 ]

Currently, KVM traps & emulates PMU counter access only if SBI PMU
is available as the guest can only configure/read PMU counters via
SBI only. However, if SBI PMU is not enabled in the host, the
guest will fallback to the legacy PMU which will try to access
cycle/instret and result in an illegal instruction trap which
is not desired.

KVM can allow dummy emulation of cycle/instret only for the guest
if SBI PMU is not enabled in the host. The dummy emulation will
still return zero as we don't to expose the host counter values
from a guest using legacy PMU.

Fixes: a9ac6c37521f ("RISC-V: KVM: Implement trap & emulate for hpmcounters")
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20240816-kvm_pmu_fixes-v1-1-cdfce386dd93@rivosinc.com
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/riscv/include/asm/kvm_vcpu_pmu.h