* [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote
@ 2026-10-22 16:31 Moe Mahhouk via B4 Relay
2026-10-22 16:31 ` [PATCH v2 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Moe Mahhouk via B4 Relay @ 2026-10-22 16:31 UTC (permalink / raw)
To: Kiryl Shutsemau, Rick Edgecombe, Dave Hansen, Erdem Aktas,
Tom Lendacky, Dan Williams
Cc: Jun Miao, Kuppuswamy Sathyanarayanan, x86, linux-coco, kvm,
linux-kernel, Moe Mahhouk
Getting a TDX Quote takes at least one second, because
wait_for_quote_completion() sleeps a full second before each status
check, while a local Quote Generation Service answers in a few
milliseconds. Patch 2 polls with an exponential backoff instead.
In v1, Kiryl noticed that the same loop gets a real timeout wrong.
Patch 1 fixes that on its own, so that it can be backported; patch 2
then replaces the loop.
The GHCI SetupEventNotifyInterrupt mechanism would avoid polling
altogether, but it relies on the VMM implementing that service. This
series keeps the existing polling model, which works with any VMM.
Jun Miao posted a patch for the same latency in September [1]. It polls
every 2 ms with read_poll_timeout() and lowers the timeout to 1 s, and
has had no review so far. This series keeps the 30 s timeout and backs
off instead of polling at a fixed rate. Patch 1 is needed for released
kernels either way.
[1] https://lore.kernel.org/all/20260917102202.750895-1-jun.miao@intel.com/
Testing on mainline a804c5742 in a TDX guest (KVM host v7.0, QEMU
11.1.2, TDX module 1.5.34, Intel QGS, guest HZ=250), through
configfs-tsm:
- Latency, 40 back-to-back Quotes: 1021-1024 ms each before, 6-12 ms
(median 8 ms) with the series. msleep_interruptible() rounds up to
jiffies; v1's usleep_range() got 2-3 ms.
- Timeout, with a QGS socket that accepts and never answers. QEMU fails
such a request itself after 30 s, so for this test getquote_timeout
was lowered to 5 s: without patch 1 the request fails with -EIO and
no message, with it -ETIMEDOUT and "GetQuote request timedout". With
the default 30 s and the old loop, QEMU's error lands in the last
sleep and is reported as -ETIMEDOUT, the second case in patch 1.
- SIGTERM to a reader waiting on such a request: it exits within one
10 ms tick of /proc/uptime with the series, as before it; with v1 it
took 110 ms.
- W=1 build of drivers/virt/coco/tdx-guest/ and checkpatch.pl --strict
are clean.
The patches and this cover letter were written with an AI coding
assistant, Claude (Claude Code, model Claude Opus 5.5), which also ran
the tests.
---
Changes in v2:
- New patch 1: fix the timeout detection on its own, for backporting
(Kiryl)
- Patch 2: msleep_interruptible() with a 1-100 ms backoff instead of
usleep_range(), which sleeps uninterruptibly (Kiryl)
- Patch 2: secs_to_jiffies() for the deadline
- Test and tool notes moved from the changelog to this cover letter
(Kiryl)
- Link to v1: https://patch.msgid.link/20261021-tdx-guest-quote-poll-v1-1-919a87812ecb@flashbots.net
To: Kiryl Shutsemau <kas@kernel.org>
To: Rick Edgecombe <rick.p.edgecombe@intel.com>
To: Dave Hansen <dave.hansen@linux.intel.com>
To: Erdem Aktas <erdemaktas@google.com>
To: Tom Lendacky <thomas.lendacky@amd.com>
To: Dan Williams <djbw@kernel.org>
To: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Cc: x86@kernel.org
Cc: linux-coco@lists.linux.dev
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
Moe Mahhouk (2):
virt: tdx-guest: Fix timeout detection in wait_for_quote_completion()
virt: tdx-guest: Poll Quote status with exponential backoff
drivers/virt/coco/tdx-guest/tdx-guest.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
---
base-commit: 7be4bc52fd9e0e55dc9a2e0232b89427d2c4b614
change-id: 20261021-tdx-guest-quote-poll-0f7bfc59900b
Best regards,
--
Moe Mahhouk <moe@flashbots.net>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion()
2026-10-22 16:31 [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
@ 2026-10-22 16:31 ` Moe Mahhouk via B4 Relay
2026-10-22 16:31 ` [PATCH v2 2/2] virt: tdx-guest: Poll Quote status with exponential backoff Moe Mahhouk via B4 Relay
2026-10-23 10:17 ` [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Kiryl Shutsemau
2 siblings, 0 replies; 4+ messages in thread
From: Moe Mahhouk via B4 Relay @ 2026-10-22 16:31 UTC (permalink / raw)
To: Kiryl Shutsemau, Rick Edgecombe, Dave Hansen, Erdem Aktas,
Tom Lendacky, Dan Williams
Cc: Jun Miao, Kuppuswamy Sathyanarayanan, x86, linux-coco, kvm,
linux-kernel, Moe Mahhouk
From: Moe Mahhouk <moe@flashbots.net>
wait_for_quote_completion() counts the seconds it has waited in i and
reports a timeout when i == timeout. That gets both outcomes of the
last second wrong:
- If the request is still in flight after the last sleep, the loop
condition increments i once more before it fails, so the loop ends
with i == timeout + 1 and the function returns 0. The caller then
returns -EIO instead of -ETIMEDOUT, without the "GetQuote request
timedout" message. Before commit 0f409eaea53e ("virt: tdx-guest:
Return error for GetQuote failures") a timed-out request even
returned success with an empty Quote.
- If the VMM completes the request during the last sleep, the loop ends
on the status check with i == timeout, and the function returns
-ETIMEDOUT for a completed request, discarding the Quote.
Decide on the Quote buffer instead: the request timed out if it is
still in flight when the wait ends.
Fixes: f4738f56d1dc ("virt: tdx-guest: Add Quote generation support using TSM_REPORTS")
Reported-by: Kiryl Shutsemau <kas@kernel.org>
Closes: https://lore.kernel.org/all/atoHWgQF-0vlTRK4@thinkstation/
Signed-off-by: Moe Mahhouk <moe@flashbots.net>
---
drivers/virt/coco/tdx-guest/tdx-guest.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
index 11d741da3b35..a5a53174f9d9 100644
--- a/drivers/virt/coco/tdx-guest/tdx-guest.c
+++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
@@ -282,7 +282,7 @@ static int wait_for_quote_completion(struct tdx_quote_buf *buf, u32 timeout)
return -EINTR;
}
- return (i == timeout) ? -ETIMEDOUT : 0;
+ return (buf->status == GET_QUOTE_IN_FLIGHT) ? -ETIMEDOUT : 0;
}
static int tdx_report_new_locked(struct tsm_report *report)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/2] virt: tdx-guest: Poll Quote status with exponential backoff
2026-10-22 16:31 [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
2026-10-22 16:31 ` [PATCH v2 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
@ 2026-10-22 16:31 ` Moe Mahhouk via B4 Relay
2026-10-23 10:17 ` [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Kiryl Shutsemau
2 siblings, 0 replies; 4+ messages in thread
From: Moe Mahhouk via B4 Relay @ 2026-10-22 16:31 UTC (permalink / raw)
To: Kiryl Shutsemau, Rick Edgecombe, Dave Hansen, Erdem Aktas,
Tom Lendacky, Dan Williams
Cc: Jun Miao, Kuppuswamy Sathyanarayanan, x86, linux-coco, kvm,
linux-kernel, Moe Mahhouk
From: Moe Mahhouk <moe@flashbots.net>
wait_for_quote_completion() sleeps for a full second before it first
checks whether the VMM has completed a GetQuote request, and then
rechecks once per second. Every Quote request therefore 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 6-12 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.
Poll with an exponential backoff instead: sleep 1 ms first and double
the interval up to 100 ms, so that a fast Quote is noticed within a few
milliseconds while a slow one costs at most ten wakeups per second. The
sleep stays interruptible, and the timeout becomes a deadline in
jiffies.
Signed-off-by: Moe Mahhouk <moe@flashbots.net>
---
drivers/virt/coco/tdx-guest/tdx-guest.c | 19 +++++++++++++------
1 file changed, 13 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..000fff4ef6f5 100644
--- a/drivers/virt/coco/tdx-guest/tdx-guest.c
+++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
@@ -16,6 +16,7 @@
#include <linux/set_memory.h>
#include <linux/io.h>
#include <linux/delay.h>
+#include <linux/jiffies.h>
#include <linux/sockptr.h>
#include <linux/tsm.h>
#include <linux/tsm-mr.h>
@@ -271,18 +272,24 @@ 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);
+ unsigned int sleep_ms = 1;
/*
- * 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. Poll with an exponential backoff, from
+ * 1 ms up to 100 ms, so that a fast Quote is noticed promptly while
+ * a slow one costs at most ten wakeups per second.
*/
- 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(sleep_ms))
return -EINTR;
+ sleep_ms = min(2 * sleep_ms, 100U);
}
- return (buf->status == GET_QUOTE_IN_FLIGHT) ? -ETIMEDOUT : 0;
+ return 0;
}
static int tdx_report_new_locked(struct tsm_report *report)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote
2026-10-22 16:31 [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
2026-10-22 16:31 ` [PATCH v2 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
2026-10-22 16:31 ` [PATCH v2 2/2] virt: tdx-guest: Poll Quote status with exponential backoff Moe Mahhouk via B4 Relay
@ 2026-10-23 10:17 ` Kiryl Shutsemau
2 siblings, 0 replies; 4+ messages in thread
From: Kiryl Shutsemau @ 2026-10-23 10:17 UTC (permalink / raw)
To: moe
Cc: Rick Edgecombe, Dave Hansen, Erdem Aktas, Tom Lendacky,
Dan Williams, Jun Miao, Kuppuswamy Sathyanarayanan, x86,
linux-coco, kvm, linux-kernel
On Thu, Oct 22, 2026 at 04:31:40PM +0000, Moe Mahhouk via B4 Relay wrote:
> Getting a TDX Quote takes at least one second, because
> wait_for_quote_completion() sleeps a full second before each status
> check, while a local Quote Generation Service answers in a few
> milliseconds. Patch 2 polls with an exponential backoff instead.
>
> In v1, Kiryl noticed that the same loop gets a real timeout wrong.
> Patch 1 fixes that on its own, so that it can be backported; patch 2
> then replaces the loop.
For the series:
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
--
Kiryl Shutsemau / Kirill A. Shutemov
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-23 10:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-22 16:31 [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
2026-10-22 16:31 ` [PATCH v2 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
2026-10-22 16:31 ` [PATCH v2 2/2] virt: tdx-guest: Poll Quote status with exponential backoff Moe Mahhouk via B4 Relay
2026-10-23 10:17 ` [PATCH v2 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Kiryl Shutsemau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®