@@ -244,14 +244,27 @@ static struct kvm_pmu_event_filter *remove_event(struct kvm_pmu_event_filter *f,
244244 return f ;
245245}
246246
247+ #define ASSERT_PMC_COUNTING_INSTRUCTIONS (count ) \
248+ do { \
249+ if (count != NUM_BRANCHES) \
250+ pr_info("%s: Branch instructions retired = %lu (expected %u)\n", \
251+ __func__, count, NUM_BRANCHES); \
252+ TEST_ASSERT(count, "Allowed PMU event is not counting."); \
253+ } while (0)
254+
255+ #define ASSERT_PMC_NOT_COUNTING_INSTRUCTIONS (count ) \
256+ do { \
257+ if (count) \
258+ pr_info("%s: Branch instructions retired = %lu (expected 0)\n", \
259+ __func__, count); \
260+ TEST_ASSERT(!count, "Disallowed PMU Event is counting"); \
261+ } while (0)
262+
247263static void test_without_filter (struct kvm_vcpu * vcpu )
248264{
249265 uint64_t count = run_vcpu_to_sync (vcpu );
250266
251- if (count != NUM_BRANCHES )
252- pr_info ("%s: Branch instructions retired = %lu (expected %u)\n" ,
253- __func__ , count , NUM_BRANCHES );
254- TEST_ASSERT (count , "Allowed PMU event is not counting" );
267+ ASSERT_PMC_COUNTING_INSTRUCTIONS (count );
255268}
256269
257270static uint64_t test_with_filter (struct kvm_vcpu * vcpu ,
@@ -269,12 +282,9 @@ static void test_amd_deny_list(struct kvm_vcpu *vcpu)
269282
270283 f = create_pmu_event_filter (& event , 1 , KVM_PMU_EVENT_DENY , 0 );
271284 count = test_with_filter (vcpu , f );
272-
273285 free (f );
274- if (count != NUM_BRANCHES )
275- pr_info ("%s: Branch instructions retired = %lu (expected %u)\n" ,
276- __func__ , count , NUM_BRANCHES );
277- TEST_ASSERT (count , "Allowed PMU event is not counting" );
286+
287+ ASSERT_PMC_COUNTING_INSTRUCTIONS (count );
278288}
279289
280290static void test_member_deny_list (struct kvm_vcpu * vcpu )
@@ -283,10 +293,8 @@ static void test_member_deny_list(struct kvm_vcpu *vcpu)
283293 uint64_t count = test_with_filter (vcpu , f );
284294
285295 free (f );
286- if (count )
287- pr_info ("%s: Branch instructions retired = %lu (expected 0)\n" ,
288- __func__ , count );
289- TEST_ASSERT (!count , "Disallowed PMU Event is counting" );
296+
297+ ASSERT_PMC_NOT_COUNTING_INSTRUCTIONS (count );
290298}
291299
292300static void test_member_allow_list (struct kvm_vcpu * vcpu )
@@ -295,10 +303,8 @@ static void test_member_allow_list(struct kvm_vcpu *vcpu)
295303 uint64_t count = test_with_filter (vcpu , f );
296304
297305 free (f );
298- if (count != NUM_BRANCHES )
299- pr_info ("%s: Branch instructions retired = %lu (expected %u)\n" ,
300- __func__ , count , NUM_BRANCHES );
301- TEST_ASSERT (count , "Allowed PMU event is not counting" );
306+
307+ ASSERT_PMC_COUNTING_INSTRUCTIONS (count );
302308}
303309
304310static void test_not_member_deny_list (struct kvm_vcpu * vcpu )
@@ -310,10 +316,8 @@ static void test_not_member_deny_list(struct kvm_vcpu *vcpu)
310316 remove_event (f , AMD_ZEN_BR_RETIRED );
311317 count = test_with_filter (vcpu , f );
312318 free (f );
313- if (count != NUM_BRANCHES )
314- pr_info ("%s: Branch instructions retired = %lu (expected %u)\n" ,
315- __func__ , count , NUM_BRANCHES );
316- TEST_ASSERT (count , "Allowed PMU event is not counting" );
319+
320+ ASSERT_PMC_COUNTING_INSTRUCTIONS (count );
317321}
318322
319323static void test_not_member_allow_list (struct kvm_vcpu * vcpu )
@@ -325,10 +329,8 @@ static void test_not_member_allow_list(struct kvm_vcpu *vcpu)
325329 remove_event (f , AMD_ZEN_BR_RETIRED );
326330 count = test_with_filter (vcpu , f );
327331 free (f );
328- if (count )
329- pr_info ("%s: Branch instructions retired = %lu (expected 0)\n" ,
330- __func__ , count );
331- TEST_ASSERT (!count , "Disallowed PMU Event is counting" );
332+
333+ ASSERT_PMC_NOT_COUNTING_INSTRUCTIONS (count );
332334}
333335
334336/*
0 commit comments