Re: [PATCH v3 13/17] KVM: x86/tdp_mmu: Support mirror root for TDP MMU
From: Edgecombe, Rick P
Date: Tue Jul 09 2024 - 18:37:19 EST
On Thu, 2024-07-04 at 16:09 +0800, Yan Zhao wrote:
> Perhaps also a comment in kvm_mmu_reload() to address concerns like why
> checking
> only root.hpa in kvm_mmu_reload() is enough.
Sounds good, and thanks again for catching this.
>
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index 03737f3aaeeb..aba98c8cc67d 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -129,6 +129,15 @@ void kvm_mmu_track_write(struct kvm_vcpu *vcpu, gpa_t
> gpa, const u8 *new,
>
> static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
> {
> + /*
> + * Checking root.hpa is sufficient even when KVM has mirror root.
> + * We can have either:
> + * (1) mirror_root_hpa = INVALID_PAGE, root.hpa = INVALID_PAGE
> + * (2) mirror_root_hpa = root , root.hpa = INVALID_PAGE
Looks good to me except for the space ^
> + * (3) mirror_root_hpa = root1, root.hpa = root2
> + * We don't ever have:
> + * mirror_root_hpa = INVALID_PAGE, root.hpa = root
> + */
> if (likely(vcpu->arch.mmu->root.hpa != INVALID_PAGE))
> return 0;
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index a5f803f1d17e..eee35e958971 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -3705,7 +3705,8 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)
> int r;
>
> if (tdp_mmu_enabled) {
> - if (kvm_has_mirrored_tdp(vcpu->kvm))
> + if (kvm_has_mirrored_tdp(vcpu->kvm) &&
> + !VALID_PAGE(mmu->mirror_root_hpa))
> kvm_tdp_mmu_alloc_root(vcpu, true);
> kvm_tdp_mmu_alloc_root(vcpu, false);
> return 0;