All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Handle timeouts for x86 CVMs
@ 2026-12-04  2:58 Mukesh R
  2026-12-04  2:58 ` [PATCH 1/3] Drivers: hv: Rename HV_STATUS_TIME_OUT Mukesh R
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Mukesh R @ 2026-12-04  2:58 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel
  Cc: haiyangz, wei.liu, decui, mhkelley58, kameroncarr

This tiny series handles timeouts for confidential VMs. Last commit
desribes the issue and the solution.

Thanks,
-Mukesh


Mukesh R (3):
  Drivers: hv: Rename HV_STATUS_TIME_OUT
  Drivers: hv: Create REP_COUNT define
  x86/hyperv: Handle hypercall timeouts on hw confidential VMs

 arch/x86/hyperv/ivm.c          | 52 +++++++++++++++++++++++++++-------
 arch/x86/kvm/hyperv.c          |  2 +-
 drivers/hv/hv_common.c         |  2 +-
 include/asm-generic/mshyperv.h | 14 ++++++++-
 include/hyperv/hvgdk_mini.h    | 10 +++++--
 5 files changed, 63 insertions(+), 17 deletions(-)

-- 
2.51.2.vfs.0.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] Drivers: hv: Rename HV_STATUS_TIME_OUT
  2026-12-04  2:58 [PATCH 0/3] Handle timeouts for x86 CVMs Mukesh R
@ 2026-12-04  2:58 ` Mukesh R
  2026-12-04  2:58 ` [PATCH 2/3] Drivers: hv: Create REP_COUNT define Mukesh R
  2026-12-04  2:58 ` [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs Mukesh R
  2 siblings, 0 replies; 8+ messages in thread
From: Mukesh R @ 2026-12-04  2:58 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel
  Cc: haiyangz, wei.liu, decui, mhkelley58, kameroncarr

Rename HV_STATUS_TIME_OUT to HV_STATUS_TIMEOUT to match the hypervisor
public header files. There is really no reason for it to be different.

Signed-off-by: Mukesh R <mrathor@linux.microsoft.com>
---
 arch/x86/hyperv/ivm.c       | 2 +-
 drivers/hv/hv_common.c      | 2 +-
 include/hyperv/hvgdk_mini.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
index 2ce4dfe53472..87857b2b2fdb 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_TIME_OUT && retry--);
+	} while (hv_result(ret) == HV_STATUS_TIMEOUT && retry--);
 
 	local_irq_restore(flags);
 
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 80981bd948cb..0e7332f4191c 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -839,7 +839,7 @@ static const struct hv_status_info hv_status_infos[] = {
 	_STATUS_INFO(HV_STATUS_INVALID_REGISTER_VALUE,		-EINVAL),
 	_STATUS_INFO(HV_STATUS_DEVICE_ALREADY_IN_DOMAIN,	-EEXIST),
 	_STATUS_INFO(HV_STATUS_OPERATION_FAILED,		-EIO),
-	_STATUS_INFO(HV_STATUS_TIME_OUT,			-EIO),
+	_STATUS_INFO(HV_STATUS_TIMEOUT,				-EIO),
 	_STATUS_INFO(HV_STATUS_CALL_PENDING,			-EIO),
 	_STATUS_INFO(HV_STATUS_VTL_ALREADY_ENABLED,		-EIO),
 #undef _STATUS_INFO
diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
index 966945f0504f..bec4e633e381 100644
--- a/include/hyperv/hvgdk_mini.h
+++ b/include/hyperv/hvgdk_mini.h
@@ -41,7 +41,7 @@ struct hv_u128 {
 #define HV_STATUS_OPERATION_FAILED			0x71
 #define HV_STATUS_INSUFFICIENT_ROOT_MEMORY		0x73
 #define HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY	0x75
-#define HV_STATUS_TIME_OUT				0x78
+#define HV_STATUS_TIMEOUT				0x78
 #define HV_STATUS_CALL_PENDING				0x79
 #define HV_STATUS_INSUFFICIENT_CONTIGUOUS_ROOT_MEMORY	0x83
 #define HV_STATUS_VTL_ALREADY_ENABLED			0x86
-- 
2.51.2.vfs.0.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] Drivers: hv: Create REP_COUNT define
  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 ` 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
  2 siblings, 1 reply; 8+ messages in thread
From: Mukesh R @ 2026-12-04  2:58 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel
  Cc: haiyangz, wei.liu, decui, mhkelley58, kameroncarr

When a repeat hypercall completes, it returns completions as part of
the status in bits 43-32, and HV_HYPERCALL_REP_COMP_MASK is used to
extract and examine it. When issuing a hypercall, the actual repeat
count is part of the input struct at same bits. However, the same
COMP_MASK is used to set it. This maybe confusing for anyone reading
the code. Add HV_HYPERCALL_REP_COUNT_MASK and use it for counts
instead of REP_COMP.

Signed-off-by: Mukesh R <mrathor@linux.microsoft.com>
---
 arch/x86/kvm/hyperv.c          | 2 +-
 include/asm-generic/mshyperv.h | 2 +-
 include/hyperv/hvgdk_mini.h    | 8 ++++++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 5d2e3617c952..ce40bb48016b 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -2579,7 +2579,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	hc.code = hc.param & 0xffff;
 	hc.var_cnt = (hc.param & HV_HYPERCALL_VARHEAD_MASK) >> HV_HYPERCALL_VARHEAD_OFFSET;
 	hc.fast = !!(hc.param & HV_HYPERCALL_FAST_BIT);
-	hc.rep_cnt = (hc.param >> HV_HYPERCALL_REP_COMP_OFFSET) & 0xfff;
+	hc.rep_cnt = (hc.param >> HV_HYPERCALL_REP_COUNT_OFFSET) & 0xfff;
 	hc.rep_idx = (hc.param >> HV_HYPERCALL_REP_START_OFFSET) & 0xfff;
 	hc.rep = !!(hc.rep_cnt || hc.rep_idx);
 
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index b9157ac8731c..9d4b4d1cdac3 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -143,7 +143,7 @@ static inline u64 hv_do_rep_hypercall_ex(u16 code, u16 rep_count,
 	u16 rep_comp;
 
 	control |= (u64)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET;
-	control |= (u64)rep_count << HV_HYPERCALL_REP_COMP_OFFSET;
+	control |= (u64)rep_count << HV_HYPERCALL_REP_COUNT_OFFSET;
 	control |= (u64)rep_start << HV_HYPERCALL_REP_START_OFFSET;
 
 	do {
diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
index bec4e633e381..160d0813e598 100644
--- a/include/hyperv/hvgdk_mini.h
+++ b/include/hyperv/hvgdk_mini.h
@@ -521,9 +521,9 @@ union hv_vp_assist_msr_contents {	 /* HV_REGISTER_VP_ASSIST_PAGE */
 #define HV_HYPERCALL_VARHEAD_MASK	GENMASK_ULL(26, 17)
 #define HV_HYPERCALL_RSVD0_MASK		GENMASK_ULL(31, 27)
 #define HV_HYPERCALL_NESTED		BIT_ULL(31)
-#define HV_HYPERCALL_REP_COMP_OFFSET	32
 #define HV_HYPERCALL_REP_COMP_1		BIT_ULL(32)
-#define HV_HYPERCALL_REP_COMP_MASK	GENMASK_ULL(43, 32)
+#define HV_HYPERCALL_REP_COUNT_OFFSET	32
+#define HV_HYPERCALL_REP_COUNT_MASK	GENMASK_ULL(43, 32)
 #define HV_HYPERCALL_RSVD1_MASK		GENMASK_ULL(47, 44)
 #define HV_HYPERCALL_REP_START_OFFSET	48
 #define HV_HYPERCALL_REP_START_MASK	GENMASK_ULL(59, 48)
@@ -532,6 +532,10 @@ union hv_vp_assist_msr_contents {	 /* HV_REGISTER_VP_ASSIST_PAGE */
 					 HV_HYPERCALL_RSVD1_MASK | \
 					 HV_HYPERCALL_RSVD2_MASK)
 
+/* Hypercall output status */
+#define HV_HYPERCALL_REP_COMP_OFFSET	32
+#define HV_HYPERCALL_REP_COMP_MASK	GENMASK_ULL(43, 32)
+
 /* HvFlushGuestPhysicalAddressSpace hypercalls */
 struct hv_guest_mapping_flush {
 	u64 address_space;
-- 
2.51.2.vfs.0.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
  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  2:58 ` Mukesh R
  2026-12-04  3:16   ` sashiko-bot
  2026-12-05  8:21   ` vdso
  2 siblings, 2 replies; 8+ messages in thread
From: Mukesh R @ 2026-12-04  2:58 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel
  Cc: haiyangz, wei.liu, decui, mhkelley58, kameroncarr

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.

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] Drivers: hv: Create REP_COUNT define
  2026-12-04  2:58 ` [PATCH 2/3] Drivers: hv: Create REP_COUNT define Mukesh R
@ 2026-12-04  3:13   ` sashiko-bot
  0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-04  3:13 UTC (permalink / raw)
  To: Mukesh R, linux-hyperv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] hv: commit message misstates REP_COUNT macro additions and usage
