···203203 case KVM_RISCV_ISA_EXT_SVADE:204204 /*205205 * The henvcfg.ADUE is read-only zero if menvcfg.ADUE is zero.206206- * Svade is not allowed to disable when the platform use Svade.206206+ * Svade can't be disabled unless we support Svadu.207207 */208208 return arch_has_hw_pte_young();209209 default:
+1
arch/riscv/kvm/vcpu_pmu.c
···666666 .type = etype,667667 .size = sizeof(struct perf_event_attr),668668 .pinned = true,669669+ .disabled = true,669670 /*670671 * It should never reach here if the platform doesn't support the sscofpmf671672 * extension as mode filtering won't work without it.
+56-25
tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
···3939#define SBI_PMU_TEST_SNAPSHOT BIT(2)4040#define SBI_PMU_TEST_OVERFLOW BIT(3)41414242-static int disabled_tests;4242+#define SBI_PMU_OVERFLOW_IRQNUM_DEFAULT 54343+struct test_args {4444+ int disabled_tests;4545+ int overflow_irqnum;4646+};4747+4848+static struct test_args targs;43494450unsigned long pmu_csr_read_num(int csr_num)4551{···124118125119 ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, counter, 1, stop_flags,126120 0, 0, 0);127127- __GUEST_ASSERT(ret.error == 0, "Unable to stop counter %ld error %ld\n",128128- counter, ret.error);121121+ __GUEST_ASSERT(ret.error == 0 || ret.error == SBI_ERR_ALREADY_STOPPED,122122+ "Unable to stop counter %ld error %ld\n", counter, ret.error);129123}130124131125static void guest_illegal_exception_handler(struct ex_regs *regs)···143137 unsigned int irq_num = regs->cause & ~CAUSE_IRQ_FLAG;144138 struct riscv_pmu_snapshot_data *snapshot_data = snapshot_gva;145139 unsigned long overflown_mask;146146- unsigned long counter_val = 0;147140148141 /* Validate that we are in the correct irq handler */149142 GUEST_ASSERT_EQ(irq_num, IRQ_PMU_OVF);···156151 GUEST_ASSERT(overflown_mask & 0x01);157152158153 WRITE_ONCE(vcpu_shared_irq_count, vcpu_shared_irq_count+1);159159-160160- counter_val = READ_ONCE(snapshot_data->ctr_values[0]);161161- /* Now start the counter to mimick the real driver behavior */162162- start_counter(counter_in_use, SBI_PMU_START_FLAG_SET_INIT_VALUE, counter_val);163154}164155165156static unsigned long get_counter_index(unsigned long cbase, unsigned long cmask,···480479481480static void test_pmu_events_overflow(void)482481{483483- int num_counters = 0;482482+ int num_counters = 0, i = 0;484483485484 /* Verify presence of SBI PMU and minimum requrired SBI version */486485 verify_sbi_requirement_assert();···497496 * Qemu supports overflow for cycle/instruction.498497 * This test may fail on any platform that do not support overflow for these two events.499498 */500500- test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);501501- GUEST_ASSERT_EQ(vcpu_shared_irq_count, 1);499499+ for (i = 0; i < targs.overflow_irqnum; i++)500500+ test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);501501+ GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);502502503503- test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);504504- GUEST_ASSERT_EQ(vcpu_shared_irq_count, 2);503503+ vcpu_shared_irq_count = 0;504504+505505+ for (i = 0; i < targs.overflow_irqnum; i++)506506+ test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);507507+ GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);505508506509 GUEST_DONE();507510}···614609 vcpu_init_vector_tables(vcpu);615610 /* Initialize guest timer frequency. */616611 timer_freq = vcpu_get_reg(vcpu, RISCV_TIMER_REG(frequency));612612+613613+ /* Export the shared variables to the guest */617614 sync_global_to_guest(vm, timer_freq);615615+ sync_global_to_guest(vm, vcpu_shared_irq_count);616616+ sync_global_to_guest(vm, targs);618617619618 run_vcpu(vcpu);620619···627618628619static void test_print_help(char *name)629620{630630- pr_info("Usage: %s [-h] [-d <test name>]\n", name);631631- pr_info("\t-d: Test to disable. Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");621621+ pr_info("Usage: %s [-h] [-t <test name>] [-n <number of LCOFI interrupt for overflow test>]\n",622622+ name);623623+ pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");624624+ pr_info("\t-n: Number of LCOFI interrupt to trigger for each event in overflow test (default: %d)\n",625625+ SBI_PMU_OVERFLOW_IRQNUM_DEFAULT);632626 pr_info("\t-h: print this help screen\n");633627}634628635629static bool parse_args(int argc, char *argv[])636630{637631 int opt;632632+ int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT |633633+ SBI_PMU_TEST_OVERFLOW;634634+ int overflow_interrupts = 0;638635639639- while ((opt = getopt(argc, argv, "hd:")) != -1) {636636+ while ((opt = getopt(argc, argv, "ht:n:")) != -1) {640637 switch (opt) {641641- case 'd':638638+ case 't':642639 if (!strncmp("basic", optarg, 5))643643- disabled_tests |= SBI_PMU_TEST_BASIC;640640+ temp_disabled_tests &= ~SBI_PMU_TEST_BASIC;644641 else if (!strncmp("events", optarg, 6))645645- disabled_tests |= SBI_PMU_TEST_EVENTS;642642+ temp_disabled_tests &= ~SBI_PMU_TEST_EVENTS;646643 else if (!strncmp("snapshot", optarg, 8))647647- disabled_tests |= SBI_PMU_TEST_SNAPSHOT;644644+ temp_disabled_tests &= ~SBI_PMU_TEST_SNAPSHOT;648645 else if (!strncmp("overflow", optarg, 8))649649- disabled_tests |= SBI_PMU_TEST_OVERFLOW;646646+ temp_disabled_tests &= ~SBI_PMU_TEST_OVERFLOW;650647 else651648 goto done;649649+ targs.disabled_tests = temp_disabled_tests;650650+ break;651651+ case 'n':652652+ overflow_interrupts = atoi_positive("Number of LCOFI", optarg);652653 break;653654 case 'h':654655 default:655656 goto done;657657+ }658658+ }659659+660660+ if (overflow_interrupts > 0) {661661+ if (targs.disabled_tests & SBI_PMU_TEST_OVERFLOW) {662662+ pr_info("-n option is only available for overflow test\n");663663+ goto done;664664+ } else {665665+ targs.overflow_irqnum = overflow_interrupts;656666 }657667 }658668···683655684656int main(int argc, char *argv[])685657{658658+ targs.disabled_tests = 0;659659+ targs.overflow_irqnum = SBI_PMU_OVERFLOW_IRQNUM_DEFAULT;660660+686661 if (!parse_args(argc, argv))687662 exit(KSFT_SKIP);688663689689- if (!(disabled_tests & SBI_PMU_TEST_BASIC)) {664664+ if (!(targs.disabled_tests & SBI_PMU_TEST_BASIC)) {690665 test_vm_basic_test(test_pmu_basic_sanity);691666 pr_info("SBI PMU basic test : PASS\n");692667 }693668694694- if (!(disabled_tests & SBI_PMU_TEST_EVENTS)) {669669+ if (!(targs.disabled_tests & SBI_PMU_TEST_EVENTS)) {695670 test_vm_events_test(test_pmu_events);696671 pr_info("SBI PMU event verification test : PASS\n");697672 }698673699699- if (!(disabled_tests & SBI_PMU_TEST_SNAPSHOT)) {674674+ if (!(targs.disabled_tests & SBI_PMU_TEST_SNAPSHOT)) {700675 test_vm_events_snapshot_test(test_pmu_events_snaphost);701676 pr_info("SBI PMU event verification with snapshot test : PASS\n");702677 }703678704704- if (!(disabled_tests & SBI_PMU_TEST_OVERFLOW)) {679679+ if (!(targs.disabled_tests & SBI_PMU_TEST_OVERFLOW)) {705680 test_vm_events_overflow(test_pmu_events_overflow);706681 pr_info("SBI PMU event verification with overflow test : PASS\n");707682 }