Skip to content

Commit c02c744

Browse files
committed
KVM: selftests: Use error codes to signal errors in PMU event filter test
Use '0' to signal success and '-errno' to signal failure in the PMU event filter test so that the values are slightly less magical/arbitrary. Using '0' in the error paths is especially confusing as understanding it's an error value requires following the breadcrumbs to the host code that ultimately consumes the value. Arguably there should also be a #define for "success", but 0/-errno is a common enough pattern that defining another macro on top would likely do more harm than good. Link: https://lore.kernel.org/r/20230407233254.957013-5-seanjc@google.com Reviewed by: Aaron Lewis <aaronlewis@google.com> Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c140e93 commit c02c744

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static const uint64_t event_list[] = {
7777
*/
7878
static void guest_gp_handler(struct ex_regs *regs)
7979
{
80-
GUEST_SYNC(0);
80+
GUEST_SYNC(-EFAULT);
8181
}
8282

8383
/*
@@ -92,12 +92,12 @@ static void check_msr(uint32_t msr, uint64_t bits_to_flip)
9292

9393
wrmsr(msr, v);
9494
if (rdmsr(msr) != v)
95-
GUEST_SYNC(0);
95+
GUEST_SYNC(-EIO);
9696

9797
v ^= bits_to_flip;
9898
wrmsr(msr, v);
9999
if (rdmsr(msr) != v)
100-
GUEST_SYNC(0);
100+
GUEST_SYNC(-EIO);
101101
}
102102

103103
static uint64_t run_and_measure_loop(uint32_t msr_base)
@@ -114,7 +114,7 @@ static void intel_guest_code(void)
114114
check_msr(MSR_CORE_PERF_GLOBAL_CTRL, 1);
115115
check_msr(MSR_P6_EVNTSEL0, 0xffff);
116116
check_msr(MSR_IA32_PMC0, 0xffff);
117-
GUEST_SYNC(1);
117+
GUEST_SYNC(0);
118118

119119
for (;;) {
120120
uint64_t count;
@@ -138,7 +138,7 @@ static void amd_guest_code(void)
138138
{
139139
check_msr(MSR_K7_EVNTSEL0, 0xffff);
140140
check_msr(MSR_K7_PERFCTR0, 0xffff);
141-
GUEST_SYNC(1);
141+
GUEST_SYNC(0);
142142

143143
for (;;) {
144144
uint64_t count;
@@ -178,13 +178,13 @@ static uint64_t run_vcpu_to_sync(struct kvm_vcpu *vcpu)
178178
*/
179179
static bool sanity_check_pmu(struct kvm_vcpu *vcpu)
180180
{
181-
bool success;
181+
uint64_t r;
182182

183183
vm_install_exception_handler(vcpu->vm, GP_VECTOR, guest_gp_handler);
184-
success = run_vcpu_to_sync(vcpu);
184+
r = run_vcpu_to_sync(vcpu);
185185
vm_install_exception_handler(vcpu->vm, GP_VECTOR, NULL);
186186

187-
return success;
187+
return !r;
188188
}
189189

190190
static struct kvm_pmu_event_filter *alloc_pmu_event_filter(uint32_t nevents)

0 commit comments

Comments
 (0)