--

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

Drivers: hv: Create REP_COUNT define

This commit adds HV_HYPERCALL_REP_COUNT_OFFSET and
HV_HYPERCALL_REP_COUNT_MASK for Hyper-V repeat hypercall inputs and
updates kvm_hv_hypercall() and hv_do_rep_hypercall_ex() to use
HV_HYPERCALL_REP_COUNT_OFFSET.

> count is part of the input struct at same bits. However, the same
> COMP_MASK is used to set it. This maybe confusing for anyone reading
> the code. Add HV_HYPERCALL_REP_COUNT_MASK and use it for counts
> instead of REP_COMP.

[Severity: Low]
Does the commit message accurately describe the macros added and updated
here?

hv_do_rep_hypercall_ex() and kvm_hv_hypercall() previously used
HV_HYPERCALL_REP_COMP_OFFSET, not HV_HYPERCALL_REP_COMP_MASK (which is
only used for output status in hv_repcomp()).

This patch adds both HV_HYPERCALL_REP_COUNT_OFFSET and
HV_HYPERCALL_REP_COUNT_MASK, and updates those two call sites to use
HV_HYPERCALL_REP_COUNT_OFFSET rather than HV_HYPERCALL_REP_COUNT_MASK.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
  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
  1 sibling, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-12-04  3:16 UTC (permalink / raw)
  To: Mukesh R, linux-hyperv

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
  2026-12-04  3:16   ` sashiko-bot
@ 2026-12-05  0:00     ` Mukesh R
  0 siblings, 0 replies; 8+ messages in thread
From: Mukesh R @ 2026-12-05  0:00 UTC (permalink / raw)
  To: sashiko-reviews, linux-hyperv

On 12/3/26 19:16, sashiko-bot@kernel.org wrote:
> 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.

Sashiko, you are a good bot, but you missed this sentence in the
commit log: "A paravisor will never return with timeouts."

So, hv_ghcb_hypercall() will not return timeouts (according to its
authors).

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

Good point. will remove it.

>> @@ -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()).

No hypercalls should be long enough that we've to touch nmi. Callers
must ensure they batch it reasonably so it returns, enable interrupts,
then disable, and redo the hypercall.

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

we could move param1 and param2 outside the loop. will fix it in V1.

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

we are ok here because hypervisor will always update r11 and will not
return without doing that.

Thanks,
-Mukesh


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
  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  8:21   ` vdso
  1 sibling, 0 replies; 8+ messages in thread
From: vdso @ 2026-12-05  8:21 UTC (permalink / raw)
  To: Mukesh R, linux-hyperv, linux-kernel
  Cc: haiyangz, wei.liu, decui, mhkelley58, kameroncarr


> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-05  8:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.