small cleanups in MMU code
cover small cleanups in MMU code
Any of those should not change functionality.
Gleb Natapov (6):
KVM: MMU: make spte_is_locklessly_modifiable() more clear
KVM: MMU: drop unneeded checks.
KVM: MMU: set base_role.nxe during mmu initialization.
KVM: MMU: drop superfluous min() call.
KVM: MMU: drop superfluous is_present_gpte() check. Revert "KVM: MMU: split kvm_mmu_free_page"
arch/x86/kvm/mmu.c | 32 +++++++++----------------------- arch/x86/kvm/paging_tmpl.h | 3 --- arch/x86/kvm/x86.c | 2 -- 3 files changed, 9 insertions(+), 28 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/6 KVM: MMU: make spte_is_locklessly_modifiable() more clear
spte_is_locklessly_modifiable() checks that both SPTE_HOST_WRITEABLE and SPTE_MMU_WRITEABLE are present on spte. Make it more explicit.
--- arch/x86/kvm/mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu.c +2 -1
@@ -448,7 +448,8 @@ static bool __check_direct_spte_mmio_pf(u64 spte)static bool spte_is_locklessly_modifiable (u64 spte) { -return !(~spte & (SPTE_HOST_WRITEABLE |SPTE_MMU_WRITEABLE )); +return (spte & (SPTE_HOST_WRITEABLE |SPTE_MMU_WRITEABLE )) == + (SPTE_HOST_WRITEABLE |SPTE_MMU_WRITEABLE ); }static bool spte_has_volatile_bits (u64 spte)
Signature · 1 line
1.7.10.4
PATCH 2/6 KVM: MMU: drop unneeded checks.
In reply to Gleb Natapov--- arch/x86/kvm/mmu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kvm/mmu.c +2 -3
@@ -2328,9 +2328,8 @@ static int mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn,if (s->role.level !=PT_PAGE_TABLE_LEVEL )return 1 ; -if (!need_unsync && !s->unsync) { +if (!s->unsync) need_unsync = true; - } }if (need_unsync)kvm_unsync_pages (vcpu, gfn);
@@ -4008,7 +4007,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, !((sp->role.word ^ vcpu->arch.mmu.base_role.word) & mask.word) && rmap_can_add(vcpu))mmu_pte_write_new_pte (vcpu, sp, spte, &gentry); -if (!remote_flush &&need_remote_flush (entry, *spte)) +if (need_remote_flush (entry, *spte)) remote_flush = true; ++spte; }
Signature · 1 line
1.7.10.4
PATCH 3/6 KVM: MMU: set base_role.nxe during mmu initialization.
In reply to Gleb NatapovMove base_role.nxe initialisation to where all other roles are initialized.
--- arch/x86/kvm/mmu.c | 1 + arch/x86/kvm/x86.c | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/mmu.c +1 -0
@@ -3687,6 +3687,7 @@ int kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *context)else r =paging32_init_context (vcpu, context); + vcpu->arch.mmu.base_role.nxe =is_nx (vcpu); vcpu->arch.mmu.base_role.cr4_pae = !!is_pae (vcpu); vcpu->arch.mmu.base_role.cr0_wp =is_write_protection (vcpu); vcpu->arch.mmu.base_role.smep_andnot_wp
arch/x86/kvm/x86.c +0 -2
@@ -870,8 +870,6 @@ static int set_efer(struct kvm_vcpu *vcpu, u64 efer) kvm_x86_ops->set_efer (vcpu, efer); - vcpu->arch.mmu.base_role.nxe = (efer &EFER_NX ) && !tdp_enabled; -/* Update reserved bits */ if ((efer ^ old_efer) &EFER_NX )kvm_mmu_reset_context (vcpu);
Signature · 1 line
1.7.10.4
PATCH 4/6 KVM: MMU: drop superfluous min() call.
In reply to Gleb Natapov--- arch/x86/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu.c +1 -1
@@ -3854,7 +3854,7 @@ static u64 mmu_pte_write_fetch_gpte(struct kvm_vcpu *vcpu, gpa_t *gpa,/* Handle a 32-bit guest writing two halves of a 64-bit gpte */ *gpa &= ~(gpa_t )7 ; *bytes =8 ; - r =kvm_read_guest (vcpu->kvm, *gpa, &gentry,min (*bytes,8 )); + r =kvm_read_guest (vcpu->kvm, *gpa, &gentry,8 );if (r) gentry =0 ; new = (const u8 *)&gentry;
Signature · 1 line
1.7.10.4
PATCH 5/6 KVM: MMU: drop superfluous is_present_gpte() check.
In reply to Gleb NatapovGust page walker puts only present ptes into ptes[] array. No need to check it again.
--- arch/x86/kvm/paging_tmpl.h | 3 --- 1 file changed, 3 deletions(-)
arch/x86/kvm/paging_tmpl.h +0 -3
@@ -409,9 +409,6 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,unsigned direct_access, access = gw->pt_access;int top_level, emulate =0 ; -if (!is_present_gpte (gw->ptes[gw->level -1 ])) -return 0 ; - direct_access = gw->pte_access; top_level = vcpu->arch.mmu.root_level;
Signature · 1 line
1.7.10.4
PATCH 6/6 Revert "KVM: MMU: split kvm_mmu_free_page"
In reply to Gleb NatapovThis reverts commit bd4c86eaa6ff10abc4e00d0f45d2a28b10b09df4.
There is not user for kvm_mmu_isolate_page() any more.
--- arch/x86/kvm/mmu.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
arch/x86/kvm/mmu.c +3 -18
@@ -1461,28 +1461,14 @@ static inline void kvm_mod_used_mmu_pages(struct kvm *kvm, int nr)percpu_counter_add (&kvm_total_used_mmu_pages, nr); } -/* -* Remove the sp from shadow page cache, after call it, -* we can not find this sp from the cache, and the shadow -* page table is still valid. -* It should be under the protection of mmu lock. -*/ -static void kvm_mmu_isolate_page (struct kvm_mmu_page *sp) +static void kvm_mmu_free_page (struct kvm_mmu_page *sp) {ASSERT (is_empty_shadow_page (sp->spt));hlist_del (&sp->hash_link); -if (!sp->role.direct) -free_page ((unsigned long )sp->gfns); -} - -/* -* Free the shadow page table and the sp, we can do it -* out of the protection of mmu lock. -*/ -static void kvm_mmu_free_page (struct kvm_mmu_page *sp) -{list_del (&sp->link);free_page ((unsigned long )sp->spt); +if (!sp->role.direct) +free_page ((unsigned long )sp->gfns);kmem_cache_free (mmu_page_header_cache, sp); }
@@ -2126,7 +2112,6 @@ static void kvm_mmu_commit_zap_page(struct kvm *kvm,do { sp = list_first_entry(invalid_list, struct kvm_mmu_page, link);WARN_ON (!sp->role.invalid || sp->root_count); -kvm_mmu_isolate_page (sp);kvm_mmu_free_page (sp); }while (!list_empty (invalid_list)); }
Signature · 1 line
1.7.10.4
Re: [PATCH 6/6] Revert "KVM: MMU: split kvm_mmu_free_page"
Quoted 7 lines · Gleb Natapov
This reverts commit
bd4c86eaa6ff10abc4e00d0f45d2a28b10b09df4.There is not user for
kvm_mmu_isolate_page()any more.Signed-off-by Gleb Natapov <[email protected]>--- arch/x86/kvm/mmu.c | 21 +++------------------
Applied all except this - Takuya's using it.
Re: [PATCH 6/6] Revert "KVM: MMU: split kvm_mmu_free_page"
Quoted 10 lines · On Mon, 4 Feb 2013 23:24:01 -0200 Marcelo Tosatti <[email protected]> wrote:
Quoted 7 lines · Gleb Natapov
This reverts commit
bd4c86eaa6ff10abc4e00d0f45d2a28b10b09df4.There is not user for
kvm_mmu_isolate_page()any more.Signed-off-by Gleb Natapov <[email protected]>--- arch/x86/kvm/mmu.c | 21 +++------------------Applied all except this - Takuya's using it.
My patch just folds it into kvm_mmu_free_page(), so this patch helps me a bit.
If you want to apply this, I can rebase my patch appropriately.
Thanks,
Takuya
Re: [PATCH 6/6] Revert "KVM: MMU: split kvm_mmu_free_page"
In reply to Marcelo TosattiQuoted 10 lines · Marcelo Tosatti
Quoted 7 lines · Gleb Natapov
This reverts commit
bd4c86eaa6ff10abc4e00d0f45d2a28b10b09df4.There is not user for
kvm_mmu_isolate_page()any more.Signed-off-by Gleb Natapov <[email protected]>--- arch/x86/kvm/mmu.c | 21 +++------------------Applied all except this - Takuya's using it.
He actually revers this commit, but in non-obvious way. Reverting it explicitly makes for more clear commit history.
--
Gleb.