[tip: x86/tdx] virt: tdx-guest: Give the Quote buffer an explicit type

From: tip-bot2 for Peter Fang

Date: Fri Oct 02 2026 - 12:32:25 EST


The following commit has been merged into the x86/tdx branch of tip:

Commit-ID: 0d3fe9bad7c9028b23f753c216d4fdc0a1c76fa7
Gitweb: https://git.kernel.org/tip/0d3fe9bad7c9028b23f753c216d4fdc0a1c76fa7
Author: Peter Fang <peter.fang@xxxxxxxxx>
AuthorDate: Wed, 30 Sep 2026 03:30:51 -07:00
Committer: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
CommitterDate: Fri, 02 Oct 2026 09:03:05 -07:00

virt: tdx-guest: Give the Quote buffer an explicit type

The Quote buffer is always a "struct tdx_quote_buf", but its global
pointer is a "void *". A function would have to convert it back to make
sense of it.

Declare the global with its actual type, and give it a better name.

This creates variable shadowing in wait_for_quote_completion(), so
rename its parameter for clarity.

AI was used under supervision to collect/apply feedback, review code and
workshop logs.

Signed-off-by: Peter Fang <peter.fang@xxxxxxxxx>
Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx>
Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260930103739.2851980-3-peter.fang@xxxxxxxxx
---
drivers/virt/coco/tdx-guest/tdx-guest.c | 36 +++++++++++-------------
1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
index a21bd03..83322cd 100644
--- a/drivers/virt/coco/tdx-guest/tdx-guest.c
+++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
@@ -191,8 +191,7 @@ struct tdx_quote_buf {
u8 data[];
};

-/* Quote data buffer */
-static void *quote_data;
+static struct tdx_quote_buf *quote_buf;

/* Lock to streamline quote requests */
static DEFINE_MUTEX(quote_lock);
@@ -209,7 +208,7 @@ 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(struct tdx_quote_buf *buf)
{
size_t len = PAGE_ALIGN(GET_QUOTE_BUF_SIZE);
unsigned int count = len >> PAGE_SHIFT;
@@ -222,25 +221,25 @@ static void free_quote_buf(void *buf)
free_pages_exact(buf, len);
}

-static void *alloc_quote_buf(void)
+static struct tdx_quote_buf *alloc_quote_buf(void)
{
size_t len = PAGE_ALIGN(GET_QUOTE_BUF_SIZE);
unsigned int count = len >> PAGE_SHIFT;
- void *addr;
+ struct tdx_quote_buf *buf;

- addr = alloc_pages_exact(len, GFP_KERNEL | __GFP_ZERO);
- if (!addr)
+ buf = alloc_pages_exact(len, GFP_KERNEL | __GFP_ZERO);
+ if (!buf)
return NULL;

- if (set_memory_decrypted((unsigned long)addr, count))
+ if (set_memory_decrypted((unsigned long)buf, count))
return NULL;

- return addr;
+ return buf;
}

/*
* wait_for_quote_completion() - Wait for Quote request completion
- * @quote_buf: Address of Quote buffer.
+ * @buf: Address of Quote buffer.
* @timeout: Timeout in seconds to wait for the Quote generation.
*
* As per TDX GHCI v1.0 specification, sec titled "TDG.VP.VMCALL<GetQuote>",
@@ -249,7 +248,7 @@ static void *alloc_quote_buf(void)
* or error code after processing is complete. So wait till the status
* changes from GET_QUOTE_IN_FLIGHT or the request being timed out.
*/
-static int wait_for_quote_completion(struct tdx_quote_buf *quote_buf, u32 timeout)
+static int wait_for_quote_completion(struct tdx_quote_buf *buf, u32 timeout)
{
int i = 0;

@@ -257,7 +256,7 @@ static int wait_for_quote_completion(struct tdx_quote_buf *quote_buf, u32 timeou
* Quote requests usually take a few seconds to complete, so waking up
* once per second to recheck the status is fine for this use case.
*/
- while (quote_buf->status == GET_QUOTE_IN_FLIGHT && i++ < timeout) {
+ while (buf->status == GET_QUOTE_IN_FLIGHT && i++ < timeout) {
if (msleep_interruptible(MSEC_PER_SEC))
return -EINTR;
}
@@ -268,7 +267,6 @@ static int wait_for_quote_completion(struct tdx_quote_buf *quote_buf, u32 timeou
static int tdx_report_new_locked(struct tsm_report *report)
{
u8 *buf;
- struct tdx_quote_buf *quote_buf = quote_data;
struct tsm_report_desc *desc = &report->desc;
u32 out_len;
int ret;
@@ -285,7 +283,7 @@ static int tdx_report_new_locked(struct tsm_report *report)
if (desc->inblob_len != TDX_REPORTDATA_LEN)
return -EINVAL;

- memset(quote_data, 0, GET_QUOTE_BUF_SIZE);
+ memset(quote_buf, 0, GET_QUOTE_BUF_SIZE);

/* Update Quote buffer header */
quote_buf->version = GET_QUOTE_CMD_VER;
@@ -296,7 +294,7 @@ static int tdx_report_new_locked(struct tsm_report *report)
if (ret)
return ret;

- err = tdx_hcall_get_quote(quote_data, GET_QUOTE_BUF_SIZE);
+ err = tdx_hcall_get_quote(quote_buf, GET_QUOTE_BUF_SIZE);
if (err) {
pr_err("GetQuote hypercall failed, status:%llx\n", err);
return -EIO;
@@ -417,8 +415,8 @@ static int __init tdx_guest_init(void)
if (ret)
goto deinit_mr;

- quote_data = alloc_quote_buf();
- if (!quote_data) {
+ quote_buf = alloc_quote_buf();
+ if (!quote_buf) {
pr_err("Failed to allocate Quote buffer\n");
ret = -ENOMEM;
goto free_misc;
@@ -431,7 +429,7 @@ static int __init tdx_guest_init(void)
return 0;

free_quote:
- free_quote_buf(quote_data);
+ free_quote_buf(quote_buf);
free_misc:
misc_deregister(&tdx_misc_dev);
deinit_mr:
@@ -444,7 +442,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_buf);
misc_deregister(&tdx_misc_dev);
tdx_mr_deinit(tdx_attr_groups[0]);
}