mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: kvm-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 11/40] KVM: MMU: Decouple mmio from shadow page tables
Date: Mon, 31 Mar 2008 17:36:55 +0300	[thread overview]
Message-ID: <1206974244-9716-12-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <1206974244-9716-1-git-send-email-avi@qumranet.com>

Currently an mmio guest pte is encoded in the shadow pagetable as a
not-present trapping pte, with the SHADOW_IO_MARK bit set.  However
nothing is ever done with this information, so maintaining it is a
useless complication.

This patch moves the check for mmio to before shadow ptes are instantiated,
so the shadow code is never invoked for ptes that reference mmio.  The code
is simpler, and with future work, can be made to handle mmio concurrently.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 arch/x86/kvm/mmu.c         |   34 +++++++++++++++-------------------
 arch/x86/kvm/paging_tmpl.h |   17 ++++++++---------
 2 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 6f8392d..6651dfa 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -101,8 +101,6 @@ static int dbg = 1;
 #define PT_FIRST_AVAIL_BITS_SHIFT 9
 #define PT64_SECOND_AVAIL_BITS_SHIFT 52
 
-#define PT_SHADOW_IO_MARK (1ULL << PT_FIRST_AVAIL_BITS_SHIFT)
-
 #define VALID_PAGE(x) ((x) != INVALID_PAGE)
 
 #define PT64_LEVEL_BITS 9
@@ -200,7 +198,6 @@ static int is_present_pte(unsigned long pte)
 
 static int is_shadow_present_pte(u64 pte)
 {
-	pte &= ~PT_SHADOW_IO_MARK;
 	return pte != shadow_trap_nonpresent_pte
 		&& pte != shadow_notrap_nonpresent_pte;
 }
@@ -215,11 +212,6 @@ static int is_dirty_pte(unsigned long pte)
 	return pte & PT_DIRTY_MASK;
 }
 
