Linux-HyperV List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mukesh R" <mrathor@linux.microsoft.com>, linux-hyperv@vger.kernel.org
Subject: Re: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
Date: Fri, 04 Dec 2026 03:16:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-249030@kernel.org> (raw)
In-Reply-To: <20261204025836.3855312-4-mrathor@linux.microsoft.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] x86/hyperv: unbounded timeout retry loops without watchdog or
  rep_comp checks
- [Medium] x86/hyperv: reuse of dirty tdx_module_args on retry in
  hv_tdx_hypercall()
- [Medium] x86/hyperv: missing timeout retry in hv_ghcb_hypercall() for
  SNP paravisor
- [Medium] x86/hyperv: dead retry loop and lost retry cap in
  hv_snp_boot_ap()
--

commit 6d87e857871bbab96f5f0cd1dc1cd6280f5a9405
Author: Mukesh R <mrathor@linux.microsoft.com>

x86/hyperv: Handle hypercall timeouts on hw confidential VMs

This commit adds retry loops for HV_STATUS_TIMEOUT to hv_snp_hypercall() and
hv_tdx_hypercall(), updating the repeat start index on repeat hypercalls, and
introduces hv_result_timeout() and hv_repcount() helpers.

> 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.

[Severity: Medium]
Does hv_ghcb_hypercall() also need timeout retry handling for SNP guests
running with a paravisor?

When ms_hyperv.paravisor_present is true, hv_post_message() (for
non-confidential VMBus) and vmbus_set_event() bypass the paravisor and call
the host hypervisor directly via hv_tdx_hypercall() on TDX and
hv_ghcb_hypercall() on SNP.  Unlike hv_tdx_hypercall(), hv_ghcb_hypercall()
is not updated to retry on HV_STATUS_TIMEOUT.  If the host returns a timeout
there, vmbus_post_msg() fails immediately with -EINVAL and vmbus_set_event()
silently drops the event signal.

> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index 87857b2b2fdb9..0cbfaf53d28c3 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);

[Severity: Medium]
Can hv_result_timeout(ret) ever be true here now?

hv_snp_boot_ap() is only registered on SEV-SNP guests without a paravisor,
where hv_do_hypercall() dispatches to hv_snp_hypercall().  Because
hv_snp_hypercall() now loops until the status is no longer HV_STATUS_TIMEOUT,
the retry = 5 loop becomes dead code, and persistent HVCALL_START_VP timeouts
spin forever with interrupts disabled instead of aborting and cleaning up the
VMSA page via snp_cleanup_vmsa().

> @@ -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;
>  }

[Severity: High]
Can this unbounded retry loop (and the matching one in hv_tdx_hypercall()
below) trigger NMI hardlockup watchdog panics or hang the vCPU with IRQs
disabled?

Long IRQ-disabled repeat hypercalls such as hv_mark_gpa_visibility() rely on
touch_nmi_watchdog() in hv_do_rep_hypercall_ex() across continuation slices,
which is bypassed while spinning inside these leaf loops.

In addition, rep_comp from the hypervisor is not checked against rep_count or
the previous rep_start for forward progress, and zero-progress retries are
unbounded.  Persistent timeouts or a non-advancing rep_comp will wedge the
vCPU indefinitely instead of returning an error to callers that have recovery
or native fallback paths (such as native_flush_tlb_multi()).

> @@ -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;

[Severity: Medium]
Should struct tdx_module_args args be re-initialized inside the retry loop?

__tdx_hypercall() loads all 13 register fields from args (exposed via
TDVMCALL_EXPOSE_REGS_MASK) and writes VMM output back into all of them on
return.  On a timeout retry, only r10, rdx, and r8 (plus rcx in
__tdx_hypercall()) are rewritten, leaving stale VMM-returned values including
HV_STATUS_TIMEOUT in args.r11 across iterations.

Because the return value of __tdx_hypercall() is ignored, if a retry fails
without the VMM updating r11, hv_status = args.r11 will observe the stale
HV_STATUS_TIMEOUT and spin indefinitely.  Declaring and zero-initializing
args inside the loop (as tdx_map_gpa() does) avoids reusing dirty state.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204025836.3855312-1-mrathor@linux.microsoft.com?part=3

      reply	other threads:[~2026-12-04  3:16 UTC|newest]

Thread overview: 6+ 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 [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=sashiko-outbox-249030@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=mrathor@linux.microsoft.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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