Skip to content

Commit 86ab6af

Browse files
Jinrong Liangsean-jc
authored andcommitted
KVM: selftests: Add test cases for unsupported PMU event filter input values
Add test cases to verify the handling of unsupported input values for the PMU event filter. The tests cover unsupported "action" values, unsupported "flags" values, and unsupported "nevents" values. All these cases should return an error, as they are currently not supported by the filter. Furthermore, the tests also cover the case where setting non-existent fixed counters in the fixed bitmap does not fail. Signed-off-by: Jinrong Liang <cloudliang@tencent.com> Reviewed-by: Isaku Yamahata <isaku.yamahata@intel.com> Link: https://lore.kernel.org/r/20230810090945.16053-5-cloudliang@tencent.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent de527b1 commit 86ab6af

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#define MAX_FILTER_EVENTS 300
3333
#define MAX_TEST_EVENTS 10
3434

35+
#define PMU_EVENT_FILTER_INVALID_ACTION (KVM_PMU_EVENT_DENY + 1)
36+
#define PMU_EVENT_FILTER_INVALID_FLAGS (KVM_PMU_EVENT_FLAGS_VALID_MASK << 1)
37+
#define PMU_EVENT_FILTER_INVALID_NEVENTS (MAX_FILTER_EVENTS + 1)
38+
3539
/*
3640
* This is how the event selector and unit mask are stored in an AMD
3741
* core performance event-select register. Intel's format is similar,
@@ -760,6 +764,8 @@ static int set_pmu_single_event_filter(struct kvm_vcpu *vcpu, uint64_t event,
760764

761765
static void test_filter_ioctl(struct kvm_vcpu *vcpu)
762766
{
767+
uint8_t nr_fixed_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_FIXED_COUNTERS);
768+
struct __kvm_pmu_event_filter f;
763769
uint64_t e = ~0ul;
764770
int r;
765771

@@ -780,6 +786,26 @@ static void test_filter_ioctl(struct kvm_vcpu *vcpu)
780786
KVM_PMU_EVENT_FLAG_MASKED_EVENTS,
781787
KVM_PMU_EVENT_ALLOW);
782788
TEST_ASSERT(r == 0, "Valid PMU Event Filter is failing");
789+
790+
f = base_event_filter;
791+
f.action = PMU_EVENT_FILTER_INVALID_ACTION;
792+
r = set_pmu_event_filter(vcpu, &f);
793+
TEST_ASSERT(r, "Set invalid action is expected to fail");
794+
795+
f = base_event_filter;
796+
f.flags = PMU_EVENT_FILTER_INVALID_FLAGS;
797+
r = set_pmu_event_filter(vcpu, &f);
798+
TEST_ASSERT(r, "Set invalid flags is expected to fail");
799+
800+
f = base_event_filter;
801+
f.nevents = PMU_EVENT_FILTER_INVALID_NEVENTS;
802+
r = set_pmu_event_filter(vcpu, &f);
803+
TEST_ASSERT(r, "Exceeding the max number of filter events should fail");
804+
805+
f = base_event_filter;
806+
f.fixed_counter_bitmap = ~GENMASK_ULL(nr_fixed_counters, 0);
807+
r = set_pmu_event_filter(vcpu, &f);
808+
TEST_ASSERT(!r, "Masking non-existent fixed counters should be allowed");
783809
}
784810

785811
int main(int argc, char *argv[])

0 commit comments

Comments
 (0)