On 5/25/2023 11:00 PM, Sean Christopherson wrote:
[...]
The MTRRs are not system wide or per-package though, they are per logical CPU.
Yes, they "need" to be consistent with respect to one another, but only when the
CPU is actually accessing memory. This is a big reason why trying to track MTRRs
as a per-VM asset in KVM is so difficult/messy. Software doesn't rendezvous all
CPUs and then do the write on just one CPU, each CPU does its own writes more or
less independently.
Ah, got it, thanks!
(Some things of each logical processor seems just a shadow of an
consolidate global one, e.g. CR0.CD. Some things are really separated
setting of each logical processor, e.g. MTRR above. Really unfathomable 😅)
BTW, with regard to KVM_X86_QUIRK_CD_NW_CLEARED, I see svm honors it while
vmx doesn't before it clear CR0.CD/NW.
svm_set_cr0():
if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED))
hcr0 &= ~(X86_CR0_CD | X86_CR0_NW);
vmx_set_cr0():
hw_cr0 = (cr0 & ~KVM_VM_CR0_ALWAYS_OFF);
Perhaps vmx side can be fixed passingly?
Sadly, no. SVM and VMX manage guest memtype completely differently. VMX doesn't
allow CR0.CD=1 when VMX is enabled, and so KVM needs to emulate CR0.CD via the EPT
memtype.
OK, get it, thanks. Wasn't aware of this through SDM.