From patchwork Thu Jul 13 15:29:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9838891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0853E602A0 for ; Thu, 13 Jul 2017 15:29:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECF8728591 for ; Thu, 13 Jul 2017 15:29:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0C5C28645; Thu, 13 Jul 2017 15:29:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 892A728591 for ; Thu, 13 Jul 2017 15:29:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751337AbdGMP31 (ORCPT ); Thu, 13 Jul 2017 11:29:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57196 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751193AbdGMP3Z (ORCPT ); Thu, 13 Jul 2017 11:29:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DC8AB9AB3; Thu, 13 Jul 2017 15:29:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0DC8AB9AB3 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=rkrcmar@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0DC8AB9AB3 Received: from potion (unknown [10.43.2.65]) by smtp.corp.redhat.com (Postfix) with SMTP id C02A317B76; Thu, 13 Jul 2017 15:29:22 +0000 (UTC) Received: by potion (sSMTP sendmail emulation); Thu, 13 Jul 2017 17:29:21 +0200 Date: Thu, 13 Jul 2017 17:29:21 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li Subject: Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler Message-ID: <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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170712214408.GH3326@potion> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 13 Jul 2017 15:29:25 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 WARN_ON_ONCE specific to VMX and also preserves the parameters that SVM had before. (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;