Set the KVM_CPUID_FLAG_SIGNIFCANT_INDEX flag in the kvm_cpuid_entry2 structures returned by KVM_TDX_CAPABILITIES if the CPUID is indexed. This ensures consistency with the CPUID entries returned by KVM_GET_SUPPORTED_CPUID. Additionally, add a WARN_ON_ONCE() to verify that the TDX module's reported entries align with KVM's expectations regarding indexed CPUID functions. Suggested-by: Sean Christopherson Signed-off-by: Changyuan Lyu --- arch/x86/kvm/vmx/tdx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 2d7a4d52ccfb4..0c524f9a94a6c 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -172,9 +172,15 @@ static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char i entry->ecx = (u32)td_conf->cpuid_config_values[idx][1]; entry->edx = td_conf->cpuid_config_values[idx][1] >> 32; - if (entry->index == KVM_TDX_CPUID_NO_SUBLEAF) + if (entry->index == KVM_TDX_CPUID_NO_SUBLEAF) { entry->index = 0; + entry->flags &= ~KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + } else { + entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + } + WARN_ON_ONCE(cpuid_function_is_indexed(entry->function) != + !!(entry->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX)); /* * The TDX module doesn't allow configuring the guest phys addr bits * (EAX[23:16]). However, KVM uses it as an interface to the userspace -- 2.53.0.371.g1d285c8824-goog