]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Use vcpu_get_cpuid_entry() in PV features test (sort of)
authorSean Christopherson <seanjc@google.com>
Tue, 14 Jun 2022 20:06:50 +0000 (20:06 +0000)
committerSean Christopherson <seanjc@google.com>
Thu, 14 Jul 2022 01:14:18 +0000 (18:14 -0700)
Add a new helper, vcpu_clear_cpuid_entry(), to do a RMW operation on the
vCPU's CPUID model to clear a given CPUID entry, and use it to clear
KVM's paravirt feature instead of operating on kvm_get_supported_cpuid()'s
static "cpuid" variable.  This also eliminates a user of
the soon-be-defunct set_cpuid() helper.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20220614200707.3315957-26-seanjc@google.com
tools/testing/selftests/kvm/include/x86_64/processor.h
tools/testing/selftests/kvm/lib/x86_64/processor.c
tools/testing/selftests/kvm/x86_64/kvm_pv_test.c

index a3d61807d2238c4ee5eed841d9472a3a0211f946..c0d40474ef2ddc0bafa0400e5bb0e36765f28796 100644 (file)
@@ -660,6 +660,7 @@ static inline void vcpu_set_cpuid(struct kvm_vcpu *vcpu)
 
 void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, uint8_t maxphyaddr);
 
+void vcpu_clear_cpuid_entry(struct kvm_vcpu *vcpu, uint32_t function);
 void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu,
                                     struct kvm_x86_cpu_feature feature,
                                     bool set);
index 27bf5dad6ec5f09572a2b9e3c1d2b1e3ca4bf8e0..a4138486333692b63e59141140abb19f19d7fdfc 100644 (file)
@@ -770,6 +770,17 @@ void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, uint8_t maxphyaddr)
        vcpu_set_cpuid(vcpu);
 }
 
+void vcpu_clear_cpuid_entry(struct kvm_vcpu *vcpu, uint32_t function)
+{
+       struct kvm_cpuid_entry2 *entry = vcpu_get_cpuid_entry(vcpu, function);
+
+       entry->eax = 0;
+       entry->ebx = 0;
+       entry->ecx = 0;
+       entry->edx = 0;
+       vcpu_set_cpuid(vcpu);
+}
+
 void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu,
                                     struct kvm_x86_cpu_feature feature,
                                     bool set)
index 986ca7282a092f9d6912a0761f268dd4594cbfa5..619655c1a1f39fbf950149a13d9feec57f8f6ea8 100644 (file)
@@ -95,15 +95,6 @@ static void guest_main(void)
        GUEST_DONE();
 }
 
-static void clear_kvm_cpuid_features(struct kvm_cpuid2 *cpuid)
-{
-       struct kvm_cpuid_entry2 ent = {0};
-
-       ent.function = KVM_CPUID_FEATURES;
-       TEST_ASSERT(set_cpuid(cpuid, &ent),
-                   "failed to clear KVM_CPUID_FEATURES leaf");
-}
-
 static void pr_msr(struct ucall *uc)
 {
        struct msr_data *msr = (struct msr_data *)uc->args[0];
@@ -156,8 +147,7 @@ int main(void)
 
        vcpu_enable_cap(vcpu, KVM_CAP_ENFORCE_PV_FEATURE_CPUID, 1);
 
-       clear_kvm_cpuid_features(vcpu->cpuid);
-       vcpu_set_cpuid(vcpu);
+       vcpu_clear_cpuid_entry(vcpu, KVM_CPUID_FEATURES);
 
        vm_init_descriptor_tables(vm);
        vcpu_init_descriptor_tables(vcpu);