[PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
From: Mukesh R
Date: Thu Dec 03 2026 - 21:59:03 EST
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@xxxxxxxxxxxxxxxxxxx>
---
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