1 // SPDX-License-Identifier: GPL-2.0
3 * Test for x86 KVM_CAP_MSR_PLATFORM_INFO
5 * Copyright (C) 2018, Google LLC.
7 * This work is licensed under the terms of the GNU GPL, version 2.
9 * Verifies expected behavior of controlling guest access to
16 #include <sys/ioctl.h>
18 #include "test_util.h"
20 #include "processor.h"
22 #define MSR_PLATFORM_INFO_MAX_TURBO_RATIO 0xff00
24 static void guest_code(void)
26 uint64_t msr_platform_info
;
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
);
35 vector
= rdmsr_safe(MSR_PLATFORM_INFO
, &msr_platform_info
);
36 GUEST_ASSERT_EQ(vector
, GP_VECTOR
);
41 int main(int argc
, char *argv
[])
43 struct kvm_vcpu
*vcpu
;
45 uint64_t msr_platform_info
;
48 TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO
));
50 vm
= vm_create_with_one_vcpu(&vcpu
, guest_code
);
52 msr_platform_info
= vcpu_get_msr(vcpu
, MSR_PLATFORM_INFO
);
53 vcpu_set_msr(vcpu
, MSR_PLATFORM_INFO
,
54 msr_platform_info
| MSR_PLATFORM_INFO_MAX_TURBO_RATIO
);
58 TEST_ASSERT_KVM_EXIT_REASON(vcpu
, KVM_EXIT_IO
);
60 switch (get_ucall(vcpu
, &uc
)) {
62 vm_enable_cap(vm
, KVM_CAP_MSR_PLATFORM_INFO
, uc
.args
[1]);
67 REPORT_GUEST_ASSERT(uc
);
69 TEST_FAIL("Unexpected ucall %lu", uc
.cmd
);