All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	kvm@vger.kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH v8 08/10] s390/vfio_ccw: move cp cleanup out of not operational
Date: Tue, 28 Jul 2026 01:49:16 +0000	[thread overview]
Message-ID: <20260728014916.D8F411F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728013509.1551753-9-farman@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Failure to cancel pending `notoper_work` during device release causes a workqueue leak and use-after-free on the `private` structure.
- [High] Missing `io_mutex` locking in `vfio_ccw_notoper_todo` leads to a data race with concurrent channel program operations.
--

--- Patch [8]: [PATCH v8 08/10] s390/vfio_ccw: move cp cleanup out of not operational ---
commit bf6c617fa515fe63ff2d80efc36831d26b7cdedc
Author: Eric Farman <farman@linux.ibm.com>

s390/vfio_ccw: move cp cleanup out of not operational

The fsm_notoper() routine is called when the device has been lost, and is
no longer operational. Push the cleanup of the private->cp resources to a
workqueue, where it can be done safely under a common locking mechanism.

> diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
> --- a/drivers/s390/cio/vfio_ccw_drv.c
> +++ b/drivers/s390/cio/vfio_ccw_drv.c
> @@ -125,6 +125,15 @@ void vfio_ccw_crw_todo(struct work_struct *work)
>  		eventfd_signal(private->crw_trigger);
>  }
>  
> +void vfio_ccw_notoper_todo(struct work_struct *work)
> +{
> +	struct vfio_ccw_private *private;
> +
> +	private = container_of(work, struct vfio_ccw_private, notoper_work);
> +
> +	cp_free(&private->cp);
> +}
> +

[Severity: High]
The commit message mentions performing the cleanup safely under a common
locking mechanism. Could this lockless call to cp_free() lead to a regression
with concurrent channel program operations?

If userspace initiates an I/O request, vfio_ccw_mdev_write_io_region()
holds io_mutex and processes the request via fsm_io_request() and
cp_init() / cp_prefetch().

Concurrently, if a hardware event triggers fsm_notoper() and queues
notoper_work, this worker executes vfio_ccw_notoper_todo() and locklessly
calls cp_free(&private->cp).

Should this function acquire io_mutex to prevent a data race with the
allocation and initialization of ccwchain structures in the I/O path?

> 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

[ ... ]

> @@ -133,7 +134,9 @@ static void vfio_ccw_mdev_release_dev(struct vfio_device *vdev)
>  
>  	/*
>  	 * Ensure these work items are fully drained, so none can
> -	 * fire after being released.
> +	 * fire after being released. The notoper_work struct is
> +	 * only meaningful if the device had been opened, which
> +	 * means it would have been cleaned in an earlier close.
>  	 */
>  	cancel_work_sync(&private->io_work);
>  	cancel_work_sync(&private->crw_work);

[Severity: High]
Is the assumption that notoper_work is only meaningful if the device had
been opened always correct?

If a machine check or path loss occurs before the mediated device is opened,
vfio_ccw_sch_event() transitions the state from STANDBY to NOT_OPER via
fsm_notoper(), queuing notoper_work unconditionally.

Since the device was never opened, vfio_ccw_mdev_close_device() (which
flushes the work) is never called.

When the device is subsequently removed, this release function omits canceling
notoper_work. This could allow the workqueue to execute vfio_ccw_notoper_todo()
after the VFIO core frees the private structure.

Should cancel_work_sync(&private->notoper_work) be added here to prevent a
potential use-after-free on the private structure?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728013509.1551753-1-farman@linux.ibm.com?part=8

  reply	other threads:[~2026-07-28  1:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  1:34 [PATCH v8 00/10] s390/vfio_ccw fixes Eric Farman
2026-07-28  1:35 ` [PATCH v8 01/10] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-28  1:51   ` sashiko-bot
2026-07-28  1:35 ` [PATCH v8 02/10] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-28  1:52   ` sashiko-bot
2026-07-28  1:35 ` [PATCH v8 03/10] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-28  1:50   ` sashiko-bot
2026-07-28  1:35 ` [PATCH v8 04/10] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-28  1:45   ` sashiko-bot
2026-07-28  1:35 ` [PATCH v8 05/10] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-28  1:49   ` sashiko-bot
2026-07-28  1:35 ` [PATCH v8 06/10] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-28  1:54   ` sashiko-bot
2026-07-28  1:35 ` [PATCH v8 07/10] s390/vfio_ccw: cancel existing workqueues Eric Farman
2026-07-28  1:53   ` sashiko-bot
2026-07-28  2:07   ` Matthew Rosato
2026-07-28  1:35 ` [PATCH v8 08/10] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-28  1:49   ` sashiko-bot [this message]
2026-07-28  2:08   ` Matthew Rosato
2026-07-28  3:23     ` Eric Farman
2026-07-28  1:35 ` [PATCH v8 09/10] s390/vfio_ccw: selectively expand io_mutex Eric Farman
2026-07-28  1:57   ` sashiko-bot
2026-07-28  2:08   ` Matthew Rosato
2026-07-28  1:35 ` [PATCH v8 10/10] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-28  2:01   ` 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=20260728014916.D8F411F000E9@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.