From: sashiko-bot@kernel.org
To: "Alexander Graf" <graf@amazon.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arnd Bergmann" <arnd@arndb.de>
Cc: "The AWS Nitro Enclaves Team"
<aws-nitro-enclaves-devel@amazon.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Marek Szyprowski" <m.szyprowski@samsung.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
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" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v2 06/23] nitro_enclaves: Retry a command the device asks us to retry
Date: Mon, 30 Nov 2026 18:35:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-241810@kernel.org> (raw)
In-Reply-To: <912dd2023d5151105ccf4629dc7150b28faf166d.1795965038.git.graf@amazon.com>
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 <graf@amazon.com>
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/nitro_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,
>
> atomic_set(&ne_pci_dev->cmd_reply_avail, 0);
>
> + if (cmd_reply->rc == -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 = ne_cmd_frees_slot(cmd_type) ?
> + NE_FREE_TIMEOUT_MSECS :
> + NE_CMD_RETRY_TOTAL_MSECS;
> +
> + deadline = jiffies + msecs_to_jiffies(budget_msecs);
> + }
> +
> + msleep(delay_msecs);
> + delay_msecs = min(delay_msecs * 2, NE_CMD_RETRY_MAX_MSECS);
> +
> + goto retry;
> + }
> +
> if (cmd_reply->rc < 0) {
> rc = cmd_reply->rc;
>
> @@ -221,7 +292,14 @@ static void ne_event_work_handler(struct work_struct *work)
> int rc = -EINVAL;
> struct slot_info_req slot_info_req = {};
>
> - 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;
>
> /*
> * 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_list_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 = 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).
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794820000.git.graf@amazon.com?part=6
next prev parent reply other threads:[~2026-11-30 18:35 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 18:21 [PATCH v2 00/23] nitro_enclaves: Fix enclave release, command retries and the CPU pool Alexander Graf
2026-11-29 18:21 ` [PATCH v2 01/23] MAINTAINERS: Take over the Nitro Enclaves driver Alexander Graf
2026-11-29 18:21 ` [PATCH v2 02/23] nitro_enclaves: Release the reference on a rejected region page Alexander Graf
2026-11-29 18:21 ` [PATCH v2 03/23] nitro_enclaves: Request write access to enclave memory regions Alexander Graf
2026-11-29 18:21 ` [PATCH v2 04/23] nitro_enclaves: Split freeing the slot from freeing the enclave Alexander Graf
2026-11-29 18:21 ` [PATCH v2 05/23] nitro_enclaves: Ignore the reply of a failed slot info command Alexander Graf
2026-11-29 18:21 ` [PATCH v2 06/23] nitro_enclaves: Retry a command the device asks us to retry Alexander Graf
2026-11-30 18:35 ` sashiko-bot [this message]
2026-11-29 18:21 ` [PATCH v2 07/23] nitro_enclaves: Stop sending commands to a broken device Alexander Graf
2026-11-29 18:21 ` [PATCH v2 08/23] nitro_enclaves: Set up the device state before requesting its interrupts Alexander Graf
2026-11-29 18:21 ` [PATCH v2 09/23] nitro_enclaves: Online and offline pool CPUs with no pool lock held Alexander Graf
2026-11-29 18:21 ` [PATCH v2 10/23] nitro_enclaves: Wait for file operations before unbinding the PCI device Alexander Graf
2026-11-29 18:21 ` [PATCH v2 11/23] nitro_enclaves: Let the region tracking arrays fall back to vmalloc Alexander Graf
2026-11-29 18:21 ` [PATCH v2 12/23] nitro_enclaves: Do not return enclave threads to a replaced CPU pool Alexander Graf
2026-11-29 18:21 ` [PATCH v2 13/23] nitro_enclaves: Do not report a torn down CPU pool as set Alexander Graf
2026-11-29 18:21 ` [PATCH v2 14/23] nitro_enclaves: Keep the CPU pool when the new CPU list does not parse Alexander Graf
2026-11-29 18:21 ` [PATCH v2 15/23] nitro_enclaves: Put the CPU pool back when the new CPU list is refused Alexander Graf
2026-11-29 18:21 ` [PATCH v2 16/23] nitro_enclaves: Initialise the CPU pool mutex statically Alexander Graf
2026-11-29 18:21 ` [PATCH v2 17/23] nitro_enclaves: Free the CPU pool when driver registration fails Alexander Graf
2026-11-29 18:21 ` [PATCH v2 18/23] nitro_enclaves: Free the CPU pool that ne_exit() does not see Alexander Graf
2026-11-29 18:21 ` [PATCH v2 19/23] nitro_enclaves: Build the boot-time CPU pool once the CPUs are online Alexander Graf
2026-11-29 18:21 ` [PATCH v2 20/23] nitro_enclaves: Set up the CPU pool under the CPU hotplug read lock Alexander Graf
2026-11-29 18:21 ` [PATCH v2 21/23] nitro_enclaves: Let 32-bit processes use the ioctl interface Alexander Graf
2026-11-29 18:21 ` [PATCH v2 22/23] nitro_enclaves: Index CPU pool cores by sibling mask Alexander Graf
2026-11-29 18:21 ` [PATCH v2 23/23] nitro_enclaves: Time the wait for the device to turn off by the clock Alexander Graf
2026-11-30 18:35 ` [PATCH v2 00/23] nitro_enclaves: Fix enclave release, command retries and the CPU pool sashiko-bot
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=sashiko-outbox-241810@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=aws-nitro-enclaves-devel@amazon.com \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=diapop@amazon.com \
--cc=eperezma@redhat.com \
--cc=graf@amazon.com \
--cc=gregkh@linuxfoundation.org \
--cc=kvm@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=mancio@amazon.com \
--cc=mknaust@amazon.com \
--cc=mst@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=pbonzini@redhat.com \
--cc=rdunlap@infradead.org \
--cc=robin.murphy@arm.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sgarzare@redhat.com \
--cc=skhan@linuxfoundation.org \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
/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.