From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
kvm@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v4 8/9] s390/vfio_ccw: implement a channel program mutex
Date: Sat, 25 Jul 2026 15:43:50 +0000 [thread overview]
Message-ID: <20260725154351.11A0C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725152705.3958100-9-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Pending asynchronous work items are not cancelled or flushed during device release, leading to a use-after-free and locking a destroyed mutex.
- [High] Unprotected update of `private->state` in `vfio_ccw_sch_io_todo()` causes a race condition that permanently bricks the device.
--
--- Patch [8]: [PATCH v4 8/9] s390/vfio_ccw: implement a channel program mutex ---
commit dd565d50b000e987452a43655c08441c643c355d
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: implement a channel program mutex
This patch introduces a cp_mutex to protect the channel_program struct
from concurrent manipulation. It updates various functions to acquire
this mutex instead of relying on the cio layer's subchannel lock.
> diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
> index c197ad5ab5805..4830f0dd9c3a3 100644
> --- a/drivers/s390/cio/vfio_ccw_drv.c
> +++ b/drivers/s390/cio/vfio_ccw_drv.c
> @@ -91,6 +91,8 @@ void vfio_ccw_sch_io_todo(struct work_struct *work)
>
> is_final = !(scsw_actl(&irb->scsw) &
> (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT));
> +
> + mutex_lock(&private->cp_mutex);
> if (scsw_is_solicited(&irb->scsw)) {
> cp_update_scsw(&private->cp, &irb->scsw);
> if (is_final && private->state == VFIO_CCW_STATE_CP_PENDING) {
> @@ -98,6 +100,8 @@ void vfio_ccw_sch_io_todo(struct work_struct *work)
> cp_is_finished = true;
> }
> }
> + mutex_unlock(&private->cp_mutex);
[Severity: High]
This is a pre-existing issue, but does this unlocked state update in
vfio_ccw_sch_io_todo() cause a race condition with concurrent close
operations?
In vfio_ccw_sch_io_todo(), private->state = VFIO_CCW_STATE_IDLE is assigned
unconditionally outside of any locks shortly after this mutex_unlock. If a
user closes the device concurrently, fsm_close() disables the subchannel and
sets the state to VFIO_CCW_STATE_STANDBY.
If vfio_ccw_sch_io_todo() then overwrites this state with IDLE, a subsequent
device open will encounter fsm_notoper() because the state machine handles
OPEN in the IDLE state by transitioning to NOT_OPER, which bricks the device
until it is manually recreated.
> +
> mutex_lock(&private->io_mutex);
> memcpy(private->io_region->irb_area, irb, sizeof(*irb));
> mutex_unlock(&private->io_mutex);
[ ... ]
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
> index 6c74d596be9de..9242a37677a06 100644
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
[ ... ]
> @@ -142,6 +149,7 @@ static void vfio_ccw_mdev_release_dev(struct vfio_device *vdev)
> kmem_cache_free(vfio_ccw_cmd_region, private->cmd_region);
> kmem_cache_free(vfio_ccw_io_region, private->io_region);
> kfree(private->cp.guest_cp);
> + mutex_destroy(&private->cp_mutex);
> mutex_destroy(&private->io_mutex);
> }
[Severity: High]
This is a pre-existing issue, but could destroying these mutexes here cause
a use-after-free and crash if pending asynchronous work items are still
active?
If an I/O interrupt fires right before the device is released (for example,
during unbind) and cio_disable_subchannel() returns 0 because the subchannel
is idle, the workqueue flush in vfio_ccw_sch_quiesce() gets skipped.
vfio_ccw_mdev_release_dev() will then destroy cp_mutex and io_mutex, and
free the private structure without cancelling queued work like io_work or
notoper_work. When vfio_ccw_sch_io_todo() or vfio_ccw_notoper_todo()
subsequently runs, it accesses the freed private struct and attempts to lock
the destroyed cp_mutex.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260725152705.3958100-1-farman@linux.ibm.com?part=8
next prev parent reply other threads:[~2026-07-25 15:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 15:26 [PATCH v4 0/9] s390/vfio_ccw fixes Eric Farman
2026-07-25 15:26 ` [PATCH v4 1/9] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-25 15:42 ` sashiko-bot
2026-07-25 15:26 ` [PATCH v4 2/9] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-25 15:39 ` sashiko-bot
2026-07-25 15:26 ` [PATCH v4 3/9] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-25 15:33 ` sashiko-bot
2026-07-25 16:09 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 4/9] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-25 15:44 ` sashiko-bot
2026-07-25 15:27 ` [PATCH v4 5/9] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-25 15:34 ` sashiko-bot
2026-07-25 15:27 ` [PATCH v4 6/9] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-25 15:42 ` sashiko-bot
2026-07-25 16:27 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 7/9] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-25 15:42 ` sashiko-bot
2026-07-25 16:39 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 8/9] s390/vfio_ccw: implement a channel program mutex Eric Farman
2026-07-25 15:43 ` sashiko-bot [this message]
2026-07-25 17:04 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 9/9] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-25 15:46 ` sashiko-bot
2026-07-25 17:03 ` Matthew Rosato
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=20260725154351.11A0C1F000E9@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.