From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796063743; b=4k9baVmoBdvhBAuaSmv5rYcnTlv0WXYzsREl8lJXYPYJRX/n0msh90/jji0qbGsgmMdc VXkvNEyvCXGmDIyEC1ZDkHV55Wk8fzTa4e6VGTP7gj5StzYPqvr8SFwjqdgmUV2+PSsM5 VKZz9aJ3jIx++sfi8JgwjH10HAmYrU36X5On/Ld0oc3/cnuPAimqRVsdfRBIesXeY9Bwc h9FJ0njVRPPDA9VAOUPUWxJcCPBFl+hauFoW+LsoRh7kPwqd3Tq1vFD58+f0LeDkDeVsH DNwwNBegeVRePntFvyFT9HCymNtE84I5r+tH/CfMqIszCrDhF996uY6G2CRbGCUvetg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796063743; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=dQsqpbLsQx6ENgZffhpLNm+QUY3b9eT28LnvWJV3sf4=; b=2tawJnmCo1TLCuCn/umcZR/RSx/NpEUvc6oYy6VDFVobFYjp98fVo78ETNYDWWP5Hpy+ XiNLGoCCkxXVgZMKqM17cVFjpOdP7Zzfi4sHHebePlD8I6R+MGSpjgFFBJ7eHcCiNa0Hm uY+iNM2R8Hi+INJvHgyxYaGKrUkk2fMXQRjzPKWfCvXONDvq1fbUR081D5IJ0EcaFyFz2 GU1jiwemnAoLyqy7gfOgE25nVCqTr3ULmJr1h66UJlGAgXsJG1Nwk06VXSoViauTFcvNo KU95AQKdbSqU40RxPhNQi6bffIA00T6Fx4UQTAXfInZJK6RIKSKEG43W98xovG6WnFw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ejc2p3C0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21CDB606A31C; Mon, 30 Nov 2026 18:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ejc2p3C0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A5BB1F000C1; Mon, 30 Nov 2026 18:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796063742; bh=dQsqpbLsQx6ENgZffhpLNm+QUY3b9eT28LnvWJV3sf4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ejc2p3C0rFE+fysq6SrLs5oBtQp5ikbmYvOjqWCT+1zL22o5KDqim6XfE4+rhjteb rS4uP63vVlEeBrI5XKglJSRQjNIxNuisgk4eS1MeoFIIHnJh4AEwbiKmiVELX0DQ1o lxDD0HO47CjuhhMVK+skv1P+PZu2jCIPLxQyrGkfrRtvn+JrTd301N5gM3uBelqE/5 bhrTtTq+bdNn7MqN5h6QD/VI589BNiLjQvc+JJQ2EVh52ph5w0eXIyEPan4K0sWoHh 9/6sy5DcfjZI14olKoOLpKjMoOD+VR5oIW689Dh8sCGyXC6cOF3UaNlcUlO1nw7rYt 9CnQQYrGOplng== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 06/23] nitro_enclaves: Retry a command the device asks us to retry Reply-To: sashiko-reviews@lists.linux.dev To: "Alexander Graf" , "Greg Kroah-Hartman" , "Arnd Bergmann" Cc: "The AWS Nitro Enclaves Team" , "Paolo Bonzini" , "Stefano Garzarella" , "Stefan Hajnoczi" , "Marek Szyprowski" , "Robin Murphy" , "Andrew Morton" , "David Hildenbrand" , "Mike Rapoport" , "Jonathan Corbet" , "Shuah Khan" , "Randy Dunlap" , diapop@amazon.com, mancio@amazon.com, mknaust@amazon.com, nh-open-source@amazon.com, kvm@vger.kernel.org, virtualization@lists.linux.dev, linux-mm@kvack.org, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <912dd2023d5151105ccf4629dc7150b28faf166d.1795965038.git.graf@amazon.com> References: <912dd2023d5151105ccf4629dc7150b28faf166d.1795965038.git.graf@amazon.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 18:35:41 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] nitro_enclaves: enclaves_list_mutex held across retry in ne_enclave_release() -- commit 6fed9d92931fd77de6660031a8280950cb317c53 Author: Alexander Graf nitro_enclaves: Retry a command the device asks us to retry This commit adds retry handling with exponential backoff in ne_do_request() when the Nitro Enclaves PCI device replies with -EAGAIN, and converts enclave and list mutex acquisitions in the ioctl and event work paths to mutex_lock_killable(). > diff --git a/drivers/virt/nitro_enclaves/ne_pci_dev.c b/drivers/virt/nitr= o_enclaves/ne_pci_dev.c > index c37777bb95b49..199c3c7f8c42e 100644 > --- a/drivers/virt/nitro_enclaves/ne_pci_dev.c > +++ b/drivers/virt/nitro_enclaves/ne_pci_dev.c [ ... ] > @@ -159,6 +209,27 @@ int ne_do_request(struct pci_dev *pdev, enum ne_pci_= dev_cmd_type cmd_type, > =20 > atomic_set(&ne_pci_dev->cmd_reply_avail, 0); > =20 > + if (cmd_reply->rc =3D=3D -EAGAIN) { > + /* > + * The device answered, so nothing is in flight and another > + * command may go out while this one waits to be sent again. > + */ > + mutex_unlock(&ne_pci_dev->pci_dev_mutex); > + > + if (!deadline) { > + unsigned int budget_msecs =3D ne_cmd_frees_slot(cmd_type) ? > + NE_FREE_TIMEOUT_MSECS : > + NE_CMD_RETRY_TOTAL_MSECS; > + > + deadline =3D jiffies + msecs_to_jiffies(budget_msecs); > + } > + > + msleep(delay_msecs); > + delay_msecs =3D min(delay_msecs * 2, NE_CMD_RETRY_MAX_MSECS); > + > + goto retry; > + } > + > if (cmd_reply->rc < 0) { > rc =3D cmd_reply->rc; > =20 > @@ -221,7 +292,14 @@ static void ne_event_work_handler(struct work_struct= *work) > int rc =3D -EINVAL; > struct slot_info_req slot_info_req =3D {}; > =20 > - mutex_lock(&ne_pci_dev->enclaves_list_mutex); > + /* > + * A release holds these locks for as long as the device takes to free > + * the slot, which can be minutes, so wait killable: that is not > + * reported as a hung task. The worker gets no signal, so the locks do > + * not fail. > + */ > + if (mutex_lock_killable(&ne_pci_dev->enclaves_list_mutex)) > + return; > =20 > /* > * Iterate over all enclaves registered for the Nitro Enclaves > @@ -229,7 +307,8 @@ static void ne_event_work_handler(struct work_struct = *work) > * is corresponding to. > */ > list_for_each_entry(ne_enclave, &ne_pci_dev->enclaves_list, enclave_lis= t_entry) { > - mutex_lock(&ne_enclave->enclave_info_mutex); > + if (mutex_lock_killable(&ne_enclave->enclave_info_mutex)) > + break; [Severity: Medium] Does holding ne_pci_dev->enclaves_list_mutex across ne_enclave_free_slot() in ne_enclave_release() block out-of-band event delivery for all other running enclaves and still trigger hung-task warnings during a slow slot release? drivers/virt/nitro_enclaves/ne_misc_dev.c:ne_enclave_release() { ... mutex_lock(&ne_pci_dev->enclaves_list_mutex); mutex_lock(&ne_enclave->enclave_info_mutex); /* * A slot the device did not free may still run on the memory and the * CPUs of the enclave, so the enclave keeps them. */ rc =3D ne_enclave_free_slot(ne_pci_dev, ne_enclave); if (!rc) ne_pci_dev_remove_enclave_entry(ne_enclave, ne_pci_dev); ... } Although ne_do_request() drops ne_pci_dev->pci_dev_mutex between -EAGAIN retries so other commands can proceed, ne_enclave_release() holds ne_pci_dev->enclaves_list_mutex across the entire ENCLAVE_STOP and SLOT_FREE retry loop (up to 10 minutes per command). While one enclave is waiting for its slot to be scrubbed, ne_event_work_handler() blocks on ne_pci_dev->enclaves_list_mutex and cannot deliver out-of-band events to user space for any other running enclave, and NE_CREATE_VM in ne_ioctl() is similarly blocked before it can issue SLOT_ALLOC. In addition, if a second enclave file descriptor is closed while the first release is retrying for longer than the hung-task timeout, the second ne_enclave_release() call blocks in uninterruptible mutex_lock() on ne_pci_dev->enclaves_list_mutex (and ne_enclave_release() cannot simply use mutex_lock_killable() because it may run from do_exit() with a fatal signal already pending). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1794820000.gi= t.graf@amazon.com?part=3D6