Re: [PATCH v2 13/18] KVM: x86: reset and reinitialize the MMU in __set_sregs_common

From: Sean Christopherson
Date: Fri Feb 18 2022 - 19:22:59 EST


On Thu, Feb 17, 2022, Paolo Bonzini wrote:
> Do a full unload of the MMU in KVM_SET_SREGS and KVM_SEST_REGS2, in
> preparation for not doing so in kvm_mmu_reset_context. There is no
> need to delay the reset until after the return, so do it directly in
> the __set_sregs_common function and remove the mmu_reset_needed output
> parameter.
>
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> ---

Reviewed-by: Sean Christopherson <seanjc@xxxxxxxxxx>

> + kvm_init_mmu(vcpu);
> if (update_pdptrs) {
> idx = srcu_read_lock(&vcpu->kvm->srcu);
> - if (is_pae_paging(vcpu)) {
> + if (is_pae_paging(vcpu))
> load_pdptrs(vcpu, kvm_read_cr3(vcpu));
> - *mmu_reset_needed = 1;

Eww (not your code, just this whole pile). It might be worth calling out in the
changelog that calling kvm_init_mmu() before load_pdptrs() will (subtly) _not_
impact the functionality of load_pdptrs(). If the MMU is nested, kvm_init_mmu()
will modify vcpu->arch.nested_mmu, whereas kvm_translate_gpa() will walk
vcpu->arch.guest_mmu. And if the MMU is not nested, kvm_translate_gpa() will not
consuming vcpu->arch.mmu other than to check if it's == &guest_mmu.

> - }
> srcu_read_unlock(&vcpu->kvm->srcu, idx);
> }
>