From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: akpm-3NddpPZAyC0@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 5/33] KVM: MU: Special treatment for shadow pae root pages
Date: Thu, 04 Jan 2007 15:54:05 -0000 [thread overview]
Message-ID: <20070104155405.F02E2250048@il.qumranet.com> (raw)
In-Reply-To: <459D21DD.5090506-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Since we're not going to cache the pae-mode shadow root pages, allocate
a single pae shadow that will hold the four lower-level pages, which
will act as roots.
Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Index: linux-2.6/drivers/kvm/mmu.c
===================================================================
--- linux-2.6.orig/drivers/kvm/mmu.c
+++ linux-2.6/drivers/kvm/mmu.c
@@ -420,19 +420,63 @@ static int nonpaging_map(struct kvm_vcpu
}
}
+static void mmu_free_roots(struct kvm_vcpu *vcpu)
+{
+ int i;
+
+#ifdef CONFIG_X86_64
+ if (vcpu->mmu.shadow_root_level == PT64_ROOT_LEVEL) {
+ hpa_t root = vcpu->mmu.root_hpa;
+
+ ASSERT(VALID_PAGE(root));
+ release_pt_page_64(vcpu, root, PT64_ROOT_LEVEL);
+ vcpu->mmu.root_hpa = INVALID_PAGE;
+ return;
+ }
+#endif
+ for (i = 0; i < 4; ++i) {
+ hpa_t root = vcpu->mmu.pae_root[i];
+
+ ASSERT(VALID_PAGE(root));
+ root &= PT64_BASE_ADDR_MASK;
+ release_pt_page_64(vcpu, root, PT32E_ROOT_LEVEL - 1);
+ vcpu->mmu.pae_root[i] = INVALID_PAGE;
+ }
+ vcpu->mmu.root_hpa = INVALID_PAGE;
+}
+
+static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
+{
+ int i;
+
+#ifdef CONFIG_X86_64
+ if (vcpu->mmu.shadow_root_level == PT64_ROOT_LEVEL) {
+ hpa_t root = vcpu->mmu.root_hpa;
+
+ ASSERT(!VALID_PAGE(root));
+ root = kvm_mmu_alloc_page(vcpu, NULL);
+ vcpu->mmu.root_hpa = root;
+ return;
+ }
+#endif
+ for (i = 0; i < 4; ++i) {
+ hpa_t root = vcpu->mmu.pae_root[i];
+
+ ASSERT(!VALID_PAGE(root));
+ root = kvm_mmu_alloc_page(vcpu, NULL);
+ vcpu->mmu.pae_root[i] = root | PT_PRESENT_MASK;
+ }
+ vcpu->mmu.root_hpa = __pa(vcpu->mmu.pae_root);
+}
+
static void nonpaging_flush(struct kvm_vcpu *vcpu)
{
hpa_t root = vcpu->mmu.root_hpa;
++kvm_stat.tlb_flush;
pgprintk("nonpaging_flush\n");
- ASSERT(VALID_PAGE(root));
- release_pt_page_64(vcpu, root, vcpu->mmu.shadow_root_level);
- root = kvm_mmu_alloc_page(vcpu, NULL);
- ASSERT(VALID_PAGE(root));
- vcpu->mmu.root_hpa = root;
- if (is_paging(vcpu))
- root |= (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK));
+ mmu_free_roots(vcpu);
+ mmu_alloc_roots(vcpu);
kvm_arch_ops->set_cr3(vcpu, root);
kvm_arch_ops->tlb_flush(vcpu);
}
@@ -475,13 +519,7 @@ static void nonpaging_inval_page(struct
static void nonpaging_free(struct kvm_vcpu *vcpu)
{
- hpa_t root;
-
- ASSERT(vcpu);
- root = vcpu->mmu.root_hpa;
- if (VALID_PAGE(root))
- release_pt_page_64(vcpu, root, vcpu->mmu.shadow_root_level);
- vcpu->mmu.root_hpa = INVALID_PAGE;
+ mmu_free_roots(vcpu);
}
static int nonpaging_init_context(struct kvm_vcpu *vcpu)
@@ -495,7 +533,7 @@ static int nonpaging_init_context(struct
context->free = nonpaging_free;
context->root_level = PT32E_ROOT_LEVEL;
context->shadow_root_level = PT32E_ROOT_LEVEL;
- context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL);
+ mmu_alloc_roots(vcpu);
ASSERT(VALID_PAGE(context->root_hpa));
kvm_arch_ops->set_cr3(vcpu, context->root_hpa);
return 0;
@@ -647,7 +685,7 @@ static void paging_free(struct kvm_vcpu
#include "paging_tmpl.h"
#undef PTTYPE
-static int paging64_init_context(struct kvm_vcpu *vcpu)
+static int paging64_init_context_common(struct kvm_vcpu *vcpu, int level)
{
struct kvm_mmu *context = &vcpu->mmu;
@@ -657,15 +695,20 @@ static int paging64_init_context(struct
context->inval_page = paging_inval_page;
context->gva_to_gpa = paging64_gva_to_gpa;
context->free = paging_free;
- context->root_level = PT64_ROOT_LEVEL;
- context->shadow_root_level = PT64_ROOT_LEVEL;
- context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL);
+ context->root_level = level;
+ context->shadow_root_level = level;
+ mmu_alloc_roots(vcpu);
ASSERT(VALID_PAGE(context->root_hpa));
kvm_arch_ops->set_cr3(vcpu, context->root_hpa |
(vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK)));
return 0;
}
+static int paging64_init_context(struct kvm_vcpu *vcpu)
+{
+ return paging64_init_context_common(vcpu, PT64_ROOT_LEVEL);
+}
+
static int paging32_init_context(struct kvm_vcpu *vcpu)
{
struct kvm_mmu *context = &vcpu->mmu;
@@ -677,7 +720,7 @@ static int paging32_init_context(struct
context->free = paging_free;
context->root_level = PT32_ROOT_LEVEL;
context->shadow_root_level = PT32E_ROOT_LEVEL;
- context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL);
+ mmu_alloc_roots(vcpu);
ASSERT(VALID_PAGE(context->root_hpa));
kvm_arch_ops->set_cr3(vcpu, context->root_hpa |
(vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK)));
@@ -686,14 +729,7 @@ static int paging32_init_context(struct
static int paging32E_init_context(struct kvm_vcpu *vcpu)
{
- int ret;
-
- if ((ret = paging64_init_context(vcpu)))
- return ret;
-
- vcpu->mmu.root_level = PT32E_ROOT_LEVEL;
- vcpu->mmu.shadow_root_level = PT32E_ROOT_LEVEL;
- return 0;
+ return paging64_init_context_common(vcpu, PT32E_ROOT_LEVEL);
}
static int init_kvm_mmu(struct kvm_vcpu *vcpu)
@@ -737,26 +773,40 @@ static void free_mmu_pages(struct kvm_vc
__free_page(pfn_to_page(page->page_hpa >> PAGE_SHIFT));
page->page_hpa = INVALID_PAGE;
}
+ free_page((unsigned long)vcpu->mmu.pae_root);
}
static int alloc_mmu_pages(struct kvm_vcpu *vcpu)
{
+ struct page *page;
int i;
ASSERT(vcpu);
for (i = 0; i < KVM_NUM_MMU_PAGES; i++) {
- struct page *page;
struct kvm_mmu_page *page_header = &vcpu->page_header_buf[i];
INIT_LIST_HEAD(&page_header->link);
- if ((page = alloc_page(GFP_KVM_MMU)) == NULL)
+ if ((page = alloc_page(GFP_KERNEL)) == NULL)
goto error_1;
page->private = (unsigned long)page_header;
page_header->page_hpa = (hpa_t)page_to_pfn(page) << PAGE_SHIFT;
memset(__va(page_header->page_hpa), 0, PAGE_SIZE);
list_add(&page_header->link, &vcpu->free_pages);
}
+
+ /*
+ * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64.
+ * Therefore we need to allocate shadow page tables in the first
+ * 4GB of memory, which happens to fit the DMA32 zone.
+ */
+ page = alloc_page(GFP_KERNEL | __GFP_DMA32);
+ if (!page)
+ goto error_1;
+ vcpu->mmu.pae_root = page_address(page);
+ for (i = 0; i < 4; ++i)
+ vcpu->mmu.pae_root[i] = INVALID_PAGE;
+
return 0;
error_1:
Index: linux-2.6/drivers/kvm/kvm.h
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm.h
+++ linux-2.6/drivers/kvm/kvm.h
@@ -123,6 +123,8 @@ struct kvm_mmu {
hpa_t root_hpa;
int root_level;
int shadow_root_level;
+
+ u64 *pae_root;
};
struct kvm_guest_debug {
@@ -548,19 +550,4 @@ static inline u32 get_rdx_init_val(void)
#define TSS_REDIRECTION_SIZE (256 / 8)
#define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
-#ifdef CONFIG_X86_64
-
-/*
- * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64. Therefore
- * we need to allocate shadow page tables in the first 4GB of memory, which
- * happens to fit the DMA32 zone.
- */
-#define GFP_KVM_MMU (GFP_KERNEL | __GFP_DMA32)
-
-#else
-
-#define GFP_KVM_MMU GFP_KERNEL
-
-#endif
-
#endif
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
next prev parent reply other threads:[~2007-01-04 15:54 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-04 15:48 [PATCH 0/33] KVM: MMU: Cache shadow page tables Avi Kivity
2007-01-04 15:50 ` [PATCH 1/33] KVM: MMU: Implement simple reverse mapping Avi Kivity
2007-01-04 16:05 ` [PATCH 16/33] KVM: MMU: kvm_mmu_put_page() only removes one link to the page Avi Kivity
[not found] ` <459D21DD.5090506-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-01-04 15:51 ` [PATCH 2/33] KVM: MMU: Teach the page table walker to track guest page table gfns Avi Kivity
2007-01-04 15:52 ` [PATCH 3/33] KVM: MMU: Load the pae pdptrs on cr3 change like the processor does Avi Kivity
2007-01-04 15:53 ` [PATCH 4/33] KVM: MMU: Fold fetch_guest() into init_walker() Avi Kivity
2007-01-04 15:54 ` Avi Kivity [this message]
2007-01-04 15:55 ` [PATCH 6/33] KVM: MMU: Use the guest pdptrs instead of mapping cr3 in pae mode Avi Kivity
2007-01-04 15:56 ` [PATCH 7/33] KVM: MMU: Make the shadow page tables also special-case pae Avi Kivity
2007-01-04 15:57 ` [PATCH 8/33] KVM: MMU: Make kvm_mmu_alloc_page() return a kvm_mmu_page pointer Avi Kivity
2007-01-04 15:58 ` [PATCH 9/33] KVM: MMU: Shadow page table caching Avi Kivity
2007-01-04 15:59 ` [PATCH 10/33] KVM: MMU: Write protect guest pages when a shadow is created for them Avi Kivity
2007-01-04 16:00 ` [PATCH 11/33] KVM: MMU: Let the walker extract the target page gfn from the pte Avi Kivity
2007-01-04 16:01 ` [PATCH 12/33] KVM: MMU: Support emulated writes into RAM Avi Kivity
2007-01-04 16:02 ` [PATCH 13/33] KVM: MMU: Zap shadow page table entries on writes to guest page tables Avi Kivity
2007-01-04 16:03 ` [PATCH 14/33] KVM: MMU: If emulating an instruction fails, try unprotecting the page Avi Kivity
2007-01-04 16:04 ` [PATCH 15/33] KVM: MMU: Implement child shadow unlinking Avi Kivity
2007-01-04 16:06 ` [PATCH 17/33] KVM: MMU: oom handling Avi Kivity
2007-01-04 16:07 ` [PATCH 18/33] KVM: MMU: Remove invlpg interception Avi Kivity
2007-01-04 16:08 ` [PATCH 19/33] KVM: MMU: Remove release_pt_page_64() Avi Kivity
2007-01-04 16:10 ` [PATCH 21/33] KVM: MMU: <ove is_empty_shadow_page() above kvm_mmu_free_page() Avi Kivity
2007-01-04 16:11 ` [PATCH 22/33] KVM: MMU: Ensure freed shadow pages are clean Avi Kivity
2007-01-04 16:13 ` [PATCH 24/33] KVM: MMU: Page table write flood protection Avi Kivity
2007-01-04 16:14 ` [PATCH 25/33] KVM: MMU: Never free a shadow page actively serving as a root Avi Kivity
2007-01-04 16:15 ` [PATCH 26/33] KVM: MMU: Fix cmpxchg8b emulation Avi Kivity
2007-01-04 16:16 ` [PATCH 27/33] KVM: MMU: Treat user-mode faults as a hint that a page is no longer a page table Avi Kivity
2007-01-04 16:17 ` [PATCH 28/33] KVM: MMU: Free pages on kvm destruction Avi Kivity
2007-01-04 16:18 ` [PATCH 29/33] KVM: MMU: Replace atomic allocations by preallocated objects Avi Kivity
2007-01-04 16:19 ` [PATCH 30/33] KVM: MMU: Detect oom conditions and propagate error to userspace Avi Kivity
2007-01-04 16:20 ` [PATCH 31/33] KVM: MMU: Flush guest tlb when reducing permissions on a pte Avi Kivity
2007-01-04 16:21 ` [PATCH 32/33] KVM: MMU: Destroy mmu while we still have a vcpu left Avi Kivity
2007-01-04 16:22 ` [PATCH 33/33] KVM: MMU: add audit code to check mappings, etc are correct Avi Kivity
2007-01-04 17:22 ` [PATCH 0/33] KVM: MMU: Cache shadow page tables Andrew Morton
[not found] ` <20070104092226.91fa2dfe.akpm-3NddpPZAyC0@public.gmane.org>
2007-01-04 17:41 ` Avi Kivity
[not found] ` <459D3C65.2090703-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-01-04 18:02 ` Ingo Molnar
2007-01-04 16:09 ` [PATCH 20/33] KVM: MMU: Handle misaligned accesses to write protected guest " Avi Kivity
2007-01-04 16:12 ` [PATCH 23/33] KVM: MMU: If an empty shadow page is not empty, report more info 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=20070104155405.F02E2250048@il.qumranet.com \
--to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=akpm-3NddpPZAyC0@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.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