Linux-HyperV List
 help / color / mirror / Atom feed
From: vdso@mailbox.org
To: Mukesh R <mrathor@linux.microsoft.com>,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
	mhkelley58@gmail.com, kameroncarr@linux.microsoft.com
Subject: Re: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
Date: Sat, 5 Dec 2026 00:21:01 -0800 (PST)	[thread overview]
Message-ID: <632435437.63501.1796458861988@app.mailbox.org> (raw)
In-Reply-To: <20261204025836.3855312-4-mrathor@linux.microsoft.com>


> On 12/03/2026 6:58 PM PST Mukesh R <mrathor@linux.microsoft.com> wrote:
> 
>  
> On Hyperv when running on hw enabled confidential computing like TDX/SNP,
> any hypercall can return with a timeout. In that case the hypercall must
> be re-issued. If it is a repeat hypercall, then the caller is expected
> to adjust the repeat start index in the input control parameter. Note,
> this does not apply when running with paravisors. A paravisor will never
> return with timeouts.

Hi Mukesh,

I thought a technical reason for the hypercall timeouts and how that works
might be a fun read for the audience here so taking the liberty to add that
to the thread.

When a _non-confidential guest_ issues a hypercall that takes a hypervisor
too long to process, the hypervisor runs the guest again but _does not
advance the instruction pointer_. If the guest enabled interrupts before
issuing the hypercall (Windows), when again entered, it can process interrupts
to stay more responsive. Once all interrupts are processed, the guest
runs the hypercall instruction again (or jumps into the hypercall page) because
_the hypervisor did not advance the instruction pointer_.

In a _confidential guest_ the hypervisor may not control the instruction
pointer. So when the confidential guest issues a hypercall that takes the
hypervisor too long to process, the hypervisor returns to the guest but
the hardware advances the instruction pointer unconditionally so the
guest cannot re-issue the hypercall automatically and the guest has to process
the timeout explicitly.

LGTM.

For the series,
Signed-off-by: Roman Kisel <vdso@mailbox.org>

> 
> Easiest is to modify the bottom most leaf function to handle the
> timeouts with special handling for repeat hypercalls.
> 
> Signed-off-by: Mukesh R <mrathor@linux.microsoft.com>
> ---
>  arch/x86/hyperv/ivm.c          | 52 +++++++++++++++++++++++++++-------
>  include/asm-generic/mshyperv.h | 12 ++++++++
>  2 files changed, 53 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index 87857b2b2fdb..0cbfaf53d28c 100644
> --- a/arch/x86/hyperv/ivm.c
> +++ b/arch/x86/hyperv/ivm.c
> @@ -365,7 +365,7 @@ int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip, unsigned int cpu)
>  	do {
>  		ret = hv_do_hypercall(HVCALL_START_VP,
>  				      start_vp_input, NULL);
> -	} while (hv_result(ret) == HV_STATUS_TIMEOUT && retry--);
> +	} while (hv_result_timeout(ret) && retry--);
>  
>  	local_irq_restore(flags);
>  
> @@ -389,12 +389,26 @@ int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip, unsigned int cpu)
>  u64 hv_snp_hypercall(u64 control, u64 param1, u64 param2)
>  {
>  	u64 hv_status;
> +	bool rep_hcall = !!hv_repcount(control);
>  
> -	register u64 __r8 asm("r8") = param2;
> -	asm volatile("vmmcall"
> -		     : "=a" (hv_status),
> -		       "+c" (control), "+d" (param1), "+r" (__r8)
> -		     : : "cc", "memory", "r9", "r10", "r11");
> +	for (;;) {
> +		register u64 __r8 asm("r8") = param2;
> +		asm volatile("vmmcall"
> +			     : "=a" (hv_status),
> +			       "+c" (control), "+d" (param1), "+r" (__r8)
> +			     : : "cc", "memory", "r9", "r10", "r11");
> +
> +		if (!hv_result_timeout(hv_status))
> +			break;
> +
> +		if (rep_hcall) {
> +			u16 rep_comp = hv_repcomp(hv_status);
> +
> +			control &= ~HV_HYPERCALL_REP_START_MASK;
> +			control |=
> +				(u64)rep_comp << HV_HYPERCALL_REP_START_OFFSET;
> +		}
> +	}
>  
>  	return hv_status;
>  }
> @@ -438,15 +452,31 @@ static void hv_tdx_msr_read(u64 msr, u64 *val)
>  
>  u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2)
>  {
> +	u64 hv_status;
> +	bool rep_hcall = !!hv_repcount(control);
>  	struct tdx_module_args args = { };
>  
> -	args.r10 = control;
> -	args.rdx = param1;
> -	args.r8  = param2;
> +	for (;;) {
> +		args.r10 = control;
> +		args.rdx = param1;
> +		args.r8  = param2;
>  
> -	(void)__tdx_hypercall(&args);
> +		(void)__tdx_hypercall(&args);
> +		hv_status = args.r11;
>  
> -	return args.r11;
> +		if (!hv_result_timeout(hv_status))
> +			break;
> +
> +		if (rep_hcall) {
> +			u16 rep_comp = hv_repcomp(hv_status);
> +
> +			control &= ~HV_HYPERCALL_REP_START_MASK;
> +			control |=
> +				(u64)rep_comp << HV_HYPERCALL_REP_START_OFFSET;
> +		}
> +	}
> +
> +	return hv_status;
>  }
>  
>  #else
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index 9d4b4d1cdac3..c59d8464ea77 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -122,6 +122,11 @@ static inline bool hv_result_success(u64 status)
>  	return hv_result(status) == HV_STATUS_SUCCESS;
>  }
>  
> +static inline bool hv_result_timeout(u64 status)
> +{
> +	return hv_result(status) == HV_STATUS_TIMEOUT;
> +}
> +
>  static inline unsigned int hv_repcomp(u64 status)
>  {
>  	/* Bits [43:32] of status have 'Reps completed' data. */
> @@ -129,6 +134,13 @@ static inline unsigned int hv_repcomp(u64 status)
>  			 HV_HYPERCALL_REP_COMP_OFFSET;
>  }
>  
> +static inline unsigned int hv_repcount(u64 control)
> +{
> +	/* Bits [43:32] of input control have 'Reps count' data. */
> +	return (control & HV_HYPERCALL_REP_COUNT_MASK) >>
> +					HV_HYPERCALL_REP_COUNT_OFFSET;
> +}
> +
>  /*
>   * Rep hypercalls. Callers of this functions are supposed to ensure that
>   * rep_count, varhead_size, and rep_start comply with Hyper-V hypercall
> -- 
> 2.51.2.vfs.0.1

      parent reply	other threads:[~2026-12-05  8:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:58 [PATCH 0/3] Handle timeouts for x86 CVMs Mukesh R
2026-12-04  2:58 ` [PATCH 1/3] Drivers: hv: Rename HV_STATUS_TIME_OUT Mukesh R
2026-12-04  2:58 ` [PATCH 2/3] Drivers: hv: Create REP_COUNT define Mukesh R
2026-12-04  3:13   ` sashiko-bot
2026-12-04  2:58 ` [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs Mukesh R
2026-12-04  3:16   ` sashiko-bot
2026-12-05  0:00     ` Mukesh R
2026-12-05  8:21   ` vdso [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=632435437.63501.1796458861988@app.mailbox.org \
    --to=vdso@mailbox.org \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kameroncarr@linux.microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhkelley58@gmail.com \
    --cc=mrathor@linux.microsoft.com \
    --cc=wei.liu@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