mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: <"http://kvm.qumranet.com"@osrc.amd.com>,
	<linux-kernel@vger.kernel.org>,
	Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 11/27] KVM: X86: Introduce pointer to mmu context used for gva_to_gpa
Date: Mon, 6 Sep 2010 17:01:46 +0200	[thread overview]
Message-ID: <1283785322-26898-12-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1283785322-26898-1-git-send-email-joerg.roedel@amd.com>

This patch introduces the walk_mmu pointer which points to
the mmu-context currently used for gva_to_gpa translations.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/include/asm/kvm_host.h |   14 ++++++++++++++
 arch/x86/kvm/mmu.c              |   10 +++++-----
 arch/x86/kvm/x86.c              |   17 ++++++++++-------
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index af8cce3..d797746 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -288,7 +288,21 @@ struct kvm_vcpu_arch {
 	u64 ia32_misc_enable_msr;
 	bool tpr_access_reporting;
 
+	/*
+	 * Paging state of the vcpu
+	 *
+	 * If the vcpu runs in guest mode with two level paging this still saves
+	 * the paging mode of the l1 guest. This context is always used to
+	 * handle faults.
+	 */
 	struct kvm_mmu mmu;
+
+	/*
+	 * Pointer to the mmu context currently used for
+	 * gva_to_gpa translations.
+	 */
+	struct kvm_mmu *walk_mmu;
+
 	/* only needed in kvm_pv_mmu_op() path, but it's hot so
 	 * put it here to avoid allocation */
 	struct kvm_pv_mmu_op_buffer mmu_op_buffer;
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 9668f91..a2cd2ce 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2707,7 +2707,7 @@ static int paging32E_init_context(struct kvm_vcpu *vcpu,
 
 static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
 {
-	struct kvm_mmu *context = &vcpu->arch.mmu;
+	struct kvm_mmu *context = vcpu->arch.walk_mmu;
 
 	context->new_cr3 = nonpaging_new_cr3;
 	context->page_fault = tdp_page_fault;
@@ -2767,11 +2767,11 @@ EXPORT_SYMBOL_GPL(kvm_init_shadow_mmu);
 
 static int init_kvm_softmmu(struct kvm_vcpu *vcpu)
 {
-	int r = kvm_init_shadow_mmu(vcpu, &vcpu->arch.mmu);
+	int r = kvm_init_shadow_mmu(vcpu, vcpu->arch.walk_mmu);
 
-	vcpu->arch.mmu.set_cr3           = kvm_x86_ops->set_cr3;
-	vcpu->arch.mmu.get_cr3           = get_cr3;
-	vcpu->arch.mmu.inject_page_fault = kvm_inject_page_fault;
+	vcpu->arch.walk_mmu->set_cr3           = kvm_x86_ops->set_cr3;
+	vcpu->arch.walk_mmu->get_cr3           = get_cr3;
+	vcpu->arch.walk_mmu->inject_page_fault = kvm_inject_page_fault;
 
 	return r;
 }
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 829efb0..e5dcf7f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3441,27 +3441,27 @@ static gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 *error)
 gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva, u32 *error)
 {
 	u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
-	return vcpu->arch.mmu.gva_to_gpa(vcpu, gva, access, error);
+	return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, error);
 }
 
  gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva, u32 *error)
 {
 	u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
 	access |= PFERR_FETCH_MASK;
-	return vcpu->arch.mmu.gva_to_gpa(vcpu, gva, access, error);
+	return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, error);
 }
 
 gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva, u32 *error)
 {
 	u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
 	access |= PFERR_WRITE_MASK;
-	return vcpu->arch.mmu.gva_to_gpa(vcpu, gva, access, error);
+	return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, error);
 }
 
 /* uses this to access any guest's mapped memory without checking CPL */
 gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, u32 *error)
 {
-	return vcpu->arch.mmu.gva_to_gpa(vcpu, gva, 0, error);
+	return vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, 0, error);
 }
 
 static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
@@ -3472,7 +3472,8 @@ static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
 	int r = X86EMUL_CONTINUE;
 
 	while (bytes) {
-		gpa_t gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, addr, access, error);
+		gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, access,
+							    error);
 		unsigned offset = addr & (PAGE_SIZE-1);
 		unsigned toread = min(bytes, (unsigned)PAGE_SIZE - offset);
 		int ret;
@@ -3527,8 +3528,9 @@ static int kvm_write_guest_virt_system(gva_t addr, void *val,
 	int r = X86EMUL_CONTINUE;
 
 	while (bytes) {
-		gpa_t gpa =  vcpu->arch.mmu.gva_to_gpa(vcpu, addr,
-						       PFERR_WRITE_MASK, error);
+		gpa_t gpa =  vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr,
+							     PFERR_WRITE_MASK,
+							     error);
 		unsigned offset = addr & (PAGE_SIZE-1);
 		unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset);
 		int ret;
