Skip to content

Commit dec79ea

Browse files
committed
KVM: selftests: Rework platform_info_test to actually verify #GP
Rework platform_info_test to actually handle and verify the expected #GP on RDMSR when the associated KVM capability is disabled. Currently, the test _deliberately_ doesn't handle the #GP, and instead lets it escalated to a triple fault shutdown. In addition to verifying that KVM generates the correct fault, handling the #GP will be necessary (without even more shenanigans) when a future change to the core KVM selftests library configures the IDT and exception handlers by default (the test subtly relies on the IDT limit being '0'). Link: https://lore.kernel.org/r/20240314232637.2538648-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 53635ec commit dec79ea

1 file changed

Lines changed: 33 additions & 33 deletions

File tree

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,57 @@
2424
static void guest_code(void)
2525
{
2626
uint64_t msr_platform_info;
27+
uint8_t vector;
2728

28-
for (;;) {
29-
msr_platform_info = rdmsr(MSR_PLATFORM_INFO);
30-
GUEST_ASSERT_EQ(msr_platform_info & MSR_PLATFORM_INFO_MAX_TURBO_RATIO,
31-
MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
32-
GUEST_SYNC(0);
33-
asm volatile ("inc %r11");
34-
}
35-
}
36-
37-
static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu)
38-
{
39-
struct ucall uc;
29+
GUEST_SYNC(true);
30+
msr_platform_info = rdmsr(MSR_PLATFORM_INFO);
31+
GUEST_ASSERT_EQ(msr_platform_info & MSR_PLATFORM_INFO_MAX_TURBO_RATIO,
32+
MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
4033

41-
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true);
42-
vcpu_run(vcpu);
43-
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
44-
45-
switch (get_ucall(vcpu, &uc)) {
46-
case UCALL_SYNC:
47-
break;
48-
case UCALL_ABORT:
49-
REPORT_GUEST_ASSERT(uc);
50-
default:
51-
TEST_FAIL("Unexpected ucall %lu", uc.cmd);
52-
break;
53-
}
54-
}
34+
GUEST_SYNC(false);
35+
vector = rdmsr_safe(MSR_PLATFORM_INFO, &msr_platform_info);
36+
GUEST_ASSERT_EQ(vector, GP_VECTOR);
5537

56-
static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu)
57-
{
58-
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false);
59-
vcpu_run(vcpu);
60-
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN);
38+
GUEST_DONE();
6139
}
6240

6341
int main(int argc, char *argv[])
6442
{
6543
struct kvm_vcpu *vcpu;
6644
struct kvm_vm *vm;
6745
uint64_t msr_platform_info;
46+
struct ucall uc;
6847

6948
TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO));
7049

7150
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
7251

52+
vm_init_descriptor_tables(vm);
53+
vcpu_init_descriptor_tables(vcpu);
54+
7355
msr_platform_info = vcpu_get_msr(vcpu, MSR_PLATFORM_INFO);
7456
vcpu_set_msr(vcpu, MSR_PLATFORM_INFO,
7557
msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
76-
test_msr_platform_info_enabled(vcpu);
77-
test_msr_platform_info_disabled(vcpu);
58+
59+
for (;;) {
60+
vcpu_run(vcpu);
61+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
62+
63+
switch (get_ucall(vcpu, &uc)) {
64+
case UCALL_SYNC:
65+
vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, uc.args[1]);
66+
break;
67+
case UCALL_DONE:
68+
goto done;
69+
case UCALL_ABORT:
70+
REPORT_GUEST_ASSERT(uc);
71+
default:
72+
TEST_FAIL("Unexpected ucall %lu", uc.cmd);
73+
break;
74+
}
75+
}
76+
77+
done:
7878
vcpu_set_msr(vcpu, MSR_PLATFORM_INFO, msr_platform_info);
7979

8080
kvm_vm_free(vm);

0 commit comments

Comments
 (0)