Re: [PATCH v5 2/6] virt: tdx-guest: Give the Quote buffer an explicit type

From: Kuppuswamy Sathyanarayanan

Date: Mon Sep 28 2026 - 16:16:29 EST


Hi,

On 9/28/2026 3:08 AM, Peter Fang wrote:
> 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>
> ---

Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx>


> v5:
> - New patch. [Dave]
> ---
> drivers/virt/coco/tdx-guest/tdx-guest.c | 35 ++++++++++++-------------
> 1 file changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
> index d0303e31e816..896eb0a09c4a 100644
> --- a/drivers/virt/coco/tdx-guest/tdx-guest.c
> +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
> @@ -192,7 +192,7 @@ struct tdx_quote_buf {
> };
>
> /* 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 +209,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 +222,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 +249,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 +257,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 +268,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, void *data)
> {
> u8 *buf;
> - struct tdx_quote_buf *quote_buf = quote_data;
> struct tsm_report_desc *desc = &report->desc;
> u32 out_len;
> int ret;
> @@ -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_buf, 0, GET_QUOTE_BUF_SIZE);
>
> /* 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_buf, GET_QUOTE_BUF_SIZE);
> if (err) {
> pr_err("GetQuote hypercall failed, status:%llx\n", err);
> return -EIO;
> @@ -417,8 +416,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 +430,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 +443,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]);
> }

--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer