Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Cedric Xing and committed by
Dan Williams
850972bc 4d2a7bfa

+7 -56
+7 -56
drivers/virt/coco/tdx-guest/tdx-guest.c
··· 202 202 203 203 static long tdx_get_report0(struct tdx_report_req __user *req) 204 204 { 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)); 236 207 } 237 208 238 209 static void free_quote_buf(void *buf) ··· 264 293 265 294 static int tdx_report_new(struct tsm_report *report, void *data) 266 295 { 267 - u8 *buf, *reportdata = NULL, *tdreport = NULL; 296 + u8 *buf; 268 297 struct tdx_quote_buf *quote_buf = quote_data; 269 298 struct tsm_desc *desc = &report->desc; 270 299 int ret; ··· 289 318 goto done; 290 319 } 291 320 292 - reportdata = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL); 293 - if (!reportdata) { 294 - ret = -ENOMEM; 295 - goto done; 296 - } 297 - 298 - tdreport = kzalloc(TDX_REPORT_LEN, GFP_KERNEL); 299 - if (!tdreport) { 300 - ret = -ENOMEM; 301 - goto done; 302 - } 303 - 304 - memcpy(reportdata, desc->inblob, desc->inblob_len); 305 - 306 - /* Generate TDREPORT0 using "TDG.MR.REPORT" TDCALL */ 307 - ret = tdx_mcall_get_report0(reportdata, tdreport); 308 - if (ret) { 309 - pr_err("GetReport call failed\n"); 310 - goto done; 311 - } 312 - 313 321 memset(quote_data, 0, GET_QUOTE_BUF_SIZE); 314 322 315 323 /* Update Quote buffer header */ 316 324 quote_buf->version = GET_QUOTE_CMD_VER; 317 325 quote_buf->in_len = TDX_REPORT_LEN; 318 326 319 - memcpy(quote_buf->data, tdreport, TDX_REPORT_LEN); 327 + ret = tdx_do_report(KERNEL_SOCKPTR(desc->inblob), 328 + KERNEL_SOCKPTR(quote_buf->data)); 329 + if (ret) 330 + goto done; 320 331 321 332 err = tdx_hcall_get_quote(quote_data, GET_QUOTE_BUF_SIZE); 322 333 if (err) { ··· 328 375 */ 329 376 done: 330 377 mutex_unlock(&quote_lock); 331 - kfree(reportdata); 332 - kfree(tdreport); 333 378 334 379 return ret; 335 380 }