Re: [PATCH v2 3/4] KVM: nVMX: Don't muck with allowed sec exec controls on CPUID changes

Paolo Bonzini
2022-12-23T17:31:17Z

On 12/13/22 07:23, Sean Christopherson wrote:
> Don't modify the set of allowed secondary execution controls, i.e. the
> virtual MSR_IA32_VMX_PROCBASED_CTLS2, in response to guest CPUID changes.
> To avoid breaking old userspace that never sets the VMX MSRs, i.e. relies
> on KVM to provide a consistent vCPU model, keep the existing behavior if
> userspace has never written MSR_IA32_VMX_PROCBASED_CTLS2.
>
> KVM should not modify the VMX capabilities presented to L1 based on CPUID
> as doing so may discard explicit settings provided by userspace. E.g. if
> userspace does KVM_SET_MSRS => KVM_SET_CPUID and disables a feature in
> the VMX MSRs but not CPUID (to prevent exposing the feature to L2), then
> stuffing the VMX MSRs during KVM_SET_CPUID will expose the feature to L2
> against userspace's wishes.

The commit message doesn't explain *why* KVM_SET_CPUID would be done
before KVM_SET_MSRS. The presence of certain MSRs or bits within is
signaled by CPUID bits, and even though KVM is more lenient on
host-initiated MSR writes it still verifies in general that the bits are
valid.

For now I applied patch 1 and (with a reworded comment) patch 2. I'm
not opposed to the rest, but I would like to better understand the
reason for them. (If it has been reported to the mailing list, please
add a "Link" trailer too).

Paolo