[patch 08/13] KVM: MMU: record guest root level on struct guest_walker

Marcelo Tosatti
2008-09-06T19:27:28Z

[-- Attachment #1: kvm-oos-record-root-level-on-guest-walker --]
[-- Type: text/plain, Size: 2612 bytes --]

For future usage.

Index: kvm/arch/x86/kvm/mmu.c
===================================================================
--- kvm.orig/arch/x86/kvm/mmu.c
+++ kvm/arch/x86/kvm/mmu.c
@@ -934,6 +934,7 @@ static int kvm_sync_page(struct kvm_vcpu
}

static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
+ gfn_t root_gfn,
gfn_t gfn,
gva_t gaddr,
unsigned level,
@@ -1343,8 +1344,8 @@ static int direct_map_entry(struct kvm_s

if (*sptep == shadow_trap_nonpresent_pte) {
pseudo_gfn = (addr & PT64_DIR_BASE_ADDR_MASK) >> PAGE_SHIFT;
- sp = kvm_mmu_get_page(vcpu, pseudo_gfn, (gva_t)addr, level - 1,
- 1, ACC_ALL, sptep);
+ sp = kvm_mmu_get_page(vcpu, -1, pseudo_gfn, (gva_t)addr,
+ level - 1, 1, ACC_ALL, sptep);
if (!sp) {
pgprintk("nonpaging_map: ENOMEM\n");
kvm_release_pfn_clean(walk->pfn);
@@ -1466,7 +1467,7 @@ static void mmu_alloc_roots(struct kvm_v
ASSERT(!VALID_PAGE(root));
if (tdp_enabled)
metaphysical = 1;
- sp = kvm_mmu_get_page(vcpu, root_gfn, 0,
+ sp = kvm_mmu_get_page(vcpu, -1, root_gfn, 0,
PT64_ROOT_LEVEL, metaphysical,
ACC_ALL, NULL);
root = __pa(sp->spt);
@@ -1489,7 +1490,7 @@ static void mmu_alloc_roots(struct kvm_v
root_gfn = vcpu->arch.pdptrs[i] >> PAGE_SHIFT;
} else if (vcpu->arch.mmu.root_level == 0)
root_gfn = 0;
- sp = kvm_mmu_get_page(vcpu, root_gfn, i << 30,
+ sp = kvm_mmu_get_page(vcpu, -1, root_gfn, i << 30,
PT32_ROOT_LEVEL, metaphysical,
ACC_ALL, NULL);
root = __pa(sp->spt);
Index: kvm/arch/x86/kvm/paging_tmpl.h
===================================================================
--- kvm.orig/arch/x86/kvm/paging_tmpl.h
+++ kvm/arch/x86/kvm/paging_tmpl.h
@@ -64,6 +64,7 @@
*/
struct guest_walker {
int level;
+ int root_level;
gfn_t table_gfn[PT_MAX_FULL_LEVELS];
pt_element_t ptes[PT_MAX_FULL_LEVELS];
gpa_t pte_gpa[PT_MAX_FULL_LEVELS];
@@ -149,6 +150,7 @@ walk:
--walker->level;
}
#endif
+ walker->root_level = walker->level;
ASSERT((!is_long_mode(vcpu) && is_pae(vcpu)) ||
(vcpu->arch.cr3 & CR3_NONPAE_RESERVED_BITS) == 0);

@@ -322,7 +324,8 @@ static int FNAME(shadow_walk_entry)(stru
metaphysical = 0;
table_gfn = gw->table_gfn[level - 2];
}
- shadow_page = kvm_mmu_get_page(vcpu, table_gfn, (gva_t)addr, level-1,
+ shadow_page = kvm_mmu_get_page(vcpu, gw->table_gfn[gw->root_level - 1],
+ table_gfn, (gva_t)addr, level-1,
metaphysical, access, sptep);
if (!metaphysical) {
r = kvm_read_guest_atomic(vcpu->kvm, gw->pte_gpa[level - 2],

--