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: Transition to scoped_cond_guard for mutex operations

Replace mutex_lock_interruptible()/mutex_unlock() with scoped_cond_guard to
enhance code readability and maintainability.

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-7-ac6ff5e9d58a@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

authored by

Cedric Xing and committed by
Dan Williams
7c3f259d 850972bc

+16 -23
+16 -23
drivers/virt/coco/tdx-guest/tdx-guest.c
··· 262 262 return (i == timeout) ? -ETIMEDOUT : 0; 263 263 } 264 264 265 - static int tdx_report_new(struct tsm_report *report, void *data) 265 + static int tdx_report_new_locked(struct tsm_report *report, void *data) 266 266 { 267 267 u8 *buf; 268 268 struct tdx_quote_buf *quote_buf = quote_data; ··· 270 270 int ret; 271 271 u64 err; 272 272 273 - /* TODO: switch to guard(mutex_intr) */ 274 - if (mutex_lock_interruptible(&quote_lock)) 275 - return -EINTR; 276 - 277 273 /* 278 274 * If the previous request is timedout or interrupted, and the 279 275 * Quote buf status is still in GET_QUOTE_IN_FLIGHT (owned by 280 276 * VMM), don't permit any new request. 281 277 */ 282 - if (quote_buf->status == GET_QUOTE_IN_FLIGHT) { 283 - ret = -EBUSY; 284 - goto done; 285 - } 278 + if (quote_buf->status == GET_QUOTE_IN_FLIGHT) 279 + return -EBUSY; 286 280 287 - if (desc->inblob_len != TDX_REPORTDATA_LEN) { 288 - ret = -EINVAL; 289 - goto done; 290 - } 281 + if (desc->inblob_len != TDX_REPORTDATA_LEN) 282 + return -EINVAL; 291 283 292 284 memset(quote_data, 0, GET_QUOTE_BUF_SIZE); 293 285 ··· 290 298 ret = tdx_do_report(KERNEL_SOCKPTR(desc->inblob), 291 299 KERNEL_SOCKPTR(quote_buf->data)); 292 300 if (ret) 293 - goto done; 301 + return ret; 294 302 295 303 err = tdx_hcall_get_quote(quote_data, GET_QUOTE_BUF_SIZE); 296 304 if (err) { 297 305 pr_err("GetQuote hypercall failed, status:%llx\n", err); 298 - ret = -EIO; 299 - goto done; 306 + return -EIO; 300 307 } 301 308 302 309 ret = wait_for_quote_completion(quote_buf, getquote_timeout); 303 310 if (ret) { 304 311 pr_err("GetQuote request timedout\n"); 305 - goto done; 312 + return ret; 306 313 } 307 314 308 315 buf = kvmemdup(quote_buf->data, quote_buf->out_len, GFP_KERNEL); 309 - if (!buf) { 310 - ret = -ENOMEM; 311 - goto done; 312 - } 316 + if (!buf) 317 + return -ENOMEM; 313 318 314 319 report->outblob = buf; 315 320 report->outblob_len = quote_buf->out_len; ··· 315 326 * TODO: parse the PEM-formatted cert chain out of the quote buffer when 316 327 * provided 317 328 */ 318 - done: 319 - mutex_unlock(&quote_lock); 320 329 321 330 return ret; 331 + } 332 + 333 + static int tdx_report_new(struct tsm_report *report, void *data) 334 + { 335 + scoped_cond_guard(mutex_intr, return -EINTR, &quote_lock) 336 + return tdx_report_new_locked(report, data); 322 337 } 323 338 324 339 static bool tdx_report_attr_visible(int n)