From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v7 09/10] s390/vfio_ccw: selectively expand io_mutex
Date: Mon, 27 Jul 2026 20:12:53 +0000 [thread overview]
Message-ID: <20260727201254.448811F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727192230.2715207-10-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] TOCTOU race in cp_iova_pinned ignores IOMMU unmap requests, leading to hardware DMA into unmapped memory.
- [High] Data race and list corruption on private->crw between process and IRQ contexts.
--
--- Patch [9]: [PATCH v7 09/10] s390/vfio_ccw: selectively expand io_mutex ---
commit e5ee662e08e75a748fbe4dadeba55875910744f0
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: selectively expand io_mutex
This patch expands the scope of the io_mutex to serialize I/O regions
alongside I/O operations themselves. It also defers cp_free() to a
workqueue to avoid acquiring mutexes in interrupt context.
> diff --git a/drivers/s390/cio/vfio_ccw_chp.c b/drivers/s390/cio/vfio_ccw_chp.c
> index f3015132d4b5f..9269b54f5cfd4 100644
> --- a/drivers/s390/cio/vfio_ccw_chp.c
> +++ b/drivers/s390/cio/vfio_ccw_chp.c
> @@ -98,13 +98,13 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private,
> if (pos + count > sizeof(*region))
> return -EINVAL;
>
> + mutex_lock(&private->io_mutex);
> crw = list_first_entry_or_null(&private->crw,
> struct vfio_ccw_crw, next);
>
> if (crw)
> list_del(&crw->next);
[Severity: High]
This is a pre-existing issue, but does holding only io_mutex provide enough
protection here?
In vfio_ccw_queue_crw(), which is called from hardware interrupt context,
items appear to be appended to private->crw locklessly:
vfio_ccw_queue_crw() {
...
list_add_tail(&crw->next, &private->crw);
queue_work(vfio_ccw_work_q, &private->crw_work);
}
Since io_mutex is a sleeping lock and cannot be acquired in IRQ context,
will concurrent list manipulations between the IRQ context and this read
corrupt the doubly-linked list pointers?
> - mutex_lock(&private->io_mutex);
> if (i >= private->num_regions) {
> ret = -EINVAL;
> goto out;
> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> index 5ef082b8289af..58722c4baa251 100644
> --- a/drivers/s390/cio/vfio_ccw_cp.c
> +++ b/drivers/s390/cio/vfio_ccw_cp.c
> @@ -977,17 +977,23 @@ void cp_update_scsw(struct channel_program *cp, union scsw *scsw)
> */
> bool cp_iova_pinned(struct channel_program *cp, u64 iova, u64 length)
> {
> + struct vfio_ccw_private *private =
> + container_of(cp, struct vfio_ccw_private, cp);
> struct ccwchain *chain;
> int i;
>
> if (!cp->initialized)
> return false;
[Severity: High]
This isn't a bug introduced by this patch, but is it safe to check
cp->initialized without holding io_mutex?
If a VFIO unmap ioctl occurs concurrently while cp_init() is pinning pages
(but before cp_init() sets cp->initialized = true at the very end), could
this lockless check return false, causing the unmap request to be
incorrectly ignored?
If the unmap request is ignored while the I/O is submitted to the hardware,
could this result in the hardware performing DMA into memory the guest
considers unmapped?
> + mutex_lock(&private->io_mutex);
> list_for_each_entry(chain, &cp->ccwchain_list, next) {
> for (i = 0; i < chain->ch_len; i++)
> - if (page_array_iova_pinned(&chain->ch_pa[i], iova, length))
> + if (page_array_iova_pinned(&chain->ch_pa[i], iova, length)) {
> + mutex_unlock(&private->io_mutex);
> return true;
> + }
> }
> + mutex_unlock(&private->io_mutex);
>
> return false;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727192230.2715207-1-farman@linux.ibm.com?part=9
next prev parent reply other threads:[~2026-07-27 20:12 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 19:22 [PATCH v7 00/10] s390/vfio_ccw fixes Eric Farman
2026-07-27 19:22 ` [PATCH v7 01/10] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-27 19:58 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 02/10] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-27 19:52 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 03/10] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-27 19:53 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 04/10] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-27 19:59 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 05/10] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-27 19:54 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 06/10] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-27 20:03 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 07/10] s390/vfio_ccw: cancel existing workqueues Eric Farman
2026-07-27 20:02 ` sashiko-bot
2026-07-27 21:54 ` Matthew Rosato
2026-07-27 19:22 ` [PATCH v7 08/10] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-27 20:04 ` sashiko-bot
2026-07-27 21:54 ` Matthew Rosato
2026-07-28 0:54 ` Eric Farman
2026-07-27 19:22 ` [PATCH v7 09/10] s390/vfio_ccw: selectively expand io_mutex Eric Farman
2026-07-27 20:12 ` sashiko-bot [this message]
2026-07-27 19:22 ` [PATCH v7 10/10] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-27 20:07 ` sashiko-bot
2026-07-27 21:35 ` Farhan Ali
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=20260727201254.448811F000E9@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.