From: Brijesh Singh <brijesh.singh@amd.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Brijesh Singh" <brijesh.singh@amd.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Thomas Lendacky" <thomas.lendacky@amd.com>
Subject: [PATCH] KVM: SVM: Limit PFERR_NESTED_GUEST_PAGE error_code check to L1 guest
Date: Mon, 7 Aug 2017 14:11:30 -0500 [thread overview]
Message-ID: <20170807191130.33299-1-brijesh.singh@amd.com> (raw)
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 <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Thomas Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
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;
}
--
2.9.4
next reply other threads:[~2017-08-07 19:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-07 19:11 Brijesh Singh [this message]
2017-08-08 10:06 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170807191130.33299-1-brijesh.singh@amd.com \
--to=brijesh.singh@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®