summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2022-06-14 23:06:43 +0300
committerSean Christopherson <seanjc@google.com>2022-07-14 04:14:15 +0300
commit7fbc6038acbaa4c0c0b374aac635038881143e84 (patch)
tree118191569d5b5115ff1d6714413382eae069e36b /tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
parentfc66963d7b01e00ef0482bd7adbc8918343f81d9 (diff)
downloadlinux-7fbc6038acbaa4c0c0b374aac635038881143e84.tar.xz
KVM: selftests: Cache CPUID in struct kvm_vcpu
Cache a vCPU's CPUID information in "struct kvm_vcpu" to allow fixing the mess where tests, often unknowingly, modify the global/static "cpuid" allocated by kvm_get_supported_cpuid(). Add vcpu_init_cpuid() to handle stuffing an entirely different CPUID model, e.g. during vCPU creation or when switching to the Hyper-V enabled CPUID model. Automatically refresh the cache on vcpu_set_cpuid() so that any adjustments made by KVM are always reflected in the cache. Drop vcpu_get_cpuid() entirely to force tests to use the cache, and to allow adding e.g. vcpu_get_cpuid_entry() in the future without creating a conflicting set of APIs where vcpu_get_cpuid() does KVM_GET_CPUID2, but vcpu_get_cpuid_entry() does not. Opportunistically convert the VMX nested state test and KVM PV test to manipulating the vCPU's CPUID (because it's easy), but use vcpu_init_cpuid() for the Hyper-V features test and "emulator error" test to effectively retain their current behavior as they're less trivial to convert. Signed-off-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20220614200707.3315957-19-seanjc@google.com
Diffstat (limited to 'tools/testing/selftests/kvm/x86_64/kvm_pv_test.c')
-rw-r--r--tools/testing/selftests/kvm/x86_64/kvm_pv_test.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c b/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
index ea452444f4af..986ca7282a09 100644
--- a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
+++ b/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
@@ -147,7 +147,6 @@ static void enter_guest(struct kvm_vcpu *vcpu)
int main(void)
{
- struct kvm_cpuid2 *best;
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
@@ -157,9 +156,8 @@ int main(void)
vcpu_enable_cap(vcpu, KVM_CAP_ENFORCE_PV_FEATURE_CPUID, 1);
- best = kvm_get_supported_cpuid();
- clear_kvm_cpuid_features(best);
- vcpu_set_cpuid(vcpu, best);
+ clear_kvm_cpuid_features(vcpu->cpuid);
+ vcpu_set_cpuid(vcpu);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);