mirror of https://lore.kernel.org/lkml/
 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; 4+ 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] 4+ 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; 4+ 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	[flat|nested] 4+ 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  2:58 ` [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs Mukesh R
  2 siblings, 0 replies; 4+ 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	[flat|nested] 4+ 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
  2 siblings, 0 replies; 4+ 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	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-04  2:58 UTC | newest]

Thread overview: 4+ 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  2:58 ` [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs Mukesh R

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®