• Sean Christopherson's avatar
    KVM: selftests: Cache CPUID in struct kvm_vcpu · 7fbc6038
    Sean Christopherson authored
    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: default avatarSean Christopherson <seanjc@google.com>
    Link: https://lore.kernel.org/r/20220614200707.3315957-19-seanjc@google.com
    7fbc6038
kvm_util_base.h 22.9 KB