tdx-guest: Make Quote buffer size dynamic
Subsystems (3)
v3 cover tdx-guest: Make Quote buffer size dynamic
Hi,
A new TDX module ABI provides the maximum attestation report size. This series changes the TDX guest driver's report buffer size from a fixed constant to that queried value. So effectively:
s/FIXED_BUF_SIZE/queried_buf_size/g
...in the TDX guest driver.
Terminology
===========
A "TD Quote" is an attestation structure signed with a platform key. It contains information about a TDX guest and the platform it's running on.
The "Quote buffer" in the TDX guest driver is a memory buffer shared between the TDX guest and the host VMM to retrieve TD Quotes. It has a header defined in the GHCI spec [1].
Device Identifier Composition Engine ("DICE") provides a framework for layering attestation evidence. This replaces the SGX model of contacting an Intel server to obtain a certificate.
Problem
=======
The fixed-size Quote buffer approach is not sustainable. As cryptographic algorithms evolve, TD Quote sizes also grow. A previous commit [2] increased the guest driver's fixed-size Quote buffer to 128 KB to accommodate DICE Quotes, but it may still be insufficient when those Quotes use post-quantum cryptography (PQC). PQC certificate chains are roughly 10x-15x larger than conventional ones, which can increase Quote sizes significantly.
What's in this series
=====================
To avoid changing the driver whenever the Quote buffer becomes too small, newer TDX modules report their maximum Quote size via a metadata field. The guest driver uses this value for its Quote buffer when available. Older TDX modules continue to use the 128 KB buffer.
Patches 2 and 3 refactor the existing fixed buffer handling. Patch 4 then makes the buffer size dynamic.
The "outblob" file in configfs-tsm no longer has a fixed maximum size. The limit can now come from this new TDX module ABI.
Patch 1/4: Add a helper to read the QUOTE_MAX_SIZE metadata field. Patch 2/4: Calculate the Quote buffer size with struct_size_t(). Patch 3/4: Store the Quote buffer size in a variable instead of a
constant.
Patch 4/4: Allocate the Quote buffer using the queried size, when
available.
AI use
======
I used Claude:claude-opus-4-8 to help edit this cover letter and the changelogs, and to collect the review feedback on lore. The series also underwent AI code review (Claude:claude-opus-4-7), but its comments were limited to style suggestions.
v2: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Split the v2 "Allocate Quote buffer dynamically" patch to do the refactoring first, then make the buffer size dynamic. [Dave]
- Improve patterns for readability. [Dave]
- Drop __GFP_NOWARN so an allocation failure warns. [Dave, Rick, Kiryl]
- Add Binbin's Reviewed-by to patch 1.
- Drop the Reviewed-by tags (Kiryl, Binbin) as the patch was reworked.
v1: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Collect Reviewed-by tags. [Kiryl, Xiaoyao, Binbin, Sathya]
- Keep the explicit (u32) cast in tdx_get_max_quote_size(). [Binbin]
- Calculate the Quote buffer size with struct_size_t(). [Kiryl, Binbin]
- Add __GFP_NOWARN to the allocation since its size comes from the host. [sashiko]
- Rename quote_data_size to quote_data_len. [Sathya]
- Drop the Assisted-by tags, as AI was not used to write the code.
[1] Guest Hypervisor Communication Interface (GHCI) Specification, Version 1.5, Section "TDG.VP.VMCALL<GetQuote>"
[2] 43185067c6fd ("configfs-tsm-report: tdx_guest: Increase Quote buffer
size to 128KB")
Kuppuswamy Sathyanarayanan (1):
virt: tdx-guest: Allocate Quote buffer dynamically
Peter Fang (3):
x86/tdx: Add helper to query maximum TD Quote size
virt: tdx-guest: Calculate the Quote buffer size safely
virt: tdx-guest: Use a variable to store the Quote buffer size
arch/x86/coco/tdx/tdx.c | 19 ++++++++++ arch/x86/include/asm/shared/tdx.h | 1 + arch/x86/include/asm/tdx.h | 2 ++ drivers/virt/coco/tdx-guest/tdx-guest.c | 46 ++++++++++++++++++------- 4 files changed, 55 insertions(+), 13 deletions(-)
base-commit: f5098b6bae761e346ebcd9da7f95622c04733cff
Signature · 1 line
2.53.0
PATCH v3 1/4 x86/tdx: Add helper to query maximum TD Quote size
TDX attestation report ("Quote") sizes can grow with newer cryptographic schemes, so guests can no longer rely on a fixed-size buffer for the Quote.
Newer TDX modules report the maximum Quote size via a TD-scope metadata field. Add a helper to query the size instead of exposing tdg_vm_rd() directly, as it can read arbitrary metadata fields.
Thanks to Xu Yilun for suggesting this in an off-list discussion.
---
v3:
- No code changes. Add Binbin's Reviewed-by.
v2:
- Keep the explicit (u32) cast to document the metadata field width. [Binbin]
- Note that Xu Yilun's suggestion was made in an off-list discussion. [Sathya]
- Drop the Assisted-by tags, as the code was not written by AI.
--- arch/x86/coco/tdx/tdx.c | 19 +++++++++++++++++++ arch/x86/include/asm/shared/tdx.h | 1 + arch/x86/include/asm/tdx.h | 2 ++ 3 files changed, 22 insertions(+)
arch/x86/coco/tdx/tdx.c +19 -0
@@ -198,6 +198,25 @@ u64 tdx_hcall_get_quote(u8 *buf, size_t size) }EXPORT_SYMBOL_GPL (tdx_hcall_get_quote); +/** +* tdx_get_max_quote_size() - Get the maximum TD Quote size +* +* Read the maximum size of a TD Quote from a 4-byte TD metadata field. The TDX +* guest driver uses it to size the buffer for Quote retrieval. Older TDX +* modules do not support this field and return an error. +* +* Return: Maximum Quote size in bytes on success, or 0 on failure. +*/ +u32 tdx_get_max_quote_size (void ) +{ +u64 val, ret; + + ret =tdg_vm_rd (TDCS_QUOTE_MAX_SIZE , &val); + +return ret ?0 : (u32 )val; +} +EXPORT_SYMBOL_GPL (tdx_get_max_quote_size); +static void __noreturn tdx_panic (const char *msg) {struct tdx_module_args args = {
arch/x86/include/asm/shared/tdx.h +1 -0
@@ -50,6 +50,7 @@/* TDX TD-Scope Metadata. To be used by TDG.VM.WR and TDG.VM.RD */ #define TDCS_CONFIG_FLAGS 0x1110000300000016#define TDCS_TD_CTLS 0x1110000300000017 +#define TDCS_QUOTE_MAX_SIZE 0x9010000200000008#define TDCS_NOTIFY_ENABLES 0x9100000000000010#define TDCS_TOPOLOGY_ENUM_CONFIGURED 0x9100000000000019
arch/x86/include/asm/tdx.h +2 -0
@@ -83,6 +83,8 @@ int tdx_mcall_extend_rtmr(u8 index, u8 *data);u64 tdx_hcall_get_quote (u8 *buf,size_t size); +u32 tdx_get_max_quote_size (void ); +void __init tdx_dump_attributes (u64 td_attr);void __init tdx_dump_td_ctls (u64 td_ctls);
Signature · 1 line
2.53.0
PATCH v3 3/4 virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangIn preparation for dynamic Quote buffer sizes, replace the fixed size constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
---
v3:
- Split out using a variable for the buffer size from the v2 "Allocate Quote buffer dynamically" patch to refactor first. [Dave]
- Pass the buffer size into alloc_quote_buf() by value. [Dave]
- Drop the Reviewed-by tags from v2 (Kiryl, Binbin) as the patch was reworked.
--- drivers/virt/coco/tdx-guest/tdx-guest.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/virt/coco/tdx-guest/tdx-guest.c +11 -11
@@ -191,8 +191,9 @@ struct tdx_quote_buf {u8 data[]; }; -/* Quote data buffer */ +/* Quote data buffer and length */ static void *quote_data; +static size_t quote_data_len;/* Lock to streamline quote requests */ static DEFINE_MUTEX (quote_lock);
@@ -209,9 +210,8 @@ static long tdx_get_report0(struct tdx_report_req __user *req) USER_SOCKPTR(req->tdreport)); } -static void free_quote_buf (void *buf) +static void free_quote_buf (void *buf,size_t len) { -size_t len =PAGE_ALIGN (GET_QUOTE_BUF_SIZE );unsigned int count = len >>PAGE_SHIFT ;if (set_memory_encrypted ((unsigned long )buf, count)) {
@@ -222,9 +222,8 @@ static void free_quote_buf(void *buf)free_pages_exact (buf, len); } -static void *alloc_quote_buf (void ) +static void *alloc_quote_buf (size_t len) { -size_t len =PAGE_ALIGN (GET_QUOTE_BUF_SIZE );unsigned int count = len >>PAGE_SHIFT ;void *addr;
@@ -285,7 +284,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)if (desc->inblob_len !=TDX_REPORTDATA_LEN )return -EINVAL ; -memset (quote_data,0 ,GET_QUOTE_BUF_SIZE ); +memset (quote_data,0 , quote_data_len);/* Update Quote buffer header */ quote_buf->version =GET_QUOTE_CMD_VER ;
@@ -296,7 +295,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)if (ret)return ret; - err =tdx_hcall_get_quote (quote_data,GET_QUOTE_BUF_SIZE ); + err =tdx_hcall_get_quote (quote_data, quote_data_len);if (err) {pr_err ("GetQuote hypercall failed, status:%llx\n" , err);return -EIO ;
@@ -315,7 +314,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data) out_len =READ_ONCE (quote_buf->out_len); -if (TDX_QUOTE_BUF_LEN (out_len) >GET_QUOTE_BUF_SIZE ) +if (TDX_QUOTE_BUF_LEN (out_len) > quote_data_len)return -EFBIG ; buf =kvmemdup (quote_buf->data, out_len,GFP_KERNEL );
@@ -417,7 +416,8 @@ static int __init tdx_guest_init(void)if (ret) goto deinit_mr; - quote_data =alloc_quote_buf (); + quote_data_len =GET_QUOTE_BUF_SIZE ; + quote_data =alloc_quote_buf (quote_data_len);if (!quote_data) {pr_err ("Failed to allocate Quote buffer\n" ); ret = -ENOMEM ;
@@ -431,7 +431,7 @@ static int __init tdx_guest_init(void)return 0 ; free_quote: -free_quote_buf (quote_data); +free_quote_buf (quote_data, quote_data_len); free_misc:misc_deregister (&tdx_misc_dev); deinit_mr:
@@ -444,7 +444,7 @@ module_init(tdx_guest_init); static void __exit tdx_guest_exit(void) {tsm_report_unregister (&tdx_tsm_ops); -free_quote_buf (quote_data); +free_quote_buf (quote_data, quote_data_len);misc_deregister (&tdx_misc_dev);tdx_mr_deinit (tdx_attr_groups[0 ]); }
Signature · 1 line
2.53.0
PATCH v3 4/4 virt: tdx-guest: Allocate Quote buffer dynamically
In reply to Peter FangFrom: Kuppuswamy Sathyanarayanan <[email protected]>
A new TDX module ABI reports the TD Quote size limit in a metadata field. This size used to be fixed at 128 KB.
The guest driver's Quote buffer is shared with the host VMM. The current fixed size may be too small for Quotes using schemes such as post-quantum cryptography (PQC), where larger certificate chains can increase the Quote size significantly.
Allocate the Quote buffer based on the reported limit. This avoids wasting memory on platforms that do not require larger Quotes. Older platforms fall back to the default 128 KB buffer.
As a result, the maximum size of the "outblob" file in configfs-tsm now depends on the TDX module.
Because the Quote buffer must be physically contiguous, its size is bound by the buddy allocator's maximum page order (4 MB), which should be sufficient for current attestation needs.
---
v3:
- Split out from the v2 "Allocate Quote buffer dynamically" patch. Add the dynamic buffer feature on top of the refactoring. [Dave]
- Improve the get_quote_buf_size() pattern for better readability. [Dave]
- Drop __GFP_NOWARN so an allocation failure warns. [Dave, Rick, Kiryl]
- Drop the Reviewed-by tags from v2 (Kiryl, Binbin) as the patch was reworked.
--- drivers/virt/coco/tdx-guest/tdx-guest.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/virt/coco/tdx-guest/tdx-guest.c +22 -2
@@ -162,7 +162,7 @@ static void tdx_mr_deinit(const struct attribute_group *mr_grp)* DICE-based attestation uses layered evidence that requires * larger Quote size (~100K). */ -#define GET_QUOTE_BUF_SIZE SZ_128K +#define GET_QUOTE_DEFAULT_BUF_SIZE SZ_128K#define GET_QUOTE_CMD_VER 1
@@ -222,11 +222,31 @@ static void free_quote_buf(void *buf, size_t len)free_pages_exact (buf, len); } +/* Return a buffer size large enough to hold a Quote */ +static size_t get_quote_buf_size (void ) +{ +u32 quote_size =tdx_get_max_quote_size (); + +/* +* Older TDX modules do not report a maximum Quote size, so use +* the default. +*/ +if (!quote_size) +return GET_QUOTE_DEFAULT_BUF_SIZE ; + +/* The reported size does not include the buffer header */ +return PAGE_ALIGN (TDX_QUOTE_BUF_LEN (quote_size)); +} +static void *alloc_quote_buf (size_t len) {unsigned int count = len >>PAGE_SHIFT ;void *addr; +/* +* This fails if the requested size exceeds the buddy allocator's +* maximum order (order-10, 4MB). +*/ addr =alloc_pages_exact (len,GFP_KERNEL | __GFP_ZERO);if (!addr)return NULL ;
@@ -416,7 +436,7 @@ static int __init tdx_guest_init(void)if (ret) goto deinit_mr; - quote_data_len =GET_QUOTE_BUF_SIZE ; + quote_data_len =get_quote_buf_size (); quote_data =alloc_quote_buf (quote_data_len);if (!quote_data) {pr_err ("Failed to allocate Quote buffer\n" );
Signature · 1 line
2.53.0
PATCH v3 2/4 virt: tdx-guest: Calculate the Quote buffer size safely
In reply to Peter Fangstruct tdx_quote_buf has a trailing flexible array member. struct_size_t() calculates the size of this kind of struct safely. It handles overflow, which is an important property since the Quote size comes from the host.
Use it in place of the fixed length limit.
---
v3:
- Split out the use of struct_size_t() for buffer length from the v2 "Allocate Quote buffer dynamically" patch to refactor first. [Dave]
- Drop the Reviewed-by tags from v2 (Kiryl, Binbin) as the patch was reworked.
--- drivers/virt/coco/tdx-guest/tdx-guest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virt/coco/tdx-guest/tdx-guest.c +2 -2
@@ -170,7 +170,7 @@ static void tdx_mr_deinit(const struct attribute_group *mr_grp)#define GET_QUOTE_SUCCESS 0#define GET_QUOTE_IN_FLIGHT 0xffffffffffffffff -#define TDX_QUOTE_MAX_LEN (GET_QUOTE_BUF_SIZE - sizeof(struct tdx_quote_buf)) +#define TDX_QUOTE_BUF_LEN (n) struct_size_t(struct tdx_quote_buf, data, n)/* struct tdx_quote_buf: Format of Quote request buffer. * @version: Quote format version, filled by TD.
@@ -315,7 +315,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data) out_len =READ_ONCE (quote_buf->out_len); -if (out_len >TDX_QUOTE_MAX_LEN ) +if (TDX_QUOTE_BUF_LEN (out_len) >GET_QUOTE_BUF_SIZE )return -EFBIG ; buf =kvmemdup (quote_buf->data, out_len,GFP_KERNEL );
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically
In reply to Peter FangThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Untrusted VMM input TDCS_QUOTE_MAX_SIZE is passed directly to the page allocator without bounding and without __GFP_NOWARN, which can trigger a kernel warning (WARN_ON_ONCE) and panic the guest if panic_on_warn is set.
Pre-existing issues:
- [High] Pre-existing UAF/Use-After-Unload race condition if module initialization fails after registering the misc device. --
--- Patch [4]: [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically --- commit 25802a377289c67ad6c07c5b41f81b3b9c799fbe
Author: Kuppuswamy Sathyanarayanan <[email protected]>
virt: tdx-guest: Allocate Quote buffer dynamically
This commit modifies the TDX guest driver to dynamically allocate the Quote buffer based on a size reported by the TDX module, replacing a fixed 128KB allocation. It removes the __GFP_NOWARN flag to ensure allocation failures produce a warning.
Quoted 4 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +0
-0
[ ... ]
Quoted 20 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +16
-0@@ -222,11 +222,31 @@ static void free_quote_buf(void *buf, size_t len)free_pages_exact (buf, len); } +/* Return a buffer size large enough to hold a Quote */ +static size_t get_quote_buf_size (void ) +{ +u32 quote_size =tdx_get_max_quote_size (); + +/* +* Older TDX modules do not report a maximum Quote size, so use +* the default. +*/ +if (!quote_size) +return GET_QUOTE_DEFAULT_BUF_SIZE ; + +/* The reported size does not include the buffer header */ +return PAGE_ALIGN (TDX_QUOTE_BUF_LEN (quote_size)); +} +
drivers/virt/coco/tdx-guest/tdx-guest.c static void free_quote_buf(void *buf, size_t len) · line 250
Quoted 10 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +4
-0static void *alloc_quote_buf (size_t len) {unsigned int count = len >>PAGE_SHIFT ;void *addr; +/* +* This fails if the requested size exceeds the buddy allocator's +* maximum order (order-10, 4MB). +*/ addr =alloc_pages_exact (len,GFP_KERNEL | __GFP_ZERO);
[Severity: High]
Does this allow an untrusted VMM to trigger a guest panic?
Since tdx_get_max_quote_size() reads the TDCS_QUOTE_MAX_SIZE metadata field, an untrusted host could supply a value that causes get_quote_buf_size() to return a length where get_order(size) > MAX_PAGE_ORDER.
Because the __GFP_NOWARN flag was removed, passing this unvalidated size to alloc_pages_exact() will trigger a WARN_ON_ONCE inside the page allocator.
If the guest boots with panic_on_warn=1, this gives the VMM a trivial denial of service.
Should the calculated size be clamped to a safe maximum before calling alloc_pages_exact(), or should the __GFP_NOWARN flag be retained?
Quoted 2 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +0
-0if (!addr)return NULL ;
[ ... ]
drivers/virt/coco/tdx-guest/tdx-guest.c static int __init tdx_guest_init(void) · line 442
Quoted 9 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +1
-1@@ -416,7 +436,7 @@ static int __init tdx_guest_init(void)if (ret) goto deinit_mr; - quote_data_len =GET_QUOTE_BUF_SIZE ; + quote_data_len =get_quote_buf_size (); quote_data =alloc_quote_buf (quote_data_len);if (!quote_data) {pr_err ("Failed to allocate Quote buffer\n" );
[Severity: High]
This is a pre-existing issue, but does this allocation failure path leave a window for a use-after-free or use-after-unload race?
The tdx_guest_init() function calls misc_register() just before attempting to allocate the quote buffer.
If alloc_quote_buf() fails, it will jump to the error path and call misc_deregister().
However, misc_deregister() does not revoke active open file descriptors. If a concurrent userspace process opens the misc device between registration and the allocation failure, it can execute ioctls after the module initialization fails.
This can result in accessing freed memory or executing unloaded code.
Since alloc_quote_buf() can now attempt larger allocations up to 4MB, it seems much more likely to fail.
Should misc_register() be moved to the end of the initialization sequence to prevent userspace from accessing a partially initialized device?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] wait_for_quote_completion timeout logic is inverted due to an off-by-one error in the loop condition. --
--- Patch [3]: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size --- commit 0a36558aa4f35238ff748cfc6efbe53e1e0e02ea
Author: Peter Fang <[email protected]>
virt: tdx-guest: Use a variable to store the Quote buffer size
This commit replaces the fixed GET_QUOTE_BUF_SIZE constant with a dynamic variable to prepare for future dynamic Quote buffer sizes. All users of the buffer size have been updated to read from this new variable.
Quoted 4 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +0
-0
[ ... ]
Quoted 18 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +2
-2@@ -285,7 +284,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)if (desc->inblob_len !=TDX_REPORTDATA_LEN )return -EINVAL ; -memset (quote_data,0 ,GET_QUOTE_BUF_SIZE ); +memset (quote_data,0 , quote_data_len);/* Update Quote buffer header */ quote_buf->version =GET_QUOTE_CMD_VER ;@@ -296,7 +295,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)if (ret)return ret; - err =tdx_hcall_get_quote (quote_data,GET_QUOTE_BUF_SIZE ); + err =tdx_hcall_get_quote (quote_data, quote_data_len);if (err) {pr_err ("GetQuote hypercall failed, status:%llx\n" , err);return -EIO ;
Quoted 1 line
}
[Severity: High]
This is a pre-existing issue, but while reviewing this code I noticed a logic flaw in wait_for_quote_completion() which is called immediately after this hypercall.
drivers/virt/coco/tdx-guest/tdx-guest.c:wait_for_quote_completion() {
...
while (quote_buf->status == GET_QUOTE_IN_FLIGHT && i++ < timeout) {
if (msleep_interruptible(MSEC_PER_SEC))
return -EINTR;
}
return (i == timeout) ? -ETIMEDOUT : 0;
}Does this timeout condition return the correct value?
Due to the post-increment in i++ < timeout, if the loop actually times out, i becomes timeout + 1. This causes i == timeout to evaluate to false and incorrectly return 0 (success).
Conversely, if the quote succeeds exactly on the last iteration, short-circuiting leaves i == timeout true, which would incorrectly return -ETIMEDOUT and cause a valid quote to be rejected.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v3 2/4] virt: tdx-guest: Calculate the Quote buffer size safely
In reply to Peter FangHi,
Quoted 7 lines · Peter Fang
struct
tdx_quote_bufhas a trailing flexible array member.struct_size_t()calculates the size of this kind of struct safely. It handles overflow, which is an important property since the Quote size comes from the host.Use it in place of the fixed length limit.
Quoted 8 lines
Signed-off-by Peter Fang <[email protected]>---
v3:
- Split out the use ofstruct_size_t()for buffer length from the v2 "Allocate Quote buffer dynamically" patch to refactor first. [Dave]
- Drop the Reviewed-by tags from v2 (Kiryl, Binbin) as the patch was reworked.
---
Quoted 25 lines
drivers/virt/coco/tdx-guest/tdx-guest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/virt/coco/tdx-guest/tdx-guest.c +2
-2@@ -170,7 +170,7 @@ static void tdx_mr_deinit(const struct attribute_group *mr_grp)#define GET_QUOTE_SUCCESS 0#define GET_QUOTE_IN_FLIGHT 0xffffffffffffffff -#define TDX_QUOTE_MAX_LEN (GET_QUOTE_BUF_SIZE - sizeof(struct tdx_quote_buf)) +#define TDX_QUOTE_BUF_LEN (n) struct_size_t(struct tdx_quote_buf, data, n)/* struct tdx_quote_buf: Format of Quote request buffer. * @version: Quote format version, filled by TD. @@ -315,7 +315,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data) out_len =READ_ONCE (quote_buf->out_len); -if (out_len >TDX_QUOTE_MAX_LEN ) +if (TDX_QUOTE_BUF_LEN (out_len) >GET_QUOTE_BUF_SIZE )return -EFBIG ; buf =kvmemdup (quote_buf->data, out_len,GFP_KERNEL );
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux Kernel Developer
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangQuoted 1 line · Peter Fang
In preparation for dynamic Quote buffer sizes, replace the fixed size
sizes -> size?
Quoted 4 lines
constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
You are also dropping PAGE_ALIGN() in alloc and free calls. You can mention it in commit log.
Quoted 3 lines
Signed-off-by Peter Fang <[email protected]>---
Quoted 102 lines
v3:
- Split out using a variable for the buffer size from the v2 "Allocate Quote buffer dynamically" patch to refactor first. [Dave]
- Pass the buffer size intoalloc_quote_buf()by value. [Dave]
- Drop the Reviewed-by tags from v2 (Kiryl, Binbin) as the patch was reworked.--- drivers/virt/coco/tdx-guest/tdx-guest.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)drivers/virt/coco/tdx-guest/tdx-guest.c +11
-11@@ -191,8 +191,9 @@ struct tdx_quote_buf {u8 data[]; }; -/* Quote data buffer */ +/* Quote data buffer and length */ static void *quote_data; +static size_t quote_data_len;/* Lock to streamline quote requests */ static DEFINE_MUTEX (quote_lock);@@ -209,9 +210,8 @@ static long tdx_get_report0(struct tdx_report_req __user *req) USER_SOCKPTR(req->tdreport)); } -static void free_quote_buf (void *buf) +static void free_quote_buf (void *buf,size_t len) { -size_t len =PAGE_ALIGN (GET_QUOTE_BUF_SIZE );unsigned int count = len >>PAGE_SHIFT ;if (set_memory_encrypted ((unsigned long )buf, count)) {@@ -222,9 +222,8 @@ static void free_quote_buf(void *buf)free_pages_exact (buf, len); } -static void *alloc_quote_buf (void ) +static void *alloc_quote_buf (size_t len) { -size_t len =PAGE_ALIGN (GET_QUOTE_BUF_SIZE );unsigned int count = len >>PAGE_SHIFT ;void *addr;@@ -285,7 +284,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)if (desc->inblob_len !=TDX_REPORTDATA_LEN )return -EINVAL ; -memset (quote_data,0 ,GET_QUOTE_BUF_SIZE ); +memset (quote_data,0 , quote_data_len);/* Update Quote buffer header */ quote_buf->version =GET_QUOTE_CMD_VER ;@@ -296,7 +295,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)if (ret)return ret; - err =tdx_hcall_get_quote (quote_data,GET_QUOTE_BUF_SIZE ); + err =tdx_hcall_get_quote (quote_data, quote_data_len);if (err) {pr_err ("GetQuote hypercall failed, status:%llx\n" , err);return -EIO ;@@ -315,7 +314,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data) out_len =READ_ONCE (quote_buf->out_len); -if (TDX_QUOTE_BUF_LEN (out_len) >GET_QUOTE_BUF_SIZE ) +if (TDX_QUOTE_BUF_LEN (out_len) > quote_data_len)return -EFBIG ; buf =kvmemdup (quote_buf->data, out_len,GFP_KERNEL );@@ -417,7 +416,8 @@ static int __init tdx_guest_init(void)if (ret) goto deinit_mr; - quote_data =alloc_quote_buf (); + quote_data_len =GET_QUOTE_BUF_SIZE ; + quote_data =alloc_quote_buf (quote_data_len);if (!quote_data) {pr_err ("Failed to allocate Quote buffer\n" ); ret = -ENOMEM ;@@ -431,7 +431,7 @@ static int __init tdx_guest_init(void)return 0 ; free_quote: -free_quote_buf (quote_data); +free_quote_buf (quote_data, quote_data_len); free_misc:misc_deregister (&tdx_misc_dev); deinit_mr:@@ -444,7 +444,7 @@ module_init(tdx_guest_init); static void __exit tdx_guest_exit(void) {tsm_report_unregister (&tdx_tsm_ops); -free_quote_buf (quote_data); +free_quote_buf (quote_data, quote_data_len);misc_deregister (&tdx_misc_dev);tdx_mr_deinit (tdx_attr_groups[0 ]); }
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux Kernel Developer
Edgecombe, Rick P
maintainerQuoted 10 lines · Peter Fang
Problem
=======The fixed-size Quote buffer approach is not sustainable. As cryptographic algorithms evolve, TD Quote sizes also grow. A previous commit [2] increased the guest driver's fixed-size Quote buffer to 128 KB to accommodate DICE Quotes, but it may still be insufficient when those Quotes use post-quantum cryptography (PQC). PQC certificate chains are roughly 10x-15x larger than conventional ones, which can increase Quote sizes significantly.
For the DICE host changes, the reason given for why the host side quote operation is TD scoped was to avoid changing the guest by increasing the report size. But actually, as this coverletter points out, the guest buffer sizes do get changed. So I think we should pause this series until we sort out the inconsistencies in the reasoning. Depending, we may want to circle back with KVM folks on what the options actually are for the DICE quote operation.
Edgecombe, Rick P
maintainerSean, Dave, Kiryl,
In PUCK we talked about how the TD scoped quote operation avoids changes in the guest. But this series is actually changing the guest, so is somewhat at odds to that assertion. It turns out there are some tradeoffs here that also connect to TDX migration uAPI. Please see below for an explanation and recommended course of action.
As a gentle recall helper... The general attestation flow converts a report to a quote, which then gets checked by a verifier. The report is like a snapshot of the guest and its environment. The quote is a signed version of the report plus hardware certs. It's signed with a hardware key and can use different kinds of crypto.
These pieces are evolving to handle a few problems at once:
- The stuff that needs to be attested is growing. Basically more platform details and devices are getting added to the blobs.
- The crypto stuff is growing. The post quantum crypto stuff is large, etc. That stuff lives in the quote.
- Migration wants a quote that is platform specific and not TD specific.
Because the platform details are growing, they need to either go into a larger report or added later via a TD scoped quote. But the post quantum crypto stuff is going to bloat the quote either way.
If the report grows to include all the TD specific details, then the QUOTE seamcall can be platform scoped because all the details that it needs are passed in as args.
But if it is TD scoped, the report can stay the same size and the extra details can just be added during the quote operation. For migration, it only needs a platform scoped quote. If there are extra details about a specific TD, the migration stuff can be fine to just ignore them. (i.e. it can get what it needs from TD scoped quotes or platform scoped quotes).
The current QUOTE seamcall supports both: platform scoped and TD scoped operations. But since we could get by with either only a platform or TD scoped seamcall for both operations, we could reduce the kernel's uAPIs, or change the API's location. Per recent discussion, Sean sees TD scoped APIs living in KVM and platform scoped things living in the host driver/tip. So all that leaves us with something like this:
|Normal quote |Migration quote |Report size|Quote size|uAPI location | -|----------------|----------------|-----------|----------|---------------| 1|Platform scoped |Platform scoped |Grows |Grows |TDX host driver| 2|TD scoped |TD scoped |Fixed |Grows |KVM | 3|TD scoped |Platform scoped |Fixed |Grows |Both |
I'm thinking we should proceed with 2 because only the quote size changes. So less guest changes over time. 3 is not really a disaster either, but we shouldn't need 2 uABIs. For 1, from early discussion it seems it can be made to work but sounds like it will require some more extensive changes to the TDX attestation stuff. So probably needs a bit more investigation before we can say it won't disturb some other VMM vendor, etc.
Sean Christopherson
reviewerQuoted 42 lines · Rick P Edgecombe
Sean, Dave, Kiryl,
In PUCK we talked about how the TD scoped quote operation avoids changes in the guest. But this series is actually changing the guest, so is somewhat at odds to that assertion. It turns out there are some tradeoffs here that also connect to TDX migration uAPI. Please see below for an explanation and recommended course of action.
As a gentle recall helper... The general attestation flow converts a report to a quote, which then gets checked by a verifier. The report is like a snapshot of the guest and its environment. The quote is a signed version of the report plus hardware certs. It's signed with a hardware key and can use different kinds of crypto.
These pieces are evolving to handle a few problems at once:
- The stuff that needs to be attested is growing. Basically more platform details and devices are getting added to the blobs.
- The crypto stuff is growing. The post quantum crypto stuff is large, etc. That stuff lives in the quote.
- Migration wants a quote that is platform specific and not TD specific.Because the platform details are growing, they need to either go into a larger report or added later via a TD scoped quote. But the post quantum crypto stuff is going to bloat the quote either way.
If the report grows to include all the TD specific details, then the QUOTE seamcall can be platform scoped because all the details that it needs are passed in as args.
But if it is TD scoped, the report can stay the same size and the extra details can just be added during the quote operation. For migration, it only needs a platform scoped quote. If there are extra details about a specific TD, the migration stuff can be fine to just ignore them. (i.e. it can get what it needs from TD scoped quotes or platform scoped quotes).
The current QUOTE seamcall supports both: platform scoped and TD scoped operations. But since we could get by with either only a platform or TD scoped seamcall for both operations, we could reduce the kernel's uAPIs, or change the API's location. Per recent discussion, Sean sees TD scoped APIs living in KVM and platform scoped things living in the host driver/tip. So all that leaves us with something like this:
Quoted 3 lines
|Normal quote |Migration quote |Report size|Quote size|uAPI location | -|----------------|----------------|-----------|----------|---------------| 1|Platform scoped |Platform scoped |Grows |Grows |TDX host driver|
With my KVM hat on, this option looks very attractive.
And with the caveat that I'm most definitely not an attestation expert, from a separate of concerns perspective, IMO it seems like the report should contain the TD-specific information while the quote just wraps that information in platform- specific goo.
In other words, to me, TD-scoped quotes feel like a hack that was thrown in to avoid having to modify the guest because y'all didn't plan ahead.
Quoted 10 lines
2|TD scoped |TD scoped |Fixed |Grows |KVM | 3|TD scoped |Platform scoped |Fixed |Grows |Both |I'm thinking we should proceed with 2 because only the quote size changes. So less guest changes over time. 3 is not really a disaster either, but we shouldn't need 2 uABIs. For 1, from early discussion it seems it can be made to work but sounds like it will require some more extensive changes to the TDX attestation stuff. So probably needs a bit more investigation before we can say it won't disturb some other VMM vendor, etc.
Edgecombe, Rick P
maintainerQuoted 6 lines · Sean Christopherson
Quoted 3 lines
|Normal quote |Migration quote |Report size|Quote size|uAPI location | -|----------------|----------------|-----------|----------|---------------| 1|Platform scoped |Platform scoped |Grows |Grows |TDX host driver|With my KVM hat on, this option looks very attractive.
Quoted 7 lines
And with the caveat that I'm most definitely not an attestation expert, from a separate of concerns perspective, IMO it seems like the report should contain the TD-specific information while the quote just wraps that information in platform-specific goo.
In other words, to me, TD-scoped quotes feel like a hack that was thrown in to avoid having to modify the guest because y'all didn't plan ahead.
Caveman crypto person here too. It seems scattered and makes me similarly suspicious about some lack of planning. But I kind of came to a different conclusion on what went wrong.
It seems to me that from the overall solution level, the report should never have had the details in it. It should just be some nonce or some type of thing that can tie the guest request to the quote that it ends up getting back. Doesn't it seem weird to get a bunch of details from the TDX module, then pass them from the guest to host KVM to host userspace then back to the TDX module... which already had all those details?
My understanding was that the original SGX attestation was a complicator of the design of this stuff. Because I'm not sure that SGX had all those details about the TD. In fact I can't see how it could have. Is that right Peter? So it needs them all to be passed in. All the extra validations etc of this shuffling is TDX's problems to deal with, but for Linux, it would be at least a lot less confusing if there was not two things that have the TD details in them.
That said, from KVM POV, (1) kicks the attestation out of KVM. I see the benefit. But a TD quote is a TD scoped operation in concept. To me at least.
Sean Christopherson
reviewerQuoted 19 lines · Rick P Edgecombe
Quoted 6 lines · Sean Christopherson
Quoted 3 lines
|Normal quote |Migration quote |Report size|Quote size|uAPI location | -|----------------|----------------|-----------|----------|---------------| 1|Platform scoped |Platform scoped |Grows |Grows |TDX host driver|With my KVM hat on, this option looks very attractive.
Quoted 7 lines
And with the caveat that I'm most definitely not an attestation expert, from a separate of concerns perspective, IMO it seems like the report should contain the TD-specific information while the quote just wraps that information in platform-specific goo.
In other words, to me, TD-scoped quotes feel like a hack that was thrown in to avoid having to modify the guest because y'all didn't plan ahead.
Caveman crypto person here too. It seems scattered and makes me similarly suspicious about some lack of planning. But I kind of came to a different conclusion on what went wrong.
Quoted 6 lines
It seems to me that from the overall solution level, the report should never have had the details in it. It should just be some nonce or some type of thing that can tie the guest request to the quote that it ends up getting back. Doesn't it seem weird to get a bunch of details from the TDX module, then pass them from the guest to host KVM to host userspace then back to the TDX module... which already had all those details?
Hmm, my mental model of this is that the report contains the "real" payload, i.e. the metadata describing what is running and whatnot, while the quote effectively signs the payload to prove the provenance of the report. That's why I view the report as TD-specific (what's running) and the quote as platform-specific (provides root of trust).
Quoted 9 lines
My understanding was that the original SGX attestation was a complicator of the design of this stuff. Because I'm not sure that SGX had all those details about the TD. In fact I can't see how it could have. Is that right Peter? So it needs them all to be passed in. All the extra validations etc of this shuffling is TDX's problems to deal with, but for Linux, it would be at least a lot less confusing if there was not two things that have the TD details in them.
That said, from KVM POV, (1) kicks the attestation out of KVM. I see the benefit. But a TD quote is a TD scoped operation in concept. To me at least.
Edgecombe, Rick P
maintainerQuoted 7 lines · Sean Christopherson
Quoted 6 lines
It seems to me that from the overall solution level, the report should never have had the details in it. It should just be some nonce or some type of thing that can tie the guest request to the quote that it ends up getting back. Doesn't it seem weird to get a bunch of details from the TDX module, then pass them from the guest to host KVM to host userspace then back to the TDX module... which already had all those details?
Quoted 5 lines
Hmm, my mental model of this is that the report contains the "real" payload, i.e. the metadata describing what is running and whatnot, while the quote effectively signs the payload to prove the provenance of the report. That's why I view the report as TD-specific (what's running) and the quote as platform-specific (provides root of trust).
Argh. So I think I was not clear enough in the description. And hopefully Peter will appear soon and clarify this is all correct, because I'm relaying what he explained to me.
We think quote *operation* can be platform specific instead of TD specific if we want. Meaning the SEAMCALL isn't passed a TDR. But the bits that actually are in the resulting quote are TD specific. In other words, at least some of the bits in the report end up in the quote too. Those TD specific bits either come from the passed in report, or added later during the quote operation based on the TDX module's TD knowledge. Because of course the attestation needs to know about the TD details.
Or I guess... if we wanted to hand the report and quote to the verifier as separate payloads. Then... from my basic crypto understanding, it could work too. Is that your model? I think it would be a major change at least.
But part of this too, is that "DICE" is an industry standard [0]. Some of the existing TDX attestation format is TDX specific, and moving to the standard is expected to make the verifier better. So TDX does not have full flexibility in choosing which bits go where. There is some. But I'm not sure which.
I think I mentioned this, but what we experienced internally on this feature is that basic questions like "where should the quote uABI live" quickly spiral into a lot of TDX arch tradeoffs and legacy complications. I'll take it we should prove out (1) a bit more to get better clarity on if there are any snags.
[0] https://trustedcomputinggroup.org/resource/dice-attestation-architecture/
Quoted 19 lines · Rick P
Quoted 6 lines · Sean Christopherson
Quoted 3 lines
|Normal quote |Migration quote |Report size|Quote size|uAPI location | -|----------------|----------------|-----------|----------|---------------| 1|Platform scoped |Platform scoped |Grows |Grows |TDX host driver|With my KVM hat on, this option looks very attractive.
Quoted 7 lines
And with the caveat that I'm most definitely not an attestation expert, from a separate of concerns perspective, IMO it seems like the report should contain the TD-specific information while the quote just wraps that information in platform-specific goo.
In other words, to me, TD-scoped quotes feel like a hack that was thrown in to avoid having to modify the guest because y'all didn't plan ahead.
Caveman crypto person here too. It seems scattered and makes me similarly suspicious about some lack of planning. But I kind of came to a different conclusion on what went wrong.
Quoted 6 lines
It seems to me that from the overall solution level, the report should never have had the details in it. It should just be some nonce or some type of thing that can tie the guest request to the quote that it ends up getting back. Doesn't it seem weird to get a bunch of details from the TDX module, then pass them from the guest to host KVM to host userspace then back to the TDX module... which already had all those details?
Yeah this has been a source of much debate internally. I feel that the directions boil down to: is now a good opportunity to design something that's more future looking (like can scale better wrt future attestation needs) or is it better to keep the old SGX design a little longer...
Quoted 7 lines
My understanding was that the original SGX attestation was a complicator of the design of this stuff. Because I'm not sure that SGX had all those details about the TD. In fact I can't see how it could have. Is that right Peter? So it needs them all to be passed in. All the extra validations etc of this shuffling is TDX's problems to deal with, but for Linux, it would be at least a lot less confusing if there was not two things that have the TD details in them.
Yep this is correct IMO. Basically the report has lots of old SGX baggage.
Quoted 3 lines
That said, from KVM POV, (1) kicks the attestation out of KVM. I see the benefit. But a TD quote is a TD scoped operation in concept. To me at least.
Quoted 18 lines · Rick P
Quoted 7 lines · Sean Christopherson
Quoted 6 lines
It seems to me that from the overall solution level, the report should never have had the details in it. It should just be some nonce or some type of thing that can tie the guest request to the quote that it ends up getting back. Doesn't it seem weird to get a bunch of details from the TDX module, then pass them from the guest to host KVM to host userspace then back to the TDX module... which already had all those details?
Quoted 5 lines
Hmm, my mental model of this is that the report contains the "real" payload, i.e. the metadata describing what is running and whatnot, while the quote effectively signs the payload to prove the provenance of the report. That's why I view the report as TD-specific (what's running) and the quote as platform-specific (provides root of trust).
Argh. So I think I was not clear enough in the description. And hopefully Peter will appear soon and clarify this is all correct, because I'm relaying what he explained to me.
Quoted 7 lines
We think quote *operation* can be platform specific instead of TD specific if we want. Meaning the SEAMCALL isn't passed a TDR. But the bits that actually are in the resulting quote are TD specific. In other words, at least some of the bits in the report end up in the quote too. Those TD specific bits either come from the passed in report, or added later during the quote operation based on the TDX module's TD knowledge. Because of course the attestation needs to know about the TD details.
Yep this is correct.
The TDX module has knowledge of the TD itself (obviously)
So:
1. Do the SGX thing and still carry all the TD details in the report, and feed it back to the TDX module (big report, no TDR needed)
Or:
2. Stop doing that, and just let the module grab what it needs (small report, TDR needed)
Quoted 4 lines
Or I guess... if we wanted to hand the report and quote to the verifier as separate payloads. Then... from my basic crypto understanding, it could work too. Is that your model? I think it would be a major change at least.
Hmm actually I don't think it would work. Not if the quote is in DICE format (see below).
Quoted 5 lines
But part of this too, is that "DICE" is an industry standard [0]. Some of the existing TDX attestation format is TDX specific, and moving to the standard is expected to make the verifier better. So TDX does not have full flexibility in choosing which bits go where. There is some. But I'm not sure which.
In the SGX era, a lot of this attestation stuff was Intel proprietary and that caused a lot of pain. To follow the DICE standard the bits in the report have specific places to go inside the quote blob. IOW the DICE quote doesn't just carry the report like an attachment, and so the two can't be separated (not without breaking the standard in some way).
Quoted 7 lines
I think I mentioned this, but what we experienced internally on this feature is that basic questions like "where should the quote uABI live" quickly spiral into a lot of TDX arch tradeoffs and legacy complications. I'll take it we should prove out (1) a bit more to get better clarity on if there are any snags.
[0] https://trustedcomputinggroup.org/resource/dice-attestation-architecture/
Edgecombe, Rick P
maintainerQuoted 7 lines · Peter Fang
Quoted 6 lines
But part of this too, is that "DICE" is an industry standard [0]. Some of the existing TDX attestation format is TDX specific, and moving to the standard is expected to make the verifier better. So TDX does not have full flexibility in choosing which bits go where. There is some. But I'm not sure which.
Quoted 5 lines
In the SGX era, a lot of this attestation stuff was Intel proprietary and that caused a lot of pain. To follow the DICE standard the bits in the report have specific places to go inside the quote blob. IOW the DICE quote doesn't just carry the report like an attachment, and so the two can't be separated (not without breaking the standard in some way).
Yea that was my suspicion. I'm not sure if separating them was really Sean's understanding or not. But the other part is that the verifiers and other VMM infrastructures are already expecting this standard format. It would have a lot of downsides.
But the "grow the report" or "grow the report and quote" are still options that leave the quote in the expected DICE format, right? Sean I'll assume you still prefer the "grow both" option for the sake of kicking the quoting responsibilities out of KVM. If so, let's see if Dave can weigh in.
Sean Christopherson
reviewerQuoted 8 lines · Rick P Edgecombe
Quoted 7 lines · Peter Fang
Quoted 6 lines
But part of this too, is that "DICE" is an industry standard [0]. Some of the existing TDX attestation format is TDX specific, and moving to the standard is expected to make the verifier better. So TDX does not have full flexibility in choosing which bits go where. There is some. But I'm not sure which.
Quoted 8 lines
Quoted 5 lines
In the SGX era, a lot of this attestation stuff was Intel proprietary and that caused a lot of pain. To follow the DICE standard the bits in the report have specific places to go inside the quote blob. IOW the DICE quote doesn't just carry the report like an attachment, and so the two can't be separated (not without breaking the standard in some way).
Yea that was my suspicion. I'm not sure if separating them was really Sean's understanding or not.
LOL, most definitely not. Though I have a naive question at this point: why can't the TDX-Module extract the bits from the report and put them in the right places when generating the quote?
Quoted 7 lines
But the other part is that the verifiers and other VMM infrastructures are already expecting this standard format. It would have a lot of downsides.
But the "grow the report" or "grow the report and quote" are still options that leave the quote in the expected DICE format, right? Sean I'll assume you still prefer the "grow both" option for the sake of kicking the quoting responsibilities out of KVM.
Not necessarily. If doing the right thing from a "what's intended and sane" perspective is to put some quoting responsibilities on KVM, then so be it. But I would like to have a passing understanding of what all is going on, if only so that I can justify why the new uAPI is being added when I send Paolo a pull request. I'm pushing back purely because I quite literally don't understand why KVM needs to be involved.
Quoted 14 lines · Rick P
Quoted 7 lines · Peter Fang
Quoted 6 lines
But part of this too, is that "DICE" is an industry standard [0]. Some of the existing TDX attestation format is TDX specific, and moving to the standard is expected to make the verifier better. So TDX does not have full flexibility in choosing which bits go where. There is some. But I'm not sure which.
Quoted 5 lines
In the SGX era, a lot of this attestation stuff was Intel proprietary and that caused a lot of pain. To follow the DICE standard the bits in the report have specific places to go inside the quote blob. IOW the DICE quote doesn't just carry the report like an attachment, and so the two can't be separated (not without breaking the standard in some way).
Quoted 7 lines
Yea that was my suspicion. I'm not sure if separating them was really Sean's understanding or not. But the other part is that the verifiers and other VMM infrastructures are already expecting this standard format. It would have a lot of downsides.
But the "grow the report" or "grow the report and quote" are still options that leave the quote in the expected DICE format, right? Sean I'll assume you still
Yes, the final quote will be the same, in DICE format.
Quoted 2 lines
prefer the "grow both" option for the sake of kicking the quoting responsibilities out of KVM. If so, let's see if Dave can weigh in.
Edgecombe, Rick P
maintainerQuoted 6 lines · Sean Christopherson
Quoted 2 lines
Yea that was my suspicion. I'm not sure if separating them was really Sean's understanding or not.
LOL, most definitely not. Though I have a naive question at this point: why can't the TDX-Module extract the bits from the report and put them in the right places when generating the quote?
It totally can. If we do the platform scoped quote operation option, then we grow the report to include all the TD details. Then the quote operation would extract them from the TDX specific report and put them in their DICE quote location. It doesn't need to have its own access to the TD details. They come in the report.
This is what drives the fallout of growing the report in that option. And I guess defining some new report formats to hold the new stuff. But that is TDX's job to manage.
Quoted 11 lines
Quoted 8 lines
But the other part is that the verifiers and other VMM infrastructures are already expecting this standard format. It would have a lot of downsides.
But the "grow the report" or "grow the report and quote" are still options that leave the quote in the expected DICE format, right? Sean I'll assume you still prefer the "grow both" option for the sake of kicking the quoting responsibilities out of KVM.
Not necessarily. If doing the right thing from a "what's intended and sane" perspective is to put some quoting responsibilities on KVM, then so be it.
I think the only pure answer is go back in time and delete the SGX based attestation. Between the two options here I give "TD scoped quote" the narrow win. If you add in that we (Intel Linux TDX folks here) don't need to go push for changes to the module, then it's a clear win. But even without that, still a narrow win I think.
Quoted 4 lines
But I would like to have a passing understanding of what all is going on, if only so that I can justify why the new uAPI is being added when I send Paolo a pull request. I'm pushing back purely because I quite literally don't understand why KVM needs to be involved.
Totally makes sense. And I only entertained the wild "split them" idea because I don't see any harm in enumerating *all* the options. I have faith we will come to some reasonable decision.
Hmm, let me flag Artem to see if he can add anymore weight one way or the other from the migration POV.
Quoted 2 lines · Rick P
Hmm, let me flag Artem to see if he can add anymore weight one way or the other from the migration POV.
Hi,
I will just assume the question is: "Is a TD-scoped quote seamcall fundamentally wrong or acceptable?"
Short answer: I would say acceptable. I see it as a practical tradeoff.
Let me lay out my mental model, which should explain how I came to this conclusion.
Mental model
============
1. SGX-based attestation
The original SGX-style flow is two steps:
1. The TD gets TD report.
2. A quoting agent signs that report and produces the quote.
What is quoting agent: a process using a special SGX enclave.
Why 2-step: the key limitation is that the quoting agent cannot fetch TD evidence such as FW hash or other per-TD data. So the quote is conceptually:
- TD report body
- signature over the report body
- trust material such as the public attestation key and certificate chain
2. DICE-based attestation
The DICE-based model keeps the same two-step flow for compatibility, but the quoting service runs in the TDX module and can read TD evidence directly. As a result, the quote can include:
- TD report body
- extra per-TD evidence
- signature over the report body and the extra evidence
- trust material
IOW: in the SGX-based design, it is impossible to add TD evidence to the quote. In the DICE-based design, it is possible.
But the question is - OK, it is possible, but why should it be done?
3. Why freezing TD report size
Linux supports 1024-byte TD reports via the TDX_CMD_GET_REPORT0 ioctl. It is already full, no more TD evidence fits, and changing TD report size would require a new ioctl.
Also, as I understand it, based on TDX feature requests from customers, there may be a need to increase TD report size more often and more significantly than one would expect.
Therefore, for DICE-based attestation the TDX module adds new TD evidence in the quote instead of expanding the TD report.
Is this the cleanest approach? Maybe not. A clear separation of concern, with TD evidence in the report and the quote only adding signature and trust material, does feel cleaner.
But on the other hand:
- The quote itself is already a per-TD data structure
- The it is inherently variable size because it contains cryptographic material and trust data
- A fixed-size TD report means that at least one of them is fixed size, not both.
4. Migration-specific case
For the normal user attestation path, the TD report is TD-scoped. For migration, the report is effectively platform-scoped, just because the migration flow does not need TD-specific evidence.
I would say that clean design is when Linux does not need to know this and care about this specific case: be able to treat all TD reports as per-TD.
Thanks,
Artem.
Edgecombe, Rick P
maintainerQuoted 41 lines · Artem Bityutskiy
Mental model
============1. SGX-based attestation
The original SGX-style flow is two steps:
1. The TD gets TD report.
2. A quoting agent signs that report and produces the quote.What is quoting agent: a process using a special SGX enclave.
Why 2-step: the key limitation is that the quoting agent cannot fetch TD evidence such as FW hash or other per-TD data. So the quote is conceptually:
- TD report body
- signature over the report body
- trust material such as the public attestation key and certificate chain2. DICE-based attestation
The DICE-based model keeps the same two-step flow for compatibility, but the quoting service runs in the TDX module and can read TD evidence directly. As a result, the quote can include:
- TD report body
- extra per-TD evidence
- signature over the report body and the extra evidence
- trust materialIOW: in the SGX-based design, it is impossible to add TD evidence to the quote. In the DICE-based design, it is possible.
But the question is - OK, it is possible, but why should it be done?
3. Why freezing TD report size
Linux supports 1024-byte TD reports via the
TDX_CMD_GET_REPORT0ioctl. It is already full, no more TD evidence fits, and changing TD report size would require a new ioctl.
Quoted 9 lines
Also, as I understand it, based on TDX feature requests from customers, there may be a need to increase TD report size more often and more significantly than one would expect.
Therefore, for DICE-based attestation the TDX module adds new TD evidence in the quote instead of expanding the TD report.
Is this the cleanest approach? Maybe not.
I was thinking the cleanest, time-travel facilitated, approach would be to have the "report" really just be a replay protection thing and not include any TD details. Then the quote could add everything it needed in the final format location. So no re-verifying and shuffling things between formats. But since that didn't work for SGX based attestation, the report has extra stuff due to legacy. But from Linux's POV, going forward we can consider the report as really an oversized replay protection blob and forget about the TD details in it. Isn't it a pretty clean separation of concerns? And for Linux (guest), the benefit shows up in not having to increase TD report size since it has really only one job.
Quoted 13 lines
A clear separation of
concern, with TD evidence in the report and the quote only adding signature and trust material, does feel cleaner.But on the other hand:
- The quote itself is already a per-TD data structure
- The it is inherently variable size because it contains cryptographic material and trust data
- A fixed-size TD report means that at least one of them is fixed size, not both.4. Migration-specific case
Quoted 7 lines
For the normal user attestation path, the TD report is TD-scoped. For migration, the report is effectively platform-scoped, just because the migration flow does not need TD-specific evidence.
I would say that clean design is when Linux does not need to know this and care about this specific case: be able to treat all TD reports as per-TD.
I was hoping you could chime in about the thing you mentioned off-list regarding *when* the quote operation is needed for migration. As in, what stage of the TD lifecycle and how it fits into a KVM VM TD scoped ioctl.
Quoted 16 lines · Rick P
Quoted 6 lines
3. Why freezing TD report size
Linux supports 1024-byte TD reports via the
TDX_CMD_GET_REPORT0ioctl. It is already full, no more TD evidence fits, and changing TD report size would require a new ioctl.Quoted 9 lines
Also, as I understand it, based on TDX feature requests from customers, there may be a need to increase TD report size more often and more significantly than one would expect.
Therefore, for DICE-based attestation the TDX module adds new TD evidence in the quote instead of expanding the TD report.
Is this the cleanest approach? Maybe not.
Quoted 10 lines
I was thinking the cleanest, time-travel facilitated, approach would be to have the "report" really just be a replay protection thing and not include any TD details. Then the quote could add everything it needed in the final format location. So no re-verifying and shuffling things between formats. But since that didn't work for SGX based attestation, the report has extra stuff due to legacy. But from Linux's POV, going forward we can consider the report as really an oversized replay protection blob and forget about the TD details in it. Isn't it a pretty clean separation of concerns? And for Linux (guest), the benefit shows up in not having to increase TD report size since it has really only one job.
Replay attack protection is a binding value between the remote party and the final quote. It must sit in final quote. It only needs to exist in the TD report because of the 2-flow design.
But why DICE-based attestation uses 2-flow design? Could TD run a TDCALL[TDG.GET.QUOTE2] or something directly. No concept of TD report would be needed. That would be my current vision of "cleanest".
But the approach that was taken is to minimize software changes. Within that tradeoff, keeping the 2-step flow, preserving the TD report format and size absolutely intact, and adding the extra information in the quote is arguably a clean practical path.
Is this the cleanest in some absolute sense? No.
Is it acceptable? I would say yes.
Quoted 7 lines
Quoted 7 lines
4. Migration-specific case
For the normal user attestation path, the TD report is TD-scoped. For migration, the report is effectively platform-scoped, just because the migration flow does not need TD-specific evidence.
Quoted 7 lines
Quoted 3 lines
I would say that clean design is when Linux does not need to know this and care about this specific case: be able to treat all TD reports as per-TD.
I was hoping you could chime in about the thing you mentioned off-list regarding *when* the quote operation is needed for migration. As in, what stage of the TD lifecycle and how it fits into a KVM VM TD scoped ioctl.
The first step in TDX live migration is TDH.MIG.SETUP seamcall. It is called multiple times on both the source and destination hosts. The TDX module keeps the setup session state and drives the protocol by telling the VMM what to do next through exit codes.
Each call follows the same pattern:
1. The VMM calls TDH.MIG.SETUP for the source TD or the destination TD.
2. The TDX module reads the optional input buffer and may produce an output buffer.
3. The exit code tells the VMM what to do before the next call.
One of the possible exit codes is TDX_MIG_SETUP_GET_QUOTE. It means:
deliver me the quote. The output buffer contains the TD report.
The idea was to pass this directly to QEMU. QEMU would call the proposed "get quote" ioctl on the TD under migration, and provide the TD report from TDH.MIG.SETUP on ioctl input. QEMU would not need to care about the scope rules and would just treat the TD report as belonging to the TD under migration.
The ioctl would then run TDH.GET.QUOTE with TDR for the TD under migration. The seamcall would handle the scope logic internally. It would be an internal TDX module detail.
Did you mean this or something else?
Quoted 28 lines · Artem Bityutskiy
Quoted 16 lines · Rick P
Quoted 6 lines
3. Why freezing TD report size
Linux supports 1024-byte TD reports via the
TDX_CMD_GET_REPORT0ioctl. It is already full, no more TD evidence fits, and changing TD report size would require a new ioctl.Quoted 9 lines
Also, as I understand it, based on TDX feature requests from customers, there may be a need to increase TD report size more often and more significantly than one would expect.
Therefore, for DICE-based attestation the TDX module adds new TD evidence in the quote instead of expanding the TD report.
Is this the cleanest approach? Maybe not.
Quoted 10 lines
I was thinking the cleanest, time-travel facilitated, approach would be to have the "report" really just be a replay protection thing and not include any TD details. Then the quote could add everything it needed in the final format location. So no re-verifying and shuffling things between formats. But since that didn't work for SGX based attestation, the report has extra stuff due to legacy. But from Linux's POV, going forward we can consider the report as really an oversized replay protection blob and forget about the TD details in it. Isn't it a pretty clean separation of concerns? And for Linux (guest), the benefit shows up in not having to increase TD report size since it has really only one job.
Quoted 7 lines
Replay attack protection is a binding value between the remote party and the final quote. It must sit in final quote. It only needs to exist in the TD report because of the 2-flow design.
But why DICE-based attestation uses 2-flow design? Could TD run a TDCALL[TDG.GET.QUOTE2] or something directly. No concept of TD report would be needed. That would be my current vision of "cleanest".
Yeah, Rick talked about this a bit in an earlier thread [1].
[1] https://lore.kernel.org/kvm/[email protected]/
Quoted 9 lines
But the approach that was taken is to minimize software changes. Within that tradeoff, keeping the 2-step flow, preserving the TD report format and size absolutely intact, and adding the extra information in the quote is arguably a clean practical path.
Is this the cleanest in some absolute sense? No.
Is it acceptable? I would say yes.
Edgecombe, Rick P
maintainerQuoted 3 lines · Artem Bityutskiy
But why DICE-based attestation uses 2-flow design? Could TD run a TDCALL[TDG.GET.QUOTE2] or something directly. No concept of TD report would be needed. That would be my current vision of "cleanest".
We discussed this approach internally and in PUCK. The problem is there is a shared resource, and so something needs to handle locking and fairness between the guests. Going to the host keeps all the scheduling type stuff in that domain.
Quoted 1 line
Quoted 9 lines · Rick P
Quoted 3 lines · Artem Bityutskiy
But why DICE-based attestation uses 2-flow design? Could TD run a TDCALL[TDG.GET.QUOTE2] or something directly. No concept of TD report would be needed. That would be my current vision of "cleanest".
We discussed this approach internally and in PUCK. The problem is there is a shared resource, and so something needs to handle locking and fairness between the guests. Going to the host keeps all the scheduling type stuff in that domain.
Good point. I did not think about this aspect.
I am curious if today this is an attestation-only problem or a pattern. I mean this "many TDs compete for a shared TDX capability, VMM needs to be involved to handle fairness".
Thanks, Artem.
Edgecombe, Rick P
maintainerQuoted 12 lines · Artem Bityutskiy
Quoted 10 lines · Rick P
Quoted 3 lines · Artem Bityutskiy
But why DICE-based attestation uses 2-flow design? Could TD run a TDCALL[TDG.GET.QUOTE2] or something directly. No concept of TD report would be needed. That would be my current vision of "cleanest".
We discussed this approach internally and in PUCK. The problem is there is a shared resource, and so something needs to handle locking and fairness between
the guests. Going to the host keeps all the scheduling type stuff in that domain.
Quoted 6 lines
Good point. I did not think about this aspect.
I am curious if today this is an attestation-only problem or a pattern. I mean this "many TDs compete for a shared TDX capability, VMM needs to be involved to handle fairness".
Yea, I think it is a really good question. This is getting off topic now, but...
There is an existing issue we have with the "host priority" (HP) bit. This is a part of the TDX arch that is designed to help with guest host contention. For example a TDG call like ACCEPT can take an S-EPT lock that the host wants to also take with a TDH call. It is sort of important to have the host be in ultimate control. So the way the HP bit works is, if the host meets contention, it sets the HP bit. The bit means if the guest tries to take the lock again, it is blocked without letting the lock get taken. This gives the host a chance to retry and succeed. After the host succeeds in taking the lock, the HP bit is cleared. This is like a crude fairness thing.
But it all depends on the host retrying. If the host never retries because userspace intervenes, then the guest stays locked out. We actually hit this condition in the tdx mmu stress selftest. So it is on the to-do list to fix in TDX arch.
Now how this connects to the 1-flow vs 2-flow design... As we have been discussing this quote/report stuff, I wondered if we couldn't solve the HP bit problems with a similar 2-flow thing. For example a TDG.ACCEPT call could exit to the host without taking any locks and providing some kind of token, that a paired TDH call could be used to complete the accept (and take the locks). TDH calls should not be able to accept guest memory arbitrarily, so there needs to be some kind of security validation on the TDH call. But then the host could control all the scheduling/priority stuff. The overall solution would be better for having this locking balancing stuff done in a single place where there are no odd overlaps. But it means we also have extra host code for every TDG call that takes a problematic lock. Probably more TDX module complexity too.
So yea, I wonder too if we could make this a general pattern.
Quoted 7 lines · Rick P
Quoted 4 lines
I am curious if today this is an attestation-only problem or a pattern. I mean this "many TDs compete for a shared TDX capability, VMM needs to be involved to handle fairness".
Yea, I think it is a really good question. This is getting off topic now, but...
Quoted 9 lines
There is an existing issue we have with the "host priority" (HP) bit. This is a part of the TDX arch that is designed to help with guest host contention. For example a TDG call like ACCEPT can take an S-EPT lock that the host wants to also take with a TDH call. It is sort of important to have the host be in ultimate control. So the way the HP bit works is, if the host meets contention, it sets the HP bit. The bit means if the guest tries to take the lock again, it is blocked without letting the lock get taken. This gives the host a chance to retry and succeed. After the host succeeds in taking the lock, the HP bit is cleared. This is like a crude fairness thing.
Thanks. Yes, sounds crude, and it does not look like it covers fairness across TDs. It only covers the "VMM has priority" part.
Quoted 4 lines
But it all depends on the host retrying. If the host never retries because userspace intervenes, then the guest stays locked out. We actually hit this condition in the tdx mmu stress selftest. So it is on the to-do list to fix in TDX arch.
I see, the VMM not making progress blocks TDs which could make progress otherwise. Thanks for the info.
TDX specs describe the HP_LOCK_TIMEOUT per-TD property (set by the host via TDH.MNG.WR), which could be used to somewhat make the symptom somewhat controllable, may be make pain less painful, but it is not a cure for the illness.
Quoted 11 lines
Now how this connects to the 1-flow vs 2-flow design... As we have been discussing this quote/report stuff, I wondered if we couldn't solve the HP bit problems with a similar 2-flow thing. For example a TDG.ACCEPT call could exit to the host without taking any locks and providing some kind of token, that a paired TDH call could be used to complete the accept (and take the locks). TDH calls should not be able to accept guest memory arbitrarily, so there needs to be some kind of security validation on the TDH call. But then the host could control all the scheduling/priority stuff. The overall solution would be better for having this locking balancing stuff done in a single place where there are no odd overlaps. But it means we also have extra host code for every TDG call that takes a problematic lock. Probably more TDX module complexity too.
Yeah. We have TDG.VP.VMCALL as an "exit to the VMM and let it handle stuff" capability.
So essentially you are pointing out that one of the approaches is turning a problematic
TDCALL[TDG.ABRA.CADABRA]
into a
TDCALL[TDG.VP.VMCALL]<AbraCadabra>.
I guess this approach could be used in few selected cases.
Thanks!
Sean Christopherson
reviewerQuoted 10 lines · Artem Bityutskiy
IOW: in the SGX-based design, it is impossible to add TD evidence to the quote. In the DICE-based design, it is possible.
But the question is - OK, it is possible, but why should it be done?
3. Why freezing TD report size
Linux supports 1024-byte TD reports via the
TDX_CMD_GET_REPORT0ioctl. It is already full, no more TD evidence fits, and changing TD report size would require a new ioctl.
So instead of adding new uAPI for the guest, TDX adds new uAPI to KVM? That's not a very compelling argument.
Quoted 3 lines
Also, as I understand it, based on TDX feature requests from customers, there may be a need to increase TD report size more often and more significantly than one would expect.
Who cares? And I mean that literally, i.e. "who" as in "what chunk of code is negatively affected if the TD report size changes". "GET" ioctls whose payloads have varying size aren't novel, nor are they particularly difficult to implement or work with. What's so bad about adding e.g. TDX_CMD_GET_REPORT0_2 to allow for a variable sized payload and any other mistakes we made with TDX_CMD_GET_REPORT0?
Quoted 7 lines
Therefore, for DICE-based attestation the TDX module adds new TD evidence in the quote instead of expanding the TD report.
Is this the cleanest approach? Maybe not. A clear separation of concern, with TD evidence in the report and the quote only adding signature and trust material, does feel cleaner.
Quoted 6 lines
But on the other hand:
- The quote itself is already a per-TD data structure
- The it is inherently variable size because it contains cryptographic material and trust data
- A fixed-size TD report means that at least one of them is fixed size, not both.
Taking this argument a step further, why even have a TD report? If DICE-based attestation can "add evidence" at quote-time, then just throw away the separate report entirely.
Quoted 3 lines
4. Migration-specific case
For the normal user attestation path, the TD report is TD-scoped. For
That's not a TD report. Call it whatever you want, but it's not a report about a TD. If the claim is that "TD" can mean something other than a TDX VM, depending on the context, then that needs to stop, because there is no way anyone is going to be able to follow along.
Quoted 6 lines
migration, the report is effectively platform-scoped, just because the migration flow does not need TD-specific evidence.
I would say that clean design is when Linux does not need to know this and care about this specific case: be able to treat all TD reports as per-TD.
Edgecombe, Rick P
maintainerQuoted 8 lines · Sean Christopherson
Quoted 5 lines
3. Why freezing TD report size
Linux supports 1024-byte TD reports via the
TDX_CMD_GET_REPORT0ioctl. It is already full, no more TD evidence fits, and changing TD report size would require a new ioctl.So instead of adding new uAPI for the guest, TDX adds new uAPI to KVM? That's not a very compelling argument.
I agree this is a weak point. The freezing of the TD report size is only a very minor benefit that results in less guest changes. I was treating it as a tie breaker level thing.
The reason to not do the quote as a TDG call is to let the host control contention on the quote resource (s3m, etc). And if we exit out to the host, adding a host uAPI (KVM or not) lets userspace decide which quoter to use. And keeps the quote exit working as before.
Just want to call your attention to some discussion on how far we might want to take this "kick out to have the host manage contention" pattern, if we want to resolve other guest locking headaches:
https://lore.kernel.org/kvm/[email protected]/
snip
Quoted 14 lines
Quoted 7 lines
Therefore, for DICE-based attestation the TDX module adds new TD evidence in the quote instead of expanding the TD report.
Is this the cleanest approach? Maybe not. A clear separation of concern, with TD evidence in the report and the quote only adding signature and trust material, does feel cleaner.
Quoted 6 lines
But on the other hand:
- The quote itself is already a per-TD data structure
- The it is inherently variable size because it contains cryptographic material and trust data
- A fixed-size TD report means that at least one of them is fixed size, not both.
Quoted 3 lines
Taking this argument a step further, why even have a TD report? If DICE-based attestation can "add evidence" at quote-time, then just throw away the separate report entirely.
I think the folks in this thread have converged on that if you did the whole thing over without SGX, you don't need a report. But you do still need to pass something from the guest to the quoter so that the guest can know that the generated quote it gets back is for itself and not some other TD. (Or some other extra guest call to check the quote after you get it I guess) A nonce only "report" is just like the report in that it is some bytes of data that the guest doesn't look at, but just without the TD details in it.
So given that we have SGX legacy stuff, leaving the report alone and having a TD scoped quote (KVM based API) is quite similar to throwing the report away. If you totally unsupported the ability to do SGX attestation, then you would only end up with a smaller blob to pass out instead of a 1KB blob. In the end it's not a huge difference, so might as well leave it able to work with SGX attestation.
But how can we close this, at this point? This is all being hashed out on the list now, but the hashing out is long and scattered. It may be inefficient for you to extract the minimum critical points to decide. We could do a more condensed writeup for you and Paolo to review?
Hi Sean,
This was just discussed off-list, thanks for guidance. I only will comment on one thing below.
Quoted 4 lines · Sean Christopherson
That's not a TD report. Call it whatever you want, but it's not a report about a TD. If the claim is that "TD" can mean something other than a TDX VM, depending on the context, then that needs to stop, because there is no way anyone is going to be able to follow along.
Oh, right, Now that you point it out, it seems obvious.
We called it "TD report" because it uses the same data structure as the TD report, only without the "TD information" sub-structure. But no doubt this is poor terminology.
Thanks,
Artem.
Quoted 12 lines · Rick P
Quoted 10 lines · Peter Fang
Problem
=======The fixed-size Quote buffer approach is not sustainable. As cryptographic algorithms evolve, TD Quote sizes also grow. A previous commit [2] increased the guest driver's fixed-size Quote buffer to 128 KB to accommodate DICE Quotes, but it may still be insufficient when those Quotes use post-quantum cryptography (PQC). PQC certificate chains are roughly 10x-15x larger than conventional ones, which can increase Quote sizes significantly.
Quoted 4 lines
For the DICE host changes, the reason given for why the host side quote operation is TD scoped was to avoid changing the guest by increasing the report size. But actually, as this coverletter points out, the guest buffer sizes do get changed. So I think we should pause this series until we sort out the
This thread has led to a lot of great discussion, and I think perhaps we can resume reviewing this series? The main open topics now seem to be the guest report and potential alternatives to GetQuote, but none of them change the fact that the quote size is growing as crypto stuff evolves... So this series applies to all the options on the table right now.
Quoted 2 lines
inconsistencies in the reasoning. Depending, we may want to circle back with KVM folks on what the options actually are for the DICE quote operation.
Edgecombe, Rick P
maintainerQuoted 6 lines · Peter Fang
Quoted 5 lines
For the DICE host changes, the reason given for why the host side quote operation is TD scoped was to avoid changing the guest by increasing the report size. But actually, as this coverletter points out, the guest buffer sizes do get changed. So I think we should pause this series until we sort out the
Quoted 6 lines
This thread has led to a lot of great discussion, and I think perhaps we can resume reviewing this series? The main open topics now seem to be the guest report and potential alternatives to GetQuote, but none of them change the fact that the quote size is growing as crypto stuff evolves... So this series applies to all the options on the table right now.
Yep, makes sense. Dynamic quotes sizes make sense regardless of how we end up getting them. Be it bigger for PQC, or smaller for regular flavor.
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Kuppuswamy SathyanarayananQuoted 6 lines · Kuppuswamy Sathyanarayanan
Quoted 1 line · Peter Fang
In preparation for dynamic Quote buffer sizes, replace the fixed size
sizes -> size?
Ack.
Quoted 8 lines
Quoted 5 lines
constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
You are also dropping
PAGE_ALIGN()in alloc and free calls. You can mention it in commit log.
Good catch. I will add this next time.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Peter Fang <[email protected]>---
Reviewed-by Kuppuswamy Sathyanarayanan <[email protected]>
Thanks Sathya!
Quoted 2 lines
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to [email protected]Quoted 5 lines · On Wed, Jul 29, 2026 at 12:58:28PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High]wait_for_quote_completiontimeout logic is inverted due to an off-by-one error in the loop condition. --
This was already reported by Adrian Hunter and is on my todo list [1].
[1] https://lore.kernel.org/all/20260614115016.GA3417767@pedri/
Quoted 1 line
Re: [PATCH v3 2/4] virt: tdx-guest: Calculate the Quote buffer size safely
In reply to Peter FangQuoted 8 lines · Peter Fang
struct
tdx_quote_bufhas a trailing flexible array member.struct_size_t()calculates the size of this kind of struct safely. It handles overflow, which is an important property since the Quote size comes from the host.Use it in place of the fixed length limit.
Signed-off-by Peter Fang <[email protected]>
Quoted 32 lines
---
v3:
- Split out the use ofstruct_size_t()for buffer length from the v2 "Allocate Quote buffer dynamically" patch to refactor first. [Dave]
- Drop the Reviewed-by tags from v2 (Kiryl, Binbin) as the patch was reworked.--- drivers/virt/coco/tdx-guest/tdx-guest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/virt/coco/tdx-guest/tdx-guest.c +2
-2@@ -170,7 +170,7 @@ static void tdx_mr_deinit(const struct attribute_group *mr_grp)#define GET_QUOTE_SUCCESS 0#define GET_QUOTE_IN_FLIGHT 0xffffffffffffffff -#define TDX_QUOTE_MAX_LEN (GET_QUOTE_BUF_SIZE - sizeof(struct tdx_quote_buf)) +#define TDX_QUOTE_BUF_LEN (n) struct_size_t(struct tdx_quote_buf, data, n)/* struct tdx_quote_buf: Format of Quote request buffer. * @version: Quote format version, filled by TD. @@ -315,7 +315,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data) out_len =READ_ONCE (quote_buf->out_len); -if (out_len >TDX_QUOTE_MAX_LEN ) +if (TDX_QUOTE_BUF_LEN (out_len) >GET_QUOTE_BUF_SIZE )return -EFBIG ; buf =kvmemdup (quote_buf->data, out_len,GFP_KERNEL );
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangQuoted 2 lines · Peter Fang
You are also dropping
PAGE_ALIGN()in alloc and free calls. You can mention it in commit log.
I think it's better to keep the PAGE_ALIGN() when assign quote_data_len, although GET_QUOTE_BUF_SIZE is aligned already. This makes it super clear we want to page size align the buffer.
And in next patch, we can make it
quote_data_len = PAGE_ALIGN(get_quote_buf_size());
Re: [PATCH v3 1/4] x86/tdx: Add helper to query maximum TD Quote size
In reply to Peter FangQuoted 7 lines · Peter Fang
arch/x86/coco/tdx/tdx.c +7
-0+/** +* tdx_get_max_quote_size() - Get the maximum TD Quote size +* +* Read the maximum size of a TD Quote from a 4-byte TD metadata field. The TDX +* guest driver uses it to size the buffer for Quote retrieval. Older TDX +* modules do not support this field and return an error. +*
arch/x86/coco/tdx/tdx.c u64 tdx_hcall_get_quote(u8 *buf, size_t size) · line 217
Quoted 10 lines
arch/x86/coco/tdx/tdx.c +10
-0+* Return: Maximum Quote size in bytes on success, or 0 on failure. +*/ +u32 tdx_get_max_quote_size (void ) +{ +u64 val, ret; + + ret =tdg_vm_rd (TDCS_QUOTE_MAX_SIZE , &val); + +return ret ?0 : (u32 )val; +}
I think you can leave out the u32 cast above.
Other than that:
Re: [PATCH v3 2/4] virt: tdx-guest: Calculate the Quote buffer size safely
In reply to Peter FangQuoted 6 lines · Peter Fang
struct
tdx_quote_bufhas a trailing flexible array member.struct_size_t()calculates the size of this kind of struct safely. It handles overflow, which is an important property since the Quote size comes from the host.Use it in place of the fixed length limit.
Re: [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically
In reply to Peter FangQuoted 11 lines · Peter Fang
A new TDX module ABI reports the TD Quote size limit in a metadata field. This size used to be fixed at 128 KB.
The guest driver's Quote buffer is shared with the host VMM. The current fixed size may be too small for Quotes using schemes such as post-quantum cryptography (PQC), where larger certificate chains can increase the Quote size significantly.
Allocate the Quote buffer based on the reported limit. This avoids wasting memory on platforms that do not require larger Quotes. Older platforms fall back to the default 128 KB buffer.
I think we need to justify why using the value reported by TDX module (i.e., QUOTE_MAX_SIZE) is safe.
From "Intel TDX Module Extension for Quoting" spec,
QUOTE_MAX_SIZE that specifies the maximum size of the buffer that must be allocated to contain the Intel TDX Quote received from Intel TDX Module.
So, TDX module only guarantees that QUOTE_MAX_SIZE is big enough to hold the quote that is generated by the TDX module. But for the current tdx guest driver, it doesn't know how host will generate the quote. Host can generate the SGX-based quote and we need to justify the QUOTE_MAX_SIZE will be enough for such case.
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangQuoted 5 lines · Peter Fang
In preparation for dynamic Quote buffer sizes, replace the fixed size constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
...
drivers/virt/coco/tdx-guest/tdx-guest.c static int __init tdx_guest_init(void) · line 423
Quoted 12 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +2
-1@@ -417,7 +416,8 @@ static int __init tdx_guest_init(void)if (ret) goto deinit_mr; - quote_data =alloc_quote_buf (); + quote_data_len =GET_QUOTE_BUF_SIZE ; + quote_data =alloc_quote_buf (quote_data_len);if (!quote_data) {pr_err ("Failed to allocate Quote buffer\n" ); ret = -ENOMEM ;
I assume the quote_data_len does not need to change after init because of a TDX module update. So:
Re: [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically
In reply to Xiaoyao LiQuoted 18 lines · Xiaoyao Li
Quoted 11 lines · Peter Fang
A new TDX module ABI reports the TD Quote size limit in a metadata field. This size used to be fixed at 128 KB.
The guest driver's Quote buffer is shared with the host VMM. The current fixed size may be too small for Quotes using schemes such as post-quantum cryptography (PQC), where larger certificate chains can increase the Quote size significantly.
Allocate the Quote buffer based on the reported limit. This avoids wasting memory on platforms that do not require larger Quotes. Older platforms fall back to the default 128 KB buffer.
I think we need to justify why using the value reported by TDX module (i.e.,
QUOTE_MAX_SIZE) is safe.From "Intel TDX Module Extension for Quoting" spec,
Quoted 8 lines
QUOTE_MAX_SIZEthat specifies the maximum size of the buffer that must be allocated to contain the Intel TDX Quote received from Intel TDX Module.So, TDX module only guarantees that
QUOTE_MAX_SIZEis big enough to hold the quote that is generated by the TDX module. But for the current tdx guest driver, it doesn't know how host will generate the quote. Host can generate the SGX-based quote and we need to justify theQUOTE_MAX_SIZEwill be enough for such case.
And can we assume the TDX module provided size does not change after init with a TDX module update?
Re: [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically
In reply to [email protected]Quoted 5 lines · On Wed, Jul 29, 2026 at 12:55:23PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Untrusted VMM inputTDCS_QUOTE_MAX_SIZEis passed directly to the page allocator without bounding and without__GFP_NOWARN, which can trigger a kernel warning (WARN_ON_ONCE) and panic the guest ifpanic_on_warnis set.
This was discussed in v2 [1][2]. __GFP_NOWARN doesn't make sense here.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/amCv00f5Q6QlztyY@thinkstation/
Quoted 3 lines
Pre-existing issues:
- [High] Pre-existing UAF/Use-After-Unload race condition if module initialization fails after registering the misc device. --
Sashiko reported this in v2 [3]. Added to my todo list.
[3] https://lore.kernel.org/all/20260727101350.GB482062@pedri/
Quoted 1 line
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangQuoted 7 lines · Peter Fang
In preparation for dynamic Quote buffer sizes, replace the fixed size constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
Signed-off-by Peter Fang <[email protected]>
Quoted 16 lines
---
v3:
- Split out using a variable for the buffer size from the v2 "Allocate Quote buffer dynamically" patch to refactor first. [Dave]
- Pass the buffer size intoalloc_quote_buf()by value. [Dave]
- Drop the Reviewed-by tags from v2 (Kiryl, Binbin) as the patch was reworked.--- drivers/virt/coco/tdx-guest/tdx-guest.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)drivers/virt/coco/tdx-guest/tdx-guest.c +0
-0
drivers/virt/coco/tdx-guest/tdx-guest.c struct tdx_quote_buf { · line 196
Quoted 7 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +2
-1@@ -191,8 +191,9 @@ struct tdx_quote_buf {u8 data[]; }; -/* Quote data buffer */ +/* Quote data buffer and length */ static void *quote_data; +static size_t quote_data_len;
Nit:
The existing code is using "quote_data", it's natural to follow the style. I personally feel the var names are a bit ambiguous on whether it's the full quote buffer or just the data part.
Re: [PATCH v3 2/4] virt: tdx-guest: Calculate the Quote buffer size safely
In reply to Peter FangQuoted 8 lines · Peter Fang
struct
tdx_quote_bufhas a trailing flexible array member.struct_size_t()calculates the size of this kind of struct safely. It handles overflow, which is an important property since the Quote size comes from the host.Use it in place of the fixed length limit.
Signed-off-by Peter Fang <[email protected]>
Re: [PATCH v3 1/4] x86/tdx: Add helper to query maximum TD Quote size
In reply to Tony LindgrenQuoted 21 lines · Tony Lindgren
Quoted 7 lines · Peter Fang
arch/x86/coco/tdx/tdx.c +7
-0+/** +* tdx_get_max_quote_size() - Get the maximum TD Quote size +* +* Read the maximum size of a TD Quote from a 4-byte TD metadata field. The TDX +* guest driver uses it to size the buffer for Quote retrieval. Older TDX +* modules do not support this field and return an error. +* arch/x86/coco/tdx/tdx.c u64 tdx_hcall_get_quote(u8 *buf, size_t size) · line 217
Quoted 10 lines
arch/x86/coco/tdx/tdx.c +10
-0+* Return: Maximum Quote size in bytes on success, or 0 on failure. +*/ +u32 tdx_get_max_quote_size (void ) +{ +u64 val, ret; + + ret =tdg_vm_rd (TDCS_QUOTE_MAX_SIZE , &val); + +return ret ?0 : (u32 )val; +}I think you can leave out the u32 cast above.
Quoted 3 lines
Other than that:
Reviewed-by Tony Lindgren <[email protected]>
Thanks Tony! This was discussed previously [1] and Binbin pointed out that this makes the field width more explicit:
[1] https://lore.kernel.org/all/20260714055421.GB3178326@pedri/
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Xiaoyao LiQuoted 11 lines · Xiaoyao Li
Quoted 2 lines · Peter Fang
You are also dropping
PAGE_ALIGN()in alloc and free calls. You can mention it in commit log.I think it's better to keep the
PAGE_ALIGN()when assignquote_data_len, althoughGET_QUOTE_BUF_SIZEis aligned already. This makes it super clear we want to page size align the buffer.And in next patch, we can make it
quote_data_len = PAGE_ALIGN(get_quote_buf_size());
Hmm... Looking at this again actually makes me think it could be reworked a bit. There's a discrepancy in alloc_quote_buf() if for whatever reason @len is not page aligned. alloc_pages_exact() rounds it up internally but set_memory_decrypted() rounds it *down*, so we'd end up with a useless page at the end...
What if alloc_quote_buf() took a @npages instead? Then the expectations would be pretty clear:
-static void *alloc_quote_buf(void) +static unsigned int get_quote_buf_npages(void) +{
+ u32 quote_size = tdx_get_max_quote_size();
+ size_t len;
+
+ if (quote_size)
+ len = TDX_QUOTE_BUF_LEN(quote_size);
+ else
+ len = GET_QUOTE_DEFAULT_BUF_SIZE;
+
+ return PFN_UP(len);
+}
+
+static void *alloc_quote_buf(unsigned int npages)
{
- size_t len = PAGE_ALIGN(GET_QUOTE_BUF_SIZE);
- unsigned int count = len >> PAGE_SHIFT;
void *addr; - addr = alloc_pages_exact(len, GFP_KERNEL | __GFP_ZERO);
+ addr = alloc_pages_exact(PAGE_SIZE * npages, GFP_KERNEL | __GFP_ZERO);
if (!addr)
return NULL; - if (set_memory_decrypted((unsigned long)addr, count))
+ if (set_memory_decrypted((unsigned long)addr, npages))
return NULL;
return addr;}
static int __init tdx_guest_init(void)
{
...
- quote_data = alloc_quote_buf();
+ quote_data_npages = get_quote_buf_npages();
+ quote_data = alloc_quote_buf(quote_data_npages);
if (!quote_data) {
...
}
}Does this look better to you?
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Tony LindgrenQuoted 23 lines · Tony Lindgren
Quoted 5 lines · Peter Fang
In preparation for dynamic Quote buffer sizes, replace the fixed size constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
...
drivers/virt/coco/tdx-guest/tdx-guest.c static int __init tdx_guest_init(void) · line 423
Quoted 12 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +2
-1@@ -417,7 +416,8 @@ static int __init tdx_guest_init(void)if (ret) goto deinit_mr; - quote_data =alloc_quote_buf (); + quote_data_len =GET_QUOTE_BUF_SIZE ; + quote_data =alloc_quote_buf (quote_data_len);if (!quote_data) {pr_err ("Failed to allocate Quote buffer\n" ); ret = -ENOMEM ;I assume the
quote_data_lendoes not need to change after init because of a TDX module update. So:
Quoted 1 line
Reviewed-by Tony Lindgren <[email protected]>
Yep true. Thanks Tony!
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Binbin WuQuoted 10 lines · Binbin Wu
Quoted 7 lines · Peter Fang
In preparation for dynamic Quote buffer sizes, replace the fixed size constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
Signed-off-by Peter Fang <[email protected]>Reviewed-by Binbin Wu <[email protected]>
Thanks Binbin!
Quoted 5 lines
Quoted 5 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +0
-0@@ -191,8 +191,9 @@ struct tdx_quote_buf {u8 data[]; };
Quoted 9 lines
drivers/virt/coco/tdx-guest/tdx-guest.c struct tdx_quote_buf { · line 196
Quoted 4 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +2
-1-/* Quote data buffer */ +/* Quote data buffer and length */ static void *quote_data; +static size_t quote_data_len;Nit:
The existing code is using "quote_data", it's natural to follow the style. I personally feel the var names are a bit ambiguous on whether it's the full quote buffer or just the data part.
Yeah I agree... How about I change it to:
static struct tdx_quote_buf *quote_buf;
This way it's explicitly typed, and should work better with functions like alloc_quote_buf() and free_quote_buf()?
Re: [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically
In reply to Tony LindgrenQuoted 19 lines · Tony Lindgren
Quoted 18 lines · Xiaoyao Li
Quoted 11 lines · Peter Fang
A new TDX module ABI reports the TD Quote size limit in a metadata field. This size used to be fixed at 128 KB.
The guest driver's Quote buffer is shared with the host VMM. The current fixed size may be too small for Quotes using schemes such as post-quantum cryptography (PQC), where larger certificate chains can increase the Quote size significantly.
Allocate the Quote buffer based on the reported limit. This avoids wasting memory on platforms that do not require larger Quotes. Older platforms fall back to the default 128 KB buffer.
I think we need to justify why using the value reported by TDX module (i.e.,
QUOTE_MAX_SIZE) is safe.From "Intel TDX Module Extension for Quoting" spec,
Quoted 8 lines
Quoted 8 lines
QUOTE_MAX_SIZEthat specifies the maximum size of the buffer that must be allocated to contain the Intel TDX Quote received from Intel TDX Module.So, TDX module only guarantees that
QUOTE_MAX_SIZEis big enough to hold the quote that is generated by the TDX module. But for the current tdx guest driver, it doesn't know how host will generate the quote. Host can generate the SGX-based quote and we need to justify theQUOTE_MAX_SIZEwill be enough for such case.
Thanks for pointing this out. I confirmed with the TDX security folks. The reported QUOTE_MAX_SIZE covers all possible quote types on the platform. If GetQuote gets routed to SGX and QUOTE_MAX_SIZE is too small for that, it's a TDX module bug.
I'll add a comment and update the changelog.
Quoted 3 lines
And can we assume the TDX module provided size does not change after init with a TDX module update?
Yep, it's safe to assume that.
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangQuoted 29 lines · Peter Fang
Quoted 10 lines · Binbin Wu
Quoted 7 lines · Peter Fang
In preparation for dynamic Quote buffer sizes, replace the fixed size constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
Signed-off-by Peter Fang <[email protected]>Reviewed-by Binbin Wu <[email protected]>Thanks Binbin!
Quoted 5 lines
Quoted 5 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +0
-0@@ -191,8 +191,9 @@ struct tdx_quote_buf {u8 data[]; };Quoted 9 lines
drivers/virt/coco/tdx-guest/tdx-guest.c struct tdx_quote_buf { · line 196
Quoted 4 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +2
-1-/* Quote data buffer */ +/* Quote data buffer and length */ static void *quote_data; +static size_t quote_data_len;Nit:
The existing code is using "quote_data", it's natural to follow the style. I personally feel the var names are a bit ambiguous on whether it's the full quote buffer or just the data part.
Quoted 6 lines
Yeah I agree... How about I change it to:
static struct
tdx_quote_buf*quote_buf;This way it's explicitly typed, and should work better with functions like
alloc_quote_buf()andfree_quote_buf()?
tdx_report_new_locked() already uses the name 'quote_buf' as a local var. :( Maybe the local var can be dropped, but tdx_hcall_get_quote() takes a "u8 *" pointer, which will require a type cast.
Anyway, this is a nit and it could be addressed in a separately if needed.
Tony Lindgren
Reviewed-byRe: [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically
In reply to Peter FangQuoted 34 lines · Peter Fang
Quoted 19 lines · Tony Lindgren
Quoted 18 lines · Xiaoyao Li
Quoted 11 lines · Peter Fang
A new TDX module ABI reports the TD Quote size limit in a metadata field. This size used to be fixed at 128 KB.
The guest driver's Quote buffer is shared with the host VMM. The current fixed size may be too small for Quotes using schemes such as post-quantum cryptography (PQC), where larger certificate chains can increase the Quote size significantly.
Allocate the Quote buffer based on the reported limit. This avoids wasting memory on platforms that do not require larger Quotes. Older platforms fall back to the default 128 KB buffer.
I think we need to justify why using the value reported by TDX module (i.e.,
QUOTE_MAX_SIZE) is safe.From "Intel TDX Module Extension for Quoting" spec,
Quoted 8 lines
Quoted 8 lines
QUOTE_MAX_SIZEthat specifies the maximum size of the buffer that must be allocated to contain the Intel TDX Quote received from Intel TDX Module.So, TDX module only guarantees that
QUOTE_MAX_SIZEis big enough to hold the quote that is generated by the TDX module. But for the current tdx guest driver, it doesn't know how host will generate the quote. Host can generate the SGX-based quote and we need to justify theQUOTE_MAX_SIZEwill be enough for such case.Thanks for pointing this out. I confirmed with the TDX security folks. The reported
QUOTE_MAX_SIZEcovers all possible quote types on the platform. If GetQuote gets routed to SGX andQUOTE_MAX_SIZEis too small for that, it's a TDX module bug.
Quoted 7 lines
I'll add a comment and update the changelog.
Quoted 3 lines
And can we assume the TDX module provided size does not change after init with a TDX module update?
Yep, it's safe to assume that.
Thanks for checking the above:
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Binbin WuQuoted 17 lines · Binbin Wu
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +0
-0@@ -191,8 +191,9 @@ struct tdx_quote_buf {u8 data[]; };Quoted 9 lines
drivers/virt/coco/tdx-guest/tdx-guest.c struct tdx_quote_buf { · line 196
Quoted 4 lines
drivers/virt/coco/tdx-guest/tdx-guest.c +2
-1-/* Quote data buffer */ +/* Quote data buffer and length */ static void *quote_data; +static size_t quote_data_len;Nit:
The existing code is using "quote_data", it's natural to follow the style. I personally feel the var names are a bit ambiguous on whether it's the full quote buffer or just the data part.Yeah I agree... How about I change it to:
Quoted 8 lines
Quoted 4 lines
static struct
tdx_quote_buf*quote_buf;This way it's explicitly typed, and should work better with functions like
alloc_quote_buf()andfree_quote_buf()?
tdx_report_new_locked()already uses the name 'quote_buf' as a local var. :( Maybe the local var can be dropped, buttdx_hcall_get_quote()takes a "u8 *" pointer, which will require a type cast.
Yes, the local variable can be dropped and it can just use the global quote_buf as is.
But yeah some tweaking is required to make tdx_hcall_get_quote() play nice...
Quoted 2 lines
Anyway, this is a nit and it could be addressed in a separately if needed.
OK, I can add it to the cleanup list. Looks like this is more work than I initially thought. Thanks for the review!
Quoted 1 line
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangQuoted 10 lines · Peter Fang
Quoted 8 lines
Quoted 5 lines
constant with a variable.
The size is currently a constant sprinkled across several places. Store it in a variable and have all the users read it from there.
You are also dropping
PAGE_ALIGN()in alloc and free calls. You can mention it in commit log.Good catch. I will add this next time.
I ended up not dropping PAGE_ALIGN() in v4 [1]. To be more precise PAGE_ALIGN() got moved out of the alloc and free calls, but was kept when initializing quote_data_len. So this didn't make it into the commit log.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 1 line
Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
In reply to Peter FangQuoted 13 lines · Peter Fang
Quoted 11 lines · Xiaoyao Li
Quoted 2 lines · Peter Fang
You are also dropping
PAGE_ALIGN()in alloc and free calls. You can mention it in commit log.I think it's better to keep the
PAGE_ALIGN()when assignquote_data_len, althoughGET_QUOTE_BUF_SIZEis aligned already. This makes it super clear we want to page size align the buffer.And in next patch, we can make it
quote_data_len = PAGE_ALIGN(get_quote_buf_size());
Quoted 8 lines
Hmm... Looking at this again actually makes me think it could be reworked a bit. There's a discrepancy in
alloc_quote_buf()if for whatever reason @len is not page aligned.alloc_pages_exact()rounds it up internally butset_memory_decrypted()rounds it *down*, so we'd end up with a useless page at the end...What if
alloc_quote_buf()took a @npages instead? Then the expectations would be pretty clear:
I took your suggestion in v4 [1]. The @npages approach was more work than expected and made the series bigger. This is simpler.
[1] https://lore.kernel.org/all/[email protected]/