From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796458866; b=ux40SOpQZ1t2WLGBHYpdTkD9ySoR9hV5ZVK6n9VPFCB6VDc3JhajdeFbi+rZU1wFFNns GnYM6iKSB7xYHzhJDv5+UWr537vWeJLqxF0eQsCCJsTZ5wegCRaH52sFYPVHvXi0e2mBN 46EuFeG2Lzewg3J8LYPa1zFqCnaWfTpnw3lsZTRi7ml+AG2+p/+ArKopWcKdDoZZuiFd4 l7eLMjtW7tDnEn0cbrtMKjUE69TvhaIR100TFYXym9O0He6xCqE/WyYMVkGij3jdchLLy Z7j/UTzx7jZt8hXnZvUdrm4mwGfF6/f+h902wLNMcsxVoPt8Qcd55Ce//PbpAHwXhrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796458866; h=DMARC-Filter:Received:DKIM-Signature:Date:From:To:Cc:Message-ID: In-Reply-To:References:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:X-Priority:Importance:X-Mailer: X-Originating-Client:X-MBO-RS-META:X-MBO-RS-ID; bh=rfXF9dAmsw/br0D9bf2w6mE7N2fe/WTehJr5Fmi/Acg=; b=SfwVR5mmipJ8l9H80OWrs6t/Ffe9pa/FNsIy07SWVIQMBvDPPcRUX1qCHVxdqjy/NmBF 5A4rxX7YO+pJNSbgwMo7gtid1rxsKTPejqn7FoPeCEGzE7kpO7tzKAeffOMwtPk/O9Ux/ 22NI2v0wC87ayYFBaQ10WNkvQeyIeXrCfYkwPWYb8geITO/TO1DYzGtgdSexNl4Gfq0g9 ZUFNxqlsb9OTaPHwERhS4X51Rq1I3qZfE7ZblNnGErwtGPpu+GkdfhB7i6UVvnkSkRHZB R86I6Q1kFulvy9tUAntajFPmZo5/xb91Ba7U8pV2iDGA2luFaStxreoWe5Zs2uQcyCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=RWZCmEm+; arc=none smtp.remote-ip=80.241.56.171 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE92C606A33B; Sat, 5 Dec 2026 08:21:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CE92C606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=RWZCmEm+ Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4jhLsp3H9SzMlmg; Sat, 05 Dec 2026 09:21:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796458862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rfXF9dAmsw/br0D9bf2w6mE7N2fe/WTehJr5Fmi/Acg=; b=RWZCmEm+WVMvCY+dZD2RQJz1rYAGZPhLbsITIrFDiIqvsD4ra1Lc/xIkX6ZG9W3fAyw5Mx 0NtaXF1/4v6CnV/Wy0zpALG02QQH3FCkEQ5xShSm+huj+wzOfe6uMLClvfY6bz1PSw1/mK 1RvvjCKrJHTPFQT7R8GNMRjcTfIPrr0L45UI2nJQzdRkUqMowXFXdovsKIDsdguW+At8tQ HejAoLKevor4n2GG+l6G0UJ93nowb2hhJNzjl0GR9+t5QzbkQSt/XZt/ah/zV6YYzj+LKY ZTV2+VOpONQlC/1HFL9vP0QIATE59WtzB+dluyaLOJNYsqF/kXC5KOTStM2Y0Q== Date: Sat, 5 Dec 2026 00:21:01 -0800 (PST) From: vdso@mailbox.org To: Mukesh R , 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 Message-ID: <632435437.63501.1796458861988@app.mailbox.org> In-Reply-To: <20261204025836.3855312-4-mrathor@linux.microsoft.com> References: <20261204025836.3855312-1-mrathor@linux.microsoft.com> <20261204025836.3855312-4-mrathor@linux.microsoft.com> Subject: Re: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v8.54.538 X-Originating-Client: open-xchange-appsuite X-MBO-RS-META: phfpbotf3pdiy8qkm6jiqgxhoonm9zaf X-MBO-RS-ID: 6d52c08d2068e4a0b6d > On 12/03/2026 6:58 PM PST Mukesh R 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 > > Easiest is to modify the bottom most leaf function to handle the > timeouts with special handling for repeat hypercalls. > > Signed-off-by: Mukesh R > --- > 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