Revert "scsi: make 'state' device attribute pollable"
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 7 Nov 2017 17:04:32 +0000 (09:04 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 7 Nov 2017 17:04:32 +0000 (09:04 -0800)
This reverts commit 8a97712e5314aefe16b3ffb4583a34deaa49de04.

This commit added a call to sysfs_notify() from within
scsi_device_set_state(), which in turn turns out to make libata very
unhappy, because ata_eh_detach_dev() does

        spin_lock_irqsave(ap->lock, flags);
        ..
        if (ata_scsi_offline_dev(dev)) {
                dev->flags |= ATA_DFLAG_DETACHED;
                ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
        }

and ata_scsi_offline_dev() then does that scsi_device_set_state() to set
it offline.

So now we called sysfs_notify() from within a spinlocked region, which
really doesn't work.  The 0day robot reported this as:

   BUG: sleeping function called from invalid context at kernel/locking/mutex.c:238

because sysfs_notify() ends up calling kernfs_find_and_get_ns() which
then does mutex_lock(&kernfs_mutex)..

The pollability of the device state isn't critical, so revert this all
for now, and maybe we'll do it differently in the future.

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_transport_srp.c

index ad3ea24f08859fb167e7297c2cacef81d646fb00..bcc1694cebcd3e184f40bba43f3a2200ea56c6e8 100644 (file)
@@ -2685,7 +2685,6 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
 
        }
        sdev->sdev_state = state;
-       sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
        return 0;
 
  illegal:
@@ -3109,7 +3108,6 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev,
        case SDEV_BLOCK:
        case SDEV_TRANSPORT_OFFLINE:
                sdev->sdev_state = new_state;
-               sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
                break;
        case SDEV_CREATED_BLOCK:
                if (new_state == SDEV_TRANSPORT_OFFLINE ||
@@ -3117,7 +3115,6 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev,
                        sdev->sdev_state = new_state;
                else
                        sdev->sdev_state = SDEV_CREATED;
-               sysfs_notify(&sdev->sdev_gendev.kobj, NULL, "state");
                break;
        case SDEV_CANCEL:
        case SDEV_OFFLINE:
index 4f6f01cf9968e70c81e4dbd6d5603a3ae4fa4f1c..36f6190931bc07f194621ff2a51633c83561fa51 100644 (file)
@@ -556,11 +556,8 @@ int srp_reconnect_rport(struct srp_rport *rport)
                 */
                shost_for_each_device(sdev, shost) {
                        mutex_lock(&sdev->state_mutex);
-                       if (sdev->sdev_state == SDEV_OFFLINE) {
+                       if (sdev->sdev_state == SDEV_OFFLINE)
                                sdev->sdev_state = SDEV_RUNNING;
-                               sysfs_notify(&sdev->sdev_gendev.kobj,
-                                            NULL, "state");
-                       }
                        mutex_unlock(&sdev->state_mutex);
                }
        } else if (rport->state == SRP_RPORT_RUNNING) {