public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org, Avi Kivity <avi@qumranet.com>
Subject: [PATCH 27/39] KVM: MMU: Convert direct maps to use the generic shadow walker
Date: Thu, 25 Sep 2008 14:54:59 +0300	[thread overview]
Message-ID: <1222343711-12508-28-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1222343711-12508-1-git-send-email-avi@redhat.com>

From: Avi Kivity <avi@qumranet.com>

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 arch/x86/kvm/mmu.c |   93 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 55 insertions(+), 38 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 8b95cf7..a1ca4ff 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1260,49 +1260,66 @@ static void nonpaging_new_cr3(struct kvm_vcpu *vcpu)
 {
 }
 
-static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
-			int largepage, gfn_t gfn, pfn_t pfn)
-{
-	hpa_t table_addr = vcpu->arch.mmu.root_hpa;
-	int pt_write = 0;
-	int level = vcpu->arch.mmu.shadow_root_level;
-
-	for (; ; level--) {
-		u32 index = PT64_INDEX(v, level);
-		u64 *table;
+struct direct_shadow_walk {
+	struct kvm_shadow_walk walker;
+	pfn_t pfn;
+	int write;
+	int largepage;
+	int pt_write;
+};
 
-		ASSERT(VALID_PAGE(table_addr));
-		table = __va(table_addr);
+static int direct_map_entry(struct kvm_shadow_walk *_walk,
+			    struct kvm_vcpu *vcpu,
+			    gva_t addr, u64 *sptep, int level)
+{
+	struct direct_shadow_walk *walk =
+		container_of(_walk, struct direct_shadow_walk, walker);
+	struct kvm_mmu_page *sp;
+	gfn_t pseudo_gfn;
+	gfn_t gfn = addr >> PAGE_SHIFT;
+
+	if (level == PT_PAGE_TABLE_LEVEL
+	    || (walk->largepage && level == PT_DIRECTORY_LEVEL)) {
+		mmu_set_spte(vcpu, sptep, ACC_ALL, ACC_ALL,
+			     0, walk->write, 1, &walk->pt_write,
+			     walk->largepage, gfn, walk->pfn, false);
+		return 1;
+	}
 
-		if (level == 1 || (largepage && level == 2)) {
-			mmu_set_spte(vcpu, &table[index], ACC_ALL, ACC_ALL,
-				     0, write, 1, &pt_write, largepage,
-				     gfn, pfn, false);
-			return pt_write;
+	if (*sptep == shadow_trap_nonpresent_pte) {
+		pseudo_gfn = (addr & PT64_DIR_BASE_ADDR_MASK) >> PAGE_SHIFT;
+		sp = kvm_mmu_get_page(vcpu, pseudo_gfn, addr, level - 1,
+				      1, ACC_ALL, sptep);
+		if (!sp) {
+			pgprintk("nonpaging_map: ENOMEM\n");
+			kvm_release_pfn_clean(walk->pfn);
+			return -ENOMEM;
 		}
 
-		if (table[index] == shadow_trap_nonpresent_pte) {
-			struct kvm_mmu_page *new_table;
-			gfn_t pseudo_gfn;
-
-			pseudo_gfn = (v & PT64_DIR_BASE_ADDR_MASK)
-				>> PAGE_SHIFT;
-			new_table = kvm_mmu_get_page(vcpu, pseudo_gfn,
-						     v, level - 1,
-						     1, ACC_ALL, &table[index]);
-			if (!new_table) {
-				pgprintk("nonpaging_map: ENOMEM\n");
-				kvm_release_pfn_clean(pfn);
-				return -ENOMEM;
-			}
-
-			set_shadow_pte(&table[index],
-				       __pa(new_table->spt)
-				       | PT_PRESENT_MASK | PT_WRITABLE_MASK
-				       | shadow_user_mask | shadow_x_mask);
-		}
-		table_addr = table[index] & PT64_BASE_ADDR_MASK;
+		set_shadow_pte(sptep,
+			       __pa(sp->spt)
+			       | PT_PRESENT_MASK | PT_WRITABLE_MASK
+			       | shadow_user_mask | shadow_x_mask);
 	}
+	return 0;
+}
+
+static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
+			int largepage, gfn_t gfn, pfn_t pfn)
+{
+	int r;
+	struct direct_shadow_walk walker = {
+		.walker = { .entry = direct_map_entry, },
+		.pfn = pfn,
+		.largepage = largepage,
+		.write = write,
+		.pt_write = 0,
+	};
+
+	r = walk_shadow(&walker.walker, vcpu, (gva_t)gfn << PAGE_SHIFT);
+	if (r < 0)
+		return r;
+	return walker.pt_write;
 }
 
 static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
-- 
1.6.0.1


  parent reply	other threads:[~2008-09-25 12:06 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-25 11:54 [PATCH 00/39] KVM Updates for 2.6.28 merge window (part 2 of 3) Avi Kivity
2008-09-25 11:54 ` [PATCH 01/39] KVM: VMX: Clean up magic number 0x66 in init_rmode_tss Avi Kivity
2008-09-25 11:54 ` [PATCH 02/39] KVM: remove unused field from the assigned dev struct Avi Kivity
2008-09-25 11:54 ` [PATCH 03/39] KVM: set debug registers after "schedulable" section Avi Kivity
2008-09-25 11:54 ` [PATCH 04/39] KVM: VMX: Use interrupt queue for !irqchip_in_kernel Avi Kivity
2008-09-25 11:54 ` [PATCH 05/39] KVM: Simplify exception entries by using __ASM_SIZE and _ASM_PTR Avi Kivity
2008-09-25 11:54 ` [PATCH 06/39] KVM: fix i8259 reset irq acking Avi Kivity
2008-09-25 11:54 ` [PATCH 07/39] KVM: Handle spurious acks for PIT interrupts Avi Kivity
2008-09-25 11:54 ` [PATCH 08/39] KVM: Device assignment: Check for privileges before assigning irq Avi Kivity
2008-09-25 11:54 ` [PATCH 09/39] KVM: VMX: Add Guest State Validity Checks Avi Kivity
2008-09-25 11:54 ` [PATCH 10/39] KVM: VMX: Add module parameter and emulation flag Avi Kivity
2008-09-25 11:54 ` [PATCH 11/39] KVM: VMX: Add invalid guest state handler Avi Kivity
2008-09-25 11:54 ` [PATCH 12/39] KVM: VMX: Modify mode switching and vmentry functions Avi Kivity
2008-09-25 11:54 ` [PATCH 13/39] KVM: SVM: Fix typo Avi Kivity
2008-09-25 11:54 ` [PATCH 14/39] KVM: Use kvm_set_irq to inject interrupts Avi Kivity
2008-09-25 11:54 ` [PATCH 15/39] KVM: make irq ack notifier functions static Avi Kivity
2008-09-25 11:54 ` [PATCH 16/39] KVM: ia64: add a dummy irq ack notification Avi Kivity
2008-09-25 11:54 ` [PATCH 17/39] KVM: VMX: Change cs reset state to be a data segment Avi Kivity
2008-09-25 11:54 ` [PATCH 18/39] KVM: VMX: Change segment dpl at reset to 3 Avi Kivity
2008-09-25 11:54 ` [PATCH 19/39] KVM: Load real mode segments correctly Avi Kivity
2008-09-25 11:54 ` [PATCH 20/39] KVM: x86 emulator: remove duplicate SrcImm Avi Kivity
2008-09-25 11:54 ` [PATCH 21/39] KVM: x86 emulator: remove bad ByteOp specifier from NEG descriptor Avi Kivity
2008-09-25 11:54 ` [PATCH 22/39] KVM: MMU: Move SHADOW_PT_INDEX to mmu.c Avi Kivity
2008-09-25 11:54 ` [PATCH 23/39] KVM: MMU: Unify direct map 4K and large page paths Avi Kivity
2008-09-25 11:54 ` [PATCH 24/39] KVM: ia64: Enable virtio driver for ia64 in Kconfig Avi Kivity
2008-09-25 11:54 ` [PATCH 25/39] KVM: MMU: Infer shadow root level in direct_map() Avi Kivity
2008-09-25 11:54 ` [PATCH 26/39] KVM: MMU: Add generic shadow walker Avi Kivity
2008-09-25 11:54 ` Avi Kivity [this message]
2008-09-25 11:55 ` [PATCH 28/39] KVM: MMU: Convert the paging mode shadow walk to use the generic walker Avi Kivity
2008-09-25 11:55 ` [PATCH 29/39] KVM: Allocate guest memory as MAP_PRIVATE, not MAP_SHARED Avi Kivity
2008-09-25 11:55 ` [PATCH 30/39] KVM: Don't call get_user_pages(.force = 1) Avi Kivity
2008-09-25 11:55 ` [PATCH 31/39] KVM: x86 emulator: Add mov r, imm instructions (opcodes 0xb0-0xbf) Avi Kivity
2008-09-25 11:55 ` [PATCH 32/39] KVM: MMU: Account for npt/ept/realmode page faults Avi Kivity
2008-09-25 11:55 ` [PATCH 33/39] KVM: MMU: Add locking around kvm_mmu_slot_remove_write_access() Avi Kivity
2008-09-25 11:55 ` [PATCH 34/39] KVM: MMU: Flush tlbs after clearing write permission when accessing dirty log Avi Kivity
2008-09-25 11:55 ` [PATCH 35/39] KVM: MMU: Fix setting the accessed bit on non-speculative sptes Avi Kivity
2008-09-25 11:55 ` [PATCH 36/39] KVM: SVM: No need to unprotect memory during event injection when using npt Avi Kivity
2008-09-25 11:55 ` [PATCH 37/39] KVM: add MC5_MISC msr read support Avi Kivity
2008-09-25 11:55 ` [PATCH 38/39] KVM: s390: Make facility bits future-proof Avi Kivity
2008-09-25 11:55 ` [PATCH 39/39] KVM: s390: change help text of guest Kconfig Avi Kivity

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=1222343711-12508-28-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=avi@qumranet.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.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