diff mbox series

[3/3] selftests: kvm/x86: Verify the pmu event filter matches the correct event

Message ID 20220517051238.2566934-3-aaronlewis@google.com (mailing list archive)
State New, archived
Headers show
Series [1/3] kvm: x86/pmu: Fix the compare function used by the pmu event filter | expand

Commit Message

Aaron Lewis May 17, 2022, 5:12 a.m. UTC
Add a test to demonstrate that when the guest programs an event select
it is matched correctly in the pmu event filter and not inadvertently
filtered.  This could happen on AMD if the high nybble[1] in the event
select gets truncated away only leaving the bottom byte[2] left for

This is a contrived example used for the convenience of demonstrating
this issue, however, this can be applied to event selects 0x28A (OC
Mode Switch) and 0x08A (L1 BTB Correction), where 0x08A could end up
being denied when the event select was only set up to deny 0x28A.

[1] bits 35:32 in the event select register and bits 11:8 in the event
[2] bits 7:0 in the event select register and bits 7:0 in the event

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
 .../kvm/x86_64/pmu_event_filter_test.c        | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series


diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
index 30c1a5804210..93d77574b255 100644
--- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
+++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
@@ -281,6 +281,22 @@  static uint64_t test_with_filter(struct kvm_vm *vm,
 	return run_vm_to_sync(vm);
+static void test_amd_deny_list(struct kvm_vm *vm)
+	uint64_t event = EVENT(0x1C2, 0);
+	struct kvm_pmu_event_filter *f;
+	uint64_t count;
+	f = create_pmu_event_filter(&event, 1, KVM_PMU_EVENT_DENY);
+	count = test_with_filter(vm, f);
+	free(f);
+	if (count != NUM_BRANCHES)
+		pr_info("%s: Branch instructions retired = %lu (expected %u)\n",
+			__func__, count, NUM_BRANCHES);
+	TEST_ASSERT(count, "Allowed PMU event is not counting");
 static void test_member_deny_list(struct kvm_vm *vm)
 	struct kvm_pmu_event_filter *f = event_filter(KVM_PMU_EVENT_DENY);
@@ -463,6 +479,9 @@  int main(int argc, char *argv[])
+	if (use_amd_pmu())
+		test_amd_deny_list(vm);