Skip to content

Commit 6d41577

Browse files
ahunter6bonzini
authored andcommitted
KVM: TDX: Disable support for TSX and WAITPKG
Support for restoring IA32_TSX_CTRL MSR and IA32_UMWAIT_CONTROL MSR is not yet implemented, so disable support for TSX and WAITPKG for now. Clear the associated CPUID bits returned by KVM_TDX_CAPABILITIES, and return an error if those bits are set in KVM_TDX_INIT_VM. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Message-ID: <20250129095902.16391-11-adrian.hunter@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent e0b4f31 commit 6d41577

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ static u32 tdx_set_guest_phys_addr_bits(const u32 eax, int addr_bits)
107107
return (eax & ~GENMASK(23, 16)) | (addr_bits & 0xff) << 16;
108108
}
109109

110+
#define TDX_FEATURE_TSX (__feature_bit(X86_FEATURE_HLE) | __feature_bit(X86_FEATURE_RTM))
111+
112+
static bool has_tsx(const struct kvm_cpuid_entry2 *entry)
113+
{
114+
return entry->function == 7 && entry->index == 0 &&
115+
(entry->ebx & TDX_FEATURE_TSX);
116+
}
117+
118+
static void clear_tsx(struct kvm_cpuid_entry2 *entry)
119+
{
120+
entry->ebx &= ~TDX_FEATURE_TSX;
121+
}
122+
123+
static bool has_waitpkg(const struct kvm_cpuid_entry2 *entry)
124+
{
125+
return entry->function == 7 && entry->index == 0 &&
126+
(entry->ecx & __feature_bit(X86_FEATURE_WAITPKG));
127+
}
128+
129+
static void clear_waitpkg(struct kvm_cpuid_entry2 *entry)
130+
{
131+
entry->ecx &= ~__feature_bit(X86_FEATURE_WAITPKG);
132+
}
133+
134+
static void tdx_clear_unsupported_cpuid(struct kvm_cpuid_entry2 *entry)
135+
{
136+
if (has_tsx(entry))
137+
clear_tsx(entry);
138+
139+
if (has_waitpkg(entry))
140+
clear_waitpkg(entry);
141+
}
142+
143+
static bool tdx_unsupported_cpuid(const struct kvm_cpuid_entry2 *entry)
144+
{
145+
return has_tsx(entry) || has_waitpkg(entry);
146+
}
147+
110148
#define KVM_TDX_CPUID_NO_SUBLEAF ((__u32)-1)
111149

112150
static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char idx)
@@ -130,6 +168,8 @@ static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char i
130168
*/
131169
if (entry->function == 0x80000008)
132170
entry->eax = tdx_set_guest_phys_addr_bits(entry->eax, 0xff);
171+
172+
tdx_clear_unsupported_cpuid(entry);
133173
}
134174

135175
static int init_kvm_tdx_caps(const struct tdx_sys_info_td_conf *td_conf,
@@ -1244,6 +1284,9 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,
12441284
if (!entry)
12451285
continue;
12461286

1287+
if (tdx_unsupported_cpuid(entry))
1288+
return -EINVAL;
1289+
12471290
copy_cnt++;
12481291

12491292
value = &td_params->cpuid_values[i];

0 commit comments

Comments
 (0)