Skip to content

Commit dab6a66

Browse files
efarmangregkh
authored andcommitted
s390/vfio_ccw: Selectively expand io_mutex
[ Upstream commit 34f4fef ] 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. Fixes: 4f76617 ("vfio-ccw: protect the I/O region") Cc: stable@vger.kernel.org Signed-off-by: Eric Farman <farman@linux.ibm.com> Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Stable-dep-of: 16b0798 ("s390/vfio_ccw: Implement a crw lock") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3acbedf commit dab6a66

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎drivers/s390/cio/vfio_ccw_chp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private,
9797
if (pos + count > sizeof(*region))
9898
return -EINVAL;
9999

100+
mutex_lock(&private->io_mutex);
100101
crw = list_first_entry_or_null(&private->crw,
101102
struct vfio_ccw_crw, next);
102103

103104
if (crw)
104105
list_del(&crw->next);
105106

106-
mutex_lock(&private->io_mutex);
107107
if (i >= private->num_regions) {
108108
ret = -EINVAL;
109109
goto out;

‎drivers/s390/cio/vfio_ccw_cp.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <asm/idals.h>
1717

1818
#include "vfio_ccw_cp.h"
19+
#include "vfio_ccw_private.h"
1920

2021
struct pfn_array {
2122
/* Starting guest physical I/O address. */
@@ -852,17 +853,23 @@ void cp_update_scsw(struct channel_program *cp, union scsw *scsw)
852853
*/
853854
bool cp_iova_pinned(struct channel_program *cp, u64 iova)
854855
{
856+
struct vfio_ccw_private *private =
857+
container_of(cp, struct vfio_ccw_private, cp);
855858
struct ccwchain *chain;
856859
int i;
857860

858861
if (!cp->initialized)
859862
return false;
860863

864+
mutex_lock(&private->io_mutex);
861865
list_for_each_entry(chain, &cp->ccwchain_list, next) {
862866
for (i = 0; i < chain->ch_len; i++)
863-
if (pfn_array_iova_pinned(chain->ch_pa + i, iova))
867+
if (pfn_array_iova_pinned(chain->ch_pa + i, iova)) {
868+
mutex_unlock(&private->io_mutex);
864869
return true;
870+
}
865871
}
872+
mutex_unlock(&private->io_mutex);
866873

867874
return false;
868875
}

‎drivers/s390/cio/vfio_ccw_drv.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,15 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work)
9393

9494
is_final = !(scsw_actl(&irb->scsw) &
9595
(SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT));
96+
mutex_lock(&private->io_mutex);
9697
if (scsw_is_solicited(&irb->scsw)) {
9798
cp_update_scsw(&private->cp, &irb->scsw);
9899
if (is_final && private->state == VFIO_CCW_STATE_CP_PENDING) {
99100
cp_free(&private->cp);
100101
cp_is_finished = true;
101102
}
102103
}
103-
mutex_lock(&private->io_mutex);
104104
memcpy(private->io_region->irb_area, irb, sizeof(*irb));
105-
mutex_unlock(&private->io_mutex);
106105

107106
/*
108107
* 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)
111110
*/
112111
if (private->mdev && cp_is_finished)
113112
private->state = VFIO_CCW_STATE_IDLE;
113+
mutex_unlock(&private->io_mutex);
114114

115115
if (private->io_trigger)
116116
eventfd_signal(private->io_trigger, 1);

‎drivers/s390/cio/vfio_ccw_private.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ struct vfio_ccw_crw {
7474
* @mdev: pointer to the mediated device
7575
* @nb: notifier for vfio events
7676
* @io_region: MMIO region to input/output I/O arguments/results
77-
* @io_mutex: protect against concurrent update of I/O regions
77+
* @io_mutex: protect against concurrent update of I/O resources
78+
* and @cp lifecycle
7879
* @region: additional regions for other subchannel operations
7980
* @cmd_region: MMIO region for asynchronous I/O commands other than START
8081
* @schib_region: MMIO region for SCHIB information

0 commit comments

Comments
 (0)