]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: SVM: Move RESET emulation to svm_vcpu_reset()
authorSean Christopherson <seanjc@google.com>
Tue, 21 Sep 2021 00:03:02 +0000 (17:03 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 30 Sep 2021 08:27:07 +0000 (04:27 -0400)
Move RESET emulation for SVM vCPUs to svm_vcpu_reset(), and drop an extra
init_vmcb() from svm_create_vcpu() in the process.  Hopefully KVM will
someday expose a dedicated RESET ioctl(), and in the meantime separating
"create" from "RESET" is a nice cleanup.

Keep the call to svm_switch_vmcb() so that misuse of svm->vmcb at worst
breaks the guest, e.g. premature accesses doesn't cause a NULL pointer
dereference.

Cc: Reiji Watanabe <reijiw@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210921000303.400537-10-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/sev.c
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h

index c36b5fe4c27ca5bf399db828927ab02e4f7d9ec7..1e8b26b93b4fb1db5d416ed108e4cb30f5bab84b 100644 (file)
@@ -2631,11 +2631,11 @@ void sev_es_init_vmcb(struct vcpu_svm *svm)
        set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTINTTOIP, 1, 1);
 }
 
-void sev_es_create_vcpu(struct vcpu_svm *svm)
+void sev_es_vcpu_reset(struct vcpu_svm *svm)
 {
        /*
-        * Set the GHCB MSR value as per the GHCB specification when creating
-        * a vCPU for an SEV-ES guest.
+        * Set the GHCB MSR value as per the GHCB specification when emulating
+        * vCPU RESET for an SEV-ES guest.
         */
        set_ghcb_msr(svm, GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX,
                                            GHCB_VERSION_MIN,
index 989685098b3ea7d62f251bd3b1ac39de7e2391c6..c770dce55ba8bc6a084607a035fa3c56b62f684c 100644 (file)
@@ -1303,6 +1303,19 @@ static void init_vmcb(struct kvm_vcpu *vcpu)
 
 }
 
+static void __svm_vcpu_reset(struct kvm_vcpu *vcpu)
+{
+       struct vcpu_svm *svm = to_svm(vcpu);
+
+       svm_vcpu_init_msrpm(vcpu, svm->msrpm);
+
+       svm_init_osvw(vcpu);
+       vcpu->arch.microcode_version = 0x01000065;
+
+       if (sev_es_guest(vcpu->kvm))
+               sev_es_vcpu_reset(svm);
+}
+
 static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
@@ -1311,6 +1324,9 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
        svm->virt_spec_ctrl = 0;
 
        init_vmcb(vcpu);
+
+       if (!init_event)
+               __svm_vcpu_reset(vcpu);
 }
 
 void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb)
@@ -1370,24 +1386,13 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)
 
        svm->vmcb01.ptr = page_address(vmcb01_page);
        svm->vmcb01.pa = __sme_set(page_to_pfn(vmcb01_page) << PAGE_SHIFT);
+       svm_switch_vmcb(svm, &svm->vmcb01);
 
        if (vmsa_page)
                svm->vmsa = page_address(vmsa_page);
 
        svm->guest_state_loaded = false;
 
-       svm_switch_vmcb(svm, &svm->vmcb01);
-       init_vmcb(vcpu);
-
-       svm_vcpu_init_msrpm(vcpu, svm->msrpm);
-
-       svm_init_osvw(vcpu);
-       vcpu->arch.microcode_version = 0x01000065;
-
-       if (sev_es_guest(vcpu->kvm))
-               /* Perform SEV-ES specific VMCB creation updates */
-               sev_es_create_vcpu(svm);
-
        return 0;
 
 error_free_vmsa_page:
index 128a54b1fbf141214a2b47acd42d68babfa36d65..c19859e62dec0d8a3df8551a42333b363a3eda32 100644 (file)
@@ -562,7 +562,7 @@ void sev_free_vcpu(struct kvm_vcpu *vcpu);
 int sev_handle_vmgexit(struct kvm_vcpu *vcpu);
 int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in);
 void sev_es_init_vmcb(struct vcpu_svm *svm);
-void sev_es_create_vcpu(struct vcpu_svm *svm);
+void sev_es_vcpu_reset(struct vcpu_svm *svm);
 void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector);
 void sev_es_prepare_guest_switch(struct vcpu_svm *svm, unsigned int cpu);
 void sev_es_unmap_ghcb(struct vcpu_svm *svm);