Skip to contentSkip to conversation

sd/usb deadlock

PATCH Tom Scanlan 1 participant 1 message Feb 20, 2006 SCSI

lore
Share & tools
lore
#0 lore raw

Not sure if I should report this or ask around elsewhere... This was also sent to [email protected], as he was first in sd.c.

sd_open in drivers/scsi/sd.c seems to have a deadlock. It was noticed when plugging and unplugging lots of usb disks in random order on a slow machine. The hotplug scripts were running fdisk -l on the devices and trying to mount the disks as they were getting (un)plugged. I saw this in version 2.4.21, but the code is the same at least up to 2.4.30.

revalidate_scsidisk marks the disk as busy, then we hit an sd_open and got stuck in a loop waiting for the disk to become not busy. The change is to fail on open if the disk is busy. Requiring a mount retry is better behavior than hanging the kernel.

The diff is attached... I'm not sure the process to getting it in a release... pointers would be helpful. If there is a reason this shouldn't be used let me know, as I'm not much of a kernel hacker.

sd.c~ renamed from sd.c +6 -4
@@ -466,10 +466,15 @@
 	 * is being re-read.
 	 */
 
- 	if  (rscsi_disks[target].device->busy) {
-		printk("device %d was busy, can't open it, try again soon.\n", target);
- 		return -ENXIO;
- 	}
+
+	while (rscsi_disks[target].device->busy) {
+		barrier();
+		cpu_relax();
+	}
+
 	/*
 	 * The following code can sleep.
 	 * Module unloading must be prevented