From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752174AbdHHKGN (ORCPT ); Tue, 8 Aug 2017 06:06:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38714 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751921AbdHHKGM (ORCPT ); Tue, 8 Aug 2017 06:06:12 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 86AFF4A702 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH] KVM: SVM: Limit PFERR_NESTED_GUEST_PAGE error_code check to L1 guest To: Brijesh Singh , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Lendacky References: <20170807191130.33299-1-brijesh.singh@amd.com> From: Paolo Bonzini Message-ID: Date: Tue, 8 Aug 2017 12:06:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170807191130.33299-1-brijesh.singh@amd.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 08 Aug 2017 10:06:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/08/2017 21:11, Brijesh Singh wrote: > Commit: 1472775 (kvm: svm: Add support for additional SVM NPF error codes) > added new error code to aid nested page fault handling. The commit > unprotect (kvm_mmu_unprotect_page) the page when we get a NFP due to > guest page table walk where the page was marked RO. > > Paolo highlighted a use case, where an L0->L2 shadow nested page table > is marked read-only, in particular when a page is read only in L1's nested > page table. If such a page is accessed by L2 while walking page tables > it can cause a nested page fault (page table walks are write accessed). > However, after kvm_mmu_unprotect_page we may get another page fault, and > again in an endless stream. > > To cover this use case, we qualify the new error_code check with > vcpu->arch.mmu_direct_map so that the error_code check would run on L1 > guest, and not the L2 guest. This would restrict it avoid hitting the above > use case. > > Cc: Paolo Bonzini > Cc: "Radim Krčmář" > Cc: Thomas Lendacky > Signed-off-by: Brijesh Singh > --- > > See http://marc.info/?l=kvm&m=150153155519373&w=2 for detail discussion on the use case and code flow. > > arch/x86/kvm/mmu.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c > index 9b1dd11..4aaa4aa 100644 > --- a/arch/x86/kvm/mmu.c > +++ b/arch/x86/kvm/mmu.c > @@ -4839,7 +4839,8 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code, > * Note: AMD only (since it supports the PFERR_GUEST_PAGE_MASK used > * in PFERR_NEXT_GUEST_PAGE) > */ > - if (error_code == PFERR_NESTED_GUEST_PAGE) { > + if (vcpu->arch.mmu.direct_map && > + (error_code == PFERR_NESTED_GUEST_PAGE)) { > kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(cr2)); > return 1; > } > Thanks, queued for 4.14. Paolo