On Wed, Apr 10, 2024 at 05:07:50PM -0700, Atish Patra wrote: > Verify PMU snapshot functionality by setting up the shared memory > correctly and reading the counter values from the shared memory > instead of the CSR. > > Reviewed-by: Andrew Jones <ajones@xxxxxxxxxxxxxxxx> > Reviewed-by: Anup Patel <anup@xxxxxxxxxxxxxx> > Signed-off-by: Atish Patra <atishp@xxxxxxxxxxxx> > --- > .../testing/selftests/kvm/include/riscv/sbi.h | 25 +++ > .../selftests/kvm/lib/riscv/processor.c | 12 ++ > .../selftests/kvm/riscv/sbi_pmu_test.c | 144 ++++++++++++++++++ > 3 files changed, 181 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/riscv/sbi.h b/tools/testing/selftests/kvm/include/riscv/sbi.h > index 6675ca673c77..1b995481a3fa 100644 > --- a/tools/testing/selftests/kvm/include/riscv/sbi.h > +++ b/tools/testing/selftests/kvm/include/riscv/sbi.h > @@ -8,6 +8,12 @@ > #ifndef SELFTEST_KVM_SBI_H > #define SELFTEST_KVM_SBI_H > > +/* SBI spec version fields */ > +#define SBI_SPEC_VERSION_DEFAULT 0x1 > +#define SBI_SPEC_VERSION_MAJOR_SHIFT 24 > +#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f > +#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff > + > /* SBI return error codes */ > #define SBI_SUCCESS 0 > #define SBI_ERR_FAILURE -1 > @@ -33,6 +39,9 @@ enum sbi_ext_id { > }; > > enum sbi_ext_base_fid { > + SBI_EXT_BASE_GET_SPEC_VERSION = 0, > + SBI_EXT_BASE_GET_IMP_ID, > + SBI_EXT_BASE_GET_IMP_VERSION, > SBI_EXT_BASE_PROBE_EXT = 3, > }; > enum sbi_ext_pmu_fid { > @@ -60,6 +69,12 @@ union sbi_pmu_ctr_info { > }; > }; > > +struct riscv_pmu_snapshot_data { > + u64 ctr_overflow_mask; > + u64 ctr_values[64]; > + u64 reserved[447]; > +}; > + > struct sbiret { > long error; > long value; > @@ -113,4 +128,14 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, > > bool guest_sbi_probe_extension(int extid, long *out_val); > > +/* Make SBI version */ > +static inline unsigned long sbi_mk_version(unsigned long major, > + unsigned long minor) > +{ > + return ((major & SBI_SPEC_VERSION_MAJOR_MASK) << SBI_SPEC_VERSION_MAJOR_SHIFT > + | (minor & SBI_SPEC_VERSION_MINOR_MASK)); Same parentheses comment as the other patch. Thanks, drew