Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'kvm-riscv-6.15-1' of https://github.com/kvm-riscv/linux into HEAD

KVM/riscv changes for 6.15

- Disable the kernel perf counter during configure
- KVM selftests improvements for PMU
- Fix warning at the time of KVM module removal

+60 -28
+2 -2
arch/riscv/kvm/main.c
··· 172 172 173 173 static void __exit riscv_kvm_exit(void) 174 174 { 175 - kvm_riscv_teardown(); 176 - 177 175 kvm_exit(); 176 + 177 + kvm_riscv_teardown(); 178 178 } 179 179 module_exit(riscv_kvm_exit);
+1 -1
arch/riscv/kvm/vcpu_onereg.c
··· 203 203 case KVM_RISCV_ISA_EXT_SVADE: 204 204 /* 205 205 * The henvcfg.ADUE is read-only zero if menvcfg.ADUE is zero. 206 - * Svade is not allowed to disable when the platform use Svade. 206 + * Svade can't be disabled unless we support Svadu. 207 207 */ 208 208 return arch_has_hw_pte_young(); 209 209 default:
+1
arch/riscv/kvm/vcpu_pmu.c
··· 666 666 .type = etype, 667 667 .size = sizeof(struct perf_event_attr), 668 668 .pinned = true, 669 + .disabled = true, 669 670 /* 670 671 * It should never reach here if the platform doesn't support the sscofpmf 671 672 * extension as mode filtering won't work without it.
+56 -25
tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
··· 39 39 #define SBI_PMU_TEST_SNAPSHOT BIT(2) 40 40 #define SBI_PMU_TEST_OVERFLOW BIT(3) 41 41 42 - static int disabled_tests; 42 + #define SBI_PMU_OVERFLOW_IRQNUM_DEFAULT 5 43 + struct test_args { 44 + int disabled_tests; 45 + int overflow_irqnum; 46 + }; 47 + 48 + static struct test_args targs; 43 49 44 50 unsigned long pmu_csr_read_num(int csr_num) 45 51 { ··· 124 118 125 119 ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, counter, 1, stop_flags, 126 120 0, 0, 0); 127 - __GUEST_ASSERT(ret.error == 0, "Unable to stop counter %ld error %ld\n", 128 - counter, ret.error); 121 + __GUEST_ASSERT(ret.error == 0 || ret.error == SBI_ERR_ALREADY_STOPPED, 122 + "Unable to stop counter %ld error %ld\n", counter, ret.error); 129 123 } 130 124 131 125 static void guest_illegal_exception_handler(struct ex_regs *regs) ··· 143 137 unsigned int irq_num = regs->cause & ~CAUSE_IRQ_FLAG; 144 138 struct riscv_pmu_snapshot_data *snapshot_data = snapshot_gva; 145 139 unsigned long overflown_mask; 146 - unsigned long counter_val = 0; 147 140 148 141 /* Validate that we are in the correct irq handler */ 149 142 GUEST_ASSERT_EQ(irq_num, IRQ_PMU_OVF); ··· 156 151 GUEST_ASSERT(overflown_mask & 0x01); 157 152 158 153 WRITE_ONCE(vcpu_shared_irq_count, vcpu_shared_irq_count+1); 159 - 160 - counter_val = READ_ONCE(snapshot_data->ctr_values[0]); 161 - /* Now start the counter to mimick the real driver behavior */ 162 - start_counter(counter_in_use, SBI_PMU_START_FLAG_SET_INIT_VALUE, counter_val); 163 154 } 164 155 165 156 static unsigned long get_counter_index(unsigned long cbase, unsigned long cmask, ··· 480 479 481 480 static void test_pmu_events_overflow(void) 482 481 { 483 - int num_counters = 0; 482 + int num_counters = 0, i = 0; 484 483 485 484 /* Verify presence of SBI PMU and minimum requrired SBI version */ 486 485 verify_sbi_requirement_assert(); ··· 497 496 * Qemu supports overflow for cycle/instruction. 498 497 * This test may fail on any platform that do not support overflow for these two events. 499 498 */ 500 - test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES); 501 - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 1); 499 + for (i = 0; i < targs.overflow_irqnum; i++) 500 + test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES); 501 + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum); 502 502 503 - test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS); 504 - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 2); 503 + vcpu_shared_irq_count = 0; 504 + 505 + for (i = 0; i < targs.overflow_irqnum; i++) 506 + test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS); 507 + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum); 505 508 506 509 GUEST_DONE(); 507 510 } ··· 614 609 vcpu_init_vector_tables(vcpu); 615 610 /* Initialize guest timer frequency. */ 616 611 timer_freq = vcpu_get_reg(vcpu, RISCV_TIMER_REG(frequency)); 612 + 613 + /* Export the shared variables to the guest */ 617 614 sync_global_to_guest(vm, timer_freq); 615 + sync_global_to_guest(vm, vcpu_shared_irq_count); 616 + sync_global_to_guest(vm, targs); 618 617 619 618 run_vcpu(vcpu); 620 619 ··· 627 618 628 619 static void test_print_help(char *name) 629 620 { 630 - pr_info("Usage: %s [-h] [-d <test name>]\n", name); 631 - pr_info("\t-d: Test to disable. Available tests are 'basic', 'events', 'snapshot', 'overflow'\n"); 621 + pr_info("Usage: %s [-h] [-t <test name>] [-n <number of LCOFI interrupt for overflow test>]\n", 622 + name); 623 + pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n"); 624 + pr_info("\t-n: Number of LCOFI interrupt to trigger for each event in overflow test (default: %d)\n", 625 + SBI_PMU_OVERFLOW_IRQNUM_DEFAULT); 632 626 pr_info("\t-h: print this help screen\n"); 633 627 } 634 628 635 629 static bool parse_args(int argc, char *argv[]) 636 630 { 637 631 int opt; 632 + int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT | 633 + SBI_PMU_TEST_OVERFLOW; 634 + int overflow_interrupts = 0; 638 635 639 - while ((opt = getopt(argc, argv, "hd:")) != -1) { 636 + while ((opt = getopt(argc, argv, "ht:n:")) != -1) { 640 637 switch (opt) { 641 - case 'd': 638 + case 't': 642 639 if (!strncmp("basic", optarg, 5)) 643 - disabled_tests |= SBI_PMU_TEST_BASIC; 640 + temp_disabled_tests &= ~SBI_PMU_TEST_BASIC; 644 641 else if (!strncmp("events", optarg, 6)) 645 - disabled_tests |= SBI_PMU_TEST_EVENTS; 642 + temp_disabled_tests &= ~SBI_PMU_TEST_EVENTS; 646 643 else if (!strncmp("snapshot", optarg, 8)) 647 - disabled_tests |= SBI_PMU_TEST_SNAPSHOT; 644 + temp_disabled_tests &= ~SBI_PMU_TEST_SNAPSHOT; 648 645 else if (!strncmp("overflow", optarg, 8)) 649 - disabled_tests |= SBI_PMU_TEST_OVERFLOW; 646 + temp_disabled_tests &= ~SBI_PMU_TEST_OVERFLOW; 650 647 else 651 648 goto done; 649 + targs.disabled_tests = temp_disabled_tests; 650 + break; 651 + case 'n': 652 + overflow_interrupts = atoi_positive("Number of LCOFI", optarg); 652 653 break; 653 654 case 'h': 654 655 default: 655 656 goto done; 657 + } 658 + } 659 + 660 + if (overflow_interrupts > 0) { 661 + if (targs.disabled_tests & SBI_PMU_TEST_OVERFLOW) { 662 + pr_info("-n option is only available for overflow test\n"); 663 + goto done; 664 + } else { 665 + targs.overflow_irqnum = overflow_interrupts; 656 666 } 657 667 } 658 668 ··· 683 655 684 656 int main(int argc, char *argv[]) 685 657 { 658 + targs.disabled_tests = 0; 659 + targs.overflow_irqnum = SBI_PMU_OVERFLOW_IRQNUM_DEFAULT; 660 + 686 661 if (!parse_args(argc, argv)) 687 662 exit(KSFT_SKIP); 688 663 689 - if (!(disabled_tests & SBI_PMU_TEST_BASIC)) { 664 + if (!(targs.disabled_tests & SBI_PMU_TEST_BASIC)) { 690 665 test_vm_basic_test(test_pmu_basic_sanity); 691 666 pr_info("SBI PMU basic test : PASS\n"); 692 667 } 693 668 694 - if (!(disabled_tests & SBI_PMU_TEST_EVENTS)) { 669 + if (!(targs.disabled_tests & SBI_PMU_TEST_EVENTS)) { 695 670 test_vm_events_test(test_pmu_events); 696 671 pr_info("SBI PMU event verification test : PASS\n"); 697 672 } 698 673 699 - if (!(disabled_tests & SBI_PMU_TEST_SNAPSHOT)) { 674 + if (!(targs.disabled_tests & SBI_PMU_TEST_SNAPSHOT)) { 700 675 test_vm_events_snapshot_test(test_pmu_events_snaphost); 701 676 pr_info("SBI PMU event verification with snapshot test : PASS\n"); 702 677 } 703 678 704 - if (!(disabled_tests & SBI_PMU_TEST_OVERFLOW)) { 679 + if (!(targs.disabled_tests & SBI_PMU_TEST_OVERFLOW)) { 705 680 test_vm_events_overflow(test_pmu_events_overflow); 706 681 pr_info("SBI PMU event verification with overflow test : PASS\n"); 707 682 }