On Mon, Nov 07, 2022, Yu Zhang wrote: > On Thu, Nov 03, 2022 at 04:53:11PM +0000, Sean Christopherson wrote: > > Ideally, KVM should NEVER manipulate VMX MSRs in response to guest CPUID changes. > > That's what I was referring to earlier by commits: ... > Thanks Sean. Let me try to rephrase my understandings of your statement( > and pls feel free to correct me): > > 1> For now, what vmx_adjust_secondary_exec_control() does, is to enable/ > disable a feature in VMX MSR(and nVMX MSR) based on cpuid changes. > 2> What makes sense is, if a feature is > a. disabled by guest CPUID, it shall not be exposed in guest VMX MSR; > b. enabled by guest CPUID, it could be either exposed or hidden in > guest VMX MSR. > 3> So your previous change is to guarantee 2.a, and userspace VMM can choose > to follow follow either choices in 2.b(depending on whether it believes this > feature is correctly supported by KVM in nested). > > Is above understanding correct? Not quite. Again, in an ideal world, KVM would not modify the VMX MSRs based on guest CPUID. But it's possible userspace is relying on KVM to hide a feature from L2 if it's hidden from L1, so to avoid breaking an otherwise valide userspace config, it's worth enforcing that in KVM. > But what if userspace VMM sets guest CPUID first, disabling a feature, and > then sets the guest VMX MSR bit with this feature enabled? Does KVM need to > check guest CPUID again, in vmx_restore_control_msr()? No. It's not KVM's responsibility to provide a sane, valid vCPU model. So long as KVM is not endangered by a bad config, userspace can do whatever it wants.