From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, linux-s390@vger.kernel.org,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v6 09/10] s390/vfio_ccw: implement a channel program mutex
Date: Sun, 26 Jul 2026 17:40:48 +0000 [thread overview]
Message-ID: <20260726174048.E3BB71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260726172153.1818056-10-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] A 3-thread AB-BC-CA deadlock is introduced involving `cp_mutex`, `iommu->lock`, and `iommu->device_list_lock`.
--
--- Patch [9]: [PATCH v6 09/10] s390/vfio_ccw: implement a channel program mutex ---
commit 24b60b7244a72b137b8847a953a24223d19d152e
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: implement a channel program mutex
This patch introduces a mutex to protect the channel program struct in the
vfio_ccw driver. The lock is held across operations that require private->cp
to ensure consistent behavior and replaces some incorrect subchannel lock uses.
> diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c
> --- a/drivers/s390/cio/vfio_ccw_fsm.c
> +++ b/drivers/s390/cio/vfio_ccw_fsm.c
> @@ -249,6 +246,8 @@ static void fsm_io_request(struct vfio_ccw_private *private,
> private->state = VFIO_CCW_STATE_CP_PROCESSING;
> memcpy(scsw, io_region->scsw_area, sizeof(*scsw));
>
> + mutex_lock(&private->cp_mutex);
> +
> if (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) {
> orb = (union orb *)io_region->orb_area;
[ ... ]
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
> @@ -38,8 +38,13 @@ static void vfio_ccw_dma_unmap(struct vfio_device *vdev, u64 iova, u64 length)
> container_of(vdev, struct vfio_ccw_private, vdev);
>
> /* Drivers MUST unpin pages in response to an invalidation. */
> - if (!cp_iova_pinned(&private->cp, iova, length))
> + mutex_lock(&private->cp_mutex);
[Severity: High]
Could this introduce a 3-way deadlock with the VFIO IOMMU subsystem?
When an I/O request is submitted, fsm_io_request() takes cp_mutex and
eventually calls cp_prefetch(), which attempts to acquire iommu->lock via
vfio_pin_pages().
At the same time, if a VFIO DMA unmap occurs, the VFIO core calls this
vfio_ccw_dma_unmap() callback while already holding device_list_lock.
This function then attempts to acquire cp_mutex.
Meanwhile, a concurrent VFIO DMA unmap could acquire iommu->lock in the
VFIO core (which drops it temporarily) and attempt to acquire
device_list_lock.
This seems to create a circular dependency:
Thread 1 (I/O submission):
fsm_io_request()
mutex_lock(&private->cp_mutex);
cp_prefetch()
...
mutex_lock(&iommu->lock);
Thread 2 (VFIO DMA unmap):
vfio_notify_dma_unmap()
mutex_lock(&iommu->device_list_lock);
vfio_ccw_dma_unmap()
mutex_lock(&private->cp_mutex);
Thread 3 (Concurrent VFIO DMA unmap):
vfio_notify_dma_unmap()
mutex_lock(&iommu->lock);
mutex_lock(&iommu->device_list_lock);
Is it possible for this sequence to freeze the CCW device operations and
the VFIO IOMMU subsystem?
> + if (!cp_iova_pinned(&private->cp, iova, length)) {
> + mutex_unlock(&private->cp_mutex);
> return;
> + }
> +
> + mutex_unlock(&private->cp_mutex);
>
> vfio_ccw_mdev_reset(private);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260726172153.1818056-1-farman@linux.ibm.com?part=9
next prev parent reply other threads:[~2026-07-26 17:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 17:21 [PATCH v6 00/10] s390/vfio_ccw fixes Eric Farman
2026-07-26 17:21 ` [PATCH v6 01/10] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-26 17:34 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 02/10] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-26 17:32 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 03/10] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-26 17:27 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 04/10] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-26 17:40 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 05/10] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-26 17:36 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 06/10] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-26 17:38 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 07/10] s390/vfio_ccw: cancel existing workqueues Eric Farman
2026-07-26 17:38 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 08/10] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-26 17:40 ` sashiko-bot
2026-07-26 17:21 ` [PATCH v6 09/10] s390/vfio_ccw: implement a channel program mutex Eric Farman
2026-07-26 17:40 ` sashiko-bot [this message]
2026-07-26 17:21 ` [PATCH v6 10/10] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-26 17:39 ` 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=20260726174048.E3BB71F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=farman@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@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.