From: Brijesh Singh <brijesh.singh@amd.com>
To: <pbonzini@redhat.com>, <rkrcmar@redhat.com>, <joro@8bytes.org>,
<kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <tglx@linutronix.de>, <mingo@redhat.com>, <hpa@zytor.com>,
<x86@kernel.org>, <Thomas.Lendacky@amd.com>,
<brijesh.singh@amd.com>
Subject: [PATCH v2] KVM: x86: Avoid guest page table walk when gpa_available is set
Date: Fri, 19 May 2017 11:12:29 -0400 [thread overview]
Message-ID: <1495206749-25393-1-git-send-email-brijesh.singh@amd.com> (raw)
From: Brijesh Singh <brijesh.singh@amd.com>
On AMD hardware when a guest causes a NPF which requires emulation,
the vcpu->arch.gpa_available flag is set to indicate that cr2 contains
a valid GPA.
Currently, emulator_read_write_onepage() makes use of gpa_available flag
to avoid a guest page walk for a known MMIO regions. Lets not limit
the gpa_available optimization to just MMIO region. The patch extends
the check to avoid page walk whenever gpa_available flag is set.
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
v1: http://marc.info/?l=kvm&m=149304930814202&w=2
Changes in v2:
- move gpa_val setting in pf_interception
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/svm.c | 4 ++++
arch/x86/kvm/x86.c | 14 +++++++-------
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 695605e..cc87e00 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -678,6 +678,7 @@ struct kvm_vcpu_arch {
/* GPA available (AMD only) */
bool gpa_available;
+ gpa_t gpa_val;
};
struct kvm_lpage_info {
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index c27ac69..27fb563 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2070,9 +2070,13 @@ static void svm_set_dr7(struct kvm_vcpu *vcpu, unsigned long value)
static int pf_interception(struct vcpu_svm *svm)
{
u64 fault_address = svm->vmcb->control.exit_info_2;
+ struct kvm_vcpu *vcpu = &svm->vcpu;
u64 error_code;
int r = 1;
+ /* On #NPF, exit_info_2 contains a valid GPA */
+ vcpu->arch.gpa_val = fault_address;
+
switch (svm->apf_reason) {
default:
error_code = svm->vmcb->control.exit_info_1;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index b54125b..d2d88ed 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4634,16 +4634,16 @@ static int emulator_read_write_onepage(unsigned long addr, void *val,
*/
if (vcpu->arch.gpa_available &&
emulator_can_use_gpa(ctxt) &&
- vcpu_is_mmio_gpa(vcpu, addr, exception->address, write) &&
(addr & ~PAGE_MASK) == (exception->address & ~PAGE_MASK)) {
- gpa = exception->address;
- goto mmio;
- }
+ gpa = vcpu->arch.gpa_val;
+ ret = vcpu_is_mmio_gpa(vcpu, addr, gpa, write);
+ } else {
- ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, write);
+ ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, write);
- if (ret < 0)
- return X86EMUL_PROPAGATE_FAULT;
+ if (ret < 0)
+ return X86EMUL_PROPAGATE_FAULT;
+ }
/* For APIC access vmexit */
if (ret)
--
2.7.4
next reply other threads:[~2017-05-19 15:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-19 15:12 Brijesh Singh [this message]
2017-05-30 9:05 ` Joerg Roedel
2017-05-30 22:09 ` Brijesh Singh
2017-07-17 21:32 ` Brijesh Singh
2017-07-19 11:19 ` Radim Krčmář
2017-07-19 13:35 ` Brijesh Singh
2017-07-20 7:43 ` Radim Krčmář
2017-08-08 19:24 ` Brijesh Singh
2017-07-27 13:49 ` 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=1495206749-25393-1-git-send-email-brijesh.singh@amd.com \
--to=brijesh.singh@amd.com \
--cc=Thomas.Lendacky@amd.com \
--cc=hpa@zytor.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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®