Enable DICE-based TDX quoting
Subsystems (5)
PATCH v3 1/8 x86/virt/tdx: Add interface to generate a Quote
In reply to Peter FangDuring TDX attestation, the TDX guest asks the host for a signed, verifiable report (a "Quote"). With the quoting extension, the TDX module generates the Quote and returns it in host pages.
Provide an interface for it. The SEAMCALL (TDH.QUOTE.GET) takes the host pages in a custom linked list format. Each node is a page-sized array holding the physical addresses of these pages. The last entry in a node is the 'next' pointer. See [1] for details.
Each Quote request needs its own session in the TDX module. Only a limited number of sessions are available. Let KVM manage the sessions by assigning a session ID and a Quote buffer to each request. This avoids resource sharing between these requests.
[1] Intel TDX Module ABI specification, Section "Physical Memory Management Types"
---
v3:
- Redesign the interface. Drop the global Quote buffer and its mutex, and let KVM pass in the Quote buffer pages. [Sean, Dave, Rick, Tony]
- Use kmalloc() for the linked list nodes, plus cleanups. [Nikolay]
- Take a session ID so KVM can generate Quotes concurrently.
- Drop DEFAULT_QUOTE_ID and use [63:32] = 0 for the default quote type.
--- arch/x86/include/asm/tdx.h | 4 ++ arch/x86/virt/vmx/tdx/tdx.c | 96 +++++++++++++++++++++++++++++++++++++ arch/x86/virt/vmx/tdx/tdx.h | 1 + 3 files changed, 101 insertions(+)
arch/x86/include/asm/tdx.h +4 -0
@@ -202,6 +202,10 @@ u64 tdh_mem_page_remove(struct tdx_td *td, u64 gpa, enum pg_level level, u64 *exu64 tdh_phymem_cache_wb (bool resume);u64 tdh_phymem_page_wbinvd_tdr (struct tdx_td *td);u64 tdh_phymem_page_wbinvd_hkid (u64 hkid,kvm_pfn_t pfn); +int tdx_quote_generate (struct tdx_td *td,u16 session_id, +struct page *report_page,u64 report_size, +struct page **quote_pages,u64 quote_buf_size, +u64 *quote_size,u64 *seamcall_err);#else static inline void tdx_init (void ) { }static inline u32 tdx_get_nr_guest_keyids (void ) {return 0 ; }
arch/x86/virt/vmx/tdx/tdx.c +96 -0
102 lines not on this page · raw message
arch/x86/virt/vmx/tdx/tdx.h +1 -0
@@ -53,6 +53,7 @@#define TDH_EXT_INIT 60#define TDH_EXT_MEM_ADD 61#define TDH_SYS_DISABLE 69 +#define TDH_QUOTE_GET 98/* TDX page types */ #define PT_NDA 0x0
Signature · 1 line
2.53.0
v3 cover Enable DICE-based TDX quoting
Hi,
This is v3 of the host side of DICE-based TDX quoting. It underwent a redesign after the v2 review and a couple of PUCK discussions, so there is quite a bit of delta. The biggest changes are keeping userspace in the GetQuote flow and supporting concurrent quoting. Userspace now requests a Quote with a new KVM VM ioctl. There is no longer a big lock serializing TDH.QUOTE.GET calls in the entire system, and as a result the static global Quote buffer is gone too. The TDX module extensions part of v2 is now its own series [1]. That series can (re)initialize quoting implicitly, so the kernel no longer needs TDH.QUOTE.INIT calls. To keep things simple, only enable quoting when there is no Dynamic PAMT.
One upside of this redesign is that it keeps the optional use of event notify interrupts in userspace. Userspace can generate the Quote in a separate thread, and use event notify to tell the guest when the Quote is ready. Also, the kernel doesn't have to worry about end-to-end attestation ABI issues. Userspace decides how quoting should be done, so a kernel upgrade shouldn't break attestation for TDs on existing platforms.
Patches 1, 2, 7 and 8 are for tip, and patches 3-6 are for KVM. The plan is for this series to go through tip, so Sean, I'd appreciate it if you could take a look at the KVM patches. Jason, this is initial host enabling only. It doesn't address the guest-side Quote type and labeling feedback [2].
Background
==========
In TDX attestation, a "Quote" is a TD Report converted into a signed form that a remote party can verify. To get a Quote, a TD passes its report to the host using the GetQuote TDVMCALL. Host KVM then exits to userspace, which sends the report to an SGX quoting enclave. SGX-based attestation requires per-platform certificates from Intel's servers, so this needs an extra step to register the platform and fetch the certificates. Now, TDX modules on newer platforms can generate DICE-based Quotes themselves. These Quotes carry layered certificate chains built from the platform, so there is no need for any extra step.
DICE-based quoting runs as a TDX module extension, a separate execution environment inside the TDX module for long-running work [3]. The TDX module generates these Quotes itself. Its signing key is certified by dedicated security hardware like the S3M. The time it takes to generate this type of Quote using the CPU should be on the order of milliseconds. Each Quote request consists of a quoting "session" (about 16KB of memory), which holds its state, and a quoting "thread" (think struct task_struct or struct kvm_vcpu, about 24KB of memory), which runs the session. Sessions and threads come from a fixed global pool shared by all TDs. A Quote request can be interrupted and resumed later, on any CPU, similar to a preempted task. Once a thread starts a request, it isn't released back to the pool until the request finishes.
Design
======
With this series, userspace can ask KVM for a Quote, and KVM does the quoting via a SEAMCALL. The design has two goals:
1. Continue using the existing GetQuote flow, to avoid disturbing the guest driver.
2. Allow as much concurrency as is reasonable, to minimize vCPU stalls.
Add a new TDX sub-ioctl, KVM_TDX_GET_QUOTE, to request a Quote from userspace. It's a VM ioctl because the SEAMCALL needs the TD's TDR page. To have a stable and maintainable ABI, both the report and the Quote buffers are page-aligned, so KVM doesn't have to deal with unaligned data in perpetuity. Userspace should check how big a Quote can be in KVM_TDX_CAPABILITIES to know how much memory the Quote buffer needs.
Every CPU should be able to generate a Quote at the same time, to avoid a noisy-neighbor problem between TDs. So when the kernel enables quoting, KVM requires at least one quoting session and thread per logical CPU. That takes up about 40KB of TDX module memory per CPU, adding up to tens of megabytes on a large system. KVM manages the quoting sessions, and it handles one request per TD at a time. A typical setup doesn't oversubscribe TDs, meaning there are no more TDs than logical CPUs. Every TD is then guaranteed to get a session whenever it asks for a Quote. On an oversubscribed host, userspace sees -EBUSY if KVM runs out of sessions, and it can retry later. The global session allocator should add a few microseconds of delay at most, which is minuscule compared to generating the Quote itself.
A DICE-based Quote can be up to several megabytes in size. When there are a large number of Quote requests in flight, using bounce buffers could cost gigabytes of kernel memory on a large system. So KVM uses GUP to pin the Quote buffer instead. This also helps reduce another noisy-neighbor problem. When userspace frees its buffer, the TLB shootdown only hits the CPUs the VMM runs on, whereas a vfree() on the kernel bounce buffer would eventually trigger a shootdown on every CPU. As a result, a TD that does aggressive quoting mostly throttles itself.
TDH.QUOTE.GET takes shared locks on the TD, so it doesn't collide with the other runtime SEAMCALLs, only with the ones that build or tear down the TD. So, instead of taking KVM's heavy tdx_vm_state_guard, only allow quoting at runtime, after the TD is finalized. This avoids causing a build-time SEAMCALL to fail and bug the VM. See patch 4 for more details.
In order to not break TDX quoting, after a compatible runtime TDX module update, the module must keep the maximum Quote size the same, and still support at least one quoting session and thread per logical CPU.
Alternatives considered
=======================
Sean suggested doing all of this quoting in the guest, with a new TDCALL. After some discussion [4] and a follow-up PUCK call on 9/23, the consensus was to go back to the host-based design and rely on the current GetQuote flow. Quotes signed directly by the S3M are out of scope for this series.
I also considered other ways to manage quoting sessions. sbitmap usually scales better than an IDA under heavy contention, but that felt like premature optimization and made the code less intuitive. It also mostly exists in the storage subsystem. A per-CPU session ID only works if the whole request is non-preemptible. A per-CPU lock, on the other hand, can protect each CPU's session, but it can cause unnecessary cross-VM contention even when there is no oversubscription.
Testing
=======
Tested with a TDX module that mocks the interruptible quoting ABI and returns a fake Quote. For the userspace side, I used a mocked quoting service in QEMU. Multiple TDs were able to receive Quotes at the same time through GetQuote and the new KVM ioctl.
What's in this series
=====================
Patches 1-2 add the core TDX interfaces, and patches 3-6 add the KVM side of quoting and document the new uABI. Patch 7 then enables DICE-based quoting, and patch 8 adds documentation for it.
Patch 1/8: Generate a Quote with TDH.QUOTE.GET.
Patch 2/8: Report the TDX module's quoting capabilities. Patch 3/8: Require a quoting session and thread per logical CPU. Patch 4/8: Add the KVM_TDX_GET_QUOTE sub-ioctl.
Patch 5/8: Report the maximum Quote size to userspace. Patch 6/8: Document KVM_TDX_GET_QUOTE.
Patch 7/8: Enable quoting at TDX init.
Patch 8/8: Document DICE-based quoting.
Base
====
This is based on v7.4-rc1, plus v6 of the TDX module extensions series [1]. You can find the full branch at [5]. A matching QEMU is at [6].
AI use
======
I used AI to polish my code, this cover letter, and the commit messages. I also used it to collect review feedback and to verify details against the TDX specs. AI generated the QEMU quoting service used for testing. The series underwent AI code review, which caught a corner case where quoting threads could run out and a few TDX documentation bugs. The other comments were limited to style suggestions.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Rebase onto v6 of the TDX module extensions series.
- Redesign the Quote generation path. Keep the GetQuote flow unchanged, and add the KVM_TDX_GET_QUOTE sub-ioctl. [Sean, Rick]
- Redesign the core TDX interface. Drop the global Quote buffer and its big lock to support concurrent quoting. [Sean, Dave, Rick, Tony]
- Use all-0s as the Quote type instead of all-1s in TDH.QUOTE.GET to improve code readability. No functional change.
- Drop the tdx_tdr_pa() move (patch 10 in v2) as it's no longer needed.
- Drop TDH.QUOTE.INIT. The TDX module now folds it into TDH.EXT.INIT.
- Drop Rick's, Dan's and Tony's RB tags on the v2 patches, as those patches were either dropped or changed substantially.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] Intel TDX Module Extension for Quoting, February 2026 (draft)
[4] https://lore.kernel.org/all/[email protected]/
[5] https://github.com/peterfang/linux/tree/tdx-host-dice-v3
[6] https://github.com/peterfang/qemu/tree/dice-mock
Peter Fang (8):
x86/virt/tdx: Add interface to generate a Quote x86/virt/tdx: Add interface to check quoting capabilities
KVM: TDX: Require at least one quoting session and thread per CPU
KVM: TDX: Add KVM_TDX_GET_QUOTE sub-ioctl for quoting
KVM: TDX: Report maximum Quote size in TDX capabilities
KVM: TDX: Document KVM_TDX_GET_QUOTE
x86/virt/tdx: Enable the quoting extension x86/virt/tdx: Add documentation for DICE-based quoting
Documentation/arch/x86/tdx.rst | 23 ++- Documentation/virt/kvm/api.rst | 21 ++- Documentation/virt/kvm/x86/intel-tdx.rst | 47 ++++- arch/x86/include/asm/tdx.h | 7 + arch/x86/include/asm/tdx_global_metadata.h | 5 + arch/x86/include/uapi/asm/kvm.h | 16 +- arch/x86/kvm/vmx/tdx.c | 180 ++++++++++++++++++++ arch/x86/kvm/vmx/tdx.h | 6 + arch/x86/virt/vmx/tdx/tdx.c | 125 +++++++++++++- arch/x86/virt/vmx/tdx/tdx.h | 1 + arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 26 +++ 11 files changed, 438 insertions(+), 19 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
prerequisite-patch-id: 5fbf78c6f40c69edec7a5016c950c35486f3ce81
prerequisite-patch-id: 3be62622e14be3de67212102aebbec7347773946
prerequisite-patch-id: ff98c5e54482da8ba3206ce825b299c29b3ca445
prerequisite-patch-id: 644cf6ce49ea8ed32adbfeba2234265537bc8576
prerequisite-patch-id: 6f9d56b183bb6344776bf837e2ca0d7f648bb81d
prerequisite-patch-id: 52e5e348d4b196e0cf79bb448b4edd6a4d4b4d9a
Signature · 1 line
2.53.0
PATCH v3 2/8 x86/virt/tdx: Add interface to check quoting capabilities
KVM will need to know the TDX module's quoting capabilities so it can expose the feature to userspace and manage the Quote requests.
To support concurrent requests, tell KVM how many quoting sessions and threads the TDX module supports. A "session" saves the state of a Quote request inside the TDX module, and a "thread" runs a request on a logical CPU. Also, tell KVM how big a Quote can be.
---
v3:
- Redesign the interface. Use the add-on feature bit instead of the original static Quote buffer check, and also read the quoting metadata fields.
- Drop Tony's Reviewed-by, as the code changed substantially.
--- arch/x86/include/asm/tdx.h | 3 +++ arch/x86/include/asm/tdx_global_metadata.h | 5 ++++ arch/x86/virt/vmx/tdx/tdx.c | 27 ++++++++++++++++++++- arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 26 ++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-)
arch/x86/include/asm/tdx.h +3 -0
@@ -38,6 +38,7 @@#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18)#define TDX_FEATURES0_DYNAMIC_PAMT BIT_ULL(36)#define TDX_FEATURES0_EXT BIT_ULL(39) +#define TDX_FEATURES0_QUOTE BIT_ULL(50)#ifndef __ASSEMBLER__
@@ -202,6 +203,8 @@ u64 tdh_mem_page_remove(struct tdx_td *td, u64 gpa, enum pg_level level, u64 *exu64 tdh_phymem_cache_wb (bool resume);u64 tdh_phymem_page_wbinvd_tdr (struct tdx_td *td);u64 tdh_phymem_page_wbinvd_hkid (u64 hkid,kvm_pfn_t pfn); +bool tdx_quoting_enabled (u32 *max_quote_size,u16 *num_sessions, +u16 *num_threads); int tdx_quote_generate(struct tdx_td *td, u16 session_id, struct page *report_page, u64 report_size, struct page **quote_pages, u64 quote_buf_size,
arch/x86/include/asm/tdx_global_metadata.h +5 -0
@@ -59,4 +59,9 @@ struct tdx_sys_info { struct tdx_sys_info_td_conf td_conf; }; +struct tdx_sys_info_quote { +u32 max_quote_size; +u16 num_sessions; +u16 num_threads; +};#endif
arch/x86/virt/vmx/tdx/tdx.c +26 -1
@@ -1036,7 +1036,7 @@ static __init int construct_tdmrs(struct list_head *tmb_list,/* List kernel-supported add-on features0 bits here */ #define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) -static __init u64 get_tdx_usable_addon_features0 (void ) +static u64 get_tdx_usable_addon_features0 (void ) {/* * The kernel doesn't yet support TDX module extensions with DPAMT.
@@ -2529,6 +2529,31 @@ void tdx_free_control_page(struct page *page) }EXPORT_SYMBOL_FOR_KVM (tdx_free_control_page); +/* +* Read the TDX module's quoting capabilities. +*/ +bool tdx_quoting_enabled (u32 *max_quote_size,u16 *num_sessions, +u16 *num_threads) +{ +struct tdx_sys_info_quote sysinfo_quote; +int ret; + +/* All usable add-on features are enabled at TDX init. */ +if (!(get_tdx_usable_addon_features0 () &TDX_FEATURES0_QUOTE )) +return false; + + ret =get_tdx_sys_info_quote (&sysinfo_quote); +if (ret) +return false; + + *max_quote_size = sysinfo_quote.max_quote_size; + *num_sessions = sysinfo_quote.num_sessions; + *num_threads = sysinfo_quote.num_threads; + +return true; +} +EXPORT_SYMBOL_FOR_KVM (tdx_quoting_enabled); + static u64 tdx_quote_get(struct tdx_td *td, u16 session_id, struct page *report_page, u64 report_size, u64 *quote_hpa_list, u64 quote_buf_size,
arch/x86/virt/vmx/tdx/tdx_global_metadata.c +26 -0
@@ -139,6 +139,32 @@ static __init int get_tdx_sys_info_ext(struct tdx_sys_info_ext *sysinfo_ext)return 0 ; } +static int get_tdx_sys_info_quote (struct tdx_sys_info_quote *sysinfo_quote) +{ +int ret; +u64 val; + + ret =read_sys_metadata_field (0x2300000200000002 , &val); +if (ret) +return ret; + + sysinfo_quote->max_quote_size = val; + + ret =read_sys_metadata_field (0x2300000100000005 , &val); +if (ret) +return ret; + + sysinfo_quote->num_sessions = val; + + ret =read_sys_metadata_field (0x2300000100000006 , &val); +if (ret) +return ret; + + sysinfo_quote->num_threads = val; + +return 0 ; +} +static __init int get_tdx_sys_info (struct tdx_sys_info *sysinfo) {int ret =0 ;
Signature · 1 line
2.53.0
PATCH v3 3/8 KVM: TDX: Require at least one quoting session and thread per CPU
In reply to Peter FangWhen the TDX-Module supports quoting, disable TDX if there are not enough quoting sessions or threads for the whole system. This avoids cross-TD contention for quoting resources in the normal setup, where TDs aren't oversubscribed [1].
Quote generation is a long-running operation in the TDX-Module, and the quoting sessions and threads come from a fixed system-wide pool shared by all TDs. Inside the module, a session stores a Quote request's state, and a thread runs the request on a logical CPU. Not having enough quoting resources creates a noisy-neighbor problem, where a TD's Quote request could fail or wait indefinitely just because other TDs are also getting their Quotes. Oversubscribing TDs, i.e. more TDs than there are logical CPUs, is less typical, so only require enough quoting resources for the normal setup.
Expect one Quote request per TD at a time, and guarantee that:
- When TDs aren't oversubscribed, there is always a free session for a Quote request.
- A quoting thread can always be scheduled on any available CPU.
Each quoting session and thread currently needs roughly 40KB of pre-allocated TDX-Module memory. This adds up to tens of megabytes on a large system with more than 1024 logical CPUs [2].
Since a platform with TDX enabled doesn't support CPU hotplug, use num_present_cpus() for the number of logical CPUs.
---
v3:
- New patch.
--- arch/x86/kvm/vmx/tdx.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
arch/x86/kvm/vmx/tdx.c +22 -0
@@ -3435,6 +3435,8 @@ void tdx_hardware_unsetup(void)static int __init __tdx_hardware_setup (void ) {const struct tdx_sys_info_td_conf *td_conf; +u16 quoting_sessions, quoting_threads; +u32 quoting_max_size;int i;for (i =0 ; i <ARRAY_SIZE (tdx_uret_msrs); i++) {
@@ -3500,6 +3502,26 @@ static int __init __tdx_hardware_setup(void)return -EINVAL ; } +/* +* KVM only allows one quoting session per TD. Make sure a free session +* is always available as long as there is no oversubscription of TDs, +* i.e. no more TDs than logical CPUs, and that a quoting thread can +* always be scheduled on any logical CPU. +*/ +if (tdx_quoting_enabled ("ing_max_size, "ing_sessions, + "ing_threads)) { +if (quoting_sessions <num_present_cpus ()) { +pr_err ("Disable TDX: QUOTING_NUM_SESSIONS (%u) smaller than number of logical CPUs (%u).\n" , + quoting_sessions,num_present_cpus ()); +return -EINVAL ; + } +if (quoting_threads <num_present_cpus ()) { +pr_err ("Disable TDX: QUOTING_NUM_THREADS (%u) smaller than number of logical CPUs (%u).\n" , + quoting_threads,num_present_cpus ()); +return -EINVAL ; + } + } +if (misc_cg_set_capacity (MISC_CG_RES_TDX ,tdx_get_nr_guest_keyids ()))return -EINVAL ;
Signature · 1 line
2.53.0
PATCH v3 5/8 KVM: TDX: Report maximum Quote size in TDX capabilities
In reply to Peter FangAdd a "quote_max_size" field to KVM_TDX_CAPABILITIES so userspace knows how big a Quote buffer should be for KVM_TDX_GET_QUOTE.
Quotes can have different size limits. They depend on the signing algorithms and platform configuration. A value of 0 means quoting isn't available in the TDX-Module.
---
v3:
- New patch.
--- arch/x86/include/uapi/asm/kvm.h | 4 +++- arch/x86/kvm/vmx/tdx.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/include/uapi/asm/kvm.h +3 -1
@@ -1012,7 +1012,9 @@ struct kvm_tdx_capabilities {__u64 kernel_tdvmcallinfo_1_r12;__u64 user_tdvmcallinfo_1_r12; -__u64 reserved[250 ]; +__u64 quote_max_size; + +__u64 reserved[249 ];/* Configurable CPUID bits for userspace */ struct kvm_cpuid2 cpuid;
arch/x86/kvm/vmx/tdx.c +6 -0
@@ -189,6 +189,8 @@ static void td_init_cpuid_entry2(struct kvm_cpuid_entry2 *entry, unsigned char istatic int init_kvm_tdx_caps (const struct tdx_sys_info_td_conf *td_conf,struct kvm_tdx_capabilities *caps) { +u16 quoting_sessions, quoting_threads; +u32 quoting_max_size;int i; caps->supported_attrs =tdx_get_supported_attrs (td_conf);
@@ -207,6 +209,10 @@ static int init_kvm_tdx_caps(const struct tdx_sys_info_td_conf *td_conf,for (i =0 ; i < td_conf->num_cpuid_config; i++)td_init_cpuid_entry2 (&caps->cpuid.entries[i], i); +if (tdx_quoting_enabled ("ing_max_size, "ing_sessions, + "ing_threads)) + caps->quote_max_size = quoting_max_size; +return 0 ; }
Signature · 1 line
2.53.0
PATCH v3 6/8 KVM: TDX: Document KVM_TDX_GET_QUOTE
In reply to Peter FangDocument the KVM_TDX_GET_QUOTE command, which lets userspace request DICE-based Quotes from the TDX module, without using a Quoting Enclave on the host.
---
v3:
- New patch based on the redesigned Quote generation path.
--- Documentation/virt/kvm/api.rst | 21 ++++++----- Documentation/virt/kvm/x86/intel-tdx.rst | 47 +++++++++++++++++++++++- 2 files changed, 58 insertions(+), 10 deletions(-)
Documentation/virt/kvm/api.rst +12 -9
@@ -7561,15 +7561,18 @@ inputs and outputs of the TDVMCALL. Currently the following values of ``nr`` are defined: * ``TDVMCALL_GET_QUOTE``: the guest has requested to generate a TD-Quote - signed by a service hosting TD-Quoting Enclave operating on the host. - Parameters and return value are in the ``get_quote`` field of the union. - The ``gpa`` field and ``size`` specify the guest physical address - (without the shared bit set) and the size of a shared-memory buffer, in - which the TDX guest passes a TD Report. The ``ret`` field represents - the return value of the GetQuote request. When the request has been - queued successfully, the TDX guest can poll the status field in the - shared-memory area to check whether the Quote generation is completed or - not. When completed, the generated Quote is returned via the same buffer. + from a TD Report, signed by a certified attestation key. Userspace can + get it from a TD-Quoting Enclave on the host. Or, if the TDX module + supports quoting, the ``KVM_TDX_GET_QUOTE`` command can generate a + DICE-based Quote. Parameters and return value are in the ``get_quote`` + field of the union. The ``gpa`` field and ``size`` specify the guest + physical address (without the shared bit set) and the size of a + shared-memory buffer, in which the TDX guest passes a TD Report. The + ``ret`` field represents the return value of the GetQuote request. When + the request has been queued successfully, the TDX guest can poll the + status field in the shared-memory area to check whether the Quote + generation is completed or not. When completed, the generated Quote is + returned via the same buffer. * ``TDVMCALL_GET_TD_VM_CALL_INFO``: the guest has requested the support status of TDVMCALLs. The output values for the given leaf should be
Documentation/virt/kvm/x86/intel-tdx.rst +46 -1
65 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v3 8/8 x86/virt/tdx: Add documentation for DICE-based quoting
In reply to Peter FangThe attestation section only covers quoting through the SGX enclave. Document the TDX module's DICE-based quoting capability, and bring the TDX guest driver's side up to date.
---
v3:
- New patch. Split from v2 16/17 and add DICE details.
--- Documentation/arch/x86/tdx.rst | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
Documentation/arch/x86/tdx.rst +17 -6
@@ -544,14 +544,25 @@ More details about the TDREPORT can be found in Intel TDX Module specification, section titled "TDG.MR.REPORT Leaf". After getting the TDREPORT, the second step of the attestation process -is to send it to the Quoting Enclave (QE) to generate the Quote. TDREPORT -by design can only be verified on the local platform as the MAC key is -bound to the platform. To support remote verification of the TDREPORT, -TDX leverages Intel SGX Quoting Enclave to verify the TDREPORT locally -and convert it to a remotely verifiable Quote. Method of sending TDREPORT +is to convert it to a Quote. TDREPORT by design can only be verified on +the local platform as the MAC key is bound to the platform. To support +remote verification of the TDREPORT, TDX can leverage Intel SGX Quoting +Enclave (QE) to verify the TDREPORT locally and convert it to a remotely +verifiable Quote in an Intel-specific format. Method of sending TDREPORT to QE is implementation specific. Attestation software can choose whatever communication channel available (i.e. vsock or TCP/IP) to -send the TDREPORT to QE and receive the Quote. +send the TDREPORT to QE and receive the Quote. If it uses the +configfs-tsm ABI, the TDX guest driver asks the host for the Quote with +TDG.VP.VMCALL<GetQuote>, as defined in TDX Guest Hypervisor Communication +Interface specification. + +Alternatively, the TDX module can generate Quotes based on DICE, an +industry standard, without a separate host service. Their certificates +come from the platform itself rather than from Intel's servers, so there +is no need to register the platform with Intel like there is for SGX. The +host kernel enables quoting whenever the TDX module supports it and there +is no Dynamic PAMT. The TDX guest driver then uses a GetQuote buffer that +fits the largest possible Quote from the module. References ==========
Signature · 1 line
2.53.0
PATCH v3 4/8 KVM: TDX: Add KVM_TDX_GET_QUOTE sub-ioctl for quoting
In reply to Peter FangAdd a new VM sub-ioctl, KVM_TDX_GET_QUOTE, so userspace can generate a DICE-based Quote through the TDX-Module if it supports quoting.
To convert the guest's local report into a remotely verifiable Quote, the host currently forwards the guest's GetQuote request to an SGX Quoting Enclave in userspace. Now the host can also request a DICE-based Quote from the TDX-Module. These Quotes leverage Intel's security hardware, such as the S3M, so they work without SGX. The GetQuote flow remains unchanged, so existing TDX setups can continue to work.
The TDX-Module needs its internal TD states to generate a Quote, so the quoting SEAMCALL (TDH.QUOTE.GET) takes the TD's TDR page as input. Make KVM_TDX_GET_QUOTE a TDX VM sub-ioctl accordingly.
Only allow quoting after the TD is finalized, so it doesn't bump into the TD build ioctls. These ioctls use SEAMCALLs that take an exclusive lock on the TD, so the quoting SEAMCALL can't take a shared lock at the same time. Doing so could fail a build-time SEAMCALL and bug the VM.
Use a plain read for the TD state without tdx_vm_state_guard. The read could race with the following:
- KVM_TDX_INIT_VM: sets the state to initialized, so a racy read would never observe a finalized state. Updating the state only changes its lowest byte, so this is true even with a torn access.
- KVM_TDX_FINALIZE_VM: the only place that sets the state to finalized, which is the stable state of a running TD.
Being a VM ioctl like KVM_TDX_FINALIZE_VM, KVM_TDX_GET_QUOTE's observation of the TD state is governed by the VFS layer. Dropping and grabbing a reference to the VM file have release and acquire semantics. This guarantees that if userspace calls KVM_TDX_GET_QUOTE after KVM_TDX_FINALIZE_VM returns, it must observe the state change fully. A racy userspace implementation would at worst fail with -EINVAL, which just means "not ready yet".
Add a mutex to allow one Quote request per TD at a time. This lets the checks at TDX init guarantee that quoting sessions never run out when there is no oversubscription of TDs. Each request has a unique "session ID", so create a session ID allocator to support concurrent requests. To keep the uABI predictable, always use the number of logical CPUs as the session limit, since userspace has no way of knowing how many sessions the TDX-Module actually supports. If userspace decides to oversubscribe TDs, it must be prepared to handle -EBUSY, as KVM could run out of quoting sessions in this case.
The TDX-Module takes quoting data blobs in pages. Rather than having to support unaligned data in the uABI in perpetuity, require both the report and the Quote blobs to be page-aligned from day one. This gives KVM the freedom to change its implementation underneath later (e.g. pin the report with GUP) without breaking userspace.
Pin the Quote buffer with GUP. DICE-based Quotes can reach several megabytes in size [1], so using bounce buffers could at worst mean gigabytes of kernel memory to shuffle data around on a large system.
---
v3:
- Redesign the Quote generation path. Keep the GetQuote flow unchanged, and let userspace request a Quote with the new KVM_TDX_GET_QUOTE sub-ioctl. [Sean, Rick]
- Allow one Quote request per TD at a time, and support concurrent requests across TDs. [Sean]
--- arch/x86/include/uapi/asm/kvm.h | 12 +++ arch/x86/kvm/vmx/tdx.c | 152 ++++++++++++++++++++++++++++++++ arch/x86/kvm/vmx/tdx.h | 6 ++ 3 files changed, 170 insertions(+)
arch/x86/include/uapi/asm/kvm.h +12 -0
@@ -980,6 +980,7 @@ enum kvm_tdx_cmd_id {KVM_TDX_INIT_MEM_REGION ,KVM_TDX_FINALIZE_VM ,KVM_TDX_GET_CPUID , +KVM_TDX_GET_QUOTE , KVM_TDX_CMD_NR_MAX, };
@@ -1017,6 +1018,17 @@ struct kvm_tdx_capabilities {struct kvm_cpuid2 cpuid; }; +struct kvm_tdx_get_quote { +__u64 report_uaddr; +__u64 report_size; + +__u64 quote_buf_uaddr; +__u64 quote_buf_size; +__u64 quote_size; + +__u64 reserved[27 ]; +}; +struct kvm_tdx_init_vm {__u64 attributes;__u64 xfam;
arch/x86/kvm/vmx/tdx.c +152 -0
176 lines not on this page · raw message
arch/x86/kvm/vmx/tdx.h +6 -0
@@ -47,6 +47,12 @@ struct kvm_tdx {* Set/unset is protected with kvm->mmu_lock. */ bool wait_for_sept_zap; + +/* +* Allow one quoting session per TD. This prevents a TD from hogging +* the quoting resources. +*/ +struct mutex quote_lock; };/* TDX module vCPU states */
Signature · 1 line
2.53.0
PATCH v3 7/8 x86/virt/tdx: Enable the quoting extension
In reply to Peter FangThe quoting extension generates TDX attestation Quotes in the TDX module, without a separate host service. Enable this feature by requesting it at TDX init when configuring the module.
For simplicity, when there is no Dynamic PAMT, the kernel enables every recognizable add-on feature that the TDX module supports. So add quoting to the list of add-on features. And once it's enabled, runtime module updates guarantee it keeps working.
KVM expects the TDX module to support quoting on every logical CPU at the same time. This takes about 40KB of memory per logical CPU. On a large system with more than 1024 logical CPUs, this consumes tens of megabytes of host RAM [1].
---
v3:
- Enable through kernel-supported add-on features.
- Don't explicitly request quoting in TDH.SYS.UPDATE.
- Drop the "Quoting engine" term. [Nikolay]
- Drop Tony's Reviewed-by, as the code changed substantially.
--- arch/x86/virt/vmx/tdx/tdx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/virt/vmx/tdx/tdx.c +1 -1
@@ -1034,7 +1034,7 @@ static __init int construct_tdmrs(struct list_head *tmb_list,#define TDX_SYS_CONFIG_DYNAMIC_PAMT BIT(16)/* List kernel-supported add-on features0 bits here */ -#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (TDX_FEATURES0_QUOTE)static u64 get_tdx_usable_addon_features0 (void ) {
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote
In reply to Peter FangThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] x86/virt/tdx: uninit HPA list nodes and tail read in tdx_quote_generate() - [Medium] x86/virt/tdx…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] x86/virt/tdx: uninit HPA list nodes and tail read in tdx_quote_generate()
- [Medium] x86/virt/tdx: missing cond_resched() in tdx_quote_get() retry loop
--
commit 822505db95798a7ae7ce913170aae5958aefcee1
Author: Peter Fang <[email protected]>
x86/virt/tdx: Add interface to generate a Quote
This commit adds tdx_quote_generate() and a TDH.QUOTE.GET SEAMCALL wrapper so KVM can request a signed TDX Quote using caller-provided host pages.
Quoted 13 lines
arch/x86/virt/vmx/tdx/tdx.c +5
-0@@ -2529,6 +2529,102 @@ void tdx_free_control_page(struct page *page) }EXPORT_SYMBOL_FOR_KVM (tdx_free_control_page); +static u64 tdx_quote_get (struct tdx_td *td,u16 session_id, +struct page *report_page,u64 report_size, +u64 *quote_hpa_list,u64 quote_buf_size, +u64 *quote_size) +{
[ ... ]
arch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2550
Quoted 3 lines
arch/x86/virt/vmx/tdx/tdx.c +3
-0+do { + r =seamcall_ret (TDH_QUOTE_GET , &args); + }while (r ==TDX_INTERRUPTED_RESUMABLE );
[Severity: Medium]
Should this retry loop call cond_resched()?
seamcall_ret() only calls preempt_enable(), which does not reschedule on CONFIG_PREEMPT_NONE or CONFIG_PREEMPT_VOLUNTARY kernels. In sleepable runtime context, spinning across TDX_INTERRUPTED_RESUMABLE retries can starve other tasks and delay RCU quiescent states, unlike init_tdmr().
[ ... ]
Quoted 47 lines
arch/x86/virt/vmx/tdx/tdx.c +47
-0+int tdx_quote_generate (struct tdx_td *td,u16 session_id, +struct page *report_page,u64 report_size, +struct page **quote_pages,u64 quote_buf_size, +u64 *quote_size,u64 *seamcall_err) +{ +int num_quote_pages, num_nodes, ret =0 ; +u64 *node_head, *node_entry; +u64 r; + +/* +* Pass the quote buffer to the TDX module as an HPA linked list. Each +* node holds 4KB page HPAs and the last entry points to the next node. +*/ + node_head =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!node_head) +return -ENOMEM ; + + node_entry = node_head; + num_quote_pages =PFN_UP (quote_buf_size); + num_nodes =1 ; + +/* Populate the linked list. Allocate new nodes as needed. */ +for (int i =0 , pages =0 ; pages < num_quote_pages; + i = (i +1 ) %HPAS_PER_NODE ) { +if (i ==HPAS_PER_NODE -1 ) { +u64 *new_node =kmalloc (PAGE_SIZE ,GFP_KERNEL ); + +if (!new_node) { + ret = -ENOMEM ; + goto out_free_nodes; + } + +/* Write the 'next' pointer. */ + node_entry[i] =__pa (new_node); + node_entry = new_node; + num_nodes++; +continue ; + } + + node_entry[i] =page_to_phys (quote_pages[pages]); + pages++; + } + + r =tdx_quote_get (td, session_id, report_page, report_size, node_head, + quote_buf_size, quote_size); + + *seamcall_err = r;
arch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2622
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+ +if (r !=TDX_SUCCESS ) + ret = -EIO ; + +out_free_nodes: +for (int i =0 ; i < num_nodes; i++) { + node_entry = node_head; + node_head =__va (node_head[HPAS_PER_NODE -1 ]); +kfree (node_entry); + }
[Severity: Medium]
Can node_head and new_node pass uninitialized slab memory to TDH_QUOTE_GET and read an uninitialized next pointer in out_free_nodes?
Both allocations use kmalloc() instead of kzalloc(), and the loop only sets entries for pages < num_quote_pages and the next pointer when chaining a new node. Unused trailing HPA slots and the final node's next pointer remain uninitialized, which can cause TDH_QUOTE_GET to fail or walk bad addresses.
The final iteration of out_free_nodes also unconditionally reads node_head[HPAS_PER_NODE - 1] on every call, including -ENOMEM, triggering an uninitialized heap read. Allocating nodes with kzalloc() and skipping the next-pointer read on the last node avoids both issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v3 6/8] KVM: TDX: Document KVM_TDX_GET_QUOTE
In reply to Peter FangThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] KVM: TDX: KVM_TDX_GET_QUOTE misdocuments hw_error as must be 0 (out) - [Low] KVM: TDX…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] KVM: TDX: KVM_TDX_GET_QUOTE misdocuments hw_error as must be 0 (out)
- [Low] KVM: TDX: KVM_TDX_GET_QUOTE quote_buf_size minimum not enforced in code
--
commit 42ca18a6ac06953778ef9347240a920d55d409db
Author: Peter Fang <[email protected]>
KVM: TDX: Document KVM_TDX_GET_QUOTE
This commit documents the KVM_TDX_GET_QUOTE VM ioctl and its quote_max_size capability field in Documentation/virt/kvm/x86/intel-tdx.rst, and updates the TDVMCALL_GET_QUOTE description in Documentation/virt/kvm/api.rst.
Quoted 4 lines
Documentation/virt/kvm/x86/intel-tdx.rst +0
-0
[ ... ]
Quoted 8 lines
Documentation/virt/kvm/x86/intel-tdx.rst +4
-0@@ -197,6 +203,45 @@ Complete measurement of the initial TD contents and mark it ready to run. - hw_error: must be 0 +KVM_TDX_GET_QUOTE +----------------- +:Type: vm ioctl +:Returns: 0 on success, <0 on error
Documentation/virt/kvm/x86/intel-tdx.rst Complete measurement of the initial TD contents and mark it ready to run. · line 219
Quoted 10 lines
Documentation/virt/kvm/x86/intel-tdx.rst +10
-0+ +Generate a DICE-based Quote from a TD Report. @report_uaddr points to the +TD Report, and @report_size is its size. @quote_buf_uaddr points to the +buffer for the Quote, and @quote_buf_size is its size. On success, KVM +writes the Quote to the buffer, and the size of the Quote to @quote_size. +This needs to be called after KVM_TDX_FINALIZE_VM succeeds. + +@report_uaddr and @quote_buf_uaddr must be page-aligned, and @report_size +must not exceed the size of a page. @quote_buf_size must be at least the +quote_max_size reported by KVM_TDX_CAPABILITIES.
[Severity: Low]
Does tdx_td_get_quote() actually enforce that quote_buf_size is at least quote_max_size?
tdx_td_get_quote() clamps quote_buf_size to max_quote_size with umin() and only returns -EINVAL when it is zero. A smaller non-zero buffer is passed to tdx_quote_generate() and may succeed or fail with -EIO, while larger values are silently capped.
Either tdx_td_get_quote() should reject quote_buf_size < max_quote_size, or the documentation should state that quote_buf_size must be non-zero, should be at least quote_max_size to guarantee the Quote fits, and is capped at quote_max_size.
Also, tdx_td_get_quote() rejects non-zero reserved[27] in struct kvm_tdx_get_quote with -EINVAL, which is not mentioned here.
[ ... ]
Documentation/virt/kvm/x86/intel-tdx.rst Complete measurement of the initial TD contents and mark it ready to run. · line 229
Quoted 4 lines
Documentation/virt/kvm/x86/intel-tdx.rst +4
-0+- id: KVM_TDX_GET_QUOTE +- flags: must be 0 +- data: pointer to struct kvm_tdx_get_quote (in/out) +- hw_error: must be 0 (out)
[Severity: Low]
Should hw_error be documented as an in/out field that must be 0 on input and returns the TDX SEAMCALL status code on output?
tdx_get_cmd() returns -EINVAL if cmd->hw_error is non-zero on input. tdx_td_get_quote() -> tdx_quote_generate() then writes the TDH.QUOTE.GET SEAMCALL status code to cmd->hw_error (returning -EIO on failure), and tdx_vm_ioctl() copies it back to userspace.
Documenting it as "must be 0 (out)" could mislead userspace into not zeroing hw_error on input or ignoring the returned SEAMCALL status on -EIO.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Quoted 5 lines · Peter Fang
Sean suggested doing all of this quoting in the guest, with a new TDCALL. After some discussion [4] and a follow-up PUCK call on 9/23, the consensus was to go back to the host-based design and rely on the current GetQuote flow. Quotes signed directly by the S3M are out of scope for this series.
This would certainly match what the other architectures are doing, maybe explain a bit more why Intel has to be so much more complicated?
Otherwise I don't have an issue with a design like this, there is no useful purpose for the host to see a VM's signed quote so it is fine for this to all be buried in KVM without involving attestation subsystem..
Jason
[email protected]
AI reviewRe: [PATCH v3 2/8] x86/virt/tdx: Add interface to check quoting capabilities
In reply to Peter FangThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] x86/virt/tdx: tdx_quoting_enabled() omits tdx_module_state.initialized check - [Low] x86/virt/tdx…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] x86/virt/tdx: tdx_quoting_enabled() omits tdx_module_state.initialized check
- [Low] x86/virt/tdx: tdx_quoting_enabled() unpacks struct tdx_sys_info_quote fields
--
commit e4978984b33087f0b69c4ea714b47633406601de
Author: Peter Fang <[email protected]>
x86/virt/tdx: Add interface to check quoting capabilities
This commit adds tdx_quoting_enabled() and a global metadata helper to expose the TDX module's quoting capabilities (maximum quote size, number of sessions, and number of threads) to KVM.
[ ... ]
Quoted 4 lines
arch/x86/virt/vmx/tdx/tdx.c +0
-0
[ ... ]
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +6
-0@@ -2529,6 +2529,31 @@ void tdx_free_control_page(struct page *page) }EXPORT_SYMBOL_FOR_KVM (tdx_free_control_page); +/* +* Read the TDX module's quoting capabilities. +*/ +bool tdx_quoting_enabled (u32 *max_quote_size,u16 *num_sessions, +u16 *num_threads) +{
arch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2547
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+struct tdx_sys_info_quote sysinfo_quote; +int ret; + +/* All usable add-on features are enabled at TDX init. */ +if (!(get_tdx_usable_addon_features0 () &TDX_FEATURES0_QUOTE )) +return false; + + ret =get_tdx_sys_info_quote (&sysinfo_quote); +if (ret) +return false;
[Severity: Medium]
Should tdx_quoting_enabled() check tdx_module_state.initialized before reading tdx_sysinfo and issuing TDH.SYS.RD?
During a runtime TDX module update, tdx_module_shutdown() clears tdx_module_state.initialized without clearing tdx_sysinfo. If tdx_module_run_update() fails in reinit_tdx_module_extensions(), tdx_module_state.initialized stays false while KVM stays active.
When TDH.SYS.RD still succeeds in that state, tdx_quoting_enabled() falsely returns true even though the quoting extension is uninitialized. When TDH.SYS.RD fails, read_sys_metadata_field() logs three unratelimited pr_err() lines via seamcall_prerr_ret() on each call.
Checking !tdx_module_state.initialized at the start of tdx_quoting_enabled(), matching tdx_get_sysinfo(), avoids both.
arch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2554
Quoted 6 lines
arch/x86/virt/vmx/tdx/tdx.c +6
-0+ *max_quote_size = sysinfo_quote.max_quote_size; + *num_sessions = sysinfo_quote.num_sessions; + *num_threads = sysinfo_quote.num_threads; + +return true; +}
[Severity: Low]
Could tdx_quoting_enabled() take a struct tdx_sys_info_quote * directly instead of three separate output pointers?
struct tdx_sys_info_quote is already exposed via asm/tdx_global_metadata.h (included by asm/tdx.h) with these exact fields. Passing two adjacent u16 * pointers (num_sessions and num_threads) makes argument-order swaps compile without warning and forces callers to declare unused local variables.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 3/8] KVM: TDX: Require at least one quoting session and thread per CPU
In reply to Peter FangThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] KVM: TDX: quoting checks return -EINVAL and abort kvm-intel load --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] KVM: TDX: quoting checks return -EINVAL and abort kvm-intel load
--
commit ad2ff9af18e518d36b330f0d2e71d20814ddc017
Author: Peter Fang <[email protected]>
KVM: TDX: Require at least one quoting session and thread per CPU
This commit checks that the TDX-Module provides at least as many quoting sessions and threads as present logical CPUs when quoting is enabled, returning -EINVAL from __tdx_hardware_setup() if either count is too small.
Quoted 4 lines
arch/x86/kvm/vmx/tdx.c +0
-0
[ ... ]
Quoted 13 lines
arch/x86/kvm/vmx/tdx.c +9
-0@@ -3500,6 +3502,26 @@ static int __init __tdx_hardware_setup(void)return -EINVAL ; } +/* +* KVM only allows one quoting session per TD. Make sure a free session +* is always available as long as there is no oversubscription of TDs, +* i.e. no more TDs than logical CPUs, and that a quoting thread can +* always be scheduled on any logical CPU. +*/ +if (tdx_quoting_enabled ("ing_max_size, "ing_sessions, + "ing_threads)) { +if (quoting_sessions <num_present_cpus ()) {
arch/x86/kvm/vmx/tdx.c static int __init __tdx_hardware_setup(void) · line 3523
Quoted 10 lines
arch/x86/kvm/vmx/tdx.c +10
-0+pr_err ("Disable TDX: QUOTING_NUM_SESSIONS (%u) smaller than number of logical CPUs (%u).\n" , + quoting_sessions,num_present_cpus ()); +return -EINVAL ; + } +if (quoting_threads <num_present_cpus ()) { +pr_err ("Disable TDX: QUOTING_NUM_THREADS (%u) smaller than number of logical CPUs (%u).\n" , + quoting_threads,num_present_cpus ()); +return -EINVAL ; + } + }
[Severity: Medium]
Does returning -EINVAL here abort kvm-intel loading instead of only disabling TDX?
In tdx_hardware_setup(), only -ENODEV from __tdx_hardware_setup() jumps to success_disable_tdx to clear enable_tdx and return 0. Any other error propagates through vt_hardware_setup() -> kvm_x86_vendor_init() and fails kvm-intel loading, breaking regular VMX guests as well.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Edgecombe, Rick P
maintainerQuoted 10 lines · Jason Gunthorpe
Quoted 5 lines · Peter Fang
Sean suggested doing all of this quoting in the guest, with a new TDCALL. After some discussion [4] and a follow-up PUCK call on 9/23, the consensus was to go back to the host-based design and rely on the current GetQuote flow. Quotes signed directly by the S3M are out of scope for this series.
This would certainly match what the other architectures are doing, maybe explain a bit more why Intel has to be so much more complicated?
Heh, which complication in particular are you referring to here?
Quoted 5 lines
Otherwise I don't have an issue with a design like this, there is no useful purpose for the host to see a VM's signed quote so it is fine for this to all be buried in KVM without involving attestation subsystem..
A TDs quote is a VM scoped thing. Extending VM lifecycle management outside of KVM would be a huge change to how things work.
Quoted 9 lines · Rick P
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Peter Fang
Sean suggested doing all of this quoting in the guest, with a new TDCALL. After some discussion [4] and a follow-up PUCK call on 9/23, the consensus was to go back to the host-based design and rely on the current GetQuote flow. Quotes signed directly by the S3M are out of scope for this series.
Quoted 4 lines
Quoted 2 lines
This would certainly match what the other architectures are doing, maybe explain a bit more why Intel has to be so much more complicated?
Heh, which complication in particular are you referring to here?
Well this entire 8 part series, a related VMM series to N VMMs, and a VMM/host API to carry it.
Vs.. None of that, like everyone else.
Naively the guest can call into TDX module just fine, so it is worth explaining why all this is needed, at least a little bit.
Jason
[email protected]
AI reviewRe: [PATCH v3 4/8] KVM: TDX: Add KVM_TDX_GET_QUOTE sub-ioctl for quoting
In reply to Peter FangThank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] KVM: TDX: unzeroed report page and zero report_size in tdx_td_get_quote() - [Medium] KVM: TDX…
Thank you for your contribution! Sashiko AI review found 6 potential issues to consider:
- [Medium] KVM: TDX: unzeroed report page and zero report_size in tdx_td_get_quote()
- [Medium] KVM: TDX: contiguous kmalloc_objs() for quote_pages in tdx_td_get_quote()
- [Medium] KVM: TDX: pin_user_pages_fast() errors overwritten in tdx_td_get_quote()
- [Medium] KVM: TDX: clean quote pages dirtied on ida_alloc_range() failure
- [Medium] x86/virt/tdx: uninitialized HPA list memory read in tdx_quote_generate()
- [Low] KVM: TDX: unmarked race on kvm_tdx->state in tdx_td_get_quote() --
commit 526e1862a4da2b03176c7fc18e3c7f4437ef1528
Author: Peter Fang <[email protected]>
KVM: TDX: Add KVM_TDX_GET_QUOTE sub-ioctl for quoting
This commit adds the KVM_TDX_GET_QUOTE VM sub-ioctl so userspace can request a DICE-based Quote directly from the TDX module for a finalized TD. It serializes quoting per TD with a mutex, limits concurrent sessions across TDs using an IDA bounded by num_present_cpus(), and pins the userspace quote buffer with GUP.
Quoted 4 lines
arch/x86/kvm/vmx/tdx.c +0
-0
[ ... ]
Quoted 10 lines
arch/x86/kvm/vmx/tdx.c +6
-0@@ -2363,6 +2367,146 @@ static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd)return ret; } +/* +* No need to take tdx_vm_state_guard here. Quoting takes TD locks as shared, so +* it doesn't run up against any other runtime SEAMCALLs. +*/ +static int tdx_td_get_quote (struct kvm *kvm,struct kvm_tdx_cmd *cmd) +{
[ ... ]
arch/x86/kvm/vmx/tdx.c static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd) · line 2399
Quoted 2 lines
arch/x86/kvm/vmx/tdx.c +2
-0+if (kvm_tdx->state !=TD_STATE_RUNNABLE ) +return -EINVAL ;
[Severity: Low]
Can this unmarked read of kvm_tdx->state trigger KCSAN data-race reports?
Because KVM_TDX_GET_QUOTE bypasses tdx_vm_state_guard, a concurrent thread running KVM_TDX_INIT_VM (tdx_td_init()) or KVM_TDX_FINALIZE_VM (tdx_td_finalize()) on the same VM fd can write kvm_tdx->state at the same time. The VFS file-reference ordering only synchronizes sequential ioctls, not concurrent ones.
Pairing READ_ONCE(kvm_tdx->state) here with WRITE_ONCE() on the state transitions avoids the data race.
[ ... ]
Quoted 7 lines
arch/x86/kvm/vmx/tdx.c +7
-0+/* The TDX-Module takes the report in a single 4K page */ +if (!PAGE_ALIGNED (gq.report_uaddr) || gq.report_size >PAGE_SIZE ) { + ret = -EINVAL ; + goto out_unlock; + } + + report =kmalloc (PAGE_SIZE ,GFP_KERNEL );
arch/x86/kvm/vmx/tdx.c static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd) · line 2438
Quoted 10 lines
arch/x86/kvm/vmx/tdx.c +10
-0+if (!report) { + ret = -ENOMEM ; + goto out_unlock; + } + +if (copy_from_user (report,u64_to_user_ptr (gq.report_uaddr), + gq.report_size)) { + ret = -EFAULT ; + goto out_free_report; + }
[Severity: Medium]
Does this pass uninitialized kernel slab memory in the tail of report to the TDX module?
For a standard 1024-byte TDREPORT, copy_from_user() leaves the remaining 3072 bytes of the kmalloc() page uninitialized when virt_to_page(report) is handed to tdx_quote_generate().
Also, gq.report_size == 0 is not rejected here (unlike !gq.quote_buf_size below), so report_uaddr == 0 with report_size == 0 bypasses copy_from_user() and proceeds to pin pages, take a quoting session, run TDH.QUOTE.GET on an uninitialized page, and dirty the quote buffer.
Rejecting !gq.report_size with -EINVAL and allocating report with kzalloc(PAGE_SIZE, GFP_KERNEL) addresses both issues.
[ ... ]
arch/x86/kvm/vmx/tdx.c static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd) · line 2454
Quoted 7 lines
arch/x86/kvm/vmx/tdx.c +7
-0+ num_quote_pages =PFN_UP (gq.quote_buf_size); + + quote_pages =kmalloc_objs (*quote_pages, num_quote_pages); +if (!quote_pages) { + ret = -ENOMEM ; + goto out_free_report; + }
[Severity: Medium]
Should quote_pages use kvmalloc_objs() and kvfree() instead of kmalloc_objs()?
DICE quotes can reach several megabytes (for example, a 16-32 MB quote needs a 32-64 KB order-3 or order-4 physically contiguous array), which can cause direct reclaim stalls or spurious -ENOMEM failures on fragmented TDX hosts. quote_pages is only iterated in software, so physical contiguity is unnecessary (compare sev_pin_memory() in arch/x86/kvm/svm/sev.c).
arch/x86/kvm/vmx/tdx.c static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd) · line 2463
Quoted 9 lines
arch/x86/kvm/vmx/tdx.c +9
-0+ + ret =pin_user_pages_fast (gq.quote_buf_uaddr, num_quote_pages, +FOLL_WRITE , quote_pages); +if (ret != num_quote_pages) { +if (ret >0 ) +unpin_user_pages (quote_pages, ret); + ret = -ENOMEM ; + goto out_free_quote; + }
[Severity: Medium]
Should this preserve negative error codes from pin_user_pages_fast() instead of unconditionally returning -ENOMEM?
When userspace passes an unmapped, read-only, or wrapping quote_buf_uaddr, pin_user_pages_fast() returns -EFAULT or -EOVERFLOW (or a short count on a partial failure), which is overwritten with -ENOMEM here. Setting ret = ret < 0 ? ret : -EFAULT preserves the underlying error and matches copy_from_user() and put_user() in this function.
Quoted 14 lines
arch/x86/kvm/vmx/tdx.c +14
-0+ +/* +* There is a 1:1 mapping between a quoting session in use and a +* quoting thread in the TDX-Module. Since KVM guarantees there are at +* least as many threads as logical CPUs, limit the number of sessions +* to the same number to ensure there is always a free thread. Using +* the module's own limit would make the ABI unpredictable. +* +* In a typical setup where TDs aren't oversubscribed, there is always a +* free session since each TD runs at most one session at a time. +* Otherwise, let userspace handle -EBUSY when sessions run out. +*/ + session_id =ida_alloc_range (&tdx_quoting_ida,0 , +num_present_cpus () -1 ,GFP_KERNEL );
arch/x86/kvm/vmx/tdx.c static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd) · line 2487
Quoted 10 lines
arch/x86/kvm/vmx/tdx.c +10
-0+if (session_id == -ENOSPC ) + session_id = -EBUSY ; +if (session_id <0 ) { + ret = session_id; + goto out_unpin_quote; + } + + ret =tdx_quote_generate (&kvm_tdx->td, session_id,virt_to_page (report), + gq.report_size, quote_pages, gq.quote_buf_size, + "e_size, &cmd->hw_error);
[Severity: Medium]
Does tdx_quote_generate() read uninitialized slab memory on every call?
In commit "x86/virt/tdx: Add interface to generate a Quote", tdx_quote_generate() allocates node_head and each chained new_node with kmalloc(PAGE_SIZE, GFP_KERNEL), only writing node_entry[HPAS_PER_NODE - 1] when allocating a subsequent node:
arch/x86/virt/vmx/tdx/tdx.c:tdx_quote_generate() {
...
node_head = kmalloc(PAGE_SIZE, GFP_KERNEL);
...
out_free_nodes:
for (int i = 0; i < num_nodes; i++) {
node_entry = node_head;
node_head = __va(node_head[HPAS_PER_NODE - 1]);
kfree(node_entry);
}
}On the final cleanup iteration (and on mid-loop allocation failure), out_free_nodes unconditionally passes the never-written terminal next-pointer slot to __va(), triggering KMSAN uninitialized-value reports. The unused trailing HPA slots and terminal next pointer in the final node are also passed uninitialized to TDH.QUOTE.GET.
Allocating the HPA list nodes with kzalloc(PAGE_SIZE, GFP_KERNEL) and only reading the next pointer when i + 1 < num_nodes fixes both issues.
arch/x86/kvm/vmx/tdx.c static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd) · line 2496
Quoted 9 lines
arch/x86/kvm/vmx/tdx.c +9
-0+ +ida_free (&tdx_quoting_ida, session_id); + +out_unpin_quote: +/* +* The TDX-Module bypasses the kernel's page tables when writing the +* quote. Mark the pages dirty so reclaim doesn't drop them silently. +*/ +unpin_user_pages_dirty_lock (quote_pages, num_quote_pages, true);
[Severity: Medium]
Should this avoid dirtying quote_pages when ida_alloc_range() fails?
When TDs are oversubscribed and ida_alloc_range() returns -ENOSPC (converted to -EBUSY), the jump to out_unpin_quote passes make_dirty = true even though tdx_quote_generate() never ran. That acquires folio_lock() and marks dirty every clean folio in the multi-megabyte buffer on every -EBUSY retry, causing unnecessary contention and writeback on file-backed mappings.
Allocating the session ID before pinning quote_pages, or unpinning without dirtying when tdx_quote_generate() was not called, avoids this.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 7/8] x86/virt/tdx: Enable the quoting extension
In reply to Peter FangThank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] x86/virt/tdx: uninitialized HPA list node read in tdx_quote_generate() - [Medium] x86/virt/tdx…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] x86/virt/tdx: uninitialized HPA list node read in tdx_quote_generate()
- [Medium] x86/virt/tdx: missing cond_resched() in tdx_quote_get() retry loop
- [Medium] x86/virt/tdx: tdx_quoting_enabled() omits tdx_module_state.initialized check
- [Medium] x86/virt/tdx: missing KeyID-0 cache flush in tdx_ext_mem_setup()
--
commit c7e2931035267288fee2d4fbd9d3880b83fc43c8
Author: Peter Fang <[email protected]>
x86/virt/tdx: Enable the quoting extension
This commit adds TDX_FEATURES0_QUOTE to TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 so the kernel requests the TDX quoting extension during TDX module initialization when Dynamic PAMT is not enabled.
arch/x86/virt/vmx/tdx/tdx.c static __init int construct_tdmrs(struct list_head *tmb_list, · line 1040
Quoted 13 lines
arch/x86/virt/vmx/tdx/tdx.c +1
-1@@ -1034,7 +1034,7 @@ static __init int construct_tdmrs(struct list_head *tmb_list,#define TDX_SYS_CONFIG_DYNAMIC_PAMT BIT(16)/* List kernel-supported add-on features0 bits here */ -#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (TDX_FEATURES0_QUOTE)static u64 get_tdx_usable_addon_features0 (void ) {
[Severity: Medium]
Now that enabling TDX_FEATURES0_QUOTE makes tdx_quote_generate() reachable, does its cleanup loop read uninitialized slab memory from node_head[]?
Both node_head and each chained new_node are allocated with kmalloc(PAGE_SIZE, GFP_KERNEL), so node_entry[HPAS_PER_NODE - 1] is never written on the final node (or when a chained allocation fails). At out_free_nodes, the loop still reads it on the last iteration:
arch/x86/virt/vmx/tdx/tdx.c:tdx_quote_generate() {
...
for (int i = 0; i < num_nodes; i++) {
node_entry = node_head;
node_head = __va(node_head[HPAS_PER_NODE - 1]);
kfree(node_entry);
}
}Every KVM_TDX_GET_QUOTE call hits this uninitialized read (triggering KMSAN) and passes uninitialized trailing entries in the final HPA list page to TDH_QUOTE_GET. Allocating the nodes with kzalloc() and only reading the next pointer when i + 1 < num_nodes would avoid both.
Similarly, tdx_td_get_quote() in arch/x86/kvm/vmx/tdx.c allocates the 4KB report page with kmalloc(), leaving bytes beyond gq.report_size uninitialized when passed to TDH_QUOTE_GET.
[Severity: Medium]
Can tdx_quote_get() monopolize the CPU on non-preemptible kernels by retrying TDH_QUOTE_GET without calling cond_resched()?
Once quoting is enabled, KVM_TDX_GET_QUOTE reaches tdx_quote_get(), which loops while seamcall_ret(TDH_QUOTE_GET, &args) returns TDX_INTERRUPTED_RESUMABLE. On CONFIG_PREEMPT_NONE or CONFIG_PREEMPT_VOLUNTARY, preempt_enable() in sc_retry() will not schedule.
Because quote generation is long-running, this can starve co-scheduled tasks and risk RCU stalls or soft-lockup warnings. Adding cond_resched() in the retry loop, as init_tdmr() does in the same file, would allow the scheduler to run between iterations.
[Severity: Medium]
Should tdx_quoting_enabled() check tdx_module_state.initialized before querying quoting metadata?
During a runtime TDX module update, tdx_module_shutdown() clears tdx_module_state.initialized, and tdx_module_run_update() only sets it again after reinit_tdx_module_extensions() succeeds. If the update fails, KVM stays loaded while the module or its extensions are uninitialized.
Unlike tdx_get_sysinfo(), tdx_quoting_enabled() only checks cached boot-time features and calls get_tdx_sys_info_quote() (TDH_SYS_RD). Later KVM_TDX_CAPABILITIES or KVM_TDX_GET_QUOTE ioctls can falsely report quoting as available or emit unratelimited pr_err() logs on every call.
[Severity: Medium]
Does tdx_ext_mem_setup() need to flush dirty KeyID-0 cachelines before passing newly allocated extension pages to TDH_EXT_MEM_ADD?
Enabling TDX_FEATURES0_QUOTE makes ext.required_pages non-zero, activating tdx_ext_mem_setup() after config_global_keyid()'s wbinvd_on_all_cpus(). It allocates fresh pages with alloc_contig_pages() and passes them to tdx_ext_mem_add() without clflush_cache_range() or wbinvd_on_all_cpus().
Both config_global_keyid() and tdx_clflush_page() flush KeyID-0 cachelines because hardware does not guarantee coherency across KeyIDs. Unless TDH_EXT_MEM_ADD flushes them internally, later writeback of dirty KeyID-0 cachelines could corrupt encrypted extension memory or trigger #MC.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Edgecombe, Rick P
maintainerQuoted 15 lines · Jason Gunthorpe
Quoted 9 lines · Rick P
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Peter Fang
Sean suggested doing all of this quoting in the guest, with a new TDCALL. After some discussion [4] and a follow-up PUCK call on 9/23, the consensus was to go back to the host-based design and rely on the current GetQuote flow. Quotes signed directly by the S3M are out of scope for this series.
Quoted 4 lines
Quoted 2 lines
This would certainly match what the other architectures are doing, maybe explain a bit more why Intel has to be so much more complicated?
Heh, which complication in particular are you referring to here?
Quoted 7 lines
Well this entire 8 part series, a related VMM series to N VMMs, and a VMM/host API to carry it.
Vs.. None of that, like everyone else.
Naively the guest can call into TDX module just fine, so it is worth explaining why all this is needed, at least a little bit.
There is a lot of history on this already, as Peter linked. Here was an earlier writeup on that direction that might be a good jumping off point:
https://lore.kernel.org/kvm/[email protected]/
SNP obviously has a much different model on the platform. I guess you are thinking about ARM? TBH I don't know how their attestation works. If it is different it would be useful to know why.
Re: [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote
In reply to Peter Fangarch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2591
Quoted 5 lines · Peter Fang
arch/x86/virt/vmx/tdx/tdx.c +5
-0+/* Populate the linked list. Allocate new nodes as needed. */ +for (int i =0 , pages =0 ; pages < num_quote_pages; + i = (i +1 ) %HPAS_PER_NODE ) { +if (i ==HPAS_PER_NODE -1 ) { +u64 *new_node =kmalloc (PAGE_SIZE ,GFP_KERNEL );
Did a human write this code?
Do the humans on cc like this code?
Re: [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote
In reply to Peter FangQuoted 32 lines · Peter Fang
arch/x86/virt/vmx/tdx/tdx.c +32
-0+int tdx_quote_generate (struct tdx_td *td,u16 session_id, +struct page *report_page,u64 report_size, +struct page **quote_pages,u64 quote_buf_size, +u64 *quote_size,u64 *seamcall_err) +{ +int num_quote_pages, num_nodes, ret =0 ; +u64 *node_head, *node_entry; +u64 r; + +/* +* Pass the quote buffer to the TDX module as an HPA linked list. Each +* node holds 4KB page HPAs and the last entry points to the next node. +*/ + node_head =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!node_head) +return -ENOMEM ; + + node_entry = node_head; + num_quote_pages =PFN_UP (quote_buf_size); + num_nodes =1 ; + +/* Populate the linked list. Allocate new nodes as needed. */ +for (int i =0 , pages =0 ; pages < num_quote_pages; + i = (i +1 ) %HPAS_PER_NODE ) { +if (i ==HPAS_PER_NODE -1 ) { +u64 *new_node =kmalloc (PAGE_SIZE ,GFP_KERNEL ); + +if (!new_node) { + ret = -ENOMEM ; + goto out_free_nodes; + } +
arch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2607
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+/* Write the 'next' pointer. */ + node_entry[i] =__pa (new_node); + node_entry = new_node; + num_nodes++; +continue ; + } + + node_entry[i] =page_to_phys (quote_pages[pages]); + pages++; + }
TDX HPA_LINKED_LIST format is used also by TDX Live Migration, so it needs to be separate from quote functions.
Edgecombe, Rick P
maintainerRe: [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote
In reply to Dave HansenQuoted 10 lines · Dave Hansen
arch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2591
Quoted 5 lines · Peter Fang
arch/x86/virt/vmx/tdx/tdx.c +5
-0+/* Populate the linked list. Allocate new nodes as needed. */ +for (int i =0 , pages =0 ; pages < num_quote_pages; + i = (i + 1) % HPAS_PER_NODE) { +if (i ==HPAS_PER_NODE -1 ) { +u64 *new_node =kmalloc (PAGE_SIZE ,GFP_KERNEL );Did a human write this code?
Do the humans on cc like this code?
Oh this is horrible. Was the intention to address this from Nikolay?
https://lore.kernel.org/lkml/[email protected]/#t
I don't think this is what he meant, but actually I'm not sure what he did.
Edgecombe, Rick P
maintainerRe: [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote
In reply to Adrian HunterQuoted 38 lines · Adrian Hunter
Quoted 37 lines · Peter Fang
arch/x86/virt/vmx/tdx/tdx.c +37
-0+int tdx_quote_generate (struct tdx_td *td,u16 session_id, + struct page *report_page, u64 report_size, + struct page **quote_pages, u64 quote_buf_size, + u64 *quote_size, u64 *seamcall_err) +{ +int num_quote_pages, num_nodes, ret =0 ; +u64 *node_head, *node_entry; +u64 r; + +/* +* Pass the quote buffer to the TDX module as an HPA linked list. Each +* node holds 4KB page HPAs and the last entry points to the next node. +*/ + node_head =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!node_head) +return -ENOMEM ; + + node_entry = node_head; + num_quote_pages =PFN_UP (quote_buf_size); + num_nodes =1 ; + +/* Populate the linked list. Allocate new nodes as needed. */ +for (int i =0 , pages =0 ; pages < num_quote_pages; + i = (i + 1) % HPAS_PER_NODE) { +if (i ==HPAS_PER_NODE -1 ) { +u64 *new_node =kmalloc (PAGE_SIZE ,GFP_KERNEL ); + +if (!new_node) { + ret = -ENOMEM ; + goto out_free_nodes; + } + +/* Write the 'next' pointer. */ + node_entry[i] =__pa (new_node); + node_entry = new_node; + num_nodes++; +continue ;
Quoted 8 lines
arch/x86/virt/vmx/tdx/tdx.c void tdx_free_control_page(struct page *page) · line 2607
Quoted 5 lines
arch/x86/virt/vmx/tdx/tdx.c +5
-0+ } + + node_entry[i] =page_to_phys (quote_pages[pages]); + pages++; + }TDX
HPA_LINKED_LISTformat is used also by TDX Live Migration, so it needs to be separate from quote functions.
No thanks. We can refactor when we get to the migration patches if appropriate when that stuff is getting reviewed.
Quoted 11 lines
Quoted 7 lines
Well this entire 8 part series, a related VMM series to N VMMs, and a VMM/host API to carry it.
Vs.. None of that, like everyone else.
Naively the guest can call into TDX module just fine, so it is worth explaining why all this is needed, at least a little bit.
There is a lot of history on this already, as Peter linked. Here was an earlier writeup on that direction that might be a good jumping off point:
https://lore.kernel.org/kvm/[email protected]/
Ugh yikes, so lots of messy things in TDX design :\
Quoted 3 lines
SNP obviously has a much different model on the platform. I guess you are thinking about ARM? TBH I don't know how their attestation works. If it is different it would be useful to know why.
RMM in general allows the guest to be interrupted at any time, and when the guest calls for any operation via a RSI that operation runs in a vCPU context and it too can be interrupted. So the RMM has the ability to suspend itself and return to kvm to process the interrupt in the middle of its signature operation without causing any issues.
So never get the mess the above thread is exploring, there is no need for dedicated context slots, it just rides on the existing vCPU context.
I wonder how the nonce is securely transfered from the guest to the TDX module? I suppose it must get loaded into per-vm private memory and then read out when the host works on the signing...
Jason
Edgecombe, Rick P
maintainerQuoted 6 lines · Jason Gunthorpe
Quoted 6 lines
Quoted 5 lines
Vs.. None of that, like everyone else.
Naively the guest can call into TDX module just fine, so it is worth explaining why all this is needed, at least a little bit.
Quoted 6 lines
Quoted 4 lines
There is a lot of history on this already, as Peter linked. Here was an earlier
writeup on that direction that might be a good jumping off point:
https://lore.kernel.org/kvm/[email protected]/Ugh yikes, so lots of messy things in TDX design :\
Oh for sure! SGX based attestation is the original sin, but the lack of guest side calls are kind of an adjacent issue.
Quoted 10 lines
Quoted 4 lines
SNP obviously has a much different model on the platform. I guess you are thinking about ARM? TBH I don't know how their attestation works. If it is different it would be useful to know why.
RMM in general allows the guest to be interrupted at any time, and when the guest calls for any operation via a RSI that operation runs in a vCPU context and it too can be interrupted. So the RMM has the ability to suspend itself and return to kvm to process the interrupt in the middle of its signature operation without causing any issues.
That thread is basically explaining how TDX could do guest side calls as well and work for quoting. The TDX Extensions are interruptible like you are describing.
If you have the long running module operations running in the vCPU context, I'm not sure exactly what that would mean. You need to have guest context and module context and save/restore between them. So two contexts really. The only difference is whether you allocate both per guest vCPU and make them 1:1, or keep it a separate thing and share between vCPUs.
The 1:1 thing was considered for TDX and there is not a fundamental blocker. I think we arrived at the "leave it" approach after weighing a bunch of stuff including the legacy issues and future plans, etc. Not because TDX could not support it.
Quoted 4 lines
So never get the mess the above thread is exploring, there is no need for dedicated context slots, it just rides on the existing vCPU context.
It sounds like you didn't get to the part in the thread about S3M and direct "HW" attestation? These days you can probably dump the mbox into an AI and ask these questions, so I'll take this as a passing comment instead of request for more info. Please let me know if I got that wrong and we can get into it more.