From: Moe Mahhouk wait_for_quote_completion() checks the status of a GetQuote request once and then sleeps for a full second before each further check. The VMM has rarely completed the request at the first check, so every Quote request takes at least one second, however quickly the host answers. With a local Quote Generation Service the VMM completes the request in a few milliseconds. On an Emerald Rapids host (KVM, QEMU 11.1, Intel QGS), back-to-back Quote requests through configfs-tsm took 1021-1024 ms each; with this change they take 14-21 ms (median 16 ms) at HZ=250. Since quote_lock serializes requests, the one-second floor also caps a TD at about one Quote per second, which hurts users that bind a fresh Quote to every connection, such as attested TLS. Recheck the status every 10 ms instead. msleep_interruptible() rounds up to whole jiffies and adds one, so at HZ=250 a step takes 16 ms. The sleep stays interruptible, and the timeout becomes a deadline in jiffies. Suggested-by: Rick Edgecombe Signed-off-by: Moe Mahhouk --- drivers/virt/coco/tdx-guest/tdx-guest.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c index a5a53174f9d9..25fa2a875c44 100644 --- a/drivers/virt/coco/tdx-guest/tdx-guest.c +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -271,18 +272,21 @@ static struct tdx_quote_buf *alloc_quote_buf(void) */ static int wait_for_quote_completion(struct tdx_quote_buf *buf, u32 timeout) { - int i = 0; + unsigned long deadline = jiffies + secs_to_jiffies(timeout); /* - * 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. + * A local Quote Generation Service usually completes the request + * within a few milliseconds, so recheck the status every 10 ms. + * msleep_interruptible() rounds up to whole jiffies. */ - while (buf->status == GET_QUOTE_IN_FLIGHT && i++ < timeout) { - if (msleep_interruptible(MSEC_PER_SEC)) + while (READ_ONCE(buf->status) == GET_QUOTE_IN_FLIGHT) { + if (time_after(jiffies, deadline)) + return -ETIMEDOUT; + if (msleep_interruptible(10)) return -EINTR; } - return (buf->status == GET_QUOTE_IN_FLIGHT) ? -ETIMEDOUT : 0; + return 0; } static int tdx_report_new_locked(struct tsm_report *report) -- 2.34.1