@@ -244,14 +244,27 @@ static struct kvm_pmu_event_filter *remove_event(struct kvm_pmu_event_filter *f,
244
244
return f ;
245
245
}
246
246
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
+
247
263
static void test_without_filter (struct kvm_vcpu * vcpu )
248
264
{
249
265
uint64_t count = run_vcpu_to_sync (vcpu );
250
266
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 );
255
268
}
256
269
257
270
static uint64_t test_with_filter (struct kvm_vcpu * vcpu ,
@@ -269,12 +282,9 @@ static void test_amd_deny_list(struct kvm_vcpu *vcpu)
269
282
270
283
f = create_pmu_event_filter (& event , 1 , KVM_PMU_EVENT_DENY , 0 );
271
284
count = test_with_filter (vcpu , f );
272
-
273
285
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 );
278
288
}
279
289
280
290
static void test_member_deny_list (struct kvm_vcpu * vcpu )
@@ -283,10 +293,8 @@ static void test_member_deny_list(struct kvm_vcpu *vcpu)
283
293
uint64_t count = test_with_filter (vcpu , f );
284
294
285
295
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 );
290
298
}
291
299
292
300
static void test_member_allow_list (struct kvm_vcpu * vcpu )
@@ -295,10 +303,8 @@ static void test_member_allow_list(struct kvm_vcpu *vcpu)
295
303
uint64_t count = test_with_filter (vcpu , f );
296
304
297
305
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 );
302
308
}
303
309
304
310
static 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)
310
316
remove_event (f , AMD_ZEN_BR_RETIRED );
311
317
count = test_with_filter (vcpu , f );
312
318
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 );
317
321
}
318
322
319
323
static 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)
325
329
remove_event (f , AMD_ZEN_BR_RETIRED );
326
330
count = test_with_filter (vcpu , f );
327
331
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 );
332
334
}
333
335
334
336
/*
0 commit comments