Skip to content

Commit 81fd924

Browse files
committed
KVM: selftests: Test post-KVM_RUN writes to PERF_CAPABILITIES
Now that KVM disallows changing PERF_CAPABILITIES after KVM_RUN, expand the host side checks to verify KVM rejects any attempts to change bits from userspace. Link: https://lore.kernel.org/r/20230311004618.920745-18-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent baa36da commit 81fd924

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static void test_guest_wrmsr_perf_capabilities(union perf_capabilities host_cap)
8585
struct kvm_vcpu *vcpu;
8686
struct kvm_vm *vm = vm_create_with_one_vcpu(&vcpu, guest_code);
8787
struct ucall uc;
88+
int r, i;
8889

8990
vm_init_descriptor_tables(vm);
9091
vcpu_init_descriptor_tables(vcpu);
@@ -106,6 +107,18 @@ static void test_guest_wrmsr_perf_capabilities(union perf_capabilities host_cap)
106107

107108
ASSERT_EQ(vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES), host_cap.capabilities);
108109

110+
vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities);
111+
112+
r = _vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, 0);
113+
TEST_ASSERT(!r, "Post-KVM_RUN write '0' didn't fail");
114+
115+
for (i = 0; i < 64; i++) {
116+
r = _vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES,
117+
host_cap.capabilities ^ BIT_ULL(i));
118+
TEST_ASSERT(!r, "Post-KVM_RUN write '0x%llx'didn't fail",
119+
host_cap.capabilities ^ BIT_ULL(i));
120+
}
121+
109122
kvm_vm_free(vm);
110123
}
111124

0 commit comments

Comments
 (0)