Re: [PATCH v2 15/18] KVM: x86/mmu: rename kvm_mmu_new_pgd, introduce variant that calls get_guest_pgd

Paolo Bonzini
2022-02-18T09:39:38Z

On 2/17/22 22:03, Paolo Bonzini wrote:
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index adcee7c305ca..9800c8883a48 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1189,7 +1189,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
> return 1;
>
> if (cr3 != kvm_read_cr3(vcpu))
> - kvm_mmu_new_pgd(vcpu, cr3);
> + kvm_mmu_update_root(vcpu);
>
> vcpu->arch.cr3 = cr3;
> kvm_register_mark_dirty(vcpu, VCPU_EXREG_CR3);

Uh-oh, this has to become:

vcpu->arch.cr3 = cr3;
kvm_register_mark_dirty(vcpu, VCPU_EXREG_CR3);
if (!is_pae_paging(vcpu))
kvm_mmu_update_root(vcpu);

The regression would go away after patch 16, but this is more tidy apart
from having to check is_pae_paging *again*.

Incremental patch:

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index adcee7c305ca..0085e9fba372 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1188,11 +1189,11 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
if (is_pae_paging(vcpu) && !load_pdptrs(vcpu, cr3))
return 1;

- if (cr3 != kvm_read_cr3(vcpu))
- kvm_mmu_update_root(vcpu);
-
vcpu->arch.cr3 = cr3;
kvm_register_mark_dirty(vcpu, VCPU_EXREG_CR3);
+ if (!is_pae_paging(vcpu))
+ kvm_mmu_update_root(vcpu);
+
/* Do not call post_set_cr3, we do not get here for confidential guests. */

An alternative is to move the vcpu->arch.cr3 update in load_pdptrs.
Reviewers, let me know if you prefer that, then I'll send v3.

Paolo