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=1796428845; b=PZTecoPnsqwLIWV95c7vlkxDyQcbw9uNRyXYVGHC9ODZHVjiJHy4LvFLYVmDjdPmuBK7 WvC6ws5/tLGWCRgPYO47EB3TwoIqOZ96wcYIXBpW6nwM+9ETcX/I2yGFXmqrFlv6ExM1O UnFG8z1xRD+B2qqikblPx7vUAGhwwOq1UVvNbnOXK5f8LyI7BbXPzYYh2og+8g9yKGlk5 jHs8m80vuxTG2+1V3gFzWSvecL+5fyRRjUmMk9nA5nUYSRfyRoQCLaPdGVCWAgR1u3nBv MbQFE5iJlyT96uxQxmCrC8XOfsxc6HcE7owSYlCCeduJCNbndOv0KLV+2e37GKPUNiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796428845; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:Content-Language:To:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding:X-Spam-Status: X-Spam-Checker-Version; bh=sk5KPwqVlDNvBLRokE5WylHa4y81pzBSrnQiJF7B72o=; b=2mJDOlDbuH9wC3TgatIDNoTnQaVTElmmf/1D2E/3TiEPhp5YUb6R6ebZvJMHN7V72Ed3 wJV5zIV1LoAasV9lytNrvNvisHppEdmVsOpz7ZRGQEcN2Ka8IucW9cq9I63QitzysZpz8 9rcGpq8jqmQGEqyOkd3NGHr66vd1bOUh8atLSUG+hl4hgPuegmieRQVy5eseyvxIR4l/K Pb0ViyzIFy/Wcu+hlc+wnLMYqD7zar/Ja6c2mm1iFRRHHa/8ZK10jSOnBQYP2NtZiyDL8 ESwKYZ9LP7zBxKcO9ezszhHSdeamN0FgMi5ecK4cIepYuFmcoHhuhFLdt9xOiNvEzUw== 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=PFORxQ5u; 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 71ED3606A333 for ; Sat, 5 Dec 2026 00:00:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 71ED3606A333 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=PFORxQ5u Received: from [192.168.0.88] (192-184-212-33.fiber.dynamic.sonic.net [192.184.212.33]) by linux.microsoft.com (Postfix) with ESMTPSA id 298E920B7178; Fri, 4 Dec 2026 16:00:43 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 298E920B7178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796428843; bh=sk5KPwqVlDNvBLRokE5WylHa4y81pzBSrnQiJF7B72o=; h=Date:Subject:To:References:From:In-Reply-To:From; b=PFORxQ5u6uGEGz+5JEFmQi1tvImeflPqZfEPVbvTgDr/LwXhv9sdK/uxJMw9wH+Od /FGssZrXK3bjFfVovcwglRMyF1waouLCLC9n7AfciR3y1uLxVB0A3FjBF7uytS8BMh yJ/kFquty7NSZR4azlTBxpQn/H9+U6xE03TWWbNs= Message-ID: Date: Fri, 4 Dec 2026 16:00:43 -0800 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 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH 3/3] x86/hyperv: Handle hypercall timeouts on hw confidential VMs Content-Language: en-US To: sashiko-reviews@lists.linux.dev, linux-hyperv@vger.kernel.org References: <20261204025836.3855312-1-mrathor@linux.microsoft.com> <20261204025836.3855312-4-mrathor@linux.microsoft.com> From: Mukesh R In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/3/26 19:16, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 4 potential > issues to consider: > - [High] x86/hyperv: unbounded timeout retry loops without watchdog or > rep_comp checks > - [Medium] x86/hyperv: reuse of dirty tdx_module_args on retry in > hv_tdx_hypercall() > - [Medium] x86/hyperv: missing timeout retry in hv_ghcb_hypercall() for > SNP paravisor > - [Medium] x86/hyperv: dead retry loop and lost retry cap in > hv_snp_boot_ap() > -- > > commit 6d87e857871bbab96f5f0cd1dc1cd6280f5a9405 > Author: Mukesh R > > x86/hyperv: Handle hypercall timeouts on hw confidential VMs > > This commit adds retry loops for HV_STATUS_TIMEOUT to hv_snp_hypercall() and > hv_tdx_hypercall(), updating the repeat start index on repeat hypercalls, and > introduces hv_result_timeout() and hv_repcount() helpers. > >> 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. > > [Severity: Medium] > Does hv_ghcb_hypercall() also need timeout retry handling for SNP guests > running with a paravisor? > > When ms_hyperv.paravisor_present is true, hv_post_message() (for > non-confidential VMBus) and vmbus_set_event() bypass the paravisor and call > the host hypervisor directly via hv_tdx_hypercall() on TDX and > hv_ghcb_hypercall() on SNP. Unlike hv_tdx_hypercall(), hv_ghcb_hypercall() > is not updated to retry on HV_STATUS_TIMEOUT. If the host returns a timeout > there, vmbus_post_msg() fails immediately with -EINVAL and vmbus_set_event() > silently drops the event signal. Sashiko, you are a good bot, but you missed this sentence in the commit log: "A paravisor will never return with timeouts." So, hv_ghcb_hypercall() will not return timeouts (according to its authors). >> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c >> index 87857b2b2fdb9..0cbfaf53d28c3 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); > > [Severity: Medium] > Can hv_result_timeout(ret) ever be true here now? > > hv_snp_boot_ap() is only registered on SEV-SNP guests without a paravisor, > where hv_do_hypercall() dispatches to hv_snp_hypercall(). Because > hv_snp_hypercall() now loops until the status is no longer HV_STATUS_TIMEOUT, > the retry = 5 loop becomes dead code, and persistent HVCALL_START_VP timeouts > spin forever with interrupts disabled instead of aborting and cleaning up the > VMSA page via snp_cleanup_vmsa(). Good point. will remove it. >> @@ -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; >> } > > [Severity: High] > Can this unbounded retry loop (and the matching one in hv_tdx_hypercall() > below) trigger NMI hardlockup watchdog panics or hang the vCPU with IRQs > disabled? > > Long IRQ-disabled repeat hypercalls such as hv_mark_gpa_visibility() rely on > touch_nmi_watchdog() in hv_do_rep_hypercall_ex() across continuation slices, > which is bypassed while spinning inside these leaf loops. > > In addition, rep_comp from the hypervisor is not checked against rep_count or > the previous rep_start for forward progress, and zero-progress retries are > unbounded. Persistent timeouts or a non-advancing rep_comp will wedge the > vCPU indefinitely instead of returning an error to callers that have recovery > or native fallback paths (such as native_flush_tlb_multi()). No hypercalls should be long enough that we've to touch nmi. Callers must ensure they batch it reasonably so it returns, enable interrupts, then disable, and redo the hypercall. >> @@ -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; > > [Severity: Medium] > Should struct tdx_module_args args be re-initialized inside the retry loop? we could move param1 and param2 outside the loop. will fix it in V1. > __tdx_hypercall() loads all 13 register fields from args (exposed via > TDVMCALL_EXPOSE_REGS_MASK) and writes VMM output back into all of them on > return. On a timeout retry, only r10, rdx, and r8 (plus rcx in > __tdx_hypercall()) are rewritten, leaving stale VMM-returned values including > HV_STATUS_TIMEOUT in args.r11 across iterations. > Because the return value of __tdx_hypercall() is ignored, if a retry fails > without the VMM updating r11, hv_status = args.r11 will observe the stale > HV_STATUS_TIMEOUT and spin indefinitely. Declaring and zero-initializing > args inside the loop (as tdx_map_gpa() does) avoids reusing dirty state. > we are ok here because hypervisor will always update r11 and will not return without doing that. Thanks, -Mukesh