From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=13.77.154.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796353132; b=DKX0ERMWj7Ia30PJolRcivUiwuAmI7+sv55xJvKEKwMHdrRrlESU2dj5YF2IN+eXnOOS WgY+1zJtPDa2T6XF7JOyLhj/+e3I44tk9B4DgBpPdmLFbS3/0kxwrtUG8FUcO8Uo+xPZ/ D5Dsnb8WPkIVmVDM7SWA6lNIfsmHJTAfhRjlBemUZpswiAyapRM+CyVAfdsuI3abH6q7T 5vMTqV+PscDx+x+3HBh55Dj8kvo0HzkRlZdpN3fveiIGH8aNz6uVaT/VsO3WIsQMMPCx4 /lKQS4T/L49r5dF6svxeP861NxORlmGVnytMbCY73CEt7GokkPi/oCs0FKdashtA76w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796353132; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Spam-Status:X-Spam-Checker-Version; bh=bzRMzY3VRLnQmvLb1DQhe/aT7+0ei1Z6bvOzv4UGkRc=; b=zkBHPCvmqltUH8bNccp4rPmcrmoBSwe0DC/re8oB6+zOH4teR1/AruVWoIGjDk+DO5qL TI7tpgTv0YI8XFMYnCNySsfp6pngbKpFv0q9VkTJgsRa85aXm+aAYwgmz/G7gxsYGsubY EWV7Uqoaq9wQBid1RTOk/H+bsPyZMtSf58NU2WkC2DZRsQHIKKM7/vF/c2rUW0e0LUKwR vgVIWiyYci8w1n2pC9UsZjpgo8OM62TfnHDk1tqo5gLRVUNSEfN9LEMWoQDAfFPOANQ2P HOnF8n7JeisWI/lTJetMh3upU6LzN0rpBpJq3g1YDUxwfk/P9vHFT43987PgxUUjsNw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=aFzBdOPW; arc=none smtp.remote-ip=13.77.154.182 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 42C96606A69D; Fri, 4 Dec 2026 02:58:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 42C96606A69D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=aFzBdOPW Received: from mrdev.corp.microsoft.com (192-184-212-33.fiber.dynamic.sonic.net [192.184.212.33]) by linux.microsoft.com (Postfix) with ESMTPSA id E1D4720B7169; Thu, 3 Dec 2026 18:58:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E1D4720B7169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796353129; bh=bzRMzY3VRLnQmvLb1DQhe/aT7+0ei1Z6bvOzv4UGkRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aFzBdOPWwy9EJyM7hC5QiGwXNNmmCsGRKU6V2sA2AEMZZk7IvLUGBNSrElfVjdSXu a6T1rab0+uaKwqxrAMj1Uk15XjCxDEXLFC2CYANGGJNY0KJfqteqJmUAjpLwV4pOvy hHMlz8TE+YXsr3kn/yfQbGRzVx/fMoB5N2TYEVyo= From: Mukesh R 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 Message-ID: <20261204025836.3855312-4-mrathor@linux.microsoft.com> X-Mailer: git-send-email 2.51.2.vfs.0.1 In-Reply-To: <20261204025836.3855312-1-mrathor@linux.microsoft.com> References: <20261204025836.3855312-1-mrathor@linux.microsoft.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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