Re: [PATCH v4 00/11] KVM: VMX: Clean up Hyper-V PV TLB flush

From: Paolo Bonzini
Date: Tue Mar 09 2021 - 03:37:00 EST


On 09/03/21 02:18, Sean Christopherson wrote:
Maybe this series is cursed. The first patch got mangled and broke SME.
It shows up as two commits with the same changelog, so maybe you intended to
split the patch and things went sideways?

There was a conflict. I admit kvm/queue is not always that good, usually I try to test it but yesterday I just didn't have time.

I'll fix up everything (also 20/24 in the other series).

Oh well, you have to break eggs to make an omelette. :)

Paolo

Anyways, commit a16241ae56fa ("KVM: x86: Get active PCID only when writing a
CR3 value") breaks SME and PCID. The kvm/queue code looks like this:


cr3 = __sme_set(root_hpa);
if (npt_enabled) {
svm->vmcb->control.nested_cr3 = root_hpa;
vmcb_mark_dirty(svm->vmcb, VMCB_NPT);

/* Loading L2's CR3 is handled by enter_svm_guest_mode. */
if (!test_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail))
return;
cr3 = vcpu->arch.cr3;
}

svm->vmcb->save.cr3 = cr3;
vmcb_mark_dirty(svm->vmcb, VMCB_CR);

but it should look like this:

if (npt_enabled) {
svm->vmcb->control.nested_cr3 = __sme_set(root);
vmcb_mark_dirty(svm->vmcb, VMCB_NPT);

/* Loading L2's CR3 is handled by enter_svm_guest_mode. */
if (!test_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail))
return;
cr3 = vcpu->arch.cr3;
} else if (vcpu->arch.mmu->shadow_root_level >= PT64_ROOT_4LEVEL) {
cr3 = __sme_set(root);
} else {
cr3 = root;
}

svm->vmcb->save.cr3 = cr3;
vmcb_mark_dirty(svm->vmcb, VMCB_CR);

I'll generate a delta patch, and test and post, just in case there is other
stuff that got lost.