All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: linux-s390@vger.kernel.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH v3 7/8] s390/vfio_ccw: implement a channel program mutex
Date: Thu, 23 Jul 2026 18:32:23 +0000	[thread overview]
Message-ID: <20260723183224.47F1D1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260723174751.1180334-8-farman@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Dropping `sch->lock` in `vfio_ccw_sch_event` before dispatching the FSM event causes `css_sched_sch_todo` to be called locklessly, leading to lost unregister events.

Pre-existing issues:
- [High] Missing locking in `vfio_ccw_mdev_reset` allows concurrent `VFIO_DEVICE_RESET` ioctls to trigger physical subchannel unregistration.
--

--- Patch [7]: [PATCH v3 7/8] s390/vfio_ccw: implement a channel program mutex ---
commit 7b4b6e7c580cf97b697d04eaf47e890ff6d29bb0
Author: Eric Farman <farman@linux.ibm.com>

s390/vfio_ccw: implement a channel program mutex
    
The channel_program struct is manipulated without a serialization
mechanism to ensure consistent behavior. Take a broad stroke of
putting the entire structure behind a mutex, and ensure everything
that needs private->cp holds this mutex.
    
Cc: stable@vger.kernel.org
Signed-off-by: Eric Farman <farman@linux.ibm.com>

> 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
> @@ -259,12 +263,16 @@ static int vfio_ccw_sch_event(struct subchannel *sch, int process)
>  	rc = 0;
>  
>  	if (cio_update_schib(sch)) {
> -		if (private)
> +		if (private) {
> +			spin_unlock_irqrestore(&sch->lock, flags);
>  			vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_NOT_OPER);
> +			goto out;
> +		}
>  	}

[Severity: High]
Since sch->lock is dropped here, does this allow css_sched_sch_todo() to be
called locklessly?

If vfio_ccw_fsm_event() routes to fsm_notoper(), we have:

vfio_ccw_sch_event()
  spin_unlock_irqrestore(&sch->lock, flags);
  vfio_ccw_fsm_event() -> fsm_notoper()
    css_sched_sch_todo(sch, SCH_TODO_UNREG);

Could this lead to a race on sch->todo, allowing other events to overwrite
SCH_TODO_UNREG and leaving the kernel state out of sync with hardware?

> 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);
> +	if (!cp_iova_pinned(&private->cp, iova, length)) {
> +		mutex_unlock(&private->cp_mutex);
>  		return;
> +	}
> +
> +	mutex_unlock(&private->cp_mutex);
>  
>  	vfio_ccw_mdev_reset(private);
>  }

[Severity: High]
This is a pre-existing issue, but does vfio_ccw_mdev_reset() lack locking
protection against concurrent invocations?

If two threads concurrently trigger vfio_ccw_mdev_reset() (e.g. via the
VFIO_DEVICE_RESET ioctl), they could interleave:

Thread A issues VFIO_CCW_EVENT_CLOSE, transitioning to STANDBY.
Before Thread A issues OPEN, Thread B issues VFIO_CCW_EVENT_CLOSE.

The FSM receives CLOSE while in STANDBY state, which routes to fsm_notoper()
and schedules SCH_TODO_UNREG. Could this cause the physical subchannel to be
permanently unregistered, acting as a host denial of service?

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

  reply	other threads:[~2026-07-23 18:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 17:47 [PATCH v3 0/8] s390/vfio_ccw fixes Eric Farman
2026-07-23 17:47 ` [PATCH v3 1/8] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-23 18:31   ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 2/8] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-23 18:26   ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 3/8] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-23 18:22   ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 4/8] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-23 18:29   ` sashiko-bot
2026-07-23 20:38     ` Eric Farman
2026-07-23 17:47 ` [PATCH v3 5/8] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-23 18:23   ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 6/8] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-23 18:30   ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 7/8] s390/vfio_ccw: implement a channel program mutex Eric Farman
2026-07-23 18:32   ` sashiko-bot [this message]
2026-07-23 17:47 ` [PATCH v3 8/8] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-23 18:34   ` 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=20260723183224.47F1D1F00A3D@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.