summaryrefslogtreecommitdiff
path: root/arch/riscv/kvm/vcpu_pmu.c
diff options
context:
space:
mode:
authorAtish Patra <atishp@rivosinc.com>2023-02-07 01:55:24 -0800
committerAnup Patel <anup@brainfault.org>2023-02-07 20:35:55 +0530
commit470926a2900cfdc39b300d87a0ccdf037fa67b9a (patch)
treeded1957c8d4df55aabd5c90b905c1c8428d15f62 /arch/riscv/kvm/vcpu_pmu.c
parentcbddc4c4cb9e30933777dbf3bc8645399af10140 (diff)
RISC-V: KVM: Make PMU functionality depend on Sscofpmf
The privilege mode filtering feature must be available in the host so that the host can inhibit the counters while the execution is in HS mode. Otherwise, the guests may have access to critical guest information. Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Signed-off-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'arch/riscv/kvm/vcpu_pmu.c')
-rw-r--r--arch/riscv/kvm/vcpu_pmu.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c
index dc3c118efb57..921340413846 100644
--- a/arch/riscv/kvm/vcpu_pmu.c
+++ b/arch/riscv/kvm/vcpu_pmu.c
@@ -80,6 +80,14 @@ void kvm_riscv_vcpu_pmu_init(struct kvm_vcpu *vcpu)
struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
struct kvm_pmc *pmc;
+ /*
+ * PMU functionality should be only available to guests if privilege mode
+ * filtering is available in the host. Otherwise, guest will always count
+ * events while the execution is in hypervisor mode.
+ */
+ if (!riscv_isa_extension_available(NULL, SSCOFPMF))
+ return;
+
ret = riscv_pmu_get_hpm_info(&hpm_width, &num_hw_ctrs);
if (ret < 0 || !hpm_width || !num_hw_ctrs)
return;