KVM: X86: Add and use shadow page with level expanded or acting as pae_root
Subsystems (4)
v2 cover KVM: X86: Add and use shadow page with level expanded or acting as pae_root
From: Lai Jiangshan <[email protected]>
(Request For Help for testing on AMD machine with 32 bit L1 hypervisor, see information below)
KVM handles root pages specially for these cases:
direct mmu (nonpaping for 32 bit guest):
gCR0_PG=0
shadow mmu (shadow paping for 32 bit guest):
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1
direct mmu (NPT for 32bit host):
hEFER_LMA=0
shadow nested NPT (for 32bit L1 hypervisor):
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0,hEFER_LMA=0
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1,hEFER_LMA=0
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE={0|1},hEFER_LMA=1,hCR4_LA57={0|1}
Shadow nested NPT for 64bit L1 hypervisor:
gEFER_LMA=1,gCR4_LA57=0,hEFER_LMA=1,hCR4_LA57=1They are either using special roots or matched the condition ((mmu->shadow_root_level > mmu->root_level) && !mm->direct_map) (refered as level expansion) or both.
All the cases are using special roots except the last one. Many cases are doing level expansion including the last one.
When special roots are used, the root page will not be backed by kvm_mmu_page. So they must be treated specially, but not all places is considering this problem, and Sean is adding some code to check this special roots.
When level expansion, the kvm treats them silently always.
These treaments incur problems or complication, see the changelog of every patch.
These patches were made when I reviewed all the usage of shadow_root_level and root_level. Many root level patches are sent and accepted.
These patches has not been tested with shadow NPT cases listed above. Because I don't have guest images can act as 32 bit L1 hypervisor, nor I can access to AMD machine with 5 level paging. I'm a bit reluctant to ask for the resource, so I send the patches and wish someone test them and modify them. At least, it provides some thinking and reveals problems of the existing code and of the AMD cases.
( *Request For Help* here.)
These patches have been tested with the all cases except the shadow-NPT cases, the code coverage is believed to be more than 95% (hundreds of code related to shadow-NPT are shoved, and be replaced with common role.pae_root and role.passthrough code with only 8 line of code is added for shadow-NPT, only 2 line of code is not covered in my tests).
[V1]: https://lore.kernel.org/lkml/[email protected]/
Changed from V1:
Apply Sean's comments and suggestion. (Too much to list. Thanks!) Add some comments.
Change changelog for role.pae_root patch.
Lai Jiangshan (4):
KVM: X86: Add arguement gfn and role to kvm_mmu_alloc_page()
KVM: X86: Introduce role.passthrough for level expanded pagetable
KVM: X86: Alloc role.pae_root shadow page
KVM: X86: Use passthrough and pae_root shadow page for 32bit guests
Documentation/virt/kvm/mmu.rst | 7 + arch/x86/include/asm/kvm_host.h | 16 +- arch/x86/kvm/mmu/mmu.c | 400 +++++++++----------------------- arch/x86/kvm/mmu/paging_tmpl.h | 15 +- 4 files changed, 138 insertions(+), 300 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b
RFC PATCH v2 1/4 KVM: X86: Add arguement gfn and role to kvm_mmu_alloc_page()
From: Lai Jiangshan <[email protected]>
kvm_mmu_alloc_page() will access to more bits of the role.
--- arch/x86/kvm/mmu/mmu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/kvm/mmu/mmu.c +6 -6
@@ -1706,13 +1706,14 @@ static void drop_parent_pte(struct kvm_mmu_page *sp,mmu_spte_clear_no_track (parent_pte); } -static struct kvm_mmu_page *kvm_mmu_alloc_page (struct kvm_vcpu *vcpu,int direct) +static struct kvm_mmu_page *kvm_mmu_alloc_page (struct kvm_vcpu *vcpu,gfn_t gfn, +union kvm_mmu_page_role role) {struct kvm_mmu_page *sp; sp =kvm_mmu_memory_cache_alloc (&vcpu->arch.mmu_page_header_cache); sp->spt =kvm_mmu_memory_cache_alloc (&vcpu->arch.mmu_shadow_page_cache); -if (!direct) +if (!role.direct) sp->gfns =kvm_mmu_memory_cache_alloc (&vcpu->arch.mmu_gfn_array_cache);set_page_private (virt_to_page (sp->spt), (unsigned long )sp);
@@ -1724,6 +1725,8 @@ static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, int direct sp->mmu_valid_gen = vcpu->kvm->arch.mmu_valid_gen;list_add (&sp->link, &vcpu->kvm->arch.active_mmu_pages);kvm_mod_used_mmu_pages (vcpu->kvm,+1 ); + sp->gfn = gfn; + sp->role = role;return sp; }
@@ -2107,10 +2110,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, ++vcpu->kvm->stat.mmu_cache_miss; - sp =kvm_mmu_alloc_page (vcpu, direct); - - sp->gfn = gfn; - sp->role = role; + sp =kvm_mmu_alloc_page (vcpu, gfn, role);hlist_add_head (&sp->hash_link, sp_list);if (!direct) {account_shadowed (vcpu->kvm, sp);
Signature · 1 line
2.19.1.6.gb485710b
RFC PATCH v2 2/4 KVM: X86: Introduce role.passthrough for level expanded pagetable
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
Level expansion occurs when mmu->shadow_root_level > mmu->root_level.
There are several cases that can cuase level expansion:
shadow mmu (shadow paging for 32 bit guest):
case1: gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0
shadow nested NPT (for 32bit L1 hypervisor):
case2: gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0,hEFER_LMA=0 case3: gCR0_PG=1,gEFER_LMA=0,hEFER_LMA=1
shadow nested NPT (for 64bit L1 hypervisor):
case4: gEFER_LMA=1,gCR4_LA57=0,hEFER_LMA=1,hCR4_LA57=1
When level expansion occurs (32bit guest, case1-3), special roots are often used. But case4 is not using special roots. It uses shadow page without fully aware of the specialty. It might work accidentally:
1) The root_page (root_sp->spt) is allocated with level = 5, and root_sp->spt[0] is allocated with the same gfn and the same role except role.level = 4. Luckly that they are different shadow pages.
2) FNAME(walk_addr_generic) sets walker->table_gfn[4] and walker->pt_access[4], which are normally unused when mmu->shadow_root_level == mmu->root_level == 4, so that FNAME(fetch) can use them to allocate shadow page for root_sp->spt[0] and link them when shadow_root_level == 5.
But it has problems.
If the guest switches from gCR4_LA57=0 to gCR4_LA57=1 (or vice verse) and uses the same gfn as the root for the nNPT before and after switching gCR4_LA57. The host (hCR4_LA57=1) wold use the same root_sp for guest even guest switches gCR4_LA57. The guest will see unexpected page mapped and L2 can hurts L1. It is lucky the the problem can't hurt L0.
The root_sp should be like role.direct=1 sometimes: its contents are not backed by gptes, root_sp->gfns is meaningless. For a normal high level sp, sp->gfns is often unused and kept zero, but it could be relevant and meaningful when sp->gfns is used because they are back by concret gptes. For expanded root_sp described before, root_sp is just a portal to contribute root_sp->spt[0], and root_sp should not have root_sp->gfns and root_sp->spt[0] should not be dropped if gpte[0] of the root gfn is changed.
This patch adds role.passthrough to address the two problems. role.passthrough is set for expanded shadow pagetable:
role.level > gMMU.level.
An alternative way to fix the problem of case4 is that: also using the special root pml5_root for it. But it would required to change many other places because it is assumption that special roots is only used for 32bit guests.
This patch also paves the way to use passthrough shadow page for case1-3, but that requires the special handling or PAE paging, so the extensive usage of it is in later patches.
--- Documentation/virt/kvm/mmu.rst | 5 +++++ arch/x86/include/asm/kvm_host.h | 5 +++-- arch/x86/kvm/mmu/mmu.c | 19 ++++++++++++++++--- arch/x86/kvm/mmu/paging_tmpl.h | 1 + 4 files changed, 25 insertions(+), 5 deletions(-)
Documentation/virt/kvm/mmu.rst +5 -0
@@ -202,6 +202,11 @@ Shadow pages contain the following information: Is 1 if the MMU instance cannot use A/D bits. EPT did not have A/D bits before Haswell; shadow EPT page tables also cannot use A/D bits if the L1 hypervisor does not enable them. + role.passthrough: + Is 1 if role.level > guest paging level when shadow paging level is + larger than guest paging level; passthrough shadow page tables must + be created on the top. Like when role.has_4_byte_gpte or shadow NPT + for 32 bit L1 or 5-level shadow NPT for 4-level NPT L1. gfn: Either the guest page table containing the translations shadowed by this page, or the base page frame for linear translations. See role.direct.
arch/x86/include/asm/kvm_host.h +3 -2
@@ -314,7 +314,7 @@ struct kvm_kernel_irq_routing_entry;* cr0_wp=0, therefore these three bits only give rise to 5 possibilities. * * Therefore, the maximum number of possible upper-level shadow pages for a -* single gfn is a bit less than 2^13. +* single gfn is a bit less than 2^14. */ union kvm_mmu_page_role {u32 word;
@@ -331,7 +331,8 @@ union kvm_mmu_page_role { unsigned smap_andnot_wp:1; unsigned ad_disabled:1; unsigned guest_mode:1; - unsigned :6; + unsigned passthrough:1; + unsigned :5;/* * This is left at the top of the word so that
arch/x86/kvm/mmu/mmu.c +16 -3
@@ -737,6 +737,9 @@ static void mmu_free_pte_list_desc(struct pte_list_desc *pte_list_desc)static gfn_t kvm_mmu_page_get_gfn (struct kvm_mmu_page *sp,int index) { +if (sp->role.passthrough) +return sp->gfn; +if (!sp->role.direct)return sp->gfns[index];
@@ -745,6 +748,11 @@ static gfn_t kvm_mmu_page_get_gfn(struct kvm_mmu_page *sp, int index)static void kvm_mmu_page_set_gfn (struct kvm_mmu_page *sp,int index,gfn_t gfn) { +if (sp->role.passthrough) { +WARN_ON_ONCE (gfn != sp->gfn); +return ; + } +if (!sp->role.direct) { sp->gfns[index] = gfn;return ;
@@ -1674,8 +1682,7 @@ static void kvm_mmu_free_page(struct kvm_mmu_page *sp)hlist_del (&sp->hash_link);list_del (&sp->link);free_page ((unsigned long )sp->spt); -if (!sp->role.direct) -free_page ((unsigned long )sp->gfns); +free_page ((unsigned long )sp->gfns);kmem_cache_free (mmu_page_header_cache, sp); }
@@ -1713,7 +1720,7 @@ static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, gfn_t gfn, sp =kvm_mmu_memory_cache_alloc (&vcpu->arch.mmu_page_header_cache); sp->spt =kvm_mmu_memory_cache_alloc (&vcpu->arch.mmu_shadow_page_cache); -if (!role.direct) +if (!role.direct && !role.passthrough) sp->gfns =kvm_mmu_memory_cache_alloc (&vcpu->arch.mmu_gfn_array_cache);set_page_private (virt_to_page (sp->spt), (unsigned long )sp);
@@ -2054,6 +2061,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, quadrant &= (1 << ((PT32_PT_BITS -PT64_PT_BITS ) * level)) -1 ; role.quadrant = quadrant; } +if (level <= vcpu->arch.mmu->root_level) + role.passthrough =0 ; sp_list = &vcpu->kvm->arch.mmu_page_hash[kvm_page_table_hashfn (gfn)];for_each_valid_sp (vcpu->kvm, sp, sp_list) {
@@ -4882,6 +4891,8 @@ kvm_calc_shadow_npt_root_page_role(struct kvm_vcpu *vcpu, role.base.direct = false; role.base.level =kvm_mmu_get_tdp_level (vcpu); +if (role.base.level >role_regs_to_root_level (regs)) + role.base.passthrough =1 ;return role; }
@@ -5312,6 +5323,8 @@ static void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, ++vcpu->kvm->stat.mmu_pte_write;for_each_gfn_indirect_valid_sp (vcpu->kvm, sp, gfn) { +if (sp->role.passthrough) +continue ;if (detect_write_misaligned (sp, gpa, bytes) ||detect_write_flooding (sp)) {kvm_mmu_prepare_zap_page (vcpu->kvm, sp, &invalid_list);
arch/x86/kvm/mmu/paging_tmpl.h +1 -0
@@ -1042,6 +1042,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) .level = 0xf, .access = 0x7, .quadrant = 0x3, + .passthrough = 0x1, };/*
Signature · 1 line
2.19.1.6.gb485710b
RFC PATCH v2 3/4 KVM: X86: Alloc role.pae_root shadow page
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
Currently pae_root is special root page, this patch adds facility to allow using kvm_mmu_get_page() to allocate pae_root shadow page.
When kvm_mmu_get_page() is called for role.level == PT32E_ROOT_LEVEL and vcpu->arch.mmu->shadow_root_level == PT32E_ROOT_LEVEL, it will get a PAE root pagetable and set role.pae_root=1 for freeing.
The role.pae_root bit is needed in the page role because:
o PAE roots must be allocated below 4gb (for kvm_mmu_get_page())
o PAE roots can not be encrypted (for kvm_mmu_get_page())
o Must be re-encrypted when freeing (for kvm_mmu_free_page())
o PAE root's PDPTE is special (for link_shadow_page())
o Not share the decrypted low-address pagetable with non-PAE-root ones or vice verse. (for kvm_mmu_get_page(), the crucial reason)
Both role.pae_root in link_shadow_page() and in kvm_mmu_get_page() can be possible changed to use shadow_root_level and role.level instead.
But in kvm_mmu_free_page(), it can't use vcpu->arch.mmu->shadow_root_level.
PAE roots must be allocated below 4gb (CR3 has only 32 bits). So a cache is introduced (mmu_pae_root_cache).
No functionality changed since this code is not activated because when vcpu->arch.mmu->shadow_root_level == PT32E_ROOT_LEVEL, kvm_mmu_get_page() is only called for level == 1 or 2 now.
--- Documentation/virt/kvm/mmu.rst | 2 + arch/x86/include/asm/kvm_host.h | 9 +++- arch/x86/kvm/mmu/mmu.c | 78 +++++++++++++++++++++++++++++++-- arch/x86/kvm/mmu/paging_tmpl.h | 1 + 4 files changed, 86 insertions(+), 4 deletions(-)
Documentation/virt/kvm/mmu.rst +2 -0
@@ -207,6 +207,8 @@ Shadow pages contain the following information: larger than guest paging level; passthrough shadow page tables must be created on the top. Like when role.has_4_byte_gpte or shadow NPT for 32 bit L1 or 5-level shadow NPT for 4-level NPT L1. + role.pae_root: + Is 1 if it is a PAE root. gfn: Either the guest page table containing the translations shadowed by this page, or the base page frame for linear translations. See role.direct.
arch/x86/include/asm/kvm_host.h +8 -1
@@ -313,6 +313,11 @@ struct kvm_kernel_irq_routing_entry;* - on top of this, smep_andnot_wp and smap_andnot_wp are only set if * cr0_wp=0, therefore these three bits only give rise to 5 possibilities. * +* - pae_root can only be set when level=3, so combinations for level and +* pae_root can be seen as 2/3/3-page_root/4/5, a.k.a 5 possibilities. +* Combined with cr0_wp, smep_andnot_wp and smap_andnot_wp, it will be +* 5X5 = 25 < 2^5. +* * Therefore, the maximum number of possible upper-level shadow pages for a * single gfn is a bit less than 2^14. */
@@ -332,7 +337,8 @@ union kvm_mmu_page_role { unsigned ad_disabled:1; unsigned guest_mode:1; unsigned passthrough:1; - unsigned :5; + unsigned pae_root:1; + unsigned :4;/* * This is left at the top of the word so that
@@ -699,6 +705,7 @@ struct kvm_vcpu_arch {struct kvm_mmu_memory_cache mmu_shadow_page_cache;struct kvm_mmu_memory_cache mmu_gfn_array_cache;struct kvm_mmu_memory_cache mmu_page_header_cache; +void *mmu_pae_root_cache;/* * QEMU userspace and the guest each have their own FPU state.
arch/x86/kvm/mmu/mmu.c +75 -3
151 lines not on this page · raw message
arch/x86/kvm/mmu/paging_tmpl.h +1 -0
@@ -1043,6 +1043,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) .access = 0x7, .quadrant = 0x3, .passthrough = 0x1, + .pae_root = 0x1, };/*
Signature · 1 line
2.19.1.6.gb485710b
RFC PATCH v2 4/4 KVM: X86: Use passthrough and pae_root shadow page for 32bit guests
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
Use role.pae_root = 1 for shadow_root_level == 3 no matter if it is shadow MMU or not.
When it is shadow MMU, level expansion might occur and use role.passthrough = 1 for expanded shadow pagetable.
And remove the unneeded special roots. Now all the root pages and pagetable pointed by a present spte in kvm_mmu are backed by struct kvm_mmu_page, and to_shadow_page() is guaranteed to be not NULL.
shadow_walk() and the intialization of shadow page are much simplified since there is not special roots.
Affect cases:
direct mmu (nonpaping for 32 bit guest):
gCR0_PG=0 (pae_root=1)
shadow mmu (shadow paping for 32 bit guest):
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0 (pae_root=1,passthrough=1)
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1 (pae_root=1,passthrough=0)
direct mmu (NPT for 32bit host):
hEFER_LMA=0 (pae_root=1)
shadow nested NPT (for 32bit L1 hypervisor):
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0,hEFER_LMA=0
(pae_root=1,passthrough=1)
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1,hEFER_LMA=0
(pae_root=1,passthrough=0)
gCR0_PG=1,gEFER_LMA=0,gCR4_PSE={0|1},hEFER_LMA=1,hCR4_LA57={0|1}
(pae_root=0,passthrough=1)
(default_pae_pdpte is not used even guest is using PAE paging)Shadow nested NPT for 64bit L1 hypervisor has been already handled:
gEFER_LMA=1,gCR4_LA57=0,hEFER_LMA=1,hCR4_LA57=1 (pae_root=0,passthrough=1)
FNAME(walk_addr_generic) adds initialization code for shadow nested NPT for 32bit L1 hypervisor when the level increment might be more than one, for example, 2->4, 2->5, 3->5.
After this patch, the PAE Page-Directory-Pointer-Table is also write protected (including NPT's).
--- arch/x86/include/asm/kvm_host.h | 4 - arch/x86/kvm/mmu/mmu.c | 295 ++------------------------------ arch/x86/kvm/mmu/paging_tmpl.h | 13 +- 3 files changed, 24 insertions(+), 288 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -4
@@ -467,10 +467,6 @@ struct kvm_mmu {*/ u32 pkru_mask; -u64 *pae_root; -u64 *pml4_root; -u64 *pml5_root; -/* * check zero bits on shadow page table entries, these * bits include not only hardware reserved bits but also
arch/x86/kvm/mmu/mmu.c +12 -283
401 lines not on this page · raw message
arch/x86/kvm/mmu/paging_tmpl.h +12 -1
@@ -365,6 +365,16 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, pte = mmu->get_guest_pgd (vcpu); have_ad =PT_HAVE_ACCESSED_DIRTY (mmu); +/* kvm_mmu_get_page() might use this values for allocating passthrough +* shadow page. +*/ + walker->table_gfn[4 ] =gpte_to_gfn (pte); + walker->pt_access[4 ] =ACC_ALL ; + walker->table_gfn[3 ] =gpte_to_gfn (pte); + walker->pt_access[3 ] =ACC_ALL ; + walker->table_gfn[2 ] =gpte_to_gfn (pte); + walker->pt_access[2 ] =ACC_ALL ; +#if PTTYPE ==64 walk_nx_mask =1ULL <<PT64_NX_SHIFT ;if (walker->level ==PT32E_ROOT_LEVEL ) {
@@ -710,7 +720,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,* Verify that the gpte in the page we've just write * protected is still there. */ -if (FNAME (gpte_changed)(vcpu, gw, it.level -1 )) +if (it.level -1 < top_level && +FNAME (gpte_changed)(vcpu, gw, it.level -1 )) goto out_gpte_changed;if (sp)
Signature · 1 line
2.19.1.6.gb485710b
Paolo Bonzini
maintainerQuoted 21 lines · Lai Jiangshan
From: Lai Jiangshan <[email protected]>
(Request For Help for testing on AMD machine with 32 bit L1 hypervisor, see information below)
KVM handles root pages specially for these cases:
direct mmu (nonpaping for 32 bit guest):
gCR0_PG=0 shadow mmu (shadow paping for 32 bit guest): gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0 gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1 direct mmu (NPT for 32bit host): hEFER_LMA=0 shadow nested NPT (for 32bit L1 hypervisor): gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0,hEFER_LMA=0 gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1,hEFER_LMA=0 gCR0_PG=1,gEFER_LMA=0,gCR4_PSE={0|1},hEFER_LMA=1,hCR4_LA57={0|1} Shadow nested NPT for 64bit L1 hypervisor: gEFER_LMA=1,gCR4_LA57=0,hEFER_LMA=1,hCR4_LA57=1
Quoted 6 lines
They are either using special roots or matched the condition ((
mmu->shadow_root_level>mmu->root_level) && !mm->direct_map) (refered as level expansion) or both.All the cases are using special roots except the last one. Many cases are doing level expansion including the last one.
Hi Jiangshan,
so the main difference between direct and passthrough shadow pages is that passthrough pages can have indirect children. A direct page maps the page at sp->gfn, while a passthrough page maps the page _table_ at sp->gfn. Is this correct?
If so, I think there is a difference between a passthrough page that maps a level-2 page from level-4, and a passthrough page that maps a level-3 page from level-4. If that is true, a single bit in the role is not enough.
One way to handle this could be to have a single field "mapping_level"
that subsumes both "direct" and "passthrough". direct==1
would correspond to "mapping_level == 0"; direct==0 && passthrough==0 would be "mapping_level == level"; anything in the middle would be a passthrough page in your series.
What do you think?
Thanks,
Paolo
Quoted 37 lines · Paolo Bonzini
Quoted 21 lines · Lai Jiangshan
From: Lai Jiangshan <[email protected]>
(Request For Help for testing on AMD machine with 32 bit L1 hypervisor, see information below)
KVM handles root pages specially for these cases:
direct mmu (nonpaping for 32 bit guest):
gCR0_PG=0 shadow mmu (shadow paping for 32 bit guest): gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0 gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1 direct mmu (NPT for 32bit host): hEFER_LMA=0 shadow nested NPT (for 32bit L1 hypervisor): gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=0,hEFER_LMA=0 gCR0_PG=1,gEFER_LMA=0,gCR4_PSE=1,hEFER_LMA=0 gCR0_PG=1,gEFER_LMA=0,gCR4_PSE={0|1},hEFER_LMA=1,hCR4_LA57={0|1} Shadow nested NPT for 64bit L1 hypervisor: gEFER_LMA=1,gCR4_LA57=0,hEFER_LMA=1,hCR4_LA57=1Quoted 6 lines
They are either using special roots or matched the condition ((
mmu->shadow_root_level>mmu->root_level) && !mm->direct_map) (refered as level expansion) or both.All the cases are using special roots except the last one. Many cases are doing level expansion including the last one.
Hi Jiangshan,
so the main difference between direct and passthrough shadow pages is that passthrough pages can have indirect children. A direct page maps the page at
sp->gfn, while a passthrough page maps the page _table_ atsp->gfn. Is this correct?
Quoted 4 lines
If so, I think there is a difference between a passthrough page that maps a level-2 page from level-4, and a passthrough page that maps a level-3 page from level-4. If that is true, a single bit in the role is not enough.
Ahhhh, you are correct.
Quoted 13 lines
One way to handle this could be to have a single field "
mapping_level" that subsumes both "direct" and "passthrough". direct==1 would correspond to "mapping_level== 0"; direct==0 && passthrough==0 would be "mapping_level== level"; anything in the middle would be a passthrough page in your series.What do you think?
Thanks,
Paolo