Re: [PATCH] virt: tdx-guest: Poll Quote status with exponential backoff
From: Kiryl Shutsemau
Date: Thu Oct 22 2026 - 09:09:45 EST
On Wed, Oct 21, 2026 at 05:16:32PM +0000, Moe Mahhouk via B4 Relay wrote:
> The latency was found while measuring TD boot and attestation times.
> The code and this changelog were written with an AI coding assistant,
> Claude (Claude Code, model Claude Opus 5.5), which also ran the tests.
> Tested on mainline a804c5742 in a TDX guest (KVM host v7.0, QEMU 11.1.2,
> TDX module 1.5.34, Intel QGS) with 40 Quote requests per kernel; builds
> with W=1 and passes checkpatch.pl.
Does anybody find this kind of dump useful? Maybe move after --- ?
> @@ -271,18 +273,25 @@ 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 + timeout * HZ;
> + unsigned int sleep_us = 100;
>
> /*
> - * 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
> + * 100 us 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 (signal_pending(current))
> return -EINTR;
> + usleep_range(sleep_us, 2 * sleep_us);
usleep_range() in uninterruptible.
Why not use the same msleep_interruptible(), but with shorten interval?
unsigned long deadline = jiffies + secs_to_jiffies(timeout);
unsigned int sleep_ms = 1;
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, 100);
}
return 0;
> + sleep_us = min(2 * sleep_us, 100 * USEC_PER_MSEC);
> }
>
> - return (i == timeout) ? -ETIMEDOUT : 0;
> + return 0;
Hm. The current code is broken: on a real timeout i ends up at
timeout + 1
--
Kiryl Shutsemau / Kirill A. Shutemov