KVM: TDX: Validate directly configurable CPUID bits
Subsystems (4)
v5 cover KVM: TDX: Validate directly configurable CPUID bits
The TDX module reports a set of CPUID bits that the VMM can directly configure for a TD, but KVM cannot blindly expose all module-supported bits to userspace. Certain features imply additional architectural state (such as one or more MSRs) that KVM must explicitly manage across host/guest transitions to prevent host state corruption.
Today, KVM hardcodes a denylist to filter out host state clobbering features that KVM doesn't support. However, a denylist doesn't scale as the TDX module evolves, i.e. host state clobbering features added by a future TDX module are not covered by the denylist, and userspace could enable a feature that KVM doesn't support.
This series builds an allowlist for directly configurable CPUID bits, and filters and validates userspace input against it, so that newly introduced TDX directly configurable CPUID feature bits can only be enabled by userspace after KVM explicitly opts in. Except for a few fixed-1 bits required for basic TDX support, host state clobbering features are either directly configurable or gated by TD ATTRIBUTES/XFAM. KVM already validates ATTRIBUTES/XFAM, so the allowlist only needs to cover directly configurable bits.
Patch 1 is a standalone fix for the existing denylist check, which uses the index of the matched userspace entry instead of the subleaf reported by the TDX module, i.e. userspace can bypass the HLE/RTM/WAITPKG check. It is tagged for stable so that it can be backported independently of the rest of the series.
Patches 2-5 build the allowlist, add CORE_CAPABILITIES to it, filter KVM_TDX_CAPABILITIES, and validate the CPUID input of KVM_TDX_INIT_VM. The last two patches are user-visible changes, which are now called out in their changelogs, along with why existing userspace and guests are not expected to be affected.
For this version, I'm hoping to continue to collect some RBs and Acks. The key discussions from v3/v4 [1] are summarized below. Note, FRED KVM support is in progress upstream [2], and no TDX module with FRED support exists yet, so there is no immediate issue. But it would be nice to get this series merged sooner rather than later.
Discussions from v3/v4:
- Rick asked whether the assumption that the reserved bits in CPUID.0x1.EAX, CPUID.{0x4,0x18,0x1F} and CPUID.0x80000008.EAX won't be used to enumerate features can be confirmed by the x86 architects [3]. Confirmation is still pending. Per the SDM/APM, these leaves/registers are defined for specific information (version, cache/TLB parameters, topology, and address sizes), so the reserved bits are expected to be used to extend the existing information rather than to enumerate features. Allowing these registers in full is a best guess, but it's still far better than the existing denylist-based check.
- Whether to restrict the TDX feature bits to kvm_cpu_caps[]. The conclusion from the discussions is to construct the allowlist based on kvm_cpu_caps[], plus a few bits that KVM can support for TDs independently of kvm_cpu_caps[]. If TDX feature enabling turns out to be consistently blocked by non-TDX VM enabling, a solution can be worked out then.
- New opt-in interface vs. backporting.
There are two options for old KVM versions that don't do the filtering and validation:
1) Add a new opt-in interface to expose features newly introduced by the TDX module.
2) Backport this series to LTS/stable branches.
The opt-in design vs. backport decision is deferred, since this series is correct and an improvement either way.
- Potential backward compatibility issue when an effective fixed-1 bit becomes directly configurable due to x86 feature deprecation. This is left for the future, i.e. it can be addressed if and when such a deprecation actually happens, e.g. by adding an opt-in interface to let users/admins choose between migration flexibility and backwards compatibility on old platforms.
Changes since v4 [1]:
- Split the CPUID entry index check out into a standalone fix, which allows it to be backported to stable independently of the rest of the series.
- Exclude XTPR from the allowlist, as neither TDX nor KVM actually virtualizes the feature and guests don't need it. (Xiaoyao, Rick)
- Rename TDX_CFG_EXTRA_F() to TDX_CFG_INDEPENDENT_F(). (Xiaoyao)
- Fix AMX_COMPLEX to be added for CPUID_7_1_EDX instead of CPUID_1E_1_EAX.
- Drop the descriptions in the TDX documentation and the uapi header, as the ioctl interfaces for KVM_TDX_CAPABILITIES and KVM_TDX_INIT_VM are unchanged by this patch series.
- Improve changelogs and comments. (Xiaoyao, Rick)
The series follows the CSV version of the CPUID virtualization document from "Intel TDX Module ABI Definitions" [4], updated in June 2026.
AI tools were used to:
- Polish the cover letter and commit messages.
- Do code review.
[1] v4: https://lore.kernel.org/all/[email protected]
v3: https://lore.kernel.org/all/[email protected] v2: https://lore.kernel.org/all/[email protected] v1: https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://cdrdv2.intel.com/v1/dl/getContent/795381
Binbin Wu (5):
KVM: TDX: Check unsupported CPUID bits against the TDX module's
subleaf
KVM: TDX: Track configurable CPUID bits allowed by KVM
KVM: TDX: Add CORE_CAPABILITIES to the allowlist
KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
arch/x86/kvm/vmx/tdx.c | 258 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 231 insertions(+), 27 deletions(-)
base-commit: dea4f6380f4ec96e8f3b0aaf2343764bd0d25ef4
Signature · 1 line
2.46.0
PATCH v5 1/5 KVM: TDX: Check unsupported CPUID bits against the TDX module's subleaf
Check for unsupported CPUID bits using the subleaf reported by the TDX module instead of the index of the matching userspace entry, so that KVM validates the same subleaf that the values are copied into.
setup_tdparams_cpuids() walks the directly configurable CPUID leaves reported by the TDX module and looks up the corresponding userspace entry via kvm_find_cpuid_entry2(). If userspace doesn't set KVM_CPUID_FLAG_SIGNIFCANT_INDEX on an entry, kvm_find_cpuid_entry2() ignores the entry's index, i.e. the matched entry's index can differ from the TDX module's subleaf. tdx_unsupported_cpuid() checks HLE, RTM and WAITPKG based on the userspace entry's index, while the register values are applied to the TDX module's subleaf, which allows userspace to bypass the check.
E.g. if userspace provides a CPUID.0x7 entry with index 3, WAITPKG set, and KVM_CPUID_FLAG_SIGNIFCANT_INDEX cleared, the entry is matched for the TDX module's subleaf 0. The check sees index 3 and passes, while ECX is copied into td_params for CPUID.0x7.0, where WAITPKG is directly configurable. The TDX module accepts the value, and the TD ends up with WAITPKG enumerated despite KVM not supporting it. The same applies to RTM and HLE.
Don't reject the mismatch outright, as the ABI allows userspace to provide an arbitrary index when KVM_CPUID_FLAG_SIGNIFCANT_INDEX is cleared. It's userspace's responsibility to provide the intended entries; KVM only needs to ensure that the values it validates are the values it applies.
---
v5:
- Split out from "KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM" as a standalone fix. Sashiko reported the issue against the TDX CPUID validation patch, but it also applies to the existing code, so split it out to allow backporting to stable independently of the rest of the series.
- Check the userspace values against the subleaf reported by the TDX module instead of rejecting the request when there is a mismatch.
A simpler alternative would be to require a zero index when KVM_CPUID_FLAG_SIGNIFCANT_INDEX is cleared, but that would be an ABI change.
--- arch/x86/kvm/vmx/tdx.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
arch/x86/kvm/vmx/tdx.c +15 -9
@@ -119,9 +119,9 @@ static u32 tdx_set_guest_phys_addr_bits(const u32 eax, int addr_bits)#define TDX_FEATURE_TSX (__feature_bit(X86_FEATURE_HLE) | __feature_bit(X86_FEATURE_RTM)) -static bool has_tsx (const struct kvm_cpuid_entry2 *entry) +static bool has_tsx (const struct kvm_cpuid_entry2 *entry,u32 index) { -return entry->function ==7 && entry->index ==0 && +return entry->function ==7 && index ==0 && (entry->ebx &TDX_FEATURE_TSX ); }
@@ -130,9 +130,9 @@ static void clear_tsx(struct kvm_cpuid_entry2 *entry) entry->ebx &= ~TDX_FEATURE_TSX ; } -static bool has_waitpkg (const struct kvm_cpuid_entry2 *entry) +static bool has_waitpkg (const struct kvm_cpuid_entry2 *entry,u32 index) { -return entry->function ==7 && entry->index ==0 && +return entry->function ==7 && index ==0 && (entry->ecx &__feature_bit (X86_FEATURE_WAITPKG )); }
@@ -143,16 +143,16 @@ static void clear_waitpkg(struct kvm_cpuid_entry2 *entry)static void tdx_clear_unsupported_cpuid (struct kvm_cpuid_entry2 *entry) { -if (has_tsx (entry)) +if (has_tsx (entry, entry->index))clear_tsx (entry); -if (has_waitpkg (entry)) +if (has_waitpkg (entry, entry->index))clear_waitpkg (entry); } -static bool tdx_unsupported_cpuid (const struct kvm_cpuid_entry2 *entry) +static bool tdx_unsupported_cpuid (const struct kvm_cpuid_entry2 *entry,u32 index) { -return has_tsx (entry) ||has_waitpkg (entry); +return has_tsx (entry, index) ||has_waitpkg (entry, index); }#define KVM_TDX_CPUID_NO_SUBLEAF ((__u32)-1)
@@ -2381,7 +2381,13 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,if (!entry)continue ; -if (tdx_unsupported_cpuid (entry)) +/* +* Check the userspace values against the subleaf reported by +* the TDX module, i.e. the subleaf the values are applied to, +* not the index of the userspace entry, which may differ if +* KVM_CPUID_FLAG_SIGNIFCANT_INDEX isn't set. +*/ +if (tdx_unsupported_cpuid (entry, tmp.index))return -EINVAL ; copy_cnt++;
Signature · 1 line
2.46.0
Sean Christopherson
maintainerRe: [PATCH v5 1/5] KVM: TDX: Check unsupported CPUID bits against the TDX module's subleaf
Quoted 20 lines · Binbin Wu
Don't reject the mismatch outright, as the ABI allows userspace to provide an arbitrary index when
KVM_CPUID_FLAG_SIGNIFCANT_INDEXis cleared. It's userspace's responsibility to provide the intended entries; KVM only needs to ensure that the values it validates are the values it applies.Fixes 6d415778f106 ("KVM: TDX: Disable support for TSX and WAITPKG")Reported-by Sashiko <[email protected]>Signed-off-by Binbin Wu <[email protected]>---
v5:
- Split out from "KVM: TDX: Validate userspace CPUID input forKVM_TDX_INIT_VM" as a standalone fix. Sashiko reported the issue against the TDX CPUID validation patch, but it also applies to the existing code, so split it out to allow backporting to stable independently of the rest of the series.
- Check the userspace values against the subleaf reported by the TDX module instead of rejecting the request when there is a mismatch.
Quoted 3 lines
A simpler alternative would be to require a zero index when
KVM_CPUID_FLAG_SIGNIFCANT_INDEXis cleared, but that would be an ABI change.
The even simpler change is to reject the incoming CPUID if userspace doesn't set KVM_CPUID_FLAG_SIGNIFCANT_INDEX as expected. Yes, that's an ABI change. No, we don't care. The rule isn't "never change the ABI", it's "don't break userspace", and there's basically zero chance a TDX guest can function properly if userspace doesn't set KVM_CPUID_FLAG_SIGNIFCANT_INDEX as appropriate.
x86/kvm/vmx/tdx.c +6 -2
@@ -151,8 +151,12 @@ static void tdx_clear_unsupported_cpuid(struct kvm_cpuid_entry2 *entry)clear_waitpkg (entry); } -static bool tdx_unsupported_cpuid (const struct kvm_cpuid_entry2 *entry) +static bool tdx_is_unsupported_cpuid_entry (const struct kvm_cpuid_entry2 *entry) { +if (cpuid_function_is_indexed (entry->function) != + !!(entry->flags &KVM_CPUID_FLAG_SIGNIFCANT_INDEX )) +return true; +return has_tsx (entry) ||has_waitpkg (entry); }
@@ -2386,7 +2390,7 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,if (!entry)continue ; -if (tdx_unsupported_cpuid (entry)) +if (tdx_is_unsupported_cpuid_entry (entry))return -EINVAL ; copy_cnt++;
Can you test the attached patches? If they boot TDX with QEMU, I'll go ahead and post.
From 73ab6386bac6625333526ab6b137c445d22ab5db Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Thu, 15 Oct 2026 18:34:12 -0700
Subject: [PATCH 1/4] x86/cpuid: Mark CPUID function 0x23 as being index
Add function 0x23 to the set of CPUID functions that are index, as per the SDM and the many sub-leafs defined in leaf_types.h.
--- arch/x86/include/asm/cpuid/api.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpuid/api.h +1 -0
@@ -181,6 +181,7 @@ static __always_inline bool cpuid_function_is_indexed(u32 function)case 0x1d :case 0x1e :case 0x1f : +case 0x23 :case 0x24 :case 0x8000001d :return true;
base-commit: dea4f6380f4ec96e8f3b0aaf2343764bd0d25ef4
Signature · 1 line
2.56.0.176.g3575e65682-goog
From 90bd7cecc21de49fc30eda93de1d9f59d0c9a428 Mon Sep 17 00:00:00 2001
From: Changyuan Lyu <[email protected]>
Date: Thu, 15 Oct 2026 18:39:30 -0700
Subject: [PATCH 2/4] KVM: TDX: Set SIGNIFCANT_INDEX flag as appropriate when
filling CPUID entries
Set the KVM_CPUID_FLAG_SIGNIFCANT_INDEX flag in the kvm_cpuid_entry2 structures returned by KVM_TDX_CAPABILITIES if the CPUID is indexed, otherwise KVM could confuse userspace and induce a configuration error. This also ensures consistency with the CPUID entries returned by KVM_GET_SUPPORTED_CPUID.
--- arch/x86/kvm/vmx/tdx.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/kvm/vmx/tdx.c +8 -0
@@ -2,6 +2,7 @@#include <linux/cleanup.h> #include <linux/cpu.h> #include <asm/cpufeature.h> +#include <asm/cpuid/api.h> #include <asm/fpu/xcr.h> #include <linux/misc_cgroup.h> #include <linux/mmu_context.h>
@@ -163,11 +164,18 @@ static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char i entry->function = (u32 )td_conf->cpuid_config_leaves[idx]; entry->index = td_conf->cpuid_config_leaves[idx] >>32 ; + entry->flags =0 ; entry->eax = (u32 )td_conf->cpuid_config_values[idx][0 ]; entry->ebx = td_conf->cpuid_config_values[idx][0 ] >>32 ; entry->ecx = (u32 )td_conf->cpuid_config_values[idx][1 ]; entry->edx = td_conf->cpuid_config_values[idx][1 ] >>32 ; +if (cpuid_function_is_indexed (entry->function)) + entry->flags |=KVM_CPUID_FLAG_SIGNIFCANT_INDEX ; + +WARN_ON_ONCE (cpuid_function_is_indexed (entry->function) != + (entry->index !=KVM_TDX_CPUID_NO_SUBLEAF )); +if (entry->index ==KVM_TDX_CPUID_NO_SUBLEAF ) entry->index =0 ;
Signature · 1 line
2.56.0.176.g3575e65682-goog
From c5cb713d03fa7cc41b999db8b014da6aa3d2a424 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Thu, 15 Oct 2026 18:42:36 -0700
Subject: [PATCH 3/4] KVM: TDX: Don't zero non-significant CPUID entry indices
Now that KVM sets KVM_CPUID_FLAG_SIGNIFCANT_INDEX when filling CPUID entries based on output from the TDX Module, don't zero the index for entries without a signficant index, as doing so incorrectly suggests that zero is somehow special, which it is not. The critical piece of info is the SIGNIFCANT_INDEX flag, which tells KVM (and userspace) to simply ignore the index.
--- arch/x86/kvm/vmx/tdx.c | 3 --- 1 file changed, 3 deletions(-)
arch/x86/kvm/vmx/tdx.c +0 -3
@@ -176,9 +176,6 @@ static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char iWARN_ON_ONCE (cpuid_function_is_indexed (entry->function) != (entry->index !=KVM_TDX_CPUID_NO_SUBLEAF )); -if (entry->index ==KVM_TDX_CPUID_NO_SUBLEAF ) - entry->index =0 ; -/* * 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
Signature · 1 line
2.56.0.176.g3575e65682-goog
From c38351fecf16d9bbb694f3a08127ab90ae64484b Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Fri, 16 Oct 2026 07:41:34 -0700
Subject: [PATCH 4/4] KVM: TDX: Reject KVM_TDX_INIT_VM if indexed CPUID
functions don't match
Reject KVM_TDX_INIT_VM if userspace doesn't configure the canonical CPUID entries correctly with respect to KVM_CPUID_FLAG_SIGNIFCANT_INDEX to fix a bug where userspace could bypass the TSX and WAITPKG checks by simply not marking a CPUID.0x7 entry as being indexed. This also sets the stage for more in-depth validation of the incoming CPUID configuration.
This is obviously an ABI change and diverges from KVM's general approach of "let userspace do what it wants". In practice, no "real" VMM that supports TDX misconfigures a TD's CPUID entries in this way, i.e. the probability of actually breaking userspace is basically nil. And unlike normal VMs, where KVM has full control and thus can deal with bizarre CPUID input without too much fuss, TDX VMs require extra care due to the TDX Module also reacting to the CPUID configuration, i.e. KVM_TDX_INIT_VM needs to be more strict than KVM_SET_CPUID{,2} to avoid creating potentially dangerous-to-the-host setups.
Opportunistically rename the helper to make it more obvious that it's checking if the passed in @entry is unsupported, as opposed to returning a set of unsupported entries or something.
--- arch/x86/kvm/vmx/tdx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/tdx.c +6 -2
@@ -151,8 +151,12 @@ static void tdx_clear_unsupported_cpuid(struct kvm_cpuid_entry2 *entry)clear_waitpkg (entry); } -static bool tdx_unsupported_cpuid (const struct kvm_cpuid_entry2 *entry) +static bool tdx_is_unsupported_cpuid_entry (const struct kvm_cpuid_entry2 *entry) { +if (cpuid_function_is_indexed (entry->function) != + !!(entry->flags &KVM_CPUID_FLAG_SIGNIFCANT_INDEX )) +return true; +return has_tsx (entry) ||has_waitpkg (entry); }
@@ -2386,7 +2390,7 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,if (!entry)continue ; -if (tdx_unsupported_cpuid (entry)) +if (tdx_is_unsupported_cpuid_entry (entry))return -EINVAL ; copy_cnt++;
Signature · 1 line
2.56.0.176.g3575e65682-goog
Re: [PATCH v5 1/5] KVM: TDX: Check unsupported CPUID bits against the TDX module's subleaf
Quoted 59 lines · Sean Christopherson
Quoted 20 lines · Binbin Wu
Don't reject the mismatch outright, as the ABI allows userspace to provide an arbitrary index when
KVM_CPUID_FLAG_SIGNIFCANT_INDEXis cleared. It's userspace's responsibility to provide the intended entries; KVM only needs to ensure that the values it validates are the values it applies.Fixes 6d415778f106 ("KVM: TDX: Disable support for TSX and WAITPKG")Reported-by Sashiko <[email protected]>Signed-off-by Binbin Wu <[email protected]>---
v5:
- Split out from "KVM: TDX: Validate userspace CPUID input forKVM_TDX_INIT_VM" as a standalone fix. Sashiko reported the issue against the TDX CPUID validation patch, but it also applies to the existing code, so split it out to allow backporting to stable independently of the rest of the series.
- Check the userspace values against the subleaf reported by the TDX module instead of rejecting the request when there is a mismatch.Quoted 3 lines
A simpler alternative would be to require a zero index when
KVM_CPUID_FLAG_SIGNIFCANT_INDEXis cleared, but that would be an ABI change.The even simpler change is to reject the incoming CPUID if userspace doesn't set
KVM_CPUID_FLAG_SIGNIFCANT_INDEXas expected. Yes, that's an ABI change. No, we don't care. The rule isn't "never change the ABI", it's "don't break userspace", and there's basically zero chance a TDX guest can function properly if userspace doesn't setKVM_CPUID_FLAG_SIGNIFCANT_INDEXas appropriate.x86/kvm/vmx/tdx.c +6
-2@@ -151,8 +151,12 @@ static void tdx_clear_unsupported_cpuid(struct kvm_cpuid_entry2 *entry)clear_waitpkg (entry); } -static bool tdx_unsupported_cpuid (const struct kvm_cpuid_entry2 *entry) +static bool tdx_is_unsupported_cpuid_entry (const struct kvm_cpuid_entry2 *entry) { +if (cpuid_function_is_indexed (entry->function) != + !!(entry->flags &KVM_CPUID_FLAG_SIGNIFCANT_INDEX )) +return true; +return has_tsx (entry) ||has_waitpkg (entry); }@@ -2386,7 +2390,7 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,if (!entry)continue ; -if (tdx_unsupported_cpuid (entry)) +if (tdx_is_unsupported_cpuid_entry (entry))return -EINVAL ; copy_cnt++;
Quoted 2 lines
Can you test the attached patches? If they boot TDX with QEMU, I'll go ahead and post.
Patch 3 "KVM: TDX: Don't zero non-significant CPUID entry indices" breaks QEMU.
QEMU uses zero as index for cpuid entries when index is not significant. And in QEMU, the lookup function doesn't consult the flags at all.
struct kvm_cpuid_entry2 *cpuid_find_entry(struct kvm_cpuid2 *cpuid,
uint32_t function,
uint32_t index)
{
int i;
for (i = 0; i < cpuid->nent; ++i) {
if (cpuid->entries[i].function == function &&
cpuid->entries[i].index == index) {
return &cpuid->entries[i];
}
}
/* not found: */
return NULL;
}If KVM doesn't zero the index for the non-significant, QEMU cannot find any entry for non-significant entries returned by KVM_TDX_CAPABILITIES.
And 0x80000008 is used to pass GPAW, and KVM_TDX_INIT_VM fails when QEMU doesn't pass it.
After dropping patch 3, QEMU can boot TD.
Also our internal TDX CI cases passed.
Sean Christopherson
maintainerRe: [PATCH v5 1/5] KVM: TDX: Check unsupported CPUID bits against the TDX module's subleaf
Quoted 10 lines · Binbin Wu
Quoted 9 lines · Sean Christopherson
On Fri, Oct 16, 2026, Binbin Wu wrote:
x86/kvm/vmx/tdx.c +1
-1@@ -2386,7 +2390,7 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,if (!entry)continue ; -if (tdx_unsupported_cpuid (entry)) +if (tdx_is_unsupported_cpuid_entry (entry))return -EINVAL ;
Quoted 8 lines
Quoted 4 lines
(quoted diff) +0
-0copy_cnt++;Can you test the attached patches? If they boot TDX with QEMU, I'll go ahead and post.
Patch 3 "KVM: TDX: Don't zero non-significant CPUID entry indices" breaks QEMU.
QEMU uses zero as index for cpuid entries when index is not significant.
Drat. __do_cpuid_func() => do_host_cpuid() also zeros the index for KVM_GET_SUPPORTED_CPUID, so the ABI is definitely baked at this point.
Quoted 10 lines
And in QEMU, the lookup function doesn't consult the flags at all.
struct
kvm_cpuid_entry2*cpuid_find_entry(structkvm_cpuid2*cpuid,uint32_t function, uint32_t index) { int i; for (i = 0; i < cpuid->nent; ++i) { if (cpuid->entries[i].function == function && cpuid->entries[i].index == index) {
Bad QEMU, bad! :-)
Quoted 9 lines
return &cpuid->entries[i]; } } /* not found: */ return NULL; }If KVM doesn't zero the index for the non-significant, QEMU cannot find any entry for non-significant entries returned by
KVM_TDX_CAPABILITIES.
I'll opportunistically add a comment to call out that even though the index should be meaningless, it has become ABI that userspace relies on.
Quoted 5 lines
And
0x80000008is used to pass GPAW, andKVM_TDX_INIT_VMfails when QEMU doesn't pass it.After dropping patch 3, QEMU can boot TD.
Also our internal TDX CI cases passed.
Thanks much!
PATCH v5 2/5 KVM: TDX: Track configurable CPUID bits allowed by KVM
In reply to Binbin WuAdd tdx_cpu_cfg_caps[] to track the subset of TDX directly configurable CPUID feature bits that KVM supports, and initialize it during TDX hardware setup.
The TDX module reports the CPUID bits that the VMM can directly configure for a TD, but KVM can't blindly expose every reported bit to userspace. Some features imply additional state, e.g. MSRs, that KVM must context switch across host/guest transitions to avoid corrupting host state. The existing hardcoded denylist can't account for such features introduced by future TDX modules.
Aside from a few fixed-1 bits required for basic TDX support, features that can clobber host state are either directly configurable or controlled by TD ATTRIBUTES/XFAM, which KVM already validates. Thus, an allowlist covering only the directly configurable bits is sufficient.
Organize tdx_cpu_cfg_caps[] like kvm_cpu_caps[] so that the allowlist can be built with feature-name based initializers. Directly configurable bits that aren't feature flags will be handled when building the per-register masks for KVM_TDX_CAPABILITIES.
Sort the directly configurable CPUID feature bits into three categories:
1) Features that KVM supports and tracks in kvm_cpu_caps[]. Use
TDX_CFG_F() so that they are also capped by kvm_cpu_caps[].
2) Features that KVM supports, or can safely allow, but doesn't track in
kvm_cpu_caps[], i.e. MWAIT and HT. Use TDX_CFG_INDEPENDENT_F().
3) Features that are obsolete or unsupported by KVM, and thus excluded, i.e. EST, TM2, CID, SDBG, XTPR, DCA, PN (PSN), ACPI, ACC (TM), PBE, HLE, RTM, CQM (RDT_M), RDT_A, PREFETCHWT1, WAITPKG, TME, PCONFIG, CORE_CAPABILITIES, RAO_INT, FRED, and AMX-TRANSPOSE.
Excluding the features in category 3 shouldn't break userspace, as userspace is expected to consult KVM_TDX_CAPABILITIES for the configurable bits before invoking KVM_TDX_INIT_VM. Nor should it break guests, as the features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems. CORE_CAPABILITIES is a special case; it will be allowed separately to accommodate its legacy fixed-1 definition.
Future changes will use tdx_cpu_cfg_caps[] to filter KVM_TDX_CAPABILITIES and to reject unsupported CPUID input to KVM_TDX_INIT_VM, so that directly configurable bits introduced by future TDX modules are neither advertised to nor configurable by userspace until KVM explicitly opts in.
---
v5:
- Simplify the commit message for excluded bits. (Xiaoyao)
- Use TDX_CFG_INDEPENDENT_F() instead of TDX_CFG_EXTRA_F(). (Xiaoyao)
- Avoid using "patch" in the commit message. (Rick)
- Remove comments for host clobbering features KVM doesn't support yet. (Xiaoyao)
- AMX_COMPLEX should be added for CPUID_7_1_EDX instead of CPUID_1E_1_EAX, it was a wrong fix in v4 to add it for CPUID_1E_1_EAX.
- Exclude XTPR since TDX/KVM doesn't actually virtualize the feature and guests don't need it.
- Move the TDX CPUID allowlist code next to the other CPUID helpers.
v4:
- Add XTPR and HT to the allowlist.
- Explain in the changelog why some directly configurable bits are not added to the allowlist.
- Improve comments/changelog. (Xiaoyao)
- Fix the bug that AMX_COMPLEX should be added for CPUID_1E_1_EAX instead of CPUID_7_1_EDX.
v3:
- Drop the new data structure in v2 and only track feature bits by following the organization of kvm_cpu_caps[], handle non-feature bits separately. (Sean)
- Use two versions of macros (TDX_CFG_F() vs. TDX_CFG_EXTRA_F()) to distinguish whether a supported TDX configurable CPUID bit should be checked against KVM's common cpu capabilities.
- Add AMX_COMPLEX since it has been defined in the CPUID virtualization doc.
--- arch/x86/kvm/vmx/tdx.c | 153 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+)
arch/x86/kvm/vmx/tdx.c +153 -0
@@ -57,6 +57,8 @@ bool enable_tdx __ro_after_init;module_param_named (tdx, enable_tdx, bool,0444 );static const struct tdx_sys_info *tdx_sysinfo; +static u32 tdx_cpu_cfg_caps[NR_KVM_CPU_CAPS ]__ro_after_init ; +static_assert (ARRAY_SIZE (tdx_cpu_cfg_caps) ==ARRAY_SIZE (kvm_cpu_caps));void tdh_vp_rd_failed (struct vcpu_tdx *tdx,char *uclass,u32 field,u64 err) {
@@ -117,6 +119,155 @@ static u32 tdx_set_guest_phys_addr_bits(const u32 eax, int addr_bits)return (eax & ~GENMASK (23 ,16 )) | (addr_bits &0xff ) <<16 ; } +#define TDX_VALIDATE_CPU_CAP_USAGE (name) \ + BUILD_BUG_ON(__feature_leaf(X86_FEATURE_##name) != \ + tdx_cpu_cap_init_in_progress) + +/* For features that are dependent on kvm_cpu_caps[]. */ +#define TDX_CFG_F (name) \ +({ \ + TDX_VALIDATE_CPU_CAP_USAGE(name); \ + tdx_cfg_caps |= feature_bit(name); \ +}) + +/* +* For features that are not dependent on kvm_cpu_caps[], e.g. MWAIT. +* Use this version only when there is a justification. +*/ +#define TDX_CFG_INDEPENDENT_F (name) \ +({ \ + TDX_VALIDATE_CPU_CAP_USAGE(name); \ + tdx_cfg_caps_independent |= feature_bit(name); \ +}) + +#define tdx_cpu_cfg_cap_init(leaf, feature_initializers...) \ +do { \ + const u32 __maybe_unused tdx_cpu_cap_init_in_progress = leaf; \ + u32 tdx_cfg_caps_independent = 0; \ + u32 tdx_cfg_caps = 0; \ + \ + feature_initializers \ + tdx_cpu_cfg_caps[leaf] = (tdx_cfg_caps & kvm_cpu_caps[leaf]) | \ + tdx_cfg_caps_independent; \ +} while (0) + +/* +* Initialize tdx_cpu_cfg_caps[], the list of CPUID features that KVM +* supports for TDX guests. It covers only the directly configurable CPUID +* bits reported by the TDX module; features controlled by XFAM and +* ATTRIBUTES are handled separately. +*/ +static void __init tdx_initialize_cpu_cfg_caps (void ) +{ +tdx_cpu_cfg_cap_init (CPUID_1_ECX , +/* +* KVM allows userspace to enumerate MONITOR+MWAIT support to +* the guest, but the MWAIT feature flag is never advertised +* to userspace for non-TDX VMs. +*/ +TDX_CFG_INDEPENDENT_F (MWAIT ), +TDX_CFG_F (TSC_DEADLINE_TIMER ), +TDX_CFG_F (AVX ), + TDX_CFG_F(F16C), + ); + +tdx_cpu_cfg_cap_init (CPUID_1_EDX , +TDX_CFG_F (MCE ), +TDX_CFG_F (MTRR ), +TDX_CFG_F (MCA ), +TDX_CFG_F (SELFSNOOP ), +/* +* HT is a topology enumeration bit that KVM doesn't care +* about, but userspace may want to expose it to the guests. +*/ + TDX_CFG_INDEPENDENT_F(HT), + ); + +tdx_cpu_cfg_cap_init (CPUID_7_0_EBX , +TDX_CFG_F (BMI1 ), +TDX_CFG_F (BMI2 ), +TDX_CFG_F (ERMS ), +TDX_CFG_F (AVX512F ), +TDX_CFG_F (AVX512DQ ), +TDX_CFG_F (ADX ), +TDX_CFG_F (AVX512IFMA ), +TDX_CFG_F (AVX512PF ), +TDX_CFG_F (AVX512ER ), +TDX_CFG_F (AVX512CD ), +TDX_CFG_F (AVX512BW ), + TDX_CFG_F(AVX512VL), + ); + +tdx_cpu_cfg_cap_init (CPUID_7_ECX , +TDX_CFG_F (UMIP ), +TDX_CFG_F (AVX512_VBMI2 ), +TDX_CFG_F (GFNI ), +TDX_CFG_F (VAES ), +TDX_CFG_F (VPCLMULQDQ ), +TDX_CFG_F (AVX512_VNNI ), +TDX_CFG_F (AVX512_BITALG ), +TDX_CFG_F (AVX512_VPOPCNTDQ ), +TDX_CFG_F (LA57 ), +TDX_CFG_F (RDPID ), + TDX_CFG_F(CLDEMOTE), + ); + +tdx_cpu_cfg_cap_init (CPUID_7_EDX , +TDX_CFG_F (AVX512_4VNNIW ), +TDX_CFG_F (AVX512_4FMAPS ), +TDX_CFG_F (FSRM ), +TDX_CFG_F (AVX512_VP2INTERSECT ), +TDX_CFG_F (SERIALIZE ), + TDX_CFG_F(TSXLDTRK), + ); + +tdx_cpu_cfg_cap_init (CPUID_7_1_EAX , +TDX_CFG_F (SHA512 ), +TDX_CFG_F (SM3 ), +TDX_CFG_F (SM4 ), +TDX_CFG_F (AVX_VNNI ), +TDX_CFG_F (AVX512_BF16 ), +TDX_CFG_F (CMPCCXADD ), +TDX_CFG_F (FZRM ), +TDX_CFG_F (FSRS ), +TDX_CFG_F (FSRC ), +TDX_CFG_F (LKGS ), +TDX_CFG_F (WRMSRNS ), +TDX_CFG_F (AMX_FP16 ), +TDX_CFG_F (AVX_IFMA ), +TDX_CFG_F (LAM ), + TDX_CFG_F(MOVRS), + ); + +tdx_cpu_cfg_cap_init (CPUID_7_1_EDX , +TDX_CFG_F (AVX_VNNI_INT8 ), +TDX_CFG_F (AVX_NE_CONVERT ), +TDX_CFG_F (AMX_COMPLEX ), +TDX_CFG_F (AVX_VNNI_INT16 ), +TDX_CFG_F (PREFETCHITI ), + TDX_CFG_F(AVX10), + ); + +tdx_cpu_cfg_cap_init (CPUID_7_2_EDX , +TDX_CFG_F (DDPD_U ), + TDX_CFG_F(MCDT_NO), + ); + +tdx_cpu_cfg_cap_init (CPUID_1E_1_EAX , +TDX_CFG_F (AMX_FP8 ), +TDX_CFG_F (AMX_TF32 ), +TDX_CFG_F (AMX_AVX512 ), + TDX_CFG_F(AMX_MOVRS), + ); + +tdx_cpu_cfg_cap_init (CPUID_8000_0008_EBX , + TDX_CFG_F(WBNOINVD), + ); +} + +#undef TDX_CFG_F +#undef TDX_CFG_INDEPENDENT_F +#define TDX_FEATURE_TSX (__feature_bit(X86_FEATURE_HLE) | __feature_bit(X86_FEATURE_RTM))static bool has_tsx (const struct kvm_cpuid_entry2 *entry,u32 index)
@@ -3529,6 +3680,8 @@ int __init tdx_hardware_setup(void)return r; } +tdx_initialize_cpu_cfg_caps (); +KVM_SANITY_CHECK_VM_STRUCT_SIZE (kvm_tdx); vt_x86_ops.vm_size = max_t(unsigned int, vt_x86_ops.vm_size, sizeof(struct kvm_tdx));
Signature · 1 line
2.46.0
Re: [PATCH v5 2/5] KVM: TDX: Track configurable CPUID bits allowed by KVM
Quoted 42 lines · Binbin Wu
Add tdx_cpu_cfg_caps[] to track the subset of TDX directly configurable CPUID feature bits that KVM supports, and initialize it during TDX hardware setup.
The TDX module reports the CPUID bits that the VMM can directly configure for a TD, but KVM can't blindly expose every reported bit to userspace. Some features imply additional state, e.g. MSRs, that KVM must context switch across host/guest transitions to avoid corrupting host state. The existing hardcoded denylist can't account for such features introduced by future TDX modules.
Aside from a few fixed-1 bits required for basic TDX support, features that can clobber host state are either directly configurable or controlled by TD ATTRIBUTES/XFAM, which KVM already validates. Thus, an allowlist covering only the directly configurable bits is sufficient.
Organize tdx_cpu_cfg_caps[] like kvm_cpu_caps[] so that the allowlist can be built with feature-name based initializers. Directly configurable bits that aren't feature flags will be handled when building the per-register masks for
KVM_TDX_CAPABILITIES.Sort the directly configurable CPUID feature bits into three categories:
1) Features that KVM supports and tracks in kvm_cpu_caps[]. Use
TDX_CFG_F()so that they are also capped by kvm_cpu_caps[].2) Features that KVM supports, or can safely allow, but doesn't track in kvm_cpu_caps[], i.e. MWAIT and HT. Use
TDX_CFG_INDEPENDENT_F().3) Features that are obsolete or unsupported by KVM, and thus excluded, i.e. EST, TM2, CID, SDBG, XTPR, DCA, PN (PSN), ACPI, ACC (TM), PBE, HLE, RTM, CQM (
RDT_M),RDT_A, PREFETCHWT1, WAITPKG, TME, PCONFIG,CORE_CAPABILITIES,RAO_INT, FRED, and AMX-TRANSPOSE.Excluding the features in category 3 shouldn't break userspace, as userspace is expected to consult
KVM_TDX_CAPABILITIESfor the configurable bits before invokingKVM_TDX_INIT_VM. Nor should it break guests, as the features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.CORE_CAPABILITIESis a special case; it will be allowed separately to accommodate its legacy fixed-1 definition.
Quoted 6 lines
Future changes will use tdx_cpu_cfg_caps[] to filter
KVM_TDX_CAPABILITIESand to reject unsupported CPUID input toKVM_TDX_INIT_VM, so that directly configurable bits introduced by future TDX modules are neither advertised to nor configurable by userspace until KVM explicitly opts in.Signed-off-by Binbin Wu <[email protected]>
Re: [PATCH v5 2/5] KVM: TDX: Track configurable CPUID bits allowed by KVM
In reply to Binbin WuQuoted 42 lines · Binbin Wu
Add tdx_cpu_cfg_caps[] to track the subset of TDX directly configurable CPUID feature bits that KVM supports, and initialize it during TDX hardware setup.
The TDX module reports the CPUID bits that the VMM can directly configure for a TD, but KVM can't blindly expose every reported bit to userspace. Some features imply additional state, e.g. MSRs, that KVM must context switch across host/guest transitions to avoid corrupting host state. The existing hardcoded denylist can't account for such features introduced by future TDX modules.
Aside from a few fixed-1 bits required for basic TDX support, features that can clobber host state are either directly configurable or controlled by TD ATTRIBUTES/XFAM, which KVM already validates. Thus, an allowlist covering only the directly configurable bits is sufficient.
Organize tdx_cpu_cfg_caps[] like kvm_cpu_caps[] so that the allowlist can be built with feature-name based initializers. Directly configurable bits that aren't feature flags will be handled when building the per-register masks for
KVM_TDX_CAPABILITIES.Sort the directly configurable CPUID feature bits into three categories:
1) Features that KVM supports and tracks in kvm_cpu_caps[]. Use
TDX_CFG_F() so that they are also capped by kvm_cpu_caps[].2) Features that KVM supports, or can safely allow, but doesn't track in
kvm_cpu_caps[], i.e. MWAIT and HT. Use TDX_CFG_INDEPENDENT_F().3) Features that are obsolete or unsupported by KVM, and thus excluded, i.e. EST, TM2, CID, SDBG, XTPR, DCA, PN (PSN), ACPI, ACC (TM), PBE, HLE, RTM, CQM (
RDT_M),RDT_A, PREFETCHWT1, WAITPKG, TME, PCONFIG,CORE_CAPABILITIES,RAO_INT, FRED, and AMX-TRANSPOSE.Excluding the features in category 3 shouldn't break userspace, as userspace is expected to consult
KVM_TDX_CAPABILITIESfor the configurable bits before invokingKVM_TDX_INIT_VM. Nor should it break guests, as the features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.CORE_CAPABILITIESis a special case; it will be allowed separately to accommodate its legacy fixed-1 definition.
Quoted 6 lines
Future changes will use tdx_cpu_cfg_caps[] to filter
KVM_TDX_CAPABILITIESand to reject unsupported CPUID input toKVM_TDX_INIT_VM, so that directly configurable bits introduced by future TDX modules are neither advertised to nor configurable by userspace until KVM explicitly opts in.Signed-off-by Binbin Wu <[email protected]>
Re: [PATCH v5 2/5] KVM: TDX: Track configurable CPUID bits allowed by KVM
In reply to Binbin WuQuoted 42 lines · Binbin Wu
Add tdx_cpu_cfg_caps[] to track the subset of TDX directly configurable CPUID feature bits that KVM supports, and initialize it during TDX hardware setup.
The TDX module reports the CPUID bits that the VMM can directly configure for a TD, but KVM can't blindly expose every reported bit to userspace. Some features imply additional state, e.g. MSRs, that KVM must context switch across host/guest transitions to avoid corrupting host state. The existing hardcoded denylist can't account for such features introduced by future TDX modules.
Aside from a few fixed-1 bits required for basic TDX support, features that can clobber host state are either directly configurable or controlled by TD ATTRIBUTES/XFAM, which KVM already validates. Thus, an allowlist covering only the directly configurable bits is sufficient.
Organize tdx_cpu_cfg_caps[] like kvm_cpu_caps[] so that the allowlist can be built with feature-name based initializers. Directly configurable bits that aren't feature flags will be handled when building the per-register masks for
KVM_TDX_CAPABILITIES.Sort the directly configurable CPUID feature bits into three categories:
1) Features that KVM supports and tracks in kvm_cpu_caps[]. Use
TDX_CFG_F() so that they are also capped by kvm_cpu_caps[].2) Features that KVM supports, or can safely allow, but doesn't track in
kvm_cpu_caps[], i.e. MWAIT and HT. Use TDX_CFG_INDEPENDENT_F().3) Features that are obsolete or unsupported by KVM, and thus excluded, i.e. EST, TM2, CID, SDBG, XTPR, DCA, PN (PSN), ACPI, ACC (TM), PBE, HLE, RTM, CQM (
RDT_M),RDT_A, PREFETCHWT1, WAITPKG, TME, PCONFIG,CORE_CAPABILITIES,RAO_INT, FRED, and AMX-TRANSPOSE.Excluding the features in category 3 shouldn't break userspace, as userspace is expected to consult
KVM_TDX_CAPABILITIESfor the configurable bits before invokingKVM_TDX_INIT_VM. Nor should it break guests, as the features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.CORE_CAPABILITIESis a special case; it will be allowed separately to accommodate its legacy fixed-1 definition.
Quoted 6 lines
Future changes will use tdx_cpu_cfg_caps[] to filter
KVM_TDX_CAPABILITIESand to reject unsupported CPUID input toKVM_TDX_INIT_VM, so that directly configurable bits introduced by future TDX modules are neither advertised to nor configurable by userspace until KVM explicitly opts in.Signed-off-by Binbin Wu <[email protected]>
PATCH v5 3/5 KVM: TDX: Add CORE_CAPABILITIES to the allowlist
In reply to Binbin WuAdd CORE_CAPABILITIES (CPUID.0x7.0.EDX[30]) to KVM's allowlist of TDX directly configurable CPUID feature bits to accommodate the legacy TDX module definition of the bit, even though KVM doesn't support MSR_IA32_CORE_CAPS for TDs.
Older TDX module specs define CORE_CAPABILITIES as fixed-1, so userspace may expect the bit to be set for TDs. The bit is redefined as directly configurable due to #VE reduction. Leaving it out of the allowlist would prevent userspace from setting it once KVM starts validating the CPUID input to KVM_TDX_INIT_VM, which would be an unexpected behavior change for such userspace.
Reporting CORE_CAPABILITIES as directly configurable also lets userspace detect that the bit is no longer fixed-1, and thus update its stale knowledge.
Keep MSR_IA32_CORE_CAPS unsupported for TDs, as no existing TDX user needs guest access to the MSR.
Note, CORE_CAPABILITIES is the only bit that is both unsupported by KVM *and* redefined from fixed-1 to directly configurable due to #VE reduction, and no further #VE reductions are expected.
---
v5:
- Clarify in the changelog that #VE reduction redefines the bit from fixed-1 to directly configurable.
- Change the shortlog from "KVM: TDX: Report CORE_CAPABILITIES as configurable" to "KVM: TDX: Add CORE_CAPABILITIES to the allowlist" since the patch doesn't change the CPUID reporting behavior yet.
- Add RB from Xiaoyao.
v4:
- Add #VE reduction related background to the changelog. (Kishen)
- Add RB from Tony.
v3:
- Drop the code for MSR_IA32_CORE_CAPS access.
--- arch/x86/kvm/vmx/tdx.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/kvm/vmx/tdx.c +7 -0
@@ -219,6 +219,13 @@ static void __init tdx_initialize_cpu_cfg_caps(void)TDX_CFG_F (AVX512_VP2INTERSECT ),TDX_CFG_F (SERIALIZE ),TDX_CFG_F (TSXLDTRK ), +/* +* KVM doesn't support MSR_IA32_CORE_CAPS, but older TDX module +* specs define this bit as fixed-1. Report it as configurable +* to accommodate the legacy TDX module definition, and to let +* userspace detect that the bit is no longer fixed-1. +*/ +TDX_CFG_INDEPENDENT_F (CORE_CAPABILITIES ), ); tdx_cpu_cfg_cap_init(CPUID_7_1_EAX,
Signature · 1 line
2.46.0
Re: [PATCH v5 3/5] KVM: TDX: Add CORE_CAPABILITIES to the allowlist
Quoted 19 lines · Binbin Wu
Add
CORE_CAPABILITIES(CPUID.0x7.0.EDX[30]) to KVM's allowlist of TDX directly configurable CPUID feature bits to accommodate the legacy TDX module definition of the bit, even though KVM doesn't supportMSR_IA32_CORE_CAPSfor TDs.Older TDX module specs define
CORE_CAPABILITIESas fixed-1, so userspace may expect the bit to be set for TDs. The bit is redefined as directly configurable due to #VE reduction. Leaving it out of the allowlist would prevent userspace from setting it once KVM starts validating the CPUID input toKVM_TDX_INIT_VM, which would be an unexpected behavior change for such userspace.Reporting
CORE_CAPABILITIESas directly configurable also lets userspace detect that the bit is no longer fixed-1, and thus update its stale knowledge.Keep
MSR_IA32_CORE_CAPSunsupported for TDs, as no existing TDX user needs guest access to the MSR.
Quoted 7 lines
Note,
CORE_CAPABILITIESis the only bit that is both unsupported by KVM *and* redefined from fixed-1 to directly configurable due to #VE reduction, and no further #VE reductions are expected.Signed-off-by Binbin Wu <[email protected]>Reviewed-by Tony Lindgren <[email protected]>Reviewed-by Xiaoyao Li <[email protected]>
Re: [PATCH v5 3/5] KVM: TDX: Add CORE_CAPABILITIES to the allowlist
In reply to Binbin WuQuoted 19 lines · Binbin Wu
Add
CORE_CAPABILITIES(CPUID.0x7.0.EDX[30]) to KVM's allowlist of TDX directly configurable CPUID feature bits to accommodate the legacy TDX module definition of the bit, even though KVM doesn't supportMSR_IA32_CORE_CAPSfor TDs.Older TDX module specs define
CORE_CAPABILITIESas fixed-1, so userspace may expect the bit to be set for TDs. The bit is redefined as directly configurable due to #VE reduction. Leaving it out of the allowlist would prevent userspace from setting it once KVM starts validating the CPUID input toKVM_TDX_INIT_VM, which would be an unexpected behavior change for such userspace.Reporting
CORE_CAPABILITIESas directly configurable also lets userspace detect that the bit is no longer fixed-1, and thus update its stale knowledge.Keep
MSR_IA32_CORE_CAPSunsupported for TDs, as no existing TDX user needs guest access to the MSR.
Quoted 7 lines
Note,
CORE_CAPABILITIESis the only bit that is both unsupported by KVM *and* redefined from fixed-1 to directly configurable due to #VE reduction, and no further #VE reductions are expected.Signed-off-by Binbin Wu <[email protected]>Reviewed-by Tony Lindgren <[email protected]>Reviewed-by Xiaoyao Li <[email protected]>
PATCH v5 4/5 KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
In reply to Binbin WuFilter the directly configurable CPUID bits reported through KVM_TDX_CAPABILITIES against KVM's TDX allowlist, and drop the hardcoded denylist-based filtering.
The TDX module reports the CPUID bits that the VMM can directly configure for a TD, but KVM must not advertise bits that it doesn't support, as blindly exposing a feature that clobbers host state can corrupt the host. The existing denylist, which clears only TSX and WAITPKG, can't account for such features introduced by future TDX modules.
Add tdx_get_cpuid_cfg_mask() to compute the mask of directly configurable bits that KVM allows for a given CPUID register, and apply it to every CPUID entry reported through KVM_TDX_CAPABILITIES. The mask combines feature bits, taken from tdx_cpu_cfg_caps[], with non-feature bits, which are identified by function, index, and register.
Treat CPUID.0x1.{EAX,EBX}, CPUID.{0x4,0x18,0x1F}, and CPUID.0x80000008.EAX as fully allowed, as these registers enumerate non-feature information, e.g. family/model/stepping, brand index, CLFLUSH line size, APIC ID, cache/TLB/topology properties, and address sizes. Allow the reserved bits in them as well. Though there's no architectural guarantee, given what these registers enumerate, the reserved bits are expected to be used to extend the existing information rather than to enumerate new features.
Also allow CPUID.0x24.0.EBX[7:0] (AVX10 version), which the TDX module reports as directly configurable when AVX10 is supported, even though the CPUID virtualization table in the "Intel TDX ABI Definitions" currently lists it as not configurable. The table is expected to be corrected.
As a result, directly configurable bits that aren't in the allowlist, including bits introduced by future TDX modules, aren't advertised to userspace until KVM explicitly opts in.
Note, the change is user-visible, as some bits that were previously reported as configurable no longer are. The ABI itself is unchanged: KVM already filtered unsupported CPUID bits out of KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of configurable bits already varies with the TDX module and KVM versions.
The change isn't expected to break userspace or guests:
- Userspace that honors KVM_TDX_CAPABILITIES simply stops setting the dropped bits, and KVM_TDX_INIT_VM still succeeds.
- CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
---
v5:
- Change the shortlog to make the change more clear.
- Update the changelog to call out the user-visible change more loudly. (Rick)
- Describe CPUID.0x24.0.EBX[7:0] in the changelog rather than in a code comment, since the comment would become stale once the spec is updated.
- Update the changelog/comments for the CPUIDs that are expected not to be repurposed to hold feature bits according to their definitions.
- Drop the note in the TDX document as the ABI itself is unchanged.
v4:
- Rename functions. (Tony)
tdx_cfg_non_feature_mask() -> tdx_get_cpuid_cfg_non_feature_mask()
tdx_cfg_feature_mask() -> tdx_get_cpuid_cfg_feature_mask()
tdx_get_allowed_cfg_cpuid_mask() -> tdx_get_cpuid_cfg_mask()
- Update documentation. (Xiaoyao, Rick)
v3:
- Handle non-feature leafs at runtime. (Sean)
- Add CPUID.0x24.0.EBX[7:0] into allowlist. There is a mismatch of the description about CPUID.0x24.0.EBX[7:0], which is listed as "XFAM & CPUID_Enabled & Native" but should be "XFAM & CPUID_Enabled & Configured & Native".
--- arch/x86/kvm/vmx/tdx.c | 95 ++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 23 deletions(-)
arch/x86/kvm/vmx/tdx.c +74 -23
@@ -283,36 +283,81 @@ static bool has_tsx(const struct kvm_cpuid_entry2 *entry, u32 index) (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,u32 index) {return entry->function ==7 && 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, entry->index)) -clear_tsx (entry); - -if (has_waitpkg (entry, entry->index)) -clear_waitpkg (entry); -} -static bool tdx_unsupported_cpuid (const struct kvm_cpuid_entry2 *entry,u32 index) {return has_tsx (entry, index) ||has_waitpkg (entry, index); } +#define TDX_CPUID_ALL_ALLOWED_MASK GENMASK_U32(31, 0) + +static u32 tdx_get_cpuid_cfg_non_feature_mask (u32 function,u32 index,int reg) +{ +/* +* Allow all bits in registers that enumerate non-feature information. +* Note, CPUID.0x1.EAX, CPUID.{0x4, 0x18, 0x1f} and CPUID.0x80000008.EAX +* contain reserved bits. Though not architecturally guaranteed, the +* reserved bits are expected to be used to extend the existing +* information rather than to enumerate features, so allow them too. +*/ +switch (function) { +case 0x1 : +if (reg ==CPUID_EAX || reg ==CPUID_EBX ) +return TDX_CPUID_ALL_ALLOWED_MASK ; +return 0 ; +case 0x4 : +case 0x18 : +case 0x1f : +return TDX_CPUID_ALL_ALLOWED_MASK ; +case 0x24 : +if (index ==0 && reg ==CPUID_EBX ) +return GENMASK_U32 (7 ,0 ); +return 0 ; +case 0x80000008 : +if (reg ==CPUID_EAX ) +return TDX_CPUID_ALL_ALLOWED_MASK ; +return 0 ; +default : +return 0 ; + } +} + +static u32 tdx_get_cpuid_cfg_feature_mask (u32 function,u32 index,int reg) +{ +for (int i =0 ; i <NR_KVM_CPU_CAPS ; i++) { +const struct cpuid_reg *cpuid = &reverse_cpuid[i]; + +if (!cpuid->function) +continue ; + +if (cpuid->function == function && cpuid->index == index && + cpuid->reg == reg) +return tdx_cpu_cfg_caps[i]; + } + +return 0 ; +} + +static u32 tdx_get_cpuid_cfg_mask (u32 function,u32 index,int reg) +{ +u32 non_feature_mask =tdx_get_cpuid_cfg_non_feature_mask (function, index, reg); + +/* Skip reverse_cpuid[] walk if it's already all allowed. */ +if (non_feature_mask ==TDX_CPUID_ALL_ALLOWED_MASK ) +return TDX_CPUID_ALL_ALLOWED_MASK ; + +/* +* It's possible that a CPUID register contains both feature and +* non-feature bits. +*/ +return non_feature_mask |tdx_get_cpuid_cfg_feature_mask (function, index, reg); +} +#define KVM_TDX_CPUID_NO_SUBLEAF ((__u32)-1)static void td_init_cpuid_entry2 (struct kvm_cpuid_entry2 *entry,unsigned char idx)
@@ -336,8 +381,6 @@ static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char i*/ if (entry->function ==0x80000008 ) entry->eax =tdx_set_guest_phys_addr_bits (entry->eax,0xff ); - -tdx_clear_unsupported_cpuid (entry); }#define TDVMCALLINFO_SETUP_EVENT_NOTIFY_INTERRUPT BIT(1)
@@ -360,8 +403,16 @@ static int init_kvm_tdx_caps(const struct tdx_sys_info_td_conf *td_conf, caps->user_tdvmcallinfo_1_r11 =TDVMCALLINFO_SETUP_EVENT_NOTIFY_INTERRUPT ; -for (i =0 ; i < td_conf->num_cpuid_config; i++) -td_init_cpuid_entry2 (&caps->cpuid.entries[i], i); +for (i =0 ; i < td_conf->num_cpuid_config; i++) { +struct kvm_cpuid_entry2 *e = &caps->cpuid.entries[i]; + +td_init_cpuid_entry2 (e, i); +/* Only report the configurable bits allowed by KVM. */ + e->eax &=tdx_get_cpuid_cfg_mask (e->function, e->index,CPUID_EAX ); + e->ebx &=tdx_get_cpuid_cfg_mask (e->function, e->index,CPUID_EBX ); + e->ecx &=tdx_get_cpuid_cfg_mask (e->function, e->index,CPUID_ECX ); + e->edx &=tdx_get_cpuid_cfg_mask (e->function, e->index,CPUID_EDX ); + }return 0 ; }
Signature · 1 line
2.46.0
Edgecombe, Rick P
maintainerRe: [PATCH v5 4/5] KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
Quoted 5 lines · Binbin Wu
Note, the change is user-visible, as some bits that were previously reported as configurable no longer are. The ABI itself is unchanged: KVM already filtered unsupported CPUID bits out of
KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of configurable bits already varies with the TDX module and KVM versions.
I'm not sure what this is saying, the change is user visible but there is no ABI change? Can't be both... so I think there is an ABI change.
Quoted 9 lines
The change isn't expected to break userspace or guests:
- Userspace that honorsKVM_TDX_CAPABILITIESsimply stops setting the dropped bits, andKVM_TDX_INIT_VMstill succeeds.
-CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
Re: [PATCH v5 4/5] KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
Quoted 9 lines · Rick P
Quoted 5 lines · Binbin Wu
Note, the change is user-visible, as some bits that were previously reported as configurable no longer are. The ABI itself is unchanged: KVM already filtered unsupported CPUID bits out of
KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of configurable bits already varies with the TDX module and KVM versions.I'm not sure what this is saying, the change is user visible but there is no ABI change? Can't be both... so I think there is an ABI change.
My understanding is KVM_TDX_CAPABILITIES reports the capabilities supported by the TDX module *and* KVM, this is not changed before and after this patch series. ABI-wise, I think userspace doesn't care how KVM do the filter, denylist-based or allowlist-based. The ABI requires userspace to consult KVM_TDX_CAPABILITIES, and what KVM_TDX_CAPABILITIES report can be changed. That's why I described the ABI itself didn't change.
How about simply noting that this is a user-visible change and dropping the ABI part to avoid any ambiguity about the scope of the ABI?
Quoted 11 lines
Quoted 10 lines
The change isn't expected to break userspace or guests:
- Userspace that honorsKVM_TDX_CAPABILITIESsimply stops setting the dropped bits, andKVM_TDX_INIT_VMstill succeeds.
-CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
Edgecombe, Rick P
maintainerRe: [PATCH v5 4/5] KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
Quoted 11 lines · Binbin Wu
Quoted 9 lines · Rick P
Quoted 5 lines · Binbin Wu
Note, the change is user-visible, as some bits that were previously reported as configurable no longer are. The ABI itself is unchanged: KVM already filtered unsupported CPUID bits out of
KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of configurable bits already varies with the TDX module and KVM versions.I'm not sure what this is saying, the change is user visible but there is no ABI change? Can't be both... so I think there is an ABI change.
Quoted 6 lines
My understanding is
KVM_TDX_CAPABILITIESreports the capabilities supported by the TDX module *and* KVM, this is not changed before and after this patch series. ABI-wise, I think userspace doesn't care how KVM do the filter, denylist-based or allowlist-based. The ABI requires userspace to consultKVM_TDX_CAPABILITIES, and whatKVM_TDX_CAPABILITIESreport can be changed. That's why I described the ABI itself didn't change.
My model is that ABI is the user visible behavior of the kernel. So if you are running a kernel on a machine, and upgrade the kernel, then the behavior changes for your (potentially misguided) userspace. That is still an ABI change.
I think you are thinking about it like a spec - that if the new behavior conforms to the spec, it is not an ABI change. I think it's not right.
Quoted 3 lines
How about simply noting that this is a user-visible change and dropping the ABI part to avoid any ambiguity about the scope of the ABI?
Eh, if you want. I'm ok as long as we don't declare there is no ABI change. And then the patch ends up breaking userspace with a log saying no ABI change because of the docs. It could come off wrong.
We are making a potentially breaking change here that we think won't impact any users. It's a sensitive thing.
Re: [PATCH v5 4/5] KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
Quoted 30 lines · Rick P
Quoted 11 lines · Binbin Wu
Quoted 9 lines · Rick P
Quoted 5 lines · Binbin Wu
Note, the change is user-visible, as some bits that were previously reported as configurable no longer are. The ABI itself is unchanged: KVM already filtered unsupported CPUID bits out of
KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of configurable bits already varies with the TDX module and KVM versions.I'm not sure what this is saying, the change is user visible but there is no ABI change? Can't be both... so I think there is an ABI change.
Quoted 6 lines
My understanding is
KVM_TDX_CAPABILITIESreports the capabilities supported by the TDX module *and* KVM, this is not changed before and after this patch series. ABI-wise, I think userspace doesn't care how KVM do the filter, denylist-based or allowlist-based. The ABI requires userspace to consultKVM_TDX_CAPABILITIES, and whatKVM_TDX_CAPABILITIESreport can be changed. That's why I described the ABI itself didn't change.My model is that ABI is the user visible behavior of the kernel. So if you are running a kernel on a machine, and upgrade the kernel, then the behavior changes for your (potentially misguided) userspace. That is still an ABI change.
I think you are thinking about it like a spec - that if the new behavior conforms to the spec, it is not an ABI change. I think it's not right.
Quoted 3 lines
How about simply noting that this is a user-visible change and dropping the ABI part to avoid any ambiguity about the scope of the ABI?
Quoted 6 lines
Eh, if you want. I'm ok as long as we don't declare there is no ABI change. And then the patch ends up breaking userspace with a log saying no ABI change because of the docs. It could come off wrong.
We are making a potentially breaking change here that we think won't impact any users. It's a sensitive thing.
Rick sent me a link about the discussions on "what ABI is".
https://lore.kernel.org/lkml/[email protected]/
I will rephrase it in the next version as following:
Note, this is an ABI change, as some bits that were previously reported as configurable no longer are. However, the semantics of KVM_TDX_CAPABILITIES are unchanged: KVM already filtered unsupported bits out of KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of reported bits already varies with the TDX module and KVM versions, i.e. userspace can't assume a fixed set.
Xiaoyao Li
Reviewed-byRe: [PATCH v5 4/5] KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
Quoted 41 lines · Binbin Wu
Quoted 30 lines · Rick P
Quoted 11 lines · Binbin Wu
Quoted 9 lines · Rick P
Quoted 5 lines · Binbin Wu
Note, the change is user-visible, as some bits that were previously reported as configurable no longer are. The ABI itself is unchanged: KVM already filtered unsupported CPUID bits out of
KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of configurable bits already varies with the TDX module and KVM versions.I'm not sure what this is saying, the change is user visible but there is no ABI change? Can't be both... so I think there is an ABI change.
Quoted 6 lines
My understanding is
KVM_TDX_CAPABILITIESreports the capabilities supported by the TDX module *and* KVM, this is not changed before and after this patch series. ABI-wise, I think userspace doesn't care how KVM do the filter, denylist-based or allowlist-based. The ABI requires userspace to consultKVM_TDX_CAPABILITIES, and whatKVM_TDX_CAPABILITIESreport can be changed. That's why I described the ABI itself didn't change.My model is that ABI is the user visible behavior of the kernel. So if you are running a kernel on a machine, and upgrade the kernel, then the behavior changes for your (potentially misguided) userspace. That is still an ABI change.
I think you are thinking about it like a spec - that if the new behavior conforms to the spec, it is not an ABI change. I think it's not right.
Quoted 3 lines
How about simply noting that this is a user-visible change and dropping the ABI part to avoid any ambiguity about the scope of the ABI?
Quoted 6 lines
Eh, if you want. I'm ok as long as we don't declare there is no ABI change. And then the patch ends up breaking userspace with a log saying no ABI change because of the docs. It could come off wrong.
We are making a potentially breaking change here that we think won't impact any users. It's a sensitive thing.
Rick sent me a link about the discussions on "what ABI is".
https://lore.kernel.org/lkml/[email protected]/
Quoted 8 lines
I will rephrase it in the next version as following:
Note, this is an ABI change, as some bits that were previously reported as configurable no longer are. However, the semantics of
KVM_TDX_CAPABILITIESare unchanged: KVM already filtered unsupported bits out ofKVM_TDX_CAPABILITIES, albeit via a denylist, and the set of reported bits already varies with the TDX module and KVM versions, i.e. userspace can't assume a fixed set.
Re: [PATCH v5 4/5] KVM: TDX: Report only KVM-allowed CPUIDs in KVM_TDX_CAPABILITIES
In reply to Binbin WuQuoted 48 lines · Binbin Wu
Filter the directly configurable CPUID bits reported through
KVM_TDX_CAPABILITIESagainst KVM's TDX allowlist, and drop the hardcoded denylist-based filtering.The TDX module reports the CPUID bits that the VMM can directly configure for a TD, but KVM must not advertise bits that it doesn't support, as blindly exposing a feature that clobbers host state can corrupt the host. The existing denylist, which clears only TSX and WAITPKG, can't account for such features introduced by future TDX modules.
Add
tdx_get_cpuid_cfg_mask()to compute the mask of directly configurable bits that KVM allows for a given CPUID register, and apply it to every CPUID entry reported throughKVM_TDX_CAPABILITIES. The mask combines feature bits, taken from tdx_cpu_cfg_caps[], with non-feature bits, which are identified by function, index, and register.Treat CPUID.0x1.{EAX,EBX}, CPUID.{0x4,0x18,0x1F}, and CPUID.0x80000008.EAX as fully allowed, as these registers enumerate non-feature information, e.g. family/model/stepping, brand index, CLFLUSH line size, APIC ID, cache/TLB/topology properties, and address sizes. Allow the reserved bits in them as well. Though there's no architectural guarantee, given what these registers enumerate, the reserved bits are expected to be used to extend the existing information rather than to enumerate new features.
Also allow CPUID.0x24.0.EBX[7:0] (AVX10 version), which the TDX module reports as directly configurable when AVX10 is supported, even though the CPUID virtualization table in the "Intel TDX ABI Definitions" currently lists it as not configurable. The table is expected to be corrected.
As a result, directly configurable bits that aren't in the allowlist, including bits introduced by future TDX modules, aren't advertised to userspace until KVM explicitly opts in.
Note, the change is user-visible, as some bits that were previously reported as configurable no longer are. The ABI itself is unchanged: KVM already filtered unsupported CPUID bits out of
KVM_TDX_CAPABILITIES, albeit via a denylist, and the set of configurable bits already varies with the TDX module and KVM versions.The change isn't expected to break userspace or guests:
- Userspace that honorsKVM_TDX_CAPABILITIESsimply stops setting the dropped bits, andKVM_TDX_INIT_VMstill succeeds.
-CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
Quoted 1 line
Signed-off-by Binbin Wu <[email protected]>
PATCH v5 5/5 KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
In reply to Binbin WuValidate the CPUID configuration provided by userspace through KVM_TDX_INIT_VM against KVM's TDX allowlist, and drop the hardcoded denylist-based check.
The TDX module lets the VMM directly configure certain CPUID bits for a TD at initialization time, but KVM must strictly govern which of those bits userspace can set, otherwise a feature that clobbers host state could be enabled behind KVM's back. The existing denylist rejects only TSX and WAITPKG, and thus would accept any bit that a future TDX module makes configurable, even if KVM knows nothing about the associated feature.
Add tdx_has_unsupported_cpuid_cfg_bit() and reject KVM_TDX_INIT_VM if userspace sets any bit outside of the mask returned by tdx_get_cpuid_cfg_mask(), i.e. the same mask used to filter KVM_TDX_CAPABILITIES. Don't bother intersecting the userspace input with the bits that the TDX module reports as directly configurable, as the TDX module itself rejects any bit outside that set.
As with the existing check, use the subleaf reported by the TDX module to look up the allowed mask. For leaves without subleaves, the TDX module's "no subleaf" index is normalized to 0, which matches how such leaves are tracked in reverse_cpuid[].
Note, the change is user-visible, as KVM_TDX_INIT_VM now rejects some input that was previously accepted. The ABI itself is unchanged: KVM already rejected unsupported CPUID bits, albeit via a denylist, and userspace has always been required to consult KVM_TDX_CAPABILITIES and set only the bits reported as configurable.
The change isn't expected to break userspace or guests:
- The newly rejected bits are no longer reported as configurable by KVM_TDX_CAPABILITIES, so userspace that honors KVM_TDX_CAPABILITIES won't set them.
- CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
---
v5:
- Update the changelog and call out the user-visible change more loudly. (Rick)
- Drop the description in TDX document and the uapi header, as the ABI itself is unchanged.
- Split the CPUID entry index check out to a separate fix patch.
v4:
- Update the comments/documentation.
- Collect RB tag from Tony.
v3:
- Check CPUID entry index mismatch b/t userspace input and TDX sysinfo configuration. (Sashiko)
- No need to mask the userspace input with TDX module reported directly configurable bits first, since the userspace input should be subset of directly configurable bits. Otherwise, the input will be rejected by the TDX module.
--- arch/x86/kvm/vmx/tdx.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)
arch/x86/kvm/vmx/tdx.c +9 -20
@@ -275,25 +275,6 @@ static void __init tdx_initialize_cpu_cfg_caps(void)#undef TDX_CFG_F#undef TDX_CFG_INDEPENDENT_F -#define TDX_FEATURE_TSX (__feature_bit(X86_FEATURE_HLE) | __feature_bit(X86_FEATURE_RTM)) - -static bool has_tsx (const struct kvm_cpuid_entry2 *entry,u32 index) -{ -return entry->function ==7 && index ==0 && - (entry->ebx &TDX_FEATURE_TSX ); -} - -static bool has_waitpkg (const struct kvm_cpuid_entry2 *entry,u32 index) -{ -return entry->function ==7 && index ==0 && - (entry->ecx &__feature_bit (X86_FEATURE_WAITPKG )); -} - -static bool tdx_unsupported_cpuid (const struct kvm_cpuid_entry2 *entry,u32 index) -{ -return has_tsx (entry, index) ||has_waitpkg (entry, index); -} -#define TDX_CPUID_ALL_ALLOWED_MASK GENMASK_U32(31, 0)static u32 tdx_get_cpuid_cfg_non_feature_mask (u32 function,u32 index,int reg)
@@ -2565,6 +2546,14 @@ static int setup_tdparams_eptp_controls(struct kvm_cpuid2 *cpuid,return 0 ; } +static bool tdx_has_unsupported_cpuid_cfg_bit (const struct kvm_cpuid_entry2 *e,u32 index) +{ +return (e->eax & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EAX )) || + (e->ebx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EBX )) || + (e->ecx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_ECX )) || + (e->edx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EDX )); +} +static int setup_tdparams_cpuids (struct kvm_cpuid2 *cpuid,struct td_params *td_params) {
@@ -2594,7 +2583,7 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,* not the index of the userspace entry, which may differ if * KVM_CPUID_FLAG_SIGNIFCANT_INDEX isn't set. */ -if (tdx_unsupported_cpuid (entry, tmp.index)) +if (tdx_has_unsupported_cpuid_cfg_bit (entry, tmp.index))return -EINVAL ; copy_cnt++;
Signature · 1 line
2.46.0
[email protected]
AI reviewRe: [PATCH v5 5/5] KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] kvm: KVM_TDX_INIT_VM rejects CPUID.0x7.0.EAX breaking guest subleaf enumeration - [High] mm: heap…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] kvm: KVM_TDX_INIT_VM rejects CPUID.0x7.0.EAX breaking guest subleaf enumeration
- [High] mm: heap buffer overflow in setup_tdparams_cpuids() via unbounded td_conf->num_cpuid_config --
commit 8ec54e6006917e96837000de9e4002c7f4499444
Author: Binbin Wu <[email protected]>
KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
This commit validates the CPUID configuration provided by userspace through KVM_TDX_INIT_VM against KVM's TDX allowlist. It drops the hardcoded denylist-based check in favor of a strict allowlist.
Quoted 4 lines
arch/x86/kvm/vmx/tdx.c +0
-0
[ ... ]
arch/x86/kvm/vmx/tdx.c static int setup_tdparams_eptp_controls(struct kvm_cpuid2 *cpuid, · line 2557
Quoted 11 lines
arch/x86/kvm/vmx/tdx.c +7
-0@@ -2567,6 +2548,14 @@ static int setup_tdparams_eptp_controls(struct kvm_cpuid2 *cpuid,return 0 ; } +static bool tdx_has_unsupported_cpuid_cfg_bit (const struct kvm_cpuid_entry2 *e,u32 index) +{ +return (e->eax & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EAX )) || + (e->ebx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EBX )) || + (e->ecx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_ECX )) || + (e->edx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EDX )); +}
[Severity: High]
Does this strict allowlist check inadvertently break guest subleaf enumeration by rejecting valid KVM_TDX_INIT_VM inputs?
CPUID leaf 0x7 subleaf 0 EAX contains the maximum supported subleaf index, which is non-feature information. However, tdx_get_cpuid_cfg_non_feature_mask() completely omits leaf 0x7, and reverse_cpuid does not track 0x7.0.EAX as a feature word.
Because tdx_get_cpuid_cfg_mask(0x7, 0, CPUID_EAX) returns 0, this new check will reject any non-zero value for CPUID.0x7.0.EAX. This strictly requires userspace to provide 0, effectively preventing exposure of subleaves 1+ (such as for AMX or AVX-VNNI) and breaking valid VM initialization requests.
Quoted 3 lines
arch/x86/kvm/vmx/tdx.c +0
-0static int setup_tdparams_cpuids (struct kvm_cpuid2 *cpuid,struct td_params *td_params) {
[ ... ]
arch/x86/kvm/vmx/tdx.c static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid, · line 2591
Quoted 9 lines
arch/x86/kvm/vmx/tdx.c +1
-1@@ -2596,7 +2585,7 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,* not the index of the userspace entry, which may differ if * KVM_CPUID_FLAG_SIGNIFCANT_INDEX isn't set. */ -if (tdx_unsupported_cpuid (entry, tmp.index)) +if (tdx_has_unsupported_cpuid_cfg_bit (entry, tmp.index))return -EINVAL ; copy_cnt++;
[Severity: High]
Can the loop enclosing this code write past the end of the td_params heap allocation?
td_conf->num_cpuid_config is read from the TDX module and bounded to 128 by KVM in get_tdx_sys_info_td_conf():
if (sysinfo_td_conf->num_cpuid_config > ARRAY_SIZE(sysinfo_td_conf->cpuid_config_leaves)) return -EINVAL;
However, td_params->cpuid_values is an array inside a union with u8 reserved3[768], which limits it to 48 tdx_cpuid_value structures:
arch/x86/kvm/vmx/tdx_arch.h:struct td_params {
...
union {
DECLARE_FLEX_ARRAY(struct tdx_cpuid_value, cpuid_values);
u8 reserved3[768];
};
} __packed __aligned(1024);td_params itself is dynamically allocated as a fixed 1024-byte object via kzalloc_obj(struct td_params) in setup_tdparams().
If the hardware returns a num_cpuid_config value greater than 48, the loop in setup_tdparams_cpuids() will exceed the 48-element capacity when assigning value = &td_params->cpuid_values[i] just below this snippet, causing a heap buffer overflow.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v5 5/5] KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
Quoted 40 lines · On 10/16/2026 5:24 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] kvm:KVM_TDX_INIT_VMrejects CPUID.0x7.0.EAX breaking guest subleaf enumeration
- [High] mm: heap buffer overflow insetup_tdparams_cpuids()via unboundedtd_conf->num_cpuid_config--commit
8ec54e6006917e96837000de9e4002c7f4499444
Author: Binbin Wu <[email protected]>KVM: TDX: Validate userspace CPUID input for
KVM_TDX_INIT_VMThis commit validates the CPUID configuration provided by userspace through
KVM_TDX_INIT_VMagainst KVM's TDX allowlist. It drops the hardcoded denylist-based check in favor of a strict allowlist.Quoted 4 lines
arch/x86/kvm/vmx/tdx.c +0
-0[ ... ]
arch/x86/kvm/vmx/tdx.c static int setup_tdparams_eptp_controls(struct kvm_cpuid2 *cpuid, · line 2557
Quoted 11 lines
arch/x86/kvm/vmx/tdx.c +7
-0@@ -2567,6 +2548,14 @@ static int setup_tdparams_eptp_controls(struct kvm_cpuid2 *cpuid,return 0 ; } +static bool tdx_has_unsupported_cpuid_cfg_bit (const struct kvm_cpuid_entry2 *e,u32 index) +{ +return (e->eax & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EAX )) || + (e->ebx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EBX )) || + (e->ecx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_ECX )) || + (e->edx & ~tdx_get_cpuid_cfg_mask (e->function, index,CPUID_EDX )); +}[Severity: High]
Does this strict allowlist check inadvertently break guest subleaf enumeration by rejecting validKVM_TDX_INIT_VMinputs?CPUID leaf
0x7subleaf 0 EAX contains the maximum supported subleaf index, which is non-feature information. However,tdx_get_cpuid_cfg_non_feature_mask()completely omits leaf0x7, andreverse_cpuiddoes not track 0x7.0.EAX as a feature word.
Quoted 4 lines
Because
tdx_get_cpuid_cfg_mask(0x7, 0, CPUID_EAX)returns 0, this new check will reject any non-zero value for CPUID.0x7.0.EAX. This strictly requires userspace to provide 0, effectively preventing exposure of subleaves 1+ (such as for AMX or AVX-VNNI) and breaking valid VM initialization requests.
This is false positive.
CPUID.0.EAX is not directly configurable in TDX. Userspace is not allowed to provide non-zero value for it.
Quoted 36 lines
Quoted 4 lines
arch/x86/kvm/vmx/tdx.c +0
-0static int setup_tdparams_cpuids (struct kvm_cpuid2 *cpuid,struct td_params *td_params) {[ ... ]
arch/x86/kvm/vmx/tdx.c static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid, · line 2591
Quoted 9 lines
arch/x86/kvm/vmx/tdx.c +1
-1@@ -2596,7 +2585,7 @@ static int setup_tdparams_cpuids(struct kvm_cpuid2 *cpuid,* not the index of the userspace entry, which may differ if * KVM_CPUID_FLAG_SIGNIFCANT_INDEX isn't set. */ -if (tdx_unsupported_cpuid (entry, tmp.index)) +if (tdx_has_unsupported_cpuid_cfg_bit (entry, tmp.index))return -EINVAL ; copy_cnt++;[Severity: High]
Can the loop enclosing this code write past the end of thetd_paramsheap allocation?
td_conf->num_cpuid_configis read from the TDX module and bounded to 128 by KVM inget_tdx_sys_info_td_conf():if (sysinfo_td_conf->num_cpuid_config > ARRAY_SIZE(sysinfo_td_conf->cpuid_config_leaves)) return -EINVAL;However,
td_params->cpuid_valuesis an array inside a union with u8 reserved3[768], which limits it to 48tdx_cpuid_valuestructures:arch/x86/kvm/vmx/tdx_arch.h:struct td_params { ... union { DECLARE_FLEX_ARRAY(struct tdx_cpuid_value, cpuid_values); u8 reserved3[768]; }; } __packed __aligned(1024);
Quoted 8 lines
td_paramsitself is dynamically allocated as a fixed 1024-byte object viakzalloc_obj(struct td_params)insetup_tdparams().If the hardware returns a
num_cpuid_configvalue greater than 48, the loop insetup_tdparams_cpuids()will exceed the 48-element capacity when assigning value = &td_params->cpuid_values[i] just below this snippet, causing a heap buffer overflow.
Here is the to reply to the same issue reported in an earlier version:
https://lore.kernel.org/kvm/[email protected]/
Re: [PATCH v5 5/5] KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
In reply to Binbin WuQuoted 39 lines · Binbin Wu
Validate the CPUID configuration provided by userspace through
KVM_TDX_INIT_VMagainst KVM's TDX allowlist, and drop the hardcoded denylist-based check.The TDX module lets the VMM directly configure certain CPUID bits for a TD at initialization time, but KVM must strictly govern which of those bits userspace can set, otherwise a feature that clobbers host state could be enabled behind KVM's back. The existing denylist rejects only TSX and WAITPKG, and thus would accept any bit that a future TDX module makes configurable, even if KVM knows nothing about the associated feature.
Add
tdx_has_unsupported_cpuid_cfg_bit()and rejectKVM_TDX_INIT_VMif userspace sets any bit outside of the mask returned bytdx_get_cpuid_cfg_mask(), i.e. the same mask used to filterKVM_TDX_CAPABILITIES. Don't bother intersecting the userspace input with the bits that the TDX module reports as directly configurable, as the TDX module itself rejects any bit outside that set.As with the existing check, use the subleaf reported by the TDX module to look up the allowed mask. For leaves without subleaves, the TDX module's "no subleaf" index is normalized to 0, which matches how such leaves are tracked in reverse_cpuid[].
Note, the change is user-visible, as
KVM_TDX_INIT_VMnow rejects some input that was previously accepted. The ABI itself is unchanged: KVM already rejected unsupported CPUID bits, albeit via a denylist, and userspace has always been required to consultKVM_TDX_CAPABILITIESand set only the bits reported as configurable.The change isn't expected to break userspace or guests:
- The newly rejected bits are no longer reported as configurable byKVM_TDX_CAPABILITIES, so userspace that honorsKVM_TDX_CAPABILITIESwon't set them.
-CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
Quoted 2 lines
Signed-off-by Binbin Wu <[email protected]>Reviewed-by Tony Lindgren <[email protected]>
Re: [PATCH v5 5/5] KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
In reply to Binbin WuQuoted 39 lines · Binbin Wu
Validate the CPUID configuration provided by userspace through
KVM_TDX_INIT_VMagainst KVM's TDX allowlist, and drop the hardcoded denylist-based check.The TDX module lets the VMM directly configure certain CPUID bits for a TD at initialization time, but KVM must strictly govern which of those bits userspace can set, otherwise a feature that clobbers host state could be enabled behind KVM's back. The existing denylist rejects only TSX and WAITPKG, and thus would accept any bit that a future TDX module makes configurable, even if KVM knows nothing about the associated feature.
Add
tdx_has_unsupported_cpuid_cfg_bit()and rejectKVM_TDX_INIT_VMif userspace sets any bit outside of the mask returned bytdx_get_cpuid_cfg_mask(), i.e. the same mask used to filterKVM_TDX_CAPABILITIES. Don't bother intersecting the userspace input with the bits that the TDX module reports as directly configurable, as the TDX module itself rejects any bit outside that set.As with the existing check, use the subleaf reported by the TDX module to look up the allowed mask. For leaves without subleaves, the TDX module's "no subleaf" index is normalized to 0, which matches how such leaves are tracked in reverse_cpuid[].
Note, the change is user-visible, as
KVM_TDX_INIT_VMnow rejects some input that was previously accepted. The ABI itself is unchanged: KVM already rejected unsupported CPUID bits, albeit via a denylist, and userspace has always been required to consultKVM_TDX_CAPABILITIESand set only the bits reported as configurable.The change isn't expected to break userspace or guests:
- The newly rejected bits are no longer reported as configurable byKVM_TDX_CAPABILITIES, so userspace that honorsKVM_TDX_CAPABILITIESwon't set them.
-CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
Quoted 2 lines
Signed-off-by Binbin Wu <[email protected]>Reviewed-by Tony Lindgren <[email protected]>
The patch generally looks good to me. However, since it depends on Patch 1, which, I assume, is going to be replaced by Sean's series[1]. If that's case, the patch will need a rebase and adjust on top.
Free feel to add
if there is no big design change in the end.
Re: [PATCH v5 5/5] KVM: TDX: Validate userspace CPUID input for KVM_TDX_INIT_VM
Quoted 40 lines · Xiaoyao Li
Quoted 39 lines · Binbin Wu
Validate the CPUID configuration provided by userspace through
KVM_TDX_INIT_VMagainst KVM's TDX allowlist, and drop the hardcoded denylist-based check.The TDX module lets the VMM directly configure certain CPUID bits for a TD at initialization time, but KVM must strictly govern which of those bits userspace can set, otherwise a feature that clobbers host state could be enabled behind KVM's back. The existing denylist rejects only TSX and WAITPKG, and thus would accept any bit that a future TDX module makes configurable, even if KVM knows nothing about the associated feature.
Add
tdx_has_unsupported_cpuid_cfg_bit()and rejectKVM_TDX_INIT_VMif userspace sets any bit outside of the mask returned bytdx_get_cpuid_cfg_mask(), i.e. the same mask used to filterKVM_TDX_CAPABILITIES. Don't bother intersecting the userspace input with the bits that the TDX module reports as directly configurable, as the TDX module itself rejects any bit outside that set.As with the existing check, use the subleaf reported by the TDX module to look up the allowed mask. For leaves without subleaves, the TDX module's "no subleaf" index is normalized to 0, which matches how such leaves are tracked in reverse_cpuid[].
Note, the change is user-visible, as
KVM_TDX_INIT_VMnow rejects some input that was previously accepted. The ABI itself is unchanged: KVM already rejected unsupported CPUID bits, albeit via a denylist, and userspace has always been required to consultKVM_TDX_CAPABILITIESand set only the bits reported as configurable.The change isn't expected to break userspace or guests:
- The newly rejected bits are no longer reported as configurable byKVM_TDX_CAPABILITIES, so userspace that honorsKVM_TDX_CAPABILITIESwon't set them.
-CORE_CAPABILITIES, which older TDX module specs defined as fixed-1, is still allowed.
- The dropped features are either obsolete or unsupported by KVM, and in the latter case, a guest relying on them would already have run into problems.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Binbin Wu <[email protected]>Reviewed-by Tony Lindgren <[email protected]>The patch generally looks good to me. However, since it depends on Patch 1, which, I assume, is going to be replaced by Sean's series[1]. If that's case, the patch will need a rebase and adjust on top.
Yes, it will be rebased.
Quoted 4 lines
Free feel to add
Reviewed-by Xiaoyao Li <[email protected]>
Thanks!
Quoted 4 lines
if there is no big design change in the end.
Quoted 5 lines · Binbin Wu
For this version, I'm hoping to continue to collect some RBs and Acks. The key discussions from v3/v4 [1] are summarized below. Note, FRED KVM support is in progress upstream [2], and no TDX module with FRED support exists yet, so there is no immediate issue. But it would be nice to get this series merged sooner rather than later.
Besides the log nit in patches 4 (and same for 5), this looks great to me. With that fixes, for the series:
It will be great to get this finally fixed. After all his review earlier it would be good to get Xiaoyao's RB too. And then let's see if we can get Sean to apply this.
Quoted 110 lines · Binbin Wu
The TDX module reports a set of CPUID bits that the VMM can directly configure for a TD, but KVM cannot blindly expose all module-supported bits to userspace. Certain features imply additional architectural state (such as one or more MSRs) that KVM must explicitly manage across host/guest transitions to prevent host state corruption.
Today, KVM hardcodes a denylist to filter out host state clobbering features that KVM doesn't support. However, a denylist doesn't scale as the TDX module evolves, i.e. host state clobbering features added by a future TDX module are not covered by the denylist, and userspace could enable a feature that KVM doesn't support.
This series builds an allowlist for directly configurable CPUID bits, and filters and validates userspace input against it, so that newly introduced TDX directly configurable CPUID feature bits can only be enabled by userspace after KVM explicitly opts in. Except for a few fixed-1 bits required for basic TDX support, host state clobbering features are either directly configurable or gated by TD ATTRIBUTES/XFAM. KVM already validates ATTRIBUTES/XFAM, so the allowlist only needs to cover directly configurable bits.
Patch 1 is a standalone fix for the existing denylist check, which uses the index of the matched userspace entry instead of the subleaf reported by the TDX module, i.e. userspace can bypass the HLE/RTM/WAITPKG check. It is tagged for stable so that it can be backported independently of the rest of the series.
Patches 2-5 build the allowlist, add
CORE_CAPABILITIESto it, filterKVM_TDX_CAPABILITIES, and validate the CPUID input ofKVM_TDX_INIT_VM. The last two patches are user-visible changes, which are now called out in their changelogs, along with why existing userspace and guests are not expected to be affected.For this version, I'm hoping to continue to collect some RBs and Acks. The key discussions from v3/v4 [1] are summarized below. Note, FRED KVM support is in progress upstream [2], and no TDX module with FRED support exists yet, so there is no immediate issue. But it would be nice to get this series merged sooner rather than later.
Discussions from v3/v4:
- Rick asked whether the assumption that the reserved bits in CPUID.0x1.EAX, CPUID.{0x4,0x18,0x1F} and CPUID.0x80000008.EAX won't be used to enumerate features can be confirmed by the x86 architects [3]. Confirmation is still pending. Per the SDM/APM, these leaves/registers are defined for specific information (version, cache/TLB parameters, topology, and address sizes), so the reserved bits are expected to be used to extend the existing information rather than to enumerate features. Allowing these registers in full is a best guess, but it's still far better than the existing denylist-based check.- Whether to restrict the TDX feature bits to kvm_cpu_caps[]. The conclusion from the discussions is to construct the allowlist based on kvm_cpu_caps[], plus a few bits that KVM can support for TDs independently of kvm_cpu_caps[]. If TDX feature enabling turns out to be consistently blocked by non-TDX VM enabling, a solution can be worked out then.
- New opt-in interface vs. backporting.
There are two options for old KVM versions that don't do the filtering and validation:
1) Add a new opt-in interface to expose features newly introduced by the TDX module.
2) Backport this series to LTS/stable branches.The opt-in design vs. backport decision is deferred, since this series is correct and an improvement either way.
- Potential backward compatibility issue when an effective fixed-1 bit becomes directly configurable due to x86 feature deprecation. This is left for the future, i.e. it can be addressed if and when such a deprecation actually happens, e.g. by adding an opt-in interface to let users/admins choose between migration flexibility and backwards compatibility on old platforms.
Changes since v4 [1]:
- Split the CPUID entry index check out into a standalone fix, which allows it to be backported to stable independently of the rest of the series.
- Exclude XTPR from the allowlist, as neither TDX nor KVM actually virtualizes the feature and guests don't need it. (Xiaoyao, Rick)
- RenameTDX_CFG_EXTRA_F()toTDX_CFG_INDEPENDENT_F(). (Xiaoyao)
- FixAMX_COMPLEXto be added forCPUID_7_1_EDXinstead ofCPUID_1E_1_EAX.
- Drop the descriptions in the TDX documentation and the uapi header, as the ioctl interfaces forKVM_TDX_CAPABILITIESandKVM_TDX_INIT_VMare unchanged by this patch series.
- Improve changelogs and comments. (Xiaoyao, Rick)The series follows the CSV version of the CPUID virtualization document from "Intel TDX Module ABI Definitions" [4], updated in June 2026.
AI tools were used to:
- Polish the cover letter and commit messages.
- Do code review.[1] v4: https://lore.kernel.org/all/[email protected]
v3: https://lore.kernel.org/all/[email protected] v2: https://lore.kernel.org/all/[email protected] v1: https://lore.kernel.org/all/[email protected][2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://cdrdv2.intel.com/v1/dl/getContent/795381Binbin Wu (5):
KVM: TDX: Check unsupported CPUID bits against the TDX module's
subleaf
KVM: TDX: Track configurable CPUID bits allowed by KVM
KVM: TDX: AddCORE_CAPABILITIESto the allowlist
KVM: TDX: Report only KVM-allowed CPUIDs inKVM_TDX_CAPABILITIES
KVM: TDX: Validate userspace CPUID input forKVM_TDX_INIT_VM
Quoted 5 lines
arch/x86/kvm/vmx/tdx.c | 258 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 231 insertions(+), 27 deletions(-)base-commit:
dea4f6380f4ec96e8f3b0aaf2343764bd0d25ef4
For the series:
Quoted 117 lines · Nikolay Borisov
Quoted 114 lines · Binbin Wu
The TDX module reports a set of CPUID bits that the VMM can directly configure for a TD, but KVM cannot blindly expose all module-supported bits to userspace. Certain features imply additional architectural state (such as one or more MSRs) that KVM must explicitly manage across host/guest transitions to prevent host state corruption.
Today, KVM hardcodes a denylist to filter out host state clobbering features that KVM doesn't support. However, a denylist doesn't scale as the TDX module evolves, i.e. host state clobbering features added by a future TDX module are not covered by the denylist, and userspace could enable a feature that KVM doesn't support.
This series builds an allowlist for directly configurable CPUID bits, and filters and validates userspace input against it, so that newly introduced TDX directly configurable CPUID feature bits can only be enabled by userspace after KVM explicitly opts in. Except for a few fixed-1 bits required for basic TDX support, host state clobbering features are either directly configurable or gated by TD ATTRIBUTES/XFAM. KVM already validates ATTRIBUTES/XFAM, so the allowlist only needs to cover directly configurable bits.
Patch 1 is a standalone fix for the existing denylist check, which uses the index of the matched userspace entry instead of the subleaf reported by the TDX module, i.e. userspace can bypass the HLE/RTM/WAITPKG check. It is tagged for stable so that it can be backported independently of the rest of the series.
Patches 2-5 build the allowlist, add
CORE_CAPABILITIESto it, filterKVM_TDX_CAPABILITIES, and validate the CPUID input ofKVM_TDX_INIT_VM. The last two patches are user-visible changes, which are now called out in their changelogs, along with why existing userspace and guests are not expected to be affected.For this version, I'm hoping to continue to collect some RBs and Acks. The key discussions from v3/v4 [1] are summarized below. Note, FRED KVM support is in progress upstream [2], and no TDX module with FRED support exists yet, so there is no immediate issue. But it would be nice to get this series merged sooner rather than later.
Discussions from v3/v4:
- Rick asked whether the assumption that the reserved bits in CPUID.0x1.EAX, CPUID.{0x4,0x18,0x1F} and CPUID.0x80000008.EAX won't be used to enumerate features can be confirmed by the x86 architects [3]. Confirmation is still pending. Per the SDM/APM, these leaves/registers are defined for specific information (version, cache/TLB parameters, topology, and address sizes), so the reserved bits are expected to be used to extend the existing information rather than to enumerate features. Allowing these registers in full is a best guess, but it's still far better than the existing denylist-based check.- Whether to restrict the TDX feature bits to kvm_cpu_caps[]. The conclusion from the discussions is to construct the allowlist based on kvm_cpu_caps[], plus a few bits that KVM can support for TDs independently of kvm_cpu_caps[]. If TDX feature enabling turns out to be consistently blocked by non-TDX VM enabling, a solution can be worked out then.
- New opt-in interface vs. backporting.
There are two options for old KVM versions that don't do the filtering and validation:
1) Add a new opt-in interface to expose features newly introduced by the TDX module.
2) Backport this series to LTS/stable branches.The opt-in design vs. backport decision is deferred, since this series is correct and an improvement either way.
- Potential backward compatibility issue when an effective fixed-1 bit becomes directly configurable due to x86 feature deprecation. This is left for the future, i.e. it can be addressed if and when such a deprecation actually happens, e.g. by adding an opt-in interface to let users/admins choose between migration flexibility and backwards compatibility on old platforms.
Changes since v4 [1]:
- Split the CPUID entry index check out into a standalone fix, which allows it to be backported to stable independently of the rest of the series.
- Exclude XTPR from the allowlist, as neither TDX nor KVM actually virtualizes the feature and guests don't need it. (Xiaoyao, Rick)
- RenameTDX_CFG_EXTRA_F()toTDX_CFG_INDEPENDENT_F(). (Xiaoyao)
- FixAMX_COMPLEXto be added forCPUID_7_1_EDXinstead ofCPUID_1E_1_EAX.
- Drop the descriptions in the TDX documentation and the uapi header, as the ioctl interfaces forKVM_TDX_CAPABILITIESandKVM_TDX_INIT_VMare unchanged by this patch series.
- Improve changelogs and comments. (Xiaoyao, Rick)The series follows the CSV version of the CPUID virtualization document from "Intel TDX Module ABI Definitions" [4], updated in June 2026.
AI tools were used to:
- Polish the cover letter and commit messages.
- Do code review.[1] v4: https://lore.kernel.org/all/[email protected]
v3: https://lore.kernel.org/all/[email protected]
v2: https://lore.kernel.org/all/[email protected]
v1: https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://cdrdv2.intel.com/v1/dl/getContent/795381Binbin Wu (5):
KVM: TDX: Check unsupported CPUID bits against the TDX module's subleaf
KVM: TDX: Track configurable CPUID bits allowed by KVM
KVM: TDX: AddCORE_CAPABILITIESto the allowlist
KVM: TDX: Report only KVM-allowed CPUIDs inKVM_TDX_CAPABILITIES
KVM: TDX: Validate userspace CPUID input forKVM_TDX_INIT_VM
arch/x86/kvm/vmx/tdx.c| 258 ++++++++++++++++++++++++++++++++++++-----1 file changed, 231 insertions(+), 27 deletions(-)
Quoted 6 lines
Quoted 1 line
base-commit:
dea4f6380f4ec96e8f3b0aaf2343764bd0d25ef4For the series:
Reviewed-by Nikolay Borisov <[email protected]>
Hi Nikolay,
Thanks for your reviews!
I noticed you later gave separate RBs for patches 2 and 3. Is that because patches 4-5 conflict with Sean's series [1] during rebase?
For now, I'll carry your RB only on patches 2 and 3 in the next version.
Quoted 123 lines · Binbin Wu
Quoted 122 lines · Nikolay Borisov
Quoted 110 lines · Binbin Wu
The TDX module reports a set of CPUID bits that the VMM can directly configure for a TD, but KVM cannot blindly expose all module-supported bits to userspace. Certain features imply additional architectural state (such as one or more MSRs) that KVM must explicitly manage across host/guest transitions to prevent host state corruption.
Today, KVM hardcodes a denylist to filter out host state clobbering features that KVM doesn't support. However, a denylist doesn't scale as the TDX module evolves, i.e. host state clobbering features added by a future TDX module are not covered by the denylist, and userspace could enable a feature that KVM doesn't support.
This series builds an allowlist for directly configurable CPUID bits, and filters and validates userspace input against it, so that newly introduced TDX directly configurable CPUID feature bits can only be enabled by userspace after KVM explicitly opts in. Except for a few fixed-1 bits required for basic TDX support, host state clobbering features are either directly configurable or gated by TD ATTRIBUTES/XFAM. KVM already validates ATTRIBUTES/XFAM, so the allowlist only needs to cover directly configurable bits.
Patch 1 is a standalone fix for the existing denylist check, which uses the index of the matched userspace entry instead of the subleaf reported by the TDX module, i.e. userspace can bypass the HLE/RTM/WAITPKG check. It is tagged for stable so that it can be backported independently of the rest of the series.
Patches 2-5 build the allowlist, add
CORE_CAPABILITIESto it, filterKVM_TDX_CAPABILITIES, and validate the CPUID input ofKVM_TDX_INIT_VM. The last two patches are user-visible changes, which are now called out in their changelogs, along with why existing userspace and guests are not expected to be affected.For this version, I'm hoping to continue to collect some RBs and Acks. The key discussions from v3/v4 [1] are summarized below. Note, FRED KVM support is in progress upstream [2], and no TDX module with FRED support exists yet, so there is no immediate issue. But it would be nice to get this series merged sooner rather than later.
Discussions from v3/v4:
- Rick asked whether the assumption that the reserved bits in CPUID.0x1.EAX, CPUID.{0x4,0x18,0x1F} and CPUID.0x80000008.EAX won't be used to enumerate features can be confirmed by the x86 architects [3]. Confirmation is still pending. Per the SDM/APM, these leaves/registers are defined for specific information (version, cache/TLB parameters, topology, and address sizes), so the reserved bits are expected to be used to extend the existing information rather than to enumerate features. Allowing these registers in full is a best guess, but it's still far better than the existing denylist-based check.- Whether to restrict the TDX feature bits to kvm_cpu_caps[]. The conclusion from the discussions is to construct the allowlist based on kvm_cpu_caps[], plus a few bits that KVM can support for TDs independently of kvm_cpu_caps[]. If TDX feature enabling turns out to be consistently blocked by non-TDX VM enabling, a solution can be worked out then.
- New opt-in interface vs. backporting.
There are two options for old KVM versions that don't do the filtering and validation:
1) Add a new opt-in interface to expose features newly introduced by the TDX module.
2) Backport this series to LTS/stable branches.The opt-in design vs. backport decision is deferred, since this series is correct and an improvement either way.
- Potential backward compatibility issue when an effective fixed-1 bit becomes directly configurable due to x86 feature deprecation. This is left for the future, i.e. it can be addressed if and when such a deprecation actually happens, e.g. by adding an opt-in interface to let users/admins choose between migration flexibility and backwards compatibility on old platforms.
Changes since v4 [1]:
- Split the CPUID entry index check out into a standalone fix, which allows it to be backported to stable independently of the rest of the series.
- Exclude XTPR from the allowlist, as neither TDX nor KVM actually virtualizes the feature and guests don't need it. (Xiaoyao, Rick)
- RenameTDX_CFG_EXTRA_F()toTDX_CFG_INDEPENDENT_F(). (Xiaoyao)
- FixAMX_COMPLEXto be added forCPUID_7_1_EDXinstead ofCPUID_1E_1_EAX.
- Drop the descriptions in the TDX documentation and the uapi header, as the ioctl interfaces forKVM_TDX_CAPABILITIESandKVM_TDX_INIT_VMare unchanged by this patch series.
- Improve changelogs and comments. (Xiaoyao, Rick)The series follows the CSV version of the CPUID virtualization document from "Intel TDX Module ABI Definitions" [4], updated in June 2026.
AI tools were used to:
- Polish the cover letter and commit messages.
- Do code review.[1] v4: https://lore.kernel.org/all/[email protected]
v3: https://lore.kernel.org/all/[email protected]
v2: https://lore.kernel.org/all/[email protected]
v1: https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://cdrdv2.intel.com/v1/dl/getContent/795381Binbin Wu (5):
KVM: TDX: Check unsupported CPUID bits against the TDX module's subleaf
KVM: TDX: Track configurable CPUID bits allowed by KVM
KVM: TDX: AddCORE_CAPABILITIESto the allowlist
KVM: TDX: Report only KVM-allowed CPUIDs inKVM_TDX_CAPABILITIES
KVM: TDX: Validate userspace CPUID input forKVM_TDX_INIT_VMQuoted 5 lines
arch/x86/kvm/vmx/tdx.c | 258 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 231 insertions(+), 27 deletions(-)base-commit:
dea4f6380f4ec96e8f3b0aaf2343764bd0d25ef4For the series:
Quoted 8 lines
Quoted 1 line
Reviewed-by Nikolay Borisov <[email protected]>Hi Nikolay,
Thanks for your reviews!
I noticed you later gave separate RBs for patches 2 and 3. Is that because patches 4-5 conflict with Sean's series [1] during rebase?
Yep, overall the whole series LGTM in isolation but given that it intersects with Sean's series I decided to give explicit RB to the patches that won't change.
Quoted 5 lines
For now, I'll carry your RB only on patches 2 and 3 in the next version.