diff mbox series

[v3,4/4] KVM: selftests: Test gp event filters don't affect fixed event filters

Message ID 20230607123700.40229-5-cloudliang@tencent.com (mailing list archive)
State New, archived
Headers show
Series KVM: selftests: Improve PMU event filter settings and add test cases | expand

Commit Message

Jinrong Liang June 7, 2023, 12:37 p.m. UTC
From: Jinrong Liang <cloudliang@tencent.com>

Add a test to ensure that setting both generic and fixed performance
event filters does not affect the consistency of the fixed performance
filter behavior in KVM. This test helps to ensure that the fixed
performance filter works as expected even when generic performance
event filters are also set.

Signed-off-by: Jinrong Liang <cloudliang@tencent.com>
---
 .../kvm/x86_64/pmu_event_filter_test.c        | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Sean Christopherson June 28, 2023, 9:30 p.m. UTC | #1
On Wed, Jun 07, 2023, Jinrong Liang wrote:
>  static void __test_fixed_counter_bitmap(struct kvm_vcpu *vcpu, uint8_t idx,
>  					uint8_t nr_fixed_counters)
>  {
> @@ -881,6 +894,25 @@ static void __test_fixed_counter_bitmap(struct kvm_vcpu *vcpu, uint8_t idx,
>  						       bitmap);
>  		TEST_ASSERT(!!count == !(bitmap & BIT(idx)),
>  			    "Fixed event filter does not work as expected.");
> +
> +		/*
> +		 * Check that setting both events[] and fixed_counter_bitmap
> +		 * does not affect the consistency of the fixed ctrs' behaviour.

Spell out "counters".  And this isn't about "consistency", the fixed_counter_bitmap
should straight up win, i.e.

		/*
		 * Check that fixed_counter_bitmap has higher priority than
		 * events[] when both are set.
		 */
diff mbox series

Patch

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 72f7fdb821e5..79bfdb64820b 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
@@ -853,6 +853,19 @@  static uint64_t test_with_fixed_counter_filter(struct kvm_vcpu *vcpu,
 	return run_vcpu_to_sync(vcpu);
 }
 
+static uint64_t test_set_gp_and_fixed_event_filter(struct kvm_vcpu *vcpu,
+						   uint32_t action,
+						   uint32_t bitmap)
+{
+	struct __kvm_pmu_event_filter f = base_event_filter;
+
+	f.action = action;
+	f.fixed_counter_bitmap = bitmap;
+	do_vcpu_set_pmu_event_filter(vcpu, &f);
+
+	return run_vcpu_to_sync(vcpu);
+}
+
 static void __test_fixed_counter_bitmap(struct kvm_vcpu *vcpu, uint8_t idx,
 					uint8_t nr_fixed_counters)
 {
@@ -881,6 +894,25 @@  static void __test_fixed_counter_bitmap(struct kvm_vcpu *vcpu, uint8_t idx,
 						       bitmap);
 		TEST_ASSERT(!!count == !(bitmap & BIT(idx)),
 			    "Fixed event filter does not work as expected.");
+
+		/*
+		 * Check that setting both events[] and fixed_counter_bitmap
+		 * does not affect the consistency of the fixed ctrs' behaviour.
+		 *
+		 * Note, the fixed_counter_bitmap has higher priority than the
+		 * events list.
+		 */
+		count = test_set_gp_and_fixed_event_filter(vcpu,
+							   KVM_PMU_EVENT_ALLOW,
+							   bitmap);
+		TEST_ASSERT(!!count == !!(bitmap & BIT(idx)),
+			    "Fixed event filter does not work as expected.");
+
+		count = test_set_gp_and_fixed_event_filter(vcpu,
+							   KVM_PMU_EVENT_DENY,
+							   bitmap);
+		TEST_ASSERT(!!count == !(bitmap & BIT(idx)),
+			    "Fixed event filter does not work as expected.");
 	}
 }