Michal Hocko 537b604c8b scsi: fix scsi_error_handler vs. scsi_host_dev_release race
b9d5c6b7ef57 ("[SCSI] cleanup setting task state in
scsi_error_handler()") has introduced a race between scsi_error_handler
and scsi_host_dev_release resulting in the hang when the device goes
away because scsi_error_handler might miss a wake up:

CPU0					CPU1
scsi_error_handler			scsi_host_dev_release
  					  kthread_stop()
  kthread_should_stop()
    test_bit(KTHREAD_SHOULD_STOP)
					    set_bit(KTHREAD_SHOULD_STOP)
					    wake_up_process()
					    wait_for_completion()

  set_current_state(TASK_INTERRUPTIBLE)
  schedule()

The most straightforward solution seems to be to invert the ordering of
the set_current_state and kthread_should_stop.

The issue has been noticed during reboot test on a 3.0 based kernel but
the current code seems to be affected in the same way.

[jejb: additional comment added]
Cc: <stable@vger.kernel.org> # 3.6+
Reported-and-debugged-by: Mike Mayer <Mike.Meyer@teradata.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-09-06 12:05:45 -07:00
..
2015-02-11 10:28:45 -08:00
2015-05-18 13:35:56 -04:00
2015-08-12 11:18:47 -07:00
2015-06-19 16:57:51 -07:00
2015-06-23 15:55:44 -07:00
2015-04-27 10:10:19 -07:00
2015-04-27 10:10:19 -07:00
2015-04-27 10:04:39 -07:00
2015-04-27 10:04:39 -07:00
2015-04-27 10:05:55 -07:00
2015-04-27 10:05:55 -07:00
2014-12-04 09:57:13 +01:00
2015-04-17 10:13:56 -07:00
2014-11-20 09:11:11 +01:00
2014-07-17 22:07:37 +02:00
2014-11-20 09:11:10 +01:00
2014-11-20 09:11:10 +01:00
2014-11-24 16:13:16 +01:00
2014-11-20 09:11:10 +01:00
2015-08-26 16:28:48 -07:00
2015-08-26 16:29:49 -07:00
2015-07-30 12:41:47 -07:00
2015-06-02 17:24:54 -07:00
2014-07-17 22:07:35 +02:00
2014-11-24 20:01:28 +01:00
2014-11-20 09:11:10 +01:00
2014-11-20 09:11:10 +01:00
2015-08-28 13:14:57 -07:00
2015-04-16 10:37:12 -07:00
2015-05-25 08:46:24 -07:00
2014-11-12 11:15:57 +01:00
2015-01-09 15:44:19 +01:00
2015-04-11 22:27:14 -04:00
2014-07-17 22:07:39 +02:00
2014-11-24 20:01:28 +01:00
2014-11-12 11:15:57 +01:00
2015-08-26 07:45:25 -07:00
2015-06-02 08:03:25 -07:00
2014-11-20 09:11:15 +01:00
2014-11-20 09:11:10 +01:00
2014-11-20 09:11:10 +01:00