Skip to content

Commit 850972b

Browse files
binxingdjbw
authored andcommitted
virt: tdx-guest: Refactor and streamline TDREPORT generation
Consolidate instances (code segments) of TDREPORT generation to improve readability and maintainability, by refactoring each instance into invoking a unified subroutine throughout the TDX guest driver. Implement proper locking around TDG.MR.REPORT and TDG.MR.RTMR.EXTEND to avoid race inside the TDX module. Preallocate TDREPORT buffer to reduce overhead in subsequent TDREPORT generation. Signed-off-by: Cedric Xing <cedric.xing@intel.com> Acked-by: Dionna Amalie Glaze <dionnaglaze@google.com> Link: https://patch.msgid.link/20250506-tdx-rtmr-v6-6-ac6ff5e9d58a@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 4d2a7bf commit 850972b

File tree

1 file changed

+7
-56
lines changed

1 file changed

+7
-56
lines changed

drivers/virt/coco/tdx-guest/tdx-guest.c

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -202,37 +202,8 @@ static u32 getquote_timeout = 30;
202202

203203
static long tdx_get_report0(struct tdx_report_req __user *req)
204204
{
205-
u8 *reportdata, *tdreport;
206-
long ret;
207-
208-
reportdata = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL);
209-
if (!reportdata)
210-
return -ENOMEM;
211-
212-
tdreport = kzalloc(TDX_REPORT_LEN, GFP_KERNEL);
213-
if (!tdreport) {
214-
ret = -ENOMEM;
215-
goto out;
216-
}
217-
218-
if (copy_from_user(reportdata, req->reportdata, TDX_REPORTDATA_LEN)) {
219-
ret = -EFAULT;
220-
goto out;
221-
}
222-
223-
/* Generate TDREPORT0 using "TDG.MR.REPORT" TDCALL */
224-
ret = tdx_mcall_get_report0(reportdata, tdreport);
225-
if (ret)
226-
goto out;
227-
228-
if (copy_to_user(req->tdreport, tdreport, TDX_REPORT_LEN))
229-
ret = -EFAULT;
230-
231-
out:
232-
kfree(reportdata);
233-
kfree(tdreport);
234-
235-
return ret;
205+
return tdx_do_report(USER_SOCKPTR(req->reportdata),
206+
USER_SOCKPTR(req->tdreport));
236207
}
237208

238209
static void free_quote_buf(void *buf)
@@ -293,7 +264,7 @@ static int wait_for_quote_completion(struct tdx_quote_buf *quote_buf, u32 timeou
293264

294265
static int tdx_report_new(struct tsm_report *report, void *data)
295266
{
296-
u8 *buf, *reportdata = NULL, *tdreport = NULL;
267+
u8 *buf;
297268
struct tdx_quote_buf *quote_buf = quote_data;
298269
struct tsm_desc *desc = &report->desc;
299270
int ret;
@@ -318,34 +289,16 @@ static int tdx_report_new(struct tsm_report *report, void *data)
318289
goto done;
319290
}
320291

321-
reportdata = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL);
322-
if (!reportdata) {
323-
ret = -ENOMEM;
324-
goto done;
325-
}
326-
327-
tdreport = kzalloc(TDX_REPORT_LEN, GFP_KERNEL);
328-
if (!tdreport) {
329-
ret = -ENOMEM;
330-
goto done;
331-
}
332-
333-
memcpy(reportdata, desc->inblob, desc->inblob_len);
334-
335-
/* Generate TDREPORT0 using "TDG.MR.REPORT" TDCALL */
336-
ret = tdx_mcall_get_report0(reportdata, tdreport);
337-
if (ret) {
338-
pr_err("GetReport call failed\n");
339-
goto done;
340-
}
341-
342292
memset(quote_data, 0, GET_QUOTE_BUF_SIZE);
343293

344294
/* Update Quote buffer header */
345295
quote_buf->version = GET_QUOTE_CMD_VER;
346296
quote_buf->in_len = TDX_REPORT_LEN;
347297

348-
memcpy(quote_buf->data, tdreport, TDX_REPORT_LEN);
298+
ret = tdx_do_report(KERNEL_SOCKPTR(desc->inblob),
299+
KERNEL_SOCKPTR(quote_buf->data));
300+
if (ret)
301+
goto done;
349302

350303
err = tdx_hcall_get_quote(quote_data, GET_QUOTE_BUF_SIZE);
351304
if (err) {
@@ -375,8 +328,6 @@ static int tdx_report_new(struct tsm_report *report, void *data)
375328
*/
376329
done:
377330
mutex_unlock(&quote_lock);
378-
kfree(reportdata);
379-
kfree(tdreport);
380331

381332
return ret;
382333
}

0 commit comments

Comments
 (0)