Re: [PATCH 09/12] KVM: MMU: look for a cached PGD when going from 32-bit to 64-bit

From: Paolo Bonzini
Date: Fri Feb 11 2022 - 06:45:36 EST


On 2/11/22 02:32, Sean Christopherson wrote:
Maybe cached_root_find_and_rotate() or cached_root_find_and_age()?

I'll go for cached_root_find_and_keep_current() and cached_root_find_without_current(), respectively.


Hmm, while we're refactoring this, I'd really prefer we not grab vcpu->arch.mmu
way down in the helpers. @vcpu is needed only for the request, so what about
doing this?

if (!fast_pgd_switch(vcpu, new_pgd, new_role)) {
/*
* <whatever kvm_mmu_reload() becomes> will set up a new root
* prior to the next VM-Enter. Free the current root if it's
* valid, i.e. if a valid root was evicted from the cache.
*/
if (VALID_PAGE(vcpu->arch.mmu->root.hpa))
kvm_mmu_free_roots(vcpu, vcpu->arch.mmu, KVM_MMU_ROOT_CURRENT);
return;
}

I tried, but it's much easier to describe the cache functions if their common postcondition is "vcpu->arch.mmu->root.hpa is never stale"; which requires not a struct kvm_vcpu* but at least a struct kvm*, for the MMU lock.

I could change kvm_mmu_free_roots and cached_root_* to take a struct kvm* plus a struct kvm_mmu*. Does that sound better?

Paolo