From: Sagi Shahar <sa...@google.com> tdp_mmu_pages counts all the active pages used by the mmu. When we transfer the state during intra-host migration we need to transfer the mirror pages but not the direct ones. The direct pages are going to be re-faulted as needed on the destination, but that approach doesn't work for mirrored pages which stores information in the secure EPT.
Keeping them in separate counters makes this transfer more efficient. Signed-off-by: Sagi Shahar <sa...@google.com> Signed-off-by: Ryan Afranji <afra...@google.com> --- arch/x86/include/asm/kvm_host.h | 7 +++++-- arch/x86/kvm/mmu/tdp_mmu.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 999872c13722..b9966394acda 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1484,10 +1484,13 @@ struct kvm_arch { #ifdef CONFIG_X86_64 #ifdef CONFIG_KVM_PROVE_MMU /* - * The number of TDP MMU pages across all roots. Used only to sanity - * check that KVM isn't leaking TDP MMU pages. + * The number of non-mirrored TDP MMU pages across all roots. + * Used only to sanity check that KVM isn't leaking TDP MMU pages. */ atomic64_t tdp_mmu_pages; + + /* Same as tdp_mmu_pages but only for mirror pages. */ + atomic64_t tdp_mirror_mmu_pages; #endif /* diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 7f3d7229b2c1..115af5e4c5ed 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -42,6 +42,7 @@ void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm) #ifdef CONFIG_KVM_PROVE_MMU KVM_MMU_WARN_ON(atomic64_read(&kvm->arch.tdp_mmu_pages)); + KVM_MMU_WARN_ON(atomic64_read(&kvm->arch.tdp_mirror_mmu_pages)); #endif WARN_ON(!list_empty(&kvm->arch.tdp_mmu_roots)); @@ -328,7 +329,10 @@ static void tdp_account_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp) { kvm_account_pgtable_pages((void *)sp->spt, +1); #ifdef CONFIG_KVM_PROVE_MMU - atomic64_inc(&kvm->arch.tdp_mmu_pages); + if (sp->role.is_mirror) + atomic64_inc(&kvm->arch.tdp_mirror_mmu_pages); + else + atomic64_inc(&kvm->arch.tdp_mmu_pages); #endif } @@ -336,7 +340,10 @@ static void tdp_unaccount_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp) { kvm_account_pgtable_pages((void *)sp->spt, -1); #ifdef CONFIG_KVM_PROVE_MMU - atomic64_dec(&kvm->arch.tdp_mmu_pages); + if (sp->role.is_mirror) + atomic64_dec(&kvm->arch.tdp_mirror_mmu_pages); + else + atomic64_dec(&kvm->arch.tdp_mmu_pages); #endif } -- 2.50.0.rc1.591.g9c95f17f64-goog