From: Cedric Xing Date: Tue, 6 May 2025 22:57:13 +0000 (-0500) Subject: virt: tdx-guest: Transition to scoped_cond_guard for mutex operations X-Git-Tag: v6.16-rc1~119^2~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c3f259dfe03f5dcd898126602818a8fbe94d3c5;p=thirdparty%2Fkernel%2Flinux.git 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 Acked-by: Dionna Amalie Glaze Link: https://patch.msgid.link/20250506-tdx-rtmr-v6-7-ac6ff5e9d58a@intel.com Signed-off-by: Dan Williams --- diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c index 34125c5018331..60466c439a4bc 100644 --- a/drivers/virt/coco/tdx-guest/tdx-guest.c +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c @@ -262,7 +262,7 @@ static int wait_for_quote_completion(struct tdx_quote_buf *quote_buf, u32 timeou return (i == timeout) ? -ETIMEDOUT : 0; } -static int tdx_report_new(struct tsm_report *report, void *data) +static int tdx_report_new_locked(struct tsm_report *report, void *data) { u8 *buf; struct tdx_quote_buf *quote_buf = quote_data; @@ -270,24 +270,16 @@ static int tdx_report_new(struct tsm_report *report, void *data) int ret; u64 err; - /* TODO: switch to guard(mutex_intr) */ - if (mutex_lock_interruptible("e_lock)) - return -EINTR; - /* * If the previous request is timedout or interrupted, and the * Quote buf status is still in GET_QUOTE_IN_FLIGHT (owned by * VMM), don't permit any new request. */ - if (quote_buf->status == GET_QUOTE_IN_FLIGHT) { - ret = -EBUSY; - goto done; - } + if (quote_buf->status == GET_QUOTE_IN_FLIGHT) + return -EBUSY; - if (desc->inblob_len != TDX_REPORTDATA_LEN) { - ret = -EINVAL; - goto done; - } + if (desc->inblob_len != TDX_REPORTDATA_LEN) + return -EINVAL; memset(quote_data, 0, GET_QUOTE_BUF_SIZE); @@ -298,26 +290,23 @@ static int tdx_report_new(struct tsm_report *report, void *data) ret = tdx_do_report(KERNEL_SOCKPTR(desc->inblob), KERNEL_SOCKPTR(quote_buf->data)); if (ret) - goto done; + return ret; err = tdx_hcall_get_quote(quote_data, GET_QUOTE_BUF_SIZE); if (err) { pr_err("GetQuote hypercall failed, status:%llx\n", err); - ret = -EIO; - goto done; + return -EIO; } ret = wait_for_quote_completion(quote_buf, getquote_timeout); if (ret) { pr_err("GetQuote request timedout\n"); - goto done; + return ret; } buf = kvmemdup(quote_buf->data, quote_buf->out_len, GFP_KERNEL); - if (!buf) { - ret = -ENOMEM; - goto done; - } + if (!buf) + return -ENOMEM; report->outblob = buf; report->outblob_len = quote_buf->out_len; @@ -326,12 +315,16 @@ static int tdx_report_new(struct tsm_report *report, void *data) * TODO: parse the PEM-formatted cert chain out of the quote buffer when * provided */ -done: - mutex_unlock("e_lock); return ret; } +static int tdx_report_new(struct tsm_report *report, void *data) +{ + scoped_cond_guard(mutex_intr, return -EINTR, "e_lock) + return tdx_report_new_locked(report, data); +} + static bool tdx_report_attr_visible(int n) { switch (n) {