Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753328AbdGNBkQ (ORCPT ); Thu, 13 Jul 2017 21:40:16 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:36623 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752731AbdGNBkE (ORCPT ); Thu, 13 Jul 2017 21:40:04 -0400 MIME-Version: 1.0 In-Reply-To: <20170713152921.GF3442@potion> References: <1498705321-3927-1-git-send-email-wanpeng.li@hotmail.com> <1498705321-3927-3-git-send-email-wanpeng.li@hotmail.com> <20170712214408.GH3326@potion> <20170713152921.GF3442@potion> From: Wanpeng Li Date: Fri, 14 Jul 2017 09:40:03 +0800 Message-ID: Subject: Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Cc: "linux-kernel@vger.kernel.org" , kvm , Paolo Bonzini , Wanpeng Li Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v6E1eUKa001073 Content-Length: 4509 Lines: 109 2017-07-13 23:29 GMT+08:00 Radim Krčmář : > 2017-07-12 23:44+0200, Radim Krčmář: >> 2017-06-28 20:01-0700, Wanpeng Li: >> > From: Wanpeng Li >> > >> > This patch adds the L1 guest async page fault #PF vmexit handler, such >> > #PF is converted into vmexit from L2 to L1 on #PF which is then handled >> > by L1 similar to ordinary async page fault. >> > >> > Cc: Paolo Bonzini >> > Cc: Radim Krčmář >> > Signed-off-by: Wanpeng Li >> > --- >> >> This patch breaks SVM, so I've taken the series off kvm/queue for now; > > The error is triggered by 'WARN_ON_ONCE(tdp_enabled);', because > pf_interception() handles both cases. (The bizzare part is that it > doesn't warn.) > > I think this hunk on top of the patch would be good. It makes the Thanks Radim! The work is really appreciated. :) > WARN_ON_ONCE specific to VMX and also preserves the parameters that SVM > had before. I replace the tdp_enabled by enable_ept in VMX since there is a warning: "tdp_enabled" in [kvm-intel.ko] undefined! Btw, I just sent out v8, hope both the v8 and vm86 stuff can catch the end of the merge window. :) Regards, Wanpeng Li > > (Passes basic tests, haven't done the nested async_pf test yet.) > > > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c > index f37c0307dcb0..338cb4c8cbb9 100644 > --- a/arch/x86/kvm/mmu.c > +++ b/arch/x86/kvm/mmu.c > @@ -3782,17 +3782,16 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn, > } > > int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code, > - u64 fault_address) > + u64 fault_address, char *insn, int insn_len, > + bool need_unprotect) > { > int r = 1; > > switch (vcpu->arch.apf.host_apf_reason) { > default: > - /* TDP won't cause page fault directly */ > - WARN_ON_ONCE(tdp_enabled); > trace_kvm_page_fault(fault_address, error_code); > > - if (kvm_event_needs_reinjection(vcpu)) > + if (need_unprotect && kvm_event_needs_reinjection(vcpu)) > kvm_mmu_unprotect_page_virt(vcpu, fault_address); > r = kvm_mmu_page_fault(vcpu, fault_address, error_code, NULL, 0); > break; > diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > index 270d9adaa039..d7d248a000dd 100644 > --- a/arch/x86/kvm/mmu.h > +++ b/arch/x86/kvm/mmu.h > @@ -78,7 +78,8 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly, > bool accessed_dirty); > bool kvm_can_do_async_pf(struct kvm_vcpu *vcpu); > int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code, > - u64 fault_address); > + u64 fault_address, char *insn, int insn_len, > + bool need_unprotect); > > static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm) > { > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 659b610c4711..fb23497cf915 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -2123,7 +2123,9 @@ static int pf_interception(struct vcpu_svm *svm) > u64 fault_address = svm->vmcb->control.exit_info_2; > u64 error_code = svm->vmcb->control.exit_info_1; > > - return kvm_handle_page_fault(&svm->vcpu, error_code, fault_address); > + return kvm_handle_page_fault(&svm->vcpu, error_code, fault_address, > + svm->vmcb->control.insn_bytes, > + svm->vmcb->control.insn_len, !npt_enabled); > } > > static int db_interception(struct vcpu_svm *svm) > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index ab33eace4f66..2e8cfb2f1371 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -5699,7 +5699,10 @@ static int handle_exception(struct kvm_vcpu *vcpu) > > if (is_page_fault(intr_info)) { > cr2 = vmcs_readl(EXIT_QUALIFICATION); > - return kvm_handle_page_fault(vcpu, error_code, cr2); > + /* TDP won't cause page fault directly */ > + WARN_ON_ONCE(!vcpu->arch.apf.host_apf_reason && tdp_enabled); > + return kvm_handle_page_fault(vcpu, error_code, cr2, NULL, 0, > + true); > } > > ex_no = intr_info & INTR_INFO_VECTOR_MASK;