mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kiryl Shutsemau <kas@kernel.org>
To: moe@flashbots.net
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>,
	 Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] virt: tdx-guest: Poll Quote status with exponential backoff
Date: Thu, 22 Oct 2026 14:02:16 +0100	[thread overview]
Message-ID: <atoHWgQF-0vlTRK4@thinkstation> (raw)
In-Reply-To: <20261021-tdx-guest-quote-poll-v1-1-919a87812ecb@flashbots.net>

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

      reply	other threads:[~2026-10-22 13:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 17:16 Moe Mahhouk via B4 Relay
2026-10-22 13:02 ` Kiryl Shutsemau [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=atoHWgQF-0vlTRK4@thinkstation \
    --to=kas@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=moe@flashbots.net \
    --cc=rick.p.edgecombe@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®