@@ -5648,6 +5650,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
 	kvm = vcpu->kvm;
 
 	vcpu->arch.emulate_ctxt.ops = &emulate_ops;
+	vcpu->arch.walk_mmu = &vcpu->arch.mmu;
 	vcpu->arch.mmu.root_hpa = INVALID_PAGE;
 	vcpu->arch.mmu.translate_gpa = translate_gpa;
 	if (!irqchip_in_kernel(kvm) || kvm_vcpu_is_bsp(vcpu))
-- 
1.7.0.4



  parent reply	other threads:[~2010-09-06 15:05 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06 15:01 [PATCH 0/27] Nested Paging Virtualization for KVM v3 Joerg Roedel
2010-09-06 15:01 ` [PATCH 01/27] KVM: MMU: Check for root_level instead of long mode Joerg Roedel
2010-09-06 15:01 ` [PATCH 02/27] KVM: MMU: Make tdp_enabled a mmu-context parameter Joerg Roedel
2010-09-06 15:01 ` [PATCH 03/27] KVM: MMU: Make set_cr3 a function pointer in kvm_mmu Joerg Roedel
2010-09-06 15:01 ` [PATCH 04/27] KVM: X86: Introduce a tdp_set_cr3 function Joerg Roedel
2010-09-06 15:01 ` [PATCH 05/27] KVM: MMU: Introduce get_cr3 function pointer Joerg Roedel
2010-09-06 15:01 ` [PATCH 06/27] KVM: MMU: Introduce inject_page_fault " Joerg Roedel
2010-09-06 15:01 ` [PATCH 07/27] KVM: MMU: Introduce kvm_init_shadow_mmu helper function Joerg Roedel
2010-09-06 15:01 ` [PATCH 08/27] KVM: MMU: Let is_rsvd_bits_set take mmu context instead of vcpu Joerg Roedel
2010-09-06 15:01 ` [PATCH 09/27] KVM: MMU: Introduce generic walk_addr function Joerg Roedel
2010-09-06 15:01 ` [PATCH 10/27] KVM: MMU: Add infrastructure for two-level page walker Joerg Roedel
2010-09-06 15:01 ` Joerg Roedel [this message]
2010-09-06 15:01 ` [PATCH 12/27] KVM: MMU: Implement nested gva_to_gpa functions Joerg Roedel
2010-09-06 15:01 ` [PATCH 13/27] KVM: X86: Add kvm_read_guest_page_tdp function Joerg Roedel
2010-09-06 15:01 ` [PATCH 14/27] KVM: MMU: Make walk_addr_generic capable for two-level walking Joerg Roedel
2010-09-06 15:01 ` [PATCH 15/27] KVM: MMU: Introduce kvm_read_guest_page_x86() Joerg Roedel
2010-09-06 15:01 ` [PATCH 16/27] KVM: MMU: Introduce init_kvm_nested_mmu() Joerg Roedel
2010-09-06 15:01 ` [PATCH 17/27] KVM: MMU: Track page fault data in struct vcpu Joerg Roedel
2010-09-06 15:01 ` [PATCH 18/27] KVM: MMU: Propagate the right fault back to the guest after gva_to_gpa Joerg Roedel
2010-09-06 15:01 ` [PATCH 19/27] KVM: X86: Propagate fetch faults Joerg Roedel
2010-09-06 15:01 ` [PATCH 20/27] KVM: MMU: Add kvm_mmu parameter to load_pdptrs function Joerg Roedel
2010-09-06 15:01 ` [PATCH 21/27] KVM: MMU: Introduce kvm_pdptr_read_mmu Joerg Roedel
2010-09-06 15:01 ` [PATCH 22/27] KVM: MMU: Refactor mmu_alloc_roots function Joerg Roedel
2010-09-06 15:01 ` [PATCH 23/27] KVM: MMU: Allow long mode shadows for legacy page tables Joerg Roedel
2010-09-06 15:01 ` [PATCH 24/27] KVM: SVM: Implement MMU helper functions for Nested Nested Paging Joerg Roedel
2010-09-06 15:02 ` [PATCH 25/27] KVM: SVM: Initialize Nested Nested MMU context on VMRUN Joerg Roedel
2010-09-06 15:02 ` [PATCH 26/27] KVM: SVM: Expect two more candiates for exit_int_info Joerg Roedel
2010-09-06 15:02 ` [PATCH 27/27] KVM: SVM: Report Nested Paging support to userspace Joerg Roedel
2010-09-06 15:55 [PATCH 0/27] Nested Paging Virtualization for KVM v3 (now with fixed Cc-List) Joerg Roedel
2010-09-06 15:55 ` [PATCH 11/27] KVM: X86: Introduce pointer to mmu context used for gva_to_gpa Joerg Roedel

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=1283785322-26898-12-git-send-email-joerg.roedel@amd.com \
    --to=joerg.roedel@amd.com \
    --cc="http://kvm.qumranet.com"@osrc.amd.com \
    --cc=avi@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.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®