]> www.infradead.org Git - users/willy/xarray.git/commitdiff
KVM: VMX: introduce vmx_need_pf_intercept
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 10 Jul 2020 15:48:08 +0000 (17:48 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 10 Jul 2020 21:01:52 +0000 (17:01 -0400)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200710154811.418214-7-mgamal@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/vmx/vmx.h

index e4080ab2df21cd3e0b8947dd84031183e4af31b3..4d561edf6f9ca6b1edf1e07f65603e0a313d4b21 100644 (file)
@@ -2438,22 +2438,28 @@ static void prepare_vmcs02_rare(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
 
        /*
         * Whether page-faults are trapped is determined by a combination of
-        * 3 settings: PFEC_MASK, PFEC_MATCH and EXCEPTION_BITMAP.PF.
-        * If enable_ept, L0 doesn't care about page faults and we should
-        * set all of these to L1's desires. However, if !enable_ept, L0 does
-        * care about (at least some) page faults, and because it is not easy
-        * (if at all possible?) to merge L0 and L1's desires, we simply ask
-        * to exit on each and every L2 page fault. This is done by setting
-        * MASK=MATCH=0 and (see below) EB.PF=1.
+        * 3 settings: PFEC_MASK, PFEC_MATCH and EXCEPTION_BITMAP.PF.  If L0
+        * doesn't care about page faults then we should set all of these to
+        * L1's desires. However, if L0 does care about (some) page faults, it
+        * is not easy (if at all possible?) to merge L0 and L1's desires, we
+        * simply ask to exit on each and every L2 page fault. This is done by
+        * setting MASK=MATCH=0 and (see below) EB.PF=1.
         * Note that below we don't need special code to set EB.PF beyond the
         * "or"ing of the EB of vmcs01 and vmcs12, because when enable_ept,
         * vmcs01's EB.PF is 0 so the "or" will take vmcs12's value, and when
         * !enable_ept, EB.PF is 1, so the "or" will always be 1.
         */
-       vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK,
-               enable_ept ? vmcs12->page_fault_error_code_mask : 0);
-       vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH,
-               enable_ept ? vmcs12->page_fault_error_code_match : 0);
+       if (vmx_need_pf_intercept(&vmx->vcpu)) {
+               /*
+                * TODO: if both L0 and L1 need the same MASK and MATCH,
+                * go ahead and use it?
+                */
+               vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, 0);
+               vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, 0);
+       } else {
+               vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, vmcs12->page_fault_error_code_mask);
+               vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, vmcs12->page_fault_error_code_match);
+       }
 
        if (cpu_has_vmx_apicv()) {
                vmcs_write64(EOI_EXIT_BITMAP0, vmcs12->eoi_exit_bitmap0);
index 8fe2999fcb1e5e2a36cf1ff0bdfef7ac57c7a6c9..6c51438c75670bba11cbdcef282c148b4c776f3f 100644 (file)
@@ -780,7 +780,7 @@ void update_exception_bitmap(struct kvm_vcpu *vcpu)
                eb |= 1u << BP_VECTOR;
        if (to_vmx(vcpu)->rmode.vm86_active)
                eb = ~0;
-       if (enable_ept)
+       if (!vmx_need_pf_intercept(vcpu))
                eb &= ~(1u << PF_VECTOR);
 
        /* When we are running a nested L2 guest and L1 specified for it a
index 639798e4a6ca74a41a59824f936d59a0a6412589..b0e5e210f1c1f2a1cca478643c25de23b85f49ca 100644 (file)
@@ -550,6 +550,11 @@ static inline bool vmx_has_waitpkg(struct vcpu_vmx *vmx)
                SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE;
 }
 
+static inline bool vmx_need_pf_intercept(struct kvm_vcpu *vcpu)
+{
+       return !enable_ept;
+}
+
 void dump_vmcs(void);
 
 #endif /* __KVM_X86_VMX_H */