FAILED: patch "[PATCH] s390/vfio_ccw: Implement a crw lock" failed to apply to 5.15-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 16b0798024c0e9117e395829ddbbe70981c79d9c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026082011-underarm-plywood-1b0f@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 16b0798024c0e9117e395829ddbbe70981c79d9c Mon Sep 17 00:00:00 2001
From: Eric Farman <[email protected]>
Date: Tue, 28 Jul 2026 05:30:22 +0200
Subject: [PATCH] s390/vfio_ccw: Implement a crw lock
Unlike the channel_program struct, which covers synchronous I/O submissions and asynchronous interrupts, the CRW region relies exclusively on asynchronous events coming from hardware.
Implement a lock to manage the list of those payloads, to ensure they are read cohesively.
drivers/s390/cio/vfio_ccw_chp.c +16 -10
@@ -93,18 +93,13 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private,loff_t pos = *ppos &VFIO_CCW_OFFSET_MASK ;struct ccw_crw_region *region;struct vfio_ccw_crw *crw; +unsigned long flags;int ret;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); -if (i >= private->num_regions) { ret = -EINVAL ; goto out;
@@ -113,6 +108,16 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, i =array_index_nospec (i, private->num_regions); region = private->region[i].data; +spin_lock_irqsave (&private->crw_lock, flags); + crw =list_first_entry_or_null (&private->crw, + struct vfio_ccw_crw, next); + +if (crw) +list_del (&crw->next); + +/* Drop CRW lock while copying to userspace */ +spin_unlock_irqrestore (&private->crw_lock, flags); +if (crw)memcpy (®ion->crw, &crw->crw,sizeof (region->crw));
@@ -122,15 +127,16 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, ret = count; region->crw =0 ; - -out: -mutex_unlock (&private->io_mutex); -kfree (crw);/* Notify the guest if more CRWs are on our queue */ +spin_lock_irqsave (&private->crw_lock, flags);if (!list_empty (&private->crw) && private->crw_trigger)eventfd_signal (private->crw_trigger); +spin_unlock_irqrestore (&private->crw_lock, flags); + +out: +mutex_unlock (&private->io_mutex);return ret; }
drivers/s390/cio/vfio_ccw_drv.c +6 -0
@@ -118,11 +118,14 @@ void vfio_ccw_sch_io_todo(struct work_struct *work)void vfio_ccw_crw_todo (struct work_struct *work) {struct vfio_ccw_private *private; +unsigned long flags; private = container_of(work, struct vfio_ccw_private, crw_work); +spin_lock_irqsave (&private->crw_lock, flags);if (!list_empty (&private->crw) && private->crw_trigger)eventfd_signal (private->crw_trigger); +spin_unlock_irqrestore (&private->crw_lock, flags); }void vfio_ccw_notoper_todo (struct work_struct *work)
@@ -286,6 +289,7 @@ static void vfio_ccw_queue_crw(struct vfio_ccw_private *private, unsigned int rsid) {struct vfio_ccw_crw *crw; +unsigned long flags;/* * If unable to allocate a CRW, just drop the event and
@@ -303,7 +307,9 @@ static void vfio_ccw_queue_crw(struct vfio_ccw_private *private, crw->crw.erc = erc; crw->crw.rsid = rsid; +spin_lock_irqsave (&private->crw_lock, flags);list_add_tail (&crw->next, &private->crw); +spin_unlock_irqrestore (&private->crw_lock, flags);queue_work (vfio_ccw_work_q, &private->crw_work); }
drivers/s390/cio/vfio_ccw_ops.c +4 -0
@@ -55,6 +55,7 @@ static int vfio_ccw_mdev_init_dev(struct vfio_device *vdev)INIT_WORK (&private->io_work, vfio_ccw_sch_io_todo);INIT_WORK (&private->crw_work, vfio_ccw_crw_todo);INIT_WORK (&private->notoper_work, vfio_ccw_notoper_todo); +spin_lock_init (&private->crw_lock); private->cp.guest_cp = kzalloc_objs(struct ccw1, CCWCHAIN_LEN_MAX);if (!private->cp.guest_cp)
@@ -131,6 +132,7 @@ static void vfio_ccw_mdev_release_dev(struct vfio_device *vdev)struct vfio_ccw_private *private = container_of(vdev, struct vfio_ccw_private, vdev);struct vfio_ccw_crw *crw, *temp; +unsigned long flags;/* * Ensure these work items are fully drained, so none can
@@ -146,10 +148,12 @@ static void vfio_ccw_mdev_release_dev(struct vfio_device *vdev)cancel_work_sync (&private->crw_work);flush_work (&private->notoper_work); +spin_lock_irqsave (&private->crw_lock, flags);list_for_each_entry_safe (crw, temp, &private->crw, next) {list_del (&crw->next);kfree (crw); } +spin_unlock_irqrestore (&private->crw_lock, flags);kmem_cache_free (vfio_ccw_crw_region, private->crw_region);kmem_cache_free (vfio_ccw_schib_region, private->schib_region);
drivers/s390/cio/vfio_ccw_private.h +4 -0
@@ -98,6 +98,8 @@ struct vfio_ccw_parent {* @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info +* @crw_lock: serialization of CRW list information +* @crw: list of Channel Report Word elements * @io_trigger: eventfd ctx for signaling userspace I/O results * @crw_trigger: eventfd ctx for signaling userspace CRW information * @req_trigger: eventfd ctx for signaling userspace to return device
@@ -120,6 +122,8 @@ struct vfio_ccw_private {struct channel_program cp;struct irb irb;union scsw scsw; + +spinlock_t crw_lock;struct list_head crw;struct eventfd_ctx *io_trigger;
Sasha Levin
maintainerPATCH 1/4 s390/vfio_ccw: Ensure index for read/write regions are within range
From: Eric Farman <[email protected]>
[ Upstream commit 9f5f9a78fedc45bc29d6a0a64e3a3472361afae5 ]
The introduction of the capability chain rightly clamped the region indexes to the range of the capabilities itself, but neglected to do so for the existing read/write regions which should also be enforced.
Stable-dep-of: 16b0798024c0 ("s390/vfio_ccw: Implement a crw lock")
--- drivers/s390/cio/vfio_ccw_async.c | 16 ++++++++++++++++ drivers/s390/cio/vfio_ccw_chp.c | 15 +++++++++++++++ drivers/s390/cio/vfio_ccw_ops.c | 7 +++---- 3 files changed, 34 insertions(+), 4 deletions(-)
drivers/s390/cio/vfio_ccw_async.c +16 -0
@@ -8,6 +8,7 @@*/ #include <linux/vfio.h> +#include <linux/nospec.h> #include <linux/mdev.h> #include "vfio_ccw_private.h"
@@ -25,11 +26,20 @@ static ssize_t vfio_ccw_async_region_read(struct vfio_ccw_private *private,return -EINVAL ;mutex_lock (&private->io_mutex); + +if (i >= private->num_regions) { + ret = -EINVAL ; + goto out_unlock; + } + + i =array_index_nospec (i, private->num_regions); region = private->region[i].data;if (copy_to_user (buf, (void *)region + pos, count)) ret = -EFAULT ;else ret = count; + +out_unlock:mutex_unlock (&private->io_mutex);return ret; }
@@ -49,6 +59,12 @@ static ssize_t vfio_ccw_async_region_write(struct vfio_ccw_private *private,if (!mutex_trylock (&private->io_mutex))return -EAGAIN ; +if (i >= private->num_regions) { + ret = -EINVAL ; + goto out_unlock; + } + + i =array_index_nospec (i, private->num_regions); region = private->region[i].data;if (copy_from_user ((void *)region + pos, buf, count)) { ret = -EFAULT ;
drivers/s390/cio/vfio_ccw_chp.c +15 -0
@@ -9,6 +9,7 @@*/ #include <linux/slab.h> +#include <linux/nospec.h> #include <linux/vfio.h> #include "vfio_ccw_private.h"
@@ -25,6 +26,13 @@ static ssize_t vfio_ccw_schib_region_read(struct vfio_ccw_private *private,return -EINVAL ;mutex_lock (&private->io_mutex); + +if (i >= private->num_regions) { + ret = -EINVAL ; + goto out; + } + + i =array_index_nospec (i, private->num_regions); region = private->region[i].data;if (cio_update_schib (private->sch)) {
@@ -96,6 +104,12 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private,list_del (&crw->next);mutex_lock (&private->io_mutex); +if (i >= private->num_regions) { + ret = -EINVAL ; + goto out; + } + + i =array_index_nospec (i, private->num_regions); region = private->region[i].data;if (crw)
@@ -108,6 +122,7 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, region->crw =0 ; +out:mutex_unlock (&private->io_mutex);kfree (crw);
drivers/s390/cio/vfio_ccw_ops.c +3 -4
@@ -251,6 +251,7 @@ static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev,return vfio_ccw_mdev_read_io_region (private, buf, count, ppos);default : index -=VFIO_CCW_NUM_REGIONS ; + index =array_index_nospec (index, private->num_regions);return private->region[index].ops->read (private, buf, count, ppos); }
@@ -304,6 +305,7 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,return vfio_ccw_mdev_write_io_region (private, buf, count, ppos);default : index -=VFIO_CCW_NUM_REGIONS ; + index =array_index_nospec (index, private->num_regions);return private->region[index].ops->write (private, buf, count, ppos); }
@@ -351,11 +353,8 @@ static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, VFIO_CCW_NUM_REGIONS + private->num_regions)return -EINVAL ; - info->index =array_index_nospec (info->index, -VFIO_CCW_NUM_REGIONS + - private->num_regions); - i = info->index -VFIO_CCW_NUM_REGIONS ; + i =array_index_nospec (i, private->num_regions); info->offset =VFIO_CCW_INDEX_TO_OFFSET (info->index); info->size = private->region[i].size;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 s390/vfio_ccw: Cancel existing workqueues
From: Eric Farman <[email protected]>
[ Upstream commit 79c60b2c61105368dcc8444eb45847e21734f7c4 ]
The initialization of the io_work and crw_work workqueues begs the question of whether they should be un-initialized. Add the corresponding cleanup tags in _release_dev to ensure work isn't dispatched after the private struct is free'd.
Stable-dep-of: 16b0798024c0 ("s390/vfio_ccw: Implement a crw lock")
--- drivers/s390/cio/vfio_ccw_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/s390/cio/vfio_ccw_ops.c +8 -0
@@ -207,6 +207,14 @@ static void vfio_ccw_mdev_close_device(struct mdev_device *mdev) }cp_free (&private->cp); + +/* +* Ensure these work items are drained, in the event the +* device is re-opened instead of released. +*/ +cancel_work_sync (&private->io_work); +cancel_work_sync (&private->crw_work); +vfio_ccw_unregister_dev_regions (private);vfio_unregister_notifier (mdev_dev (mdev),VFIO_IOMMU_NOTIFY , &private->nb);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 s390/vfio_ccw: Selectively expand io_mutex
In reply to Sasha LevinFrom: Eric Farman <[email protected]>
[ Upstream commit 34f4feff3e90bd09308fad0974e97113b23b812a ]
The io_mutex was defined to serialize the io_regions, but then has also sort of been associated with the I/O themselves because of the close relationship they share.
With the handful of races that are possible, the choices are either to:
A) expand the scope of io_mutex to close these remaining windows, or
B) reduce the scope of io_mutex to just io_region, and introduce a new lock mechanism for the remaining I/O resources
This patch implements A, since B brings with it a lot more interactions that would need to be tracked and kept in a correct hierarchy. It also takes advantage of the workqueue element for cp_free() that now gets called out of fsm_notoper(), which could be invoked out of an interrupt context and thus cannot acquire a mutex itself.
Stable-dep-of: 16b0798024c0 ("s390/vfio_ccw: Implement a crw lock")
--- drivers/s390/cio/vfio_ccw_chp.c | 2 +- drivers/s390/cio/vfio_ccw_cp.c | 9 ++++++++- drivers/s390/cio/vfio_ccw_drv.c | 4 ++-- drivers/s390/cio/vfio_ccw_private.h | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-)
drivers/s390/cio/vfio_ccw_chp.c +1 -1
@@ -97,13 +97,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); -mutex_lock (&private->io_mutex);if (i >= private->num_regions) { ret = -EINVAL ; goto out;
drivers/s390/cio/vfio_ccw_cp.c +8 -1
@@ -16,6 +16,7 @@#include <asm/idals.h> #include "vfio_ccw_cp.h" +#include "vfio_ccw_private.h" struct pfn_array {/* Starting guest physical I/O address. */
@@ -852,17 +853,23 @@ void cp_update_scsw(struct channel_program *cp, union scsw *scsw)*/ bool cp_iova_pinned (struct channel_program *cp,u64 iova) { +struct vfio_ccw_private *private = + container_of(cp, struct vfio_ccw_private, cp);struct ccwchain *chain;int i;if (!cp->initialized)return false; +mutex_lock (&private->io_mutex);list_for_each_entry (chain, &cp->ccwchain_list, next) {for (i =0 ; i < chain->ch_len; i++) -if (pfn_array_iova_pinned (chain->ch_pa + i, iova)) +if (pfn_array_iova_pinned (chain->ch_pa + i, iova)) { +mutex_unlock (&private->io_mutex);return true; + } } +mutex_unlock (&private->io_mutex);return false; }
drivers/s390/cio/vfio_ccw_drv.c +2 -2
@@ -93,6 +93,7 @@ static 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->io_mutex);if (scsw_is_solicited (&irb->scsw)) {cp_update_scsw (&private->cp, &irb->scsw);if (is_final && private->state ==VFIO_CCW_STATE_CP_PENDING ) {
@@ -100,9 +101,7 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) cp_is_finished = true; } } -mutex_lock (&private->io_mutex);memcpy (private->io_region->irb_area, irb,sizeof (*irb)); -mutex_unlock (&private->io_mutex);/* * Reset to IDLE only if processing of a channel program
@@ -111,6 +110,7 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work)*/ if (private->mdev && cp_is_finished) private->state =VFIO_CCW_STATE_IDLE ; +mutex_unlock (&private->io_mutex);if (private->io_trigger)eventfd_signal (private->io_trigger,1 );
drivers/s390/cio/vfio_ccw_private.h +2 -1
@@ -74,7 +74,8 @@ struct vfio_ccw_crw {* @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results -* @io_mutex: protect against concurrent update of I/O regions +* @io_mutex: protect against concurrent update of I/O resources +* and @cp lifecycle * @region: additional regions for other subchannel operations * @cmd_region: MMIO region for asynchronous I/O commands other than START * @schib_region: MMIO region for SCHIB information
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 s390/vfio_ccw: Implement a crw lock
In reply to Sasha LevinFrom: Eric Farman <[email protected]>
[ Upstream commit 16b0798024c0e9117e395829ddbbe70981c79d9c ]
Unlike the channel_program struct, which covers synchronous I/O submissions and asynchronous interrupts, the CRW region relies exclusively on asynchronous events coming from hardware.
Implement a lock to manage the list of those payloads, to ensure they are read cohesively.
--- drivers/s390/cio/vfio_ccw_chp.c | 26 ++++++++++++++++---------- drivers/s390/cio/vfio_ccw_drv.c | 10 ++++++++++ drivers/s390/cio/vfio_ccw_private.h | 4 ++++ 3 files changed, 30 insertions(+), 10 deletions(-)
drivers/s390/cio/vfio_ccw_chp.c +16 -10
@@ -92,18 +92,13 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private,loff_t pos = *ppos &VFIO_CCW_OFFSET_MASK ;struct ccw_crw_region *region;struct vfio_ccw_crw *crw; +unsigned long flags;int ret;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); -if (i >= private->num_regions) { ret = -EINVAL ; goto out;
@@ -112,6 +107,16 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, i =array_index_nospec (i, private->num_regions); region = private->region[i].data; +spin_lock_irqsave (&private->crw_lock, flags); + crw =list_first_entry_or_null (&private->crw, + struct vfio_ccw_crw, next); + +if (crw) +list_del (&crw->next); + +/* Drop CRW lock while copying to userspace */ +spin_unlock_irqrestore (&private->crw_lock, flags); +if (crw)memcpy (®ion->crw, &crw->crw,sizeof (region->crw));
@@ -121,15 +126,16 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, ret = count; region->crw =0 ; - -out: -mutex_unlock (&private->io_mutex); -kfree (crw);/* Notify the guest if more CRWs are on our queue */ +spin_lock_irqsave (&private->crw_lock, flags);if (!list_empty (&private->crw) && private->crw_trigger)eventfd_signal (private->crw_trigger,1 ); +spin_unlock_irqrestore (&private->crw_lock, flags); + +out: +mutex_unlock (&private->io_mutex);return ret; }
drivers/s390/cio/vfio_ccw_drv.c +10 -0
@@ -119,11 +119,14 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work)static void vfio_ccw_crw_todo (struct work_struct *work) {struct vfio_ccw_private *private; +unsigned long flags; private = container_of(work, struct vfio_ccw_private, crw_work); +spin_lock_irqsave (&private->crw_lock, flags);if (!list_empty (&private->crw) && private->crw_trigger)eventfd_signal (private->crw_trigger,1 ); +spin_unlock_irqrestore (&private->crw_lock, flags); }/*
@@ -207,6 +210,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)INIT_LIST_HEAD (&private->crw);INIT_WORK (&private->io_work, vfio_ccw_sch_io_todo);INIT_WORK (&private->crw_work, vfio_ccw_crw_todo); +spin_lock_init (&private->crw_lock);atomic_set (&private->avail,1 ); private->state =VFIO_CCW_STATE_STANDBY ;
@@ -238,13 +242,16 @@ static void vfio_ccw_sch_remove(struct subchannel *sch) {struct vfio_ccw_private *private =dev_get_drvdata (&sch->dev);struct vfio_ccw_crw *crw, *temp; +unsigned long flags;vfio_ccw_sch_quiesce (sch); +spin_lock_irqsave (&private->crw_lock, flags);list_for_each_entry_safe (crw, temp, &private->crw, next) {list_del (&crw->next);kfree (crw); } +spin_unlock_irqrestore (&private->crw_lock, flags);vfio_ccw_mdev_unreg (sch);
@@ -304,6 +311,7 @@ static void vfio_ccw_queue_crw(struct vfio_ccw_private *private, unsigned int rsid) {struct vfio_ccw_crw *crw; +unsigned long flags;/* * If unable to allocate a CRW, just drop the event and
@@ -321,7 +329,9 @@ static void vfio_ccw_queue_crw(struct vfio_ccw_private *private, crw->crw.erc = erc; crw->crw.rsid = rsid; +spin_lock_irqsave (&private->crw_lock, flags);list_add_tail (&crw->next, &private->crw); +spin_unlock_irqrestore (&private->crw_lock, flags);queue_work (vfio_ccw_work_q, &private->crw_work); }
drivers/s390/cio/vfio_ccw_private.h +4 -0
@@ -84,6 +84,8 @@ struct vfio_ccw_crw {* @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info +* @crw_lock: serialization of CRW list information +* @crw: list of Channel Report Word elements * @io_trigger: eventfd ctx for signaling userspace I/O results * @crw_trigger: eventfd ctx for signaling userspace CRW information * @req_trigger: eventfd ctx for signaling userspace to return device
@@ -108,6 +110,8 @@ struct vfio_ccw_private {struct channel_program cp;struct irb irb;union scsw scsw; + +spinlock_t crw_lock;struct list_head crw;struct eventfd_ctx *io_trigger;
Signature · 1 line
2.53.0