Skip to content

Commit 8ac2f77

Browse files
committed
KVM: selftests: Refactor LBR_FMT test to avoid use of separate macro
Rework the LBR format test to use the bitfield instead of a separate mask macro, mainly so that adding a nearly-identical PEBS format test doesn't have to copy-paste-tweak the macro too. No functional change intended. Link: https://lore.kernel.org/r/20230311004618.920745-20-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent bc7bb00 commit 8ac2f77

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "kvm_util.h"
2020
#include "vmx.h"
2121

22-
#define PMU_CAP_LBR_FMT 0x3f
23-
2422
union perf_capabilities {
2523
struct {
2624
u64 lbr_format:6;
@@ -169,7 +167,7 @@ static void test_immutable_perf_capabilities(union perf_capabilities host_cap)
169167

170168
struct kvm_vcpu *vcpu;
171169
struct kvm_vm *vm = vm_create_with_one_vcpu(&vcpu, NULL);
172-
uint64_t val;
170+
union perf_capabilities val = host_cap;
173171
int r, bit;
174172

175173
for_each_set_bit(bit, &reserved_caps, 64) {
@@ -184,12 +182,13 @@ static void test_immutable_perf_capabilities(union perf_capabilities host_cap)
184182
* KVM only supports the host's native LBR format, as well as '0' (to
185183
* disable LBR support). Verify KVM rejects all other LBR formats.
186184
*/
187-
for (val = 1; val <= PMU_CAP_LBR_FMT; val++) {
188-
if (val == (host_cap.capabilities & PMU_CAP_LBR_FMT))
185+
for (val.lbr_format = 1; val.lbr_format; val.lbr_format++) {
186+
if (val.lbr_format == host_cap.lbr_format)
189187
continue;
190188

191-
r = _vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, val);
192-
TEST_ASSERT(!r, "Bad LBR FMT = 0x%lx didn't fail", val);
189+
r = _vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, val.capabilities);
190+
TEST_ASSERT(!r, "Bad LBR FMT = 0x%x didn't fail, host = 0x%x",
191+
val.lbr_format, host_cap.lbr_format);
193192
}
194193

195194
kvm_vm_free(vm);

0 commit comments

Comments
 (0)