kvm x86 mmu: simplify kvm_mmu_unlink_parents()
PATCH 1/1 kvm x86 mmu: simplify kvm_mmu_unlink_parents()
mmu_page_remove_parent_pte() does much maintenance works, but kvm_mmu_unlink_parents() unlink all parents, so such maintenance works are not need.
This patch simplifies the works of kvm_mmu_unlink_parents() by unlinking parents without so many maintenance works.
Signed-off-by Lai Jiangshan <[email protected]>
---
arch/x86/kvm/mmu.c +23 -12
@@ -1453,22 +1453,33 @@ static void kvm_mmu_reset_last_pte_updated(struct kvm *kvm)static void kvm_mmu_unlink_parents (struct kvm *kvm,struct kvm_mmu_page *sp) { -u64 *parent_pte; +if (!sp->multimapped) { +if (!sp->parent_pte) +return ; -while (sp->multimapped || sp->parent_pte) { -if (!sp->multimapped) - parent_pte = sp->parent_pte; -else { -struct kvm_pte_chain *chain; +__set_spte (sp->parent_pte, shadow_trap_nonpresent_pte); + sp->parent_pte =NULL ; +return ; + } - chain =container_of (sp->parent_ptes.first, - struct kvm_pte_chain, link); - parent_pte = chain->parent_ptes[0 ]; +while (!hlist_empty (&sp->parent_ptes)) { +struct kvm_pte_chain *chain; +u64 *parent_pte; +int i; + + chain =hlist_entry (sp->parent_ptes.first, + struct kvm_pte_chain, link); +for (i =0 ; i <NR_PTE_CHAIN_ENTRIES ; ++i) { + parent_pte = chain->parent_ptes[i]; +if (!parent_pte) +break ; +__set_spte (parent_pte, shadow_trap_nonpresent_pte); } -BUG_ON (!parent_pte); -kvm_mmu_put_page (sp, parent_pte); -__set_spte (parent_pte, shadow_trap_nonpresent_pte); +hlist_del (&chain->link); +mmu_free_pte_chain (chain); } + sp->multimapped =0 ; + sp->parent_pte =NULL ; } static int mmu_zap_unsync_children(struct kvm *kvm,
Quoted 51 lines · Lai Jiangshan
mmu_page_remove_parent_pte()does much maintenance works, butkvm_mmu_unlink_parents()unlink all parents, so such maintenance works are not need.This patch simplifies the works of
kvm_mmu_unlink_parents()by unlinking parents without so many maintenance works.Signed-off-by Lai Jiangshan <[email protected]>---
arch/x86/kvm/mmu.c +19
-10@@ -1453,22 +1453,33 @@ static void kvm_mmu_reset_last_pte_updated(struct kvm *kvm)static void kvm_mmu_unlink_parents (struct kvm *kvm,struct kvm_mmu_page *sp) { -u64 *parent_pte; +if (!sp->multimapped) { +if (!sp->parent_pte) +return ; -while (sp->multimapped || sp->parent_pte) { -if (!sp->multimapped) - parent_pte = sp->parent_pte; -else { -struct kvm_pte_chain *chain; +__set_spte (sp->parent_pte, shadow_trap_nonpresent_pte); + sp->parent_pte =NULL ; +return ; + } - chain =container_of (sp->parent_ptes.first, - struct kvm_pte_chain, link); - parent_pte = chain->parent_ptes[0 ]; +while (!hlist_empty (&sp->parent_ptes)) { +struct kvm_pte_chain *chain; +u64 *parent_pte; +int i; + + chain =hlist_entry (sp->parent_ptes.first, + struct kvm_pte_chain, link); +for (i =0 ; i <NR_PTE_CHAIN_ENTRIES ; ++i) { + parent_pte = chain->parent_ptes[i]; +if (!parent_pte) +break ; +__set_spte (parent_pte, shadow_trap_nonpresent_pte); } -BUG_ON (!parent_pte);
arch/x86/kvm/mmu.c static void kvm_mmu_reset_last_pte_updated(struct kvm *kvm) · line 1485
Quoted 10 lines
arch/x86/kvm/mmu.c +4
-2-kvm_mmu_put_page (sp, parent_pte); -__set_spte (parent_pte, shadow_trap_nonpresent_pte); +hlist_del (&chain->link); +mmu_free_pte_chain (chain); } + sp->multimapped =0 ; + sp->parent_pte =NULL ; } static int mmu_zap_unsync_children(struct kvm *kvm,
Personally i don't see why this is any better than the previous code.