From: Mukesh R <mrathor@linux.microsoft.com>
To: 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: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs
Date: Thu, 3 Dec 2026 18:58:36 -0800 [thread overview]
Message-ID: <20261204025836.3855312-4-mrathor@linux.microsoft.com> (raw)
In-Reply-To: <20261204025836.3855312-1-mrathor@linux.microsoft.com>
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
next prev parent reply other threads:[~2026-12-04 2:58 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 ` Mukesh R [this message]
2026-12-04 3:16 ` [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs sashiko-bot
2026-12-05 0:00 ` Mukesh R
2026-12-05 8:21 ` vdso
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=20261204025836.3855312-4-mrathor@linux.microsoft.com \
--to=mrathor@linux.microsoft.com \
--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=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 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.