On Wed, 2023-08-16 at 14:33 -0700, Sean Christopherson wrote: > On Wed, Aug 16, 2023, Kai Huang wrote: > > > > > > > --- a/arch/x86/kvm/vmx/vmx.c > > > > > +++ b/arch/x86/kvm/vmx/vmx.c > > > > > @@ -7783,6 +7783,9 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) > > > > > vmx->msr_ia32_feature_control_valid_bits &= > > > > > ~FEAT_CTL_SGX_LC_ENABLED; > > > > > > > > > > + if (boot_cpu_has(X86_FEATURE_LAM)) > > > > > + kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LAM); > > > > > + > > > > If you want to use boot_cpu_has(), it's better to be done at your last patch to > > > > only set the cap bit when boot_cpu_has() is true, I suppose. > > > Yes, but new version of kvm_governed_feature_check_and_set() of > > > KVM-governed feature framework will check against kvm_cpu_cap_has() as well. > > > I will remove the if statement and call > > > kvm_governed_feature_check_and_set() directly. > > > https://lore.kernel.org/kvm/20230815203653.519297-2-seanjc@xxxxxxxxxx/ > > > > > > > I mean kvm_cpu_cap_has() checks against the host CPUID directly while here you > > are using boot_cpu_has(). They are not the same. > > > > If LAM should be only supported when boot_cpu_has() is true then it seems you > > can just only set the LAM cap bit when boot_cpu_has() is true. As you also > > mentioned above the kvm_governed_feature_check_and_set() here internally does > > kvm_cpu_cap_has(). > > That's covered by the last patch: > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index e961e9a05847..06061c11d74d 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -677,7 +677,7 @@ void kvm_set_cpu_caps(void) > kvm_cpu_cap_mask(CPUID_7_1_EAX, > F(AVX_VNNI) | F(AVX512_BF16) | F(CMPCCXADD) | > F(FZRM) | F(FSRS) | F(FSRC) | > - F(AMX_FP16) | F(AVX_IFMA) > + F(AMX_FP16) | F(AVX_IFMA) | F(LAM) > ); > > kvm_cpu_cap_init_kvm_defined(CPUID_7_1_EDX, > Ah I missed this piece of code in kvm_set_cpu_caps(): memcpy(&kvm_cpu_caps, &boot_cpu_data.x86_capability, sizeof(kvm_cpu_caps) - (NKVMCAPINTS * sizeof(*kvm_cpu_caps))); which makes sure KVM only reports one feature when it is set in boot_cpu_data, which is obviously more reasonable. Sorry for the noise :-)