From: Andrew Jones Date: Thu, 2 Feb 2023 18:30:40 +0100 Subject: [PATCH v4 09/14] RISC-V: KVM: Make PMU functionality depend on Sscofpmf In-Reply-To: <20230201231250.3806412-10-atishp@rivosinc.com> References: <20230201231250.3806412-1-atishp@rivosinc.com> <20230201231250.3806412-10-atishp@rivosinc.com> Message-ID: <20230202173040.e4rdrkdeuq7vdauk@orel> List-Id: To: kvm-riscv@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Wed, Feb 01, 2023 at 03:12:45PM -0800, Atish Patra wrote: > 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 > Signed-off-by: Atish Patra > --- > arch/riscv/kvm/vcpu_pmu.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c > index 2dad37f..9a531fe 100644 > --- a/arch/riscv/kvm/vcpu_pmu.c > +++ b/arch/riscv/kvm/vcpu_pmu.c > @@ -79,6 +79,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; > -- > 2.25.1 > Reviewed-by: Andrew Jones