race condition between shutdown() and post_reset() resulting in deadlock
Subsystems (3)
Oliver Neukum
maintainerHi,
looking at your last patch I noticed something.
I think it fails to work if we hit a peculiar race condition. It looks to me like we can get the following:
task A
pre_reset()
--> calling scsi_block_requests()
task B shutdown() --> setting the shutdown flag
post_reset()
--> checking the flag -> do nothing -> deadlock
So we need in addition something like the below patch. What do you think?
Regards
Oliver
From 68cc8940d7dde8e2a48217d8086cd692809e7980 Mon Sep 17 00:00:00 2001
From: Oliver Neukum <[email protected]>
Date: Mon, 15 Jan 2018 13:56:59 +0100
Subject: [PATCH] UAS: fix race between post_reset() and shutdown()
Disconnect due to shutdown can happen after pre_reset() has been called. Thus the host must be unblocked even in the shutdown case.
Signed-off-by Oliver Neukum <[email protected]>
--- drivers/usb/storage/uas.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/storage/uas.c +4 -2
@@ -1046,10 +1046,11 @@ static int uas_post_reset(struct usb_interface *intf)struct Scsi_Host *shost =usb_get_intfdata (intf);struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata;unsigned long flags; -int err; +int err =1 ; +/* We may have lost the race and shutdown after pre_reset() */ if (devinfo->shutdown) -return 0 ; + goto skip; err =uas_configure_endpoints (devinfo);if (err && err !=ENODEV )
@@ -1062,6 +1063,7 @@ static int uas_post_reset(struct usb_interface *intf)scsi_report_bus_reset (shost,0 );spin_unlock_irqrestore (shost->host_lock, flags); +skip:scsi_unblock_requests (shost);return err ?1 :0 ;