FAILED: patch "[PATCH] s390/vfio_ccw: Implement a crw lock" failed to apply to 6.1-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.1-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-6.1.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-january-overcook-6d98@gregkh' --subject-prefix 'PATCH 6.1.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: 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/s390/cio/vfio_ccw_ops.c +15 -0
@@ -86,6 +86,13 @@ static void vfio_ccw_mdev_release_dev(struct vfio_device *vdev)struct vfio_ccw_private *private = container_of(vdev, struct vfio_ccw_private, vdev); +/* +* Ensure these work items are fully drained, so none can +* fire after being released. +*/ +cancel_work_sync (&private->io_work); +cancel_work_sync (&private->crw_work); +/* * We cannot free vfio_ccw_private here because it includes * parent info which must be free'ed by css driver.
@@ -162,6 +169,14 @@ static void vfio_ccw_mdev_close_device(struct vfio_device *vdev) container_of(vdev, struct vfio_ccw_private, vdev);vfio_ccw_fsm_event (private,VFIO_CCW_EVENT_CLOSE ); + +/* +* 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); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 s390/vfio_ccw: Move cp cleanup out of not operational
From: Eric Farman <[email protected]>
[ Upstream commit 0c11f61a876ed6fcca53d442ed3f33ea8362a0f9 ]
The fsm_notoper() routine is called when the device has been lost, and is (by definition) no longer operational. Since this can happen asynchronously from the normal behavior of the driver, the cleanup may happen when holding other locks in the calling sequence (notably, the cio subchannel lock).
Push the cleanup of the private->cp resources to a workqueue, where it can be done out from under that lock sequence and a future patch can safely manage the locking requirements.
Stable-dep-of: 16b0798024c0 ("s390/vfio_ccw: Implement a crw lock")
--- drivers/s390/cio/vfio_ccw_drv.c | 10 ++++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 3 +-- drivers/s390/cio/vfio_ccw_ops.c | 12 ++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +10 -0
@@ -116,6 +116,15 @@ static void vfio_ccw_crw_todo(struct work_struct *work)eventfd_signal (private->crw_trigger,1 ); } +static 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); +} +/* * Css driver callbacks */
@@ -141,6 +150,7 @@ static struct vfio_ccw_private *vfio_ccw_alloc_private(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); +INIT_WORK (&private->notoper_work, vfio_ccw_notoper_todo); private->cp.guest_cp =kcalloc (CCWCHAIN_LEN_MAX ,sizeof (struct ccw1 ),GFP_KERNEL );
drivers/s390/cio/vfio_ccw_fsm.c +1 -2
@@ -176,8 +176,7 @@ static void fsm_notoper(struct vfio_ccw_private *private,css_sched_sch_todo (sch,SCH_TODO_UNREG ); private->state =VFIO_CCW_STATE_NOT_OPER ; -/* This is usually handled during CLOSE event */ -cp_free (&private->cp); +queue_work (vfio_ccw_work_q, &private->notoper_work); }/*
drivers/s390/cio/vfio_ccw_ops.c +12 -0
@@ -89,9 +89,16 @@ 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. +* +* notoper_work should have nothing to do here, because only +* open devices could have channel_program resources in use +* and those would be released during close. Nevertheless, +* call flush here as well to be certain anything that was +* allocated is freed. */ cancel_work_sync (&private->io_work);cancel_work_sync (&private->crw_work); +flush_work (&private->notoper_work);/* * We cannot free vfio_ccw_private here because it includes
@@ -173,9 +180,14 @@ static void vfio_ccw_mdev_close_device(struct vfio_device *vdev)/* * Ensure these work items are drained, in the event the * device is re-opened instead of released. +* +* notoper_work needs to be given a chance to run if it +* is queued, so any memory associated with the channel +* program can be returned. */ cancel_work_sync (&private->io_work);cancel_work_sync (&private->crw_work); +flush_work (&private->notoper_work);vfio_ccw_unregister_dev_regions (private); }
drivers/s390/cio/vfio_ccw_private.h +2 -0
@@ -88,6 +88,7 @@ struct vfio_ccw_crw {* @req_trigger: eventfd ctx for signaling userspace to return device * @io_work: work for deferral process of I/O handling * @crw_work: work for deferral process of CRW handling +* @notoper_work: work for deferred processing in not-operational state * @release_comp: synchronization helper for vfio device release * @parent: parent data structures for mdevs created */
@@ -114,6 +115,7 @@ struct vfio_ccw_private {struct eventfd_ctx *req_trigger;struct work_struct io_work;struct work_struct crw_work; +struct work_struct notoper_work;struct completion release_comp;
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 | 8 +++++++- drivers/s390/cio/vfio_ccw_drv.c | 6 ++++-- drivers/s390/cio/vfio_ccw_fsm.c | 5 +++++ drivers/s390/cio/vfio_ccw_private.h | 3 ++- 5 files changed, 19 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 +7 -1
@@ -904,17 +904,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; +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; }
drivers/s390/cio/vfio_ccw_drv.c +4 -2
@@ -82,6 +82,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 ) {
@@ -89,9 +90,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
@@ -101,6 +100,7 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work)*/ if (cp_is_finished) private->state =VFIO_CCW_STATE_IDLE ; +mutex_unlock (&private->io_mutex);if (private->io_trigger)eventfd_signal (private->io_trigger,1 );
@@ -122,7 +122,9 @@ static void vfio_ccw_notoper_todo(struct work_struct *work) private = container_of(work, struct vfio_ccw_private, notoper_work); +mutex_lock (&private->io_mutex);cp_free (&private->cp); +mutex_unlock (&private->io_mutex); }/*
drivers/s390/cio/vfio_ccw_fsm.c +5 -0
@@ -176,6 +176,7 @@ static void fsm_notoper(struct vfio_ccw_private *private,css_sched_sch_todo (sch,SCH_TODO_UNREG ); private->state =VFIO_CCW_STATE_NOT_OPER ; +/* This routine could be called from IRQ context, so defer */ queue_work (vfio_ccw_work_q, &private->notoper_work); }
@@ -412,7 +413,11 @@ static void fsm_close(struct vfio_ccw_private *private, private->state =VFIO_CCW_STATE_STANDBY ;spin_unlock_irq (sch->lock); + +mutex_lock (&private->io_mutex);cp_free (&private->cp); +mutex_unlock (&private->io_mutex); +return ; err_unlock:
drivers/s390/cio/vfio_ccw_private.h +2 -1
@@ -74,7 +74,8 @@ struct vfio_ccw_crw {* @state: internal state of the device * @completion: synchronization helper of the I/O completion * @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
@@ -109,11 +109,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); }static void vfio_ccw_notoper_todo (struct work_struct *work)
@@ -153,6 +156,7 @@ static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch)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 =kcalloc (CCWCHAIN_LEN_MAX ,sizeof (struct ccw1 ),GFP_KERNEL );
@@ -199,11 +203,14 @@ static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch)static void vfio_ccw_free_private (struct vfio_ccw_private *private) {struct vfio_ccw_crw *crw, *temp; +unsigned long flags; +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);
@@ -314,6 +321,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
@@ -331,7 +339,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
@@ -109,6 +111,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