]> git.itanic.dy.fi Git - linux-stable/commitdiff
KVM: nVMX: hyper-v: Cache VP assist page in 'struct kvm_vcpu_hv'
authorVitaly Kuznetsov <vkuznets@redhat.com>
Tue, 1 Nov 2022 14:54:03 +0000 (15:54 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 18 Nov 2022 17:59:16 +0000 (12:59 -0500)
In preparation to enabling L2 TLB flush, cache VP assist page in
'struct kvm_vcpu_hv'. While on it, rename nested_enlightened_vmentry()
to nested_get_evmptr() and make it return eVMCS GPA directly.

No functional change intended.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20221101145426.251680-26-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/hyperv.c
arch/x86/kvm/hyperv.h
arch/x86/kvm/vmx/hyperv.c
arch/x86/kvm/vmx/hyperv.h
arch/x86/kvm/vmx/nested.c

index ebf90f4f1a21e5b289d19c0e60b3f5b71718462b..d1013c4f673cac9c65bc05a7a315e7d0f84e6367 100644 (file)
@@ -669,6 +669,8 @@ struct kvm_vcpu_hv {
        /* Preallocated buffer for handling hypercalls passing sparse vCPU set */
        u64 sparse_banks[HV_MAX_SPARSE_VCPU_BANKS];
 
+       struct hv_vp_assist_page vp_assist_page;
+
        struct {
                u64 pa_page_gpa;
                u64 vm_id;
index 3715a6f026a231fb225c3143f323e2bd26a492c5..ce245e37d08fc9d9618ba185220fd28935092f93 100644 (file)
@@ -900,13 +900,15 @@ bool kvm_hv_assist_page_enabled(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_hv_assist_page_enabled);
 
-bool kvm_hv_get_assist_page(struct kvm_vcpu *vcpu,
-                           struct hv_vp_assist_page *assist_page)
+bool kvm_hv_get_assist_page(struct kvm_vcpu *vcpu)
 {
-       if (!kvm_hv_assist_page_enabled(vcpu))
+       struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
+
+       if (!hv_vcpu || !kvm_hv_assist_page_enabled(vcpu))
                return false;
+
        return !kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.pv_eoi.data,
-                                     assist_page, sizeof(*assist_page));
+                                     &hv_vcpu->vp_assist_page, sizeof(struct hv_vp_assist_page));
 }
 EXPORT_SYMBOL_GPL(kvm_hv_get_assist_page);
 
index bd698eb2bda10cbb7420b1e921113ee3b4770a3b..81313e418b80a48a5ae2fb05dd8a5c850d775ba8 100644 (file)
@@ -108,8 +108,7 @@ int kvm_hv_activate_synic(struct kvm_vcpu *vcpu, bool dont_zero_synic_pages);
 void kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu);
 
 bool kvm_hv_assist_page_enabled(struct kvm_vcpu *vcpu);
-bool kvm_hv_get_assist_page(struct kvm_vcpu *vcpu,
-                           struct hv_vp_assist_page *assist_page);
+bool kvm_hv_get_assist_page(struct kvm_vcpu *vcpu);
 
 static inline struct kvm_vcpu_hv_stimer *to_hv_stimer(struct kvm_vcpu *vcpu,
                                                      int timer_index)
index f05464db4fdc1201c12945b49ae584976a0d1351..bceca1a99804fdac96d5ca582f68ad9daba2d4fa 100644 (file)
@@ -321,24 +321,17 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = {
 };
 const unsigned int nr_evmcs_1_fields = ARRAY_SIZE(vmcs_field_to_evmcs_1);
 
-bool nested_enlightened_vmentry(struct kvm_vcpu *vcpu, u64 *evmcs_gpa)
+u64 nested_get_evmptr(struct kvm_vcpu *vcpu)
 {
-       struct hv_vp_assist_page assist_page;
-
-       *evmcs_gpa = -1ull;
-
-       if (unlikely(!kvm_hv_get_assist_page(vcpu, &assist_page)))
-               return false;
-
-       if (unlikely(!assist_page.enlighten_vmentry))
-               return false;
+       struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
 
-       if (unlikely(!evmptr_is_valid(assist_page.current_nested_vmcs)))
-               return false;
+       if (unlikely(!kvm_hv_get_assist_page(vcpu)))
+               return EVMPTR_INVALID;
 
-       *evmcs_gpa = assist_page.current_nested_vmcs;
+       if (unlikely(!hv_vcpu->vp_assist_page.enlighten_vmentry))
+               return EVMPTR_INVALID;
 
-       return true;
+       return hv_vcpu->vp_assist_page.current_nested_vmcs;
 }
 
 uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu)
index 8efaffe9215bf2ce9b58a6874c8ebdd93046862d..8bf366730d333cda68b4963683011f5c66733e22 100644 (file)
@@ -237,7 +237,7 @@ enum nested_evmptrld_status {
        EVMPTRLD_ERROR,
 };
 
-bool nested_enlightened_vmentry(struct kvm_vcpu *vcpu, u64 *evmcs_gpa);
+u64 nested_get_evmptr(struct kvm_vcpu *vcpu);
 uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu);
 int nested_enable_evmcs(struct kvm_vcpu *vcpu,
                        uint16_t *vmcs_version);
index 396712d13211fc63bdafea4e6fdfaf8ba12d4512..38e6cb8abe62736d56b7600cf11146e6975caa4d 100644 (file)
@@ -1992,7 +1992,8 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(
        if (likely(!guest_cpuid_has_evmcs(vcpu)))
                return EVMPTRLD_DISABLED;
 
-       if (!nested_enlightened_vmentry(vcpu, &evmcs_gpa)) {
+       evmcs_gpa = nested_get_evmptr(vcpu);
+       if (!evmptr_is_valid(evmcs_gpa)) {
                nested_release_evmcs(vcpu);
                return EVMPTRLD_DISABLED;
        }
@@ -5221,7 +5222,6 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)
        struct vcpu_vmx *vmx = to_vmx(vcpu);
        u32 zero = 0;
        gpa_t vmptr;
-       u64 evmcs_gpa;
        int r;
 
        if (!nested_vmx_check_permission(vcpu))
@@ -5247,7 +5247,7 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)
         * vmx->nested.hv_evmcs but this shouldn't be a problem.
         */
        if (likely(!guest_cpuid_has_evmcs(vcpu) ||
-                  !nested_enlightened_vmentry(vcpu, &evmcs_gpa))) {
+                  !evmptr_is_valid(nested_get_evmptr(vcpu)))) {
                if (vmptr == vmx->nested.current_vmptr)
                        nested_release_vmcs12(vcpu);