kvm: x86: Move last_cpu into kvm_vcpu_arch as last_vmentry_cpu
authorJim Mattson <jmattson@google.com>
Wed, 3 Jun 2020 23:56:22 +0000 (16:56 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 Jul 2020 20:21:45 +0000 (16:21 -0400)
Both the vcpu_vmx structure and the vcpu_svm structure have a
'last_cpu' field. Move the common field into the kvm_vcpu_arch
structure. For clarity, rename it to 'last_vmentry_cpu.'

Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Oliver Upton <oupton@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
Message-Id: <20200603235623.245638-6-jmattson@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm/sev.c
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/vmx/vmx.h

index 89e1a66ebee9d95bf13472a2704d0011b4bbaa9b..2357763bf7f26b3647d7af46c4cfc17e9c561037 100644 (file)
@@ -827,6 +827,9 @@ struct kvm_vcpu_arch {
        /* Flush the L1 Data cache for L1TF mitigation on VMENTER */
        bool l1tf_flush_l1d;
 
+       /* Host CPU on which VM-entry was most recently attempted */
+       unsigned int last_vmentry_cpu;
+
        /* AMD MSRC001_0015 Hardware Configuration */
        u64 msr_hwcr;
 };
index a8444c74430e926d2dd279371332c0935cc4bf21..e09aef93e92b2608789b10ea25f632c5f83b8968 100644 (file)
@@ -1186,7 +1186,7 @@ void pre_sev_run(struct vcpu_svm *svm, int cpu)
         * 2) or this VMCB was executed on different host CPU in previous VMRUNs.
         */
        if (sd->sev_vmcbs[asid] == svm->vmcb &&
-           svm->last_cpu == cpu)
+           svm->vcpu.arch.last_vmentry_cpu == cpu)
                return;
 
        sd->sev_vmcbs[asid] = svm->vmcb;
index 8ecd46f2cb1ec25c585dcda58db825665a466d16..c55ebf76ec6d56823aa68e58e155f1560cfa46de 100644 (file)
@@ -2947,7 +2947,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
                kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
                kvm_run->fail_entry.hardware_entry_failure_reason
                        = svm->vmcb->control.exit_code;
-               kvm_run->fail_entry.cpu = svm->last_cpu;
+               kvm_run->fail_entry.cpu = vcpu->arch.last_vmentry_cpu;
                dump_vmcb(vcpu);
                return 0;
        }
@@ -2973,7 +2973,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
                        KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
                vcpu->run->internal.ndata = 2;
                vcpu->run->internal.data[0] = exit_code;
-               vcpu->run->internal.data[1] = svm->last_cpu;
+               vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
                return 0;
        }
 
@@ -3398,7 +3398,7 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
         */
        x86_spec_ctrl_set_guest(svm->spec_ctrl, svm->virt_spec_ctrl);
 
-       svm->last_cpu = vcpu->cpu;
+       vcpu->arch.last_vmentry_cpu = vcpu->cpu;
        __svm_vcpu_run(svm->vmcb_pa, (unsigned long *)&svm->vcpu.arch.regs);
 
 #ifdef CONFIG_X86_64
index 6ac4c00a5d826927ea703b679c19320a458a9a85..613356f85da6ada4068d4b29164e26da89445830 100644 (file)
@@ -158,9 +158,6 @@ struct vcpu_svm {
         */
        struct list_head ir_list;
        spinlock_t ir_list_lock;
-
-       /* which host CPU was used for running this vcpu */
-       unsigned int last_cpu;
 };
 
 struct svm_cpu_data {
index b52bcebfa09436de36a0058ff61eaa4be5ffd3bb..d9ee31b0679b1802cabac5a2257a5d484498ae50 100644 (file)
@@ -4785,7 +4785,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
                vcpu->run->internal.data[0] = vect_info;
                vcpu->run->internal.data[1] = intr_info;
                vcpu->run->internal.data[2] = error_code;
-               vcpu->run->internal.data[3] = vmx->last_cpu;
+               vcpu->run->internal.data[3] = vcpu->arch.last_vmentry_cpu;
                return 0;
        }
 
@@ -6007,7 +6007,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
                vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
                vcpu->run->fail_entry.hardware_entry_failure_reason
                        = exit_reason;
-               vcpu->run->fail_entry.cpu = vmx->last_cpu;
+               vcpu->run->fail_entry.cpu = vcpu->arch.last_vmentry_cpu;
                return 0;
        }
 
@@ -6016,7 +6016,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
                vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
                vcpu->run->fail_entry.hardware_entry_failure_reason
                        = vmcs_read32(VM_INSTRUCTION_ERROR);
-               vcpu->run->fail_entry.cpu = vmx->last_cpu;
+               vcpu->run->fail_entry.cpu = vcpu->arch.last_vmentry_cpu;
                return 0;
        }
 
@@ -6044,7 +6044,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
                                vmcs_read64(GUEST_PHYSICAL_ADDRESS);
                }
                vcpu->run->internal.data[vcpu->run->internal.ndata++] =
-                       vmx->last_cpu;
+                       vcpu->arch.last_vmentry_cpu;
                return 0;
        }
 
@@ -6102,7 +6102,7 @@ unexpected_vmexit:
                        KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
        vcpu->run->internal.ndata = 2;
        vcpu->run->internal.data[0] = exit_reason;
-       vcpu->run->internal.data[1] = vmx->last_cpu;
+       vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
        return 0;
 }
 
@@ -6740,7 +6740,7 @@ reenter_guest:
        if (vcpu->arch.cr2 != read_cr2())
                write_cr2(vcpu->arch.cr2);
 
-       vmx->last_cpu = vcpu->cpu;
+       vcpu->arch.last_vmentry_cpu = vcpu->cpu;
        vmx->fail = __vmx_vcpu_run(vmx, (unsigned long *)&vcpu->arch.regs,
                                   vmx->loaded_vmcs->launched);
 
index f8f9e214d285f0644bc028e23eb7fac3b43b3ef2..639798e4a6ca74a41a59824f936d59a0a6412589 100644 (file)
@@ -300,9 +300,6 @@ struct vcpu_vmx {
        u64 ept_pointer;
 
        struct pt_desc pt_desc;
-
-       /* which host CPU was used for running this vcpu */
-       unsigned int last_cpu;
 };
 
 enum ept_pointers_status {