s390/cio: introduce locking for register/unregister functions
authorVineeth Vijayan <vneethv@linux.ibm.com>
Fri, 11 Nov 2022 12:46:33 +0000 (13:46 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Tue, 31 Jan 2023 17:56:36 +0000 (18:56 +0100)
commit0c6924c262e819c4997b9cae0df6bd6e7b0b8754
tree4dc69f4bdc69cb7909c41f2205072fb426bd8b19
parent05178996e1a77e2a4664536e6d101a086a905034
s390/cio: introduce locking for register/unregister functions

Unbinding an I/O subchannel with a child-CCW device in disconnected
state sometimes causes a kernel-panic. The race condition was seen
mostly during testing, when setting all the CHPIDs of a device to
offline and at the same time, the unbinding the I/O subchannel driver.

The kernel-panic occurs because of double delete, the I/O subchannel
driver calls device_del on the CCW device while another device_del
invocation for the same device is in-flight.  For instance, disabling
all the CHPIDs will trigger the ccw_device_remove function, which will
call a ccw_device_unregister(), which ends up calling the device_del()
which is asynchronous via cdev's todo workqueue. And unbinding the I/O
subchannel driver calls io_subchannel_remove() function which calls the
ccw_device_unregister() and device_del().

This double delete can be prevented by serializing all CCW device
registration/unregistration calls into the driver core. This patch
introduces a mutex which will be used for this purpose.

Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Reported-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/include/asm/ccwdev.h
drivers/s390/cio/device.c