-static int is_io_pte(unsigned long pte)
-{
-	return pte & PT_SHADOW_IO_MARK;
-}
-
 static int is_rmap_pte(u64 pte)
 {
 	return is_shadow_present_pte(pte);
@@ -538,7 +530,7 @@ static int is_empty_shadow_page(u64 *spt)
 	u64 *end;
 
 	for (pos = spt, end = pos + PAGE_SIZE / sizeof(u64); pos != end; pos++)
-		if ((*pos & ~PT_SHADOW_IO_MARK) != shadow_trap_nonpresent_pte) {
+		if (*pos != shadow_trap_nonpresent_pte) {
 			printk(KERN_ERR "%s: %p %llx\n", __FUNCTION__,
 			       pos, *pos);
 			return 0;
@@ -926,13 +918,6 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
 	if (pte_access & ACC_USER_MASK)
 		spte |= PT_USER_MASK;
 
-	if (is_error_page(page)) {
-		set_shadow_pte(shadow_pte,
-			       shadow_trap_nonpresent_pte | PT_SHADOW_IO_MARK);
-		kvm_release_page_clean(page);
-		return;
-	}
-
 	spte |= page_to_phys(page);
 
 	if ((pte_access & ACC_WRITE_MASK)
@@ -1002,7 +987,7 @@ static int __nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write,
 		if (level == 1) {
 			mmu_set_spte(vcpu, &table[index], ACC_ALL, ACC_ALL,
 				     0, write, 1, &pt_write, gfn, page);
-			return pt_write || is_io_pte(table[index]);
+			return pt_write;
 		}
 
 		if (table[index] == shadow_trap_nonpresent_pte) {
@@ -1039,6 +1024,13 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
 	page = gfn_to_page(vcpu->kvm, gfn);
 	up_read(&current->mm->mmap_sem);
 
+	/* mmio */
+	if (is_error_page(page)) {
+		kvm_release_page_clean(page);
+		up_read(&vcpu->kvm->slots_lock);
+		return 1;
+	}
+
 	spin_lock(&vcpu->kvm->mmu_lock);
 	kvm_mmu_free_some_pages(vcpu);
 	r = __nonpaging_map(vcpu, v, write, gfn, page);
@@ -1406,10 +1398,14 @@ static void mmu_guess_page_from_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 		return;
 	gfn = (gpte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
 
-	down_read(&current->mm->mmap_sem);
+	down_read(&vcpu->kvm->slots_lock);
 	page = gfn_to_page(vcpu->kvm, gfn);
-	up_read(&current->mm->mmap_sem);
+	up_read(&vcpu->kvm->slots_lock);
 
+	if (is_error_page(page)) {
+		kvm_release_page_clean(page);
+		return;
+	}
 	vcpu->arch.update_pte.gfn = gfn;
 	vcpu->arch.update_pte.page = page;
 }
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index c2fd2b9..4b55f46 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -399,6 +399,14 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
 	page = gfn_to_page(vcpu->kvm, walker.gfn);
 	up_read(&current->mm->mmap_sem);
 
+	/* mmio */
+	if (is_error_page(page)) {
+		pgprintk("gfn %x is mmio\n", walker.gfn);
+		kvm_release_page_clean(page);
+		up_read(&vcpu->kvm->slots_lock);
+		return 1;
+	}
+
 	spin_lock(&vcpu->kvm->mmu_lock);
 	kvm_mmu_free_some_pages(vcpu);
 	shadow_pte = FNAME(fetch)(vcpu, addr, &walker, user_fault, write_fault,
@@ -409,15 +417,6 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
 	if (!write_pt)
 		vcpu->arch.last_pt_write_count = 0; /* reset fork detector */
 
-	/*
-	 * mmio: emulate if accessible, otherwise its a guest fault.
-	 */
-	if (shadow_pte && is_io_pte(*shadow_pte)) {
-		spin_unlock(&vcpu->kvm->mmu_lock);
-		up_read(&vcpu->kvm->slots_lock);
-		return 1;
-	}
-
 	++vcpu->stat.pf_fixed;
 	kvm_mmu_audit(vcpu, "post page fault (fixed)");
 	spin_unlock(&vcpu->kvm->mmu_lock);
-- 
1.5.4.5


  parent reply	other threads:[~2008-03-31 14:41 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-31 14:36 [PATCH 00/40] KVM updates for the 2.6.26 merge window (part I) Avi Kivity
2008-03-31 14:36 ` [PATCH 01/40] KVM: MMU: Update shadow ptes on partial guest pte writes Avi Kivity
2008-03-31 14:36 ` [PATCH 02/40] KVM: MMU: Simplify hash table indexing Avi Kivity
2008-03-31 14:36 ` [PATCH 03/40] KVM: x86 emulator: add support for group decoding Avi Kivity
2008-03-31 14:36 ` [PATCH 04/40] KVM: x86 emulator: group decoding for group 1A Avi Kivity
2008-03-31 14:36 ` [PATCH 05/40] KVM: x86 emulator: Group decoding for group 3 Avi Kivity
2008-03-31 14:36 ` [PATCH 06/40] KVM: x86 emulator: Group decoding for groups 4 and 5 Avi Kivity
2008-03-31 14:36 ` [PATCH 07/40] KVM: x86 emulator: add group 7 decoding Avi Kivity
2008-03-31 14:36 ` [PATCH 08/40] KVM: constify function pointer tables Avi Kivity
2008-03-31 14:36 ` [PATCH 09/40] KVM: Only x86 has pio Avi Kivity
2008-03-31 14:36 ` [PATCH 10/40] KVM: x86 emulator: group decoding for group 1 instructions Avi Kivity
2008-03-31 14:36 ` Avi Kivity [this message]
2008-03-31 14:36 ` [PATCH 12/40] KVM: Limit vcpu mmap size to one page on non-x86 Avi Kivity
2008-03-31 14:36 ` [PATCH 13/40] KVM: VMX: Enable Virtual Processor Identification (VPID) Avi Kivity
2008-03-31 14:36 ` [PATCH 14/40] KVM: Use CONFIG_PREEMPT_NOTIFIERS around struct preempt_notifier Avi Kivity
2008-03-31 14:36 ` [PATCH 15/40] KVM: Disable pagefaults during copy_from_user_inatomic() Avi Kivity
2008-03-31 14:37 ` [PATCH 16/40] KVM: make EFER_RESERVED_BITS configurable for architecture code Avi Kivity
2008-03-31 14:37 ` [PATCH 17/40] KVM: align valid EFER bits with the features of the host system Avi Kivity
2008-03-31 14:37 ` [PATCH 18/40] KVM: VMX: unifdef the EFER specific code Avi Kivity
2008-03-31 14:37 ` [PATCH 19/40] KVM: allow access to EFER in 32bit KVM Avi Kivity
2008-03-31 14:37 ` [PATCH 20/40] KVM: SVM: move feature detection to hardware setup code Avi Kivity
2008-03-31 14:37 ` [PATCH 21/40] KVM: SVM: add detection of Nested Paging feature Avi Kivity
2008-03-31 14:37 ` [PATCH 22/40] KVM: SVM: add module parameter to disable Nested Paging Avi Kivity
2008-03-31 14:37 ` [PATCH 23/40] KVM: export information about NPT to generic x86 code Avi Kivity
2008-03-31 14:37 ` [PATCH 24/40] KVM: MMU: make the __nonpaging_map function generic Avi Kivity
2008-03-31 14:37 ` [PATCH 25/40] KVM: export the load_pdptrs() function to modules Avi Kivity
2008-03-31 14:37 ` [PATCH 26/40] KVM: MMU: add TDP support to the KVM MMU Avi Kivity
2008-03-31 14:37 ` [PATCH 27/40] KVM: SVM: add support for Nested Paging Avi Kivity
2008-03-31 14:37 ` [PATCH 28/40] KVM: VMX: fix typo in VMX header define Avi Kivity
2008-03-31 14:37 ` [PATCH 29/40] KVM: SVM: let init_vmcb() take struct vcpu_svm as parameter Avi Kivity
2008-03-31 14:37 ` [PATCH 30/40] KVM: SVM: allocate the MSR permission map per VCPU Avi Kivity
2008-03-31 14:37 ` [PATCH 31/40] KVM: SVM: enable LBR virtualization Avi Kivity
2008-03-31 14:37 ` [PATCH 32/40] KVM: paravirtualized clocksource: host part Avi Kivity
2008-03-31 14:37 ` [PATCH 33/40] x86: KVM guest: paravirtualized clocksource Avi Kivity
2008-03-31 14:37 ` [PATCH 34/40] KVM: x86 emulator: add ad_mask static inline Avi Kivity
2008-03-31 14:37 ` [PATCH 35/40] KVM: x86 emulator: make register_address, address_mask static inlines Avi Kivity
2008-03-31 14:37 ` [PATCH 36/40] KVM: x86 emulator: make register_address_increment and JMP_REL " Avi Kivity
2008-03-31 14:37 ` [PATCH 37/40] KVM: Add API to retrieve the number of supported vcpus per vm Avi Kivity
2008-03-31 14:37 ` [PATCH 38/40] KVM: Increase vcpu count to 16 Avi Kivity
2008-03-31 14:37 ` [PATCH 39/40] KVM: Add API for determining the number of supported memory slots Avi Kivity
2008-03-31 14:37 ` [PATCH 40/40] KVM: Increase the number of user memory slots per vm 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=1206974244-9716-12-git-send-email-avi@qumranet.com \
    --to=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --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

all inboxes | Powered by JetHome®