* [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote
@ 2026-11-25 14:11 Moe Mahhouk via B4 Relay
2026-11-25 14:11 ` [PATCH v4 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-11-25 14:11 UTC (permalink / raw)
To: Kiryl Shutsemau, Rick Edgecombe, Dave Hansen, Erdem Aktas,
Tom Lendacky, Dan Williams, Kuppuswamy Sathyanarayanan,
Xiaoyao Li
Cc: Jun Miao, x86, linux-coco, kvm, linux-kernel, stable, 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 rechecks the status every 10 ms 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. This
series keeps the 30 s timeout. 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 7be4bc52fd9e 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, 120 back-to-back Quotes: 1021-1024 ms each before (v3
numbers, same setup), 14-20 ms (median 16 ms) with the series. At
HZ=250, msleep_interruptible(10) sleeps 4 jiffies, 16 ms, and the
first check right after the request almost never succeeds.
- Stress, 1000 back-to-back Quotes: none empty, 14-21 ms (median
16 ms).
- Timeout, with a QGS socket that accepts and never answers: the read
fails with -ETIMEDOUT after 30 s. Patch 1 is unchanged from v3, where
the lowered-timeout test showed the fix.
- SIGTERM to a reader waiting on such a request: it exits within the
same 10 ms tick of /proc/uptime.
- 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 v4:
- Patch 2: recheck every 10 ms instead of backing off from 1 to 100 ms
(Rick). Title changed to "Poll Quote status every 10 ms"
- Patch 2: changelog says the first check comes before the first sleep
(Xiaoyao)
- Patch 2: dropped Kiryl's and Sathyanarayanan's Reviewed-by, since the
code changed
- Patch 1: collected Reviewed-by (Xiaoyao)
- Link to v3: https://patch.msgid.link/20261024-tdx-guest-quote-poll-v3-0-6a83bb767314@flashbots.net
---
Moe Mahhouk (2):
virt: tdx-guest: Fix timeout detection in wait_for_quote_completion()
virt: tdx-guest: Poll Quote status every 10 ms
drivers/virt/coco/tdx-guest/tdx-guest.c | 16 ++++++++++------
1 file changed, 10 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 v4 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion()
2026-11-25 14:11 [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
@ 2026-11-25 14:11 ` Moe Mahhouk via B4 Relay
2026-11-25 14:11 ` [PATCH v4 2/2] virt: tdx-guest: Poll Quote status every 10 ms Moe Mahhouk via B4 Relay
2026-11-25 21:42 ` [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Edgecombe, Rick P
2 siblings, 0 replies; 4+ messages in thread
From: Moe Mahhouk via B4 Relay @ 2026-11-25 14:11 UTC (permalink / raw)
To: Kiryl Shutsemau, Rick Edgecombe, Dave Hansen, Erdem Aktas,
Tom Lendacky, Dan Williams, Kuppuswamy Sathyanarayanan,
Xiaoyao Li
Cc: Jun Miao, x86, linux-coco, kvm, linux-kernel, stable, 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")
Cc: stable@vger.kernel.org
Reported-by: Kiryl Shutsemau <kas@kernel.org>
Closes: https://lore.kernel.org/all/atoHWgQF-0vlTRK4@thinkstation/
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
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 v4 2/2] virt: tdx-guest: Poll Quote status every 10 ms
2026-11-25 14:11 [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
2026-11-25 14:11 ` [PATCH v4 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
@ 2026-11-25 14:11 ` Moe Mahhouk via B4 Relay
2026-11-25 21:42 ` [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Edgecombe, Rick P
2 siblings, 0 replies; 4+ messages in thread
From: Moe Mahhouk via B4 Relay @ 2026-11-25 14:11 UTC (permalink / raw)
To: Kiryl Shutsemau, Rick Edgecombe, Dave Hansen, Erdem Aktas,
Tom Lendacky, Dan Williams, Kuppuswamy Sathyanarayanan,
Xiaoyao Li
Cc: Jun Miao, x86, linux-coco, kvm, linux-kernel, Moe Mahhouk
From: Moe Mahhouk <moe@flashbots.net>
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 <rick.p.edgecombe@intel.com>
Signed-off-by: Moe Mahhouk <moe@flashbots.net>
---
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 <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,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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote
2026-11-25 14:11 [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
2026-11-25 14:11 ` [PATCH v4 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
2026-11-25 14:11 ` [PATCH v4 2/2] virt: tdx-guest: Poll Quote status every 10 ms Moe Mahhouk via B4 Relay
@ 2026-11-25 21:42 ` Edgecombe, Rick P
2 siblings, 0 replies; 4+ messages in thread
From: Edgecombe, Rick P @ 2026-11-25 21:42 UTC (permalink / raw)
To: dave.hansen, kas, Li, Xiaoyao, sathyanarayanan.kuppuswamy,
thomas.lendacky, Aktas, Erdem, djbw, moe
Cc: kvm, linux-coco, Miao, Jun, linux-kernel, stable, x86
On Wed, 2026-11-25 at 14:11 +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 rechecks the status every 10 ms instead.
I think something went wrong in the send. All I got was the coverletter and it
looks like lore did too.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 21:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 14:11 [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
2026-11-25 14:11 ` [PATCH v4 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
2026-11-25 14:11 ` [PATCH v4 2/2] virt: tdx-guest: Poll Quote status every 10 ms Moe Mahhouk via B4 Relay
2026-11-25 21:42 ` [PATCH v4 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Edgecombe, Rick P
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®