[PATCH v6 08/10] s390/vfio_ccw: move cp cleanup out of not operational
From: Eric Farman
Date: Sun Jul 26 2026 - 13:28:07 EST
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 for this
scenario out to the closure of the entire MDEV, where it
be done out from under that lock sequence and (soon) under
its own serialization mechanism.
Fixes: 204b394a23ad ("vfio/ccw: Move FSM open/close to MDEV open/close")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Eric Farman <farman@xxxxxxxxxxxxx>
---
drivers/s390/cio/vfio_ccw_fsm.c | 3 ---
drivers/s390/cio/vfio_ccw_ops.c | 9 +++++++++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c
index 4d7988ea47ef..248adf1e7707 100644
--- a/drivers/s390/cio/vfio_ccw_fsm.c
+++ b/drivers/s390/cio/vfio_ccw_fsm.c
@@ -169,9 +169,6 @@ 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);
}
/*
diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index bd488e40e153..a717174675bd 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -210,6 +210,15 @@ static void vfio_ccw_mdev_close_device(struct vfio_device *vdev)
cancel_work_sync(&private->io_work);
cancel_work_sync(&private->crw_work);
+ /*
+ * Ensure that a not-operational device has indeed
+ * freed any resources. Normally the interrupt handler
+ * or FSM close should do this, but there exists the
+ * possibility that a device removed from the config
+ * would have left some of this about.
+ */
+ cp_free(&private->cp);
+
vfio_ccw_unregister_dev_regions(private);
}
--
2.53.0