>+#define TDX_FEATURE_TSX (__feature_bit(X86_FEATURE_HLE) | __feature_bit(X86_FEATURE_RTM)) >+ >+static bool has_tsx(const struct kvm_cpuid_entry2 *entry) >+{ >+ return entry->function == 7 && entry->index == 0 && >+ (entry->ebx & TDX_FEATURE_TSX); >+} >+ >+static void clear_tsx(struct kvm_cpuid_entry2 *entry) >+{ >+ entry->ebx &= ~TDX_FEATURE_TSX; >+} >+ >+static bool has_waitpkg(const struct kvm_cpuid_entry2 *entry) >+{ >+ return entry->function == 7 && entry->index == 0 && >+ (entry->ecx & __feature_bit(X86_FEATURE_WAITPKG)); >+} >+ >+static void clear_waitpkg(struct kvm_cpuid_entry2 *entry) >+{ >+ entry->ecx &= ~__feature_bit(X86_FEATURE_WAITPKG); >+} >+ >+static void tdx_clear_unsupported_cpuid(struct kvm_cpuid_entry2 *entry) >+{ >+ if (has_tsx(entry)) >+ clear_tsx(entry); >+ >+ if (has_waitpkg(entry)) >+ clear_waitpkg(entry); >+} >+ >+static bool tdx_unsupported_cpuid(const struct kvm_cpuid_entry2 *entry) >+{ >+ return has_tsx(entry) || has_waitpkg(entry); >+} No need to check TSX/WAITPKG explicitly because setup_tdparams_cpuids() already ensures that unconfigurable bits are not set by userspace. >+ > #define KVM_TDX_CPUID_NO_SUBLEAF ((__u32)-1) > > static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char idx) >@@ -124,6 +162,8 @@ static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char i > /* Work around missing support on old TDX modules */ > if (entry->function == 0x80000008) > entry->eax = tdx_set_guest_phys_addr_bits(entry->eax, 0xff); >+ >+ tdx_clear_unsupported_cpuid(entry); > } > > static int init_kvm_tdx_caps(const struct tdx_sys_info_td_conf *td_conf, >@@ -1235,6 +1275,9 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid, > if (!entry) > continue; > >+ if (tdx_unsupported_cpuid(entry)) >+ return -EINVAL; >+ > copy_cnt++; > > value = &td_params->cpuid_values[i]; >-- >2.43.0 >