Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: moe@flashbots.net, Kiryl Shutsemau <kas@kernel.org>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Erdem Aktas <erdemaktas@google.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Dan Williams <djbw@kernel.org>,
	Kuppuswamy Sathyanarayanan
	<sathyanarayanan.kuppuswamy@linux.intel.com>
Cc: Jun Miao <jun.miao@intel.com>,
	x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] virt: tdx-guest: Poll Quote status with exponential backoff
Date: Tue, 27 Oct 2026 22:08:39 +0800	[thread overview]
Message-ID: <7a832e5c-eaff-426f-adff-7935be265bbd@intel.com> (raw)
In-Reply-To: <20261024-tdx-guest-quote-poll-v3-2-6a83bb767314@flashbots.net>

On 10/25/2026 3:17 AM, Moe Mahhouk via B4 Relay wrote:
> 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.

It's not 100% correct.

I think it's possible that the host VMM completes the GetQuote request before
the first check in wait_for_quote_completion()

> 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: double the sleep from 1 ms 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.
> msleep_interruptible() rounds up to whole jiffies, so at HZ=250 the 1, 2
> and 4 ms steps are one 4 ms tick each. The sleep stays interruptible,
> and the timeout becomes a deadline in jiffies.
> 
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>

With the statement of the first paragraph fixed,

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

> Signed-off-by: Moe Mahhouk <moe@flashbots.net>
> ---
>  drivers/virt/coco/tdx-guest/tdx-guest.c | 20 ++++++++++++++------
>  1 file changed, 14 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..d58c8eccb26b 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,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 + 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 of up
> +	 * to 100 ms, so that a fast Quote is noticed promptly while a slow
> +	 * one costs at most ten wakeups per second. msleep_interruptible()
> +	 * rounds up to whole jiffies, so the shortest steps take one tick.
>  	 */
> -	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)
> 


      reply	other threads:[~2026-10-27 14:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24 19:17 [PATCH v3 0/2] virt: tdx-guest: Fix and speed up the wait for a Quote Moe Mahhouk via B4 Relay
2026-10-24 19:17 ` [PATCH v3 1/2] virt: tdx-guest: Fix timeout detection in wait_for_quote_completion() Moe Mahhouk via B4 Relay
2026-10-27 13:50   ` Xiaoyao Li
2026-10-24 19:17 ` [PATCH v3 2/2] virt: tdx-guest: Poll Quote status with exponential backoff Moe Mahhouk via B4 Relay
2026-10-27 14:08   ` Xiaoyao Li [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=7a832e5c-eaff-426f-adff-7935be265bbd@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=djbw@kernel.org \
    --cc=erdemaktas@google.com \
    --cc=jun.miao@intel.com \
    --cc=kas@kernel.org \
    --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=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=thomas.lendacky@amd.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