Putting my community hat on, I continue to be uncomfortable with the basic concept of this, unless we either: - cover all devices with this and know that there's no hit - find a NICE way to specify unsafe devices
In addition, the only case when we trip on this is the Red Hat installer, which really likes to do many funny things in parallel. Red Hat obviously has no choice but to ship this or its equivalent for an update of their 2.4 based legacy distros, but that's the price of the distro lifespan commitment for them. This is something which asks to be addressed in a development tree first. -- Pete diff -urp -X dontdiff linux-2.4.27-pre2/drivers/usb/devio.c linux-2.4.27-pre2-usb/drivers/usb/devio.c --- linux-2.4.27-pre2/drivers/usb/devio.c 2003-11-29 18:53:02.000000000 -0800 +++ linux-2.4.27-pre2-usb/drivers/usb/devio.c 2004-05-15 23:06:11.000000000 -0700 @@ -1157,6 +1157,13 @@ static int usbdev_ioctl(struct inode *in up_read(&ps->devsem); return -ENODEV; } + + /* + * grab device's exclusive_access mutex to prevent its driver from + * using this device while it is being accessed by us. + */ + down(&ps->dev->exclusive_access); + switch (cmd) { case USBDEVFS_CONTROL: ret = proc_control(ps, (void *)arg); @@ -1236,6 +1243,7 @@ static int usbdev_ioctl(struct inode *in ret = proc_ioctl(ps, (void *) arg); break; } + up(&ps->dev->exclusive_access); up_read(&ps->devsem); if (ret >= 0) inode->i_atime = CURRENT_TIME; diff -urp -X dontdiff linux-2.4.27-pre2/drivers/usb/storage/transport.c linux-2.4.27-pre2-usb/drivers/usb/storage/transport.c --- linux-2.4.27-pre2/drivers/usb/storage/transport.c 2004-02-26 14:09:59.000000000 -0800 +++ linux-2.4.27-pre2-usb/drivers/usb/storage/transport.c 2004-05-15 23:06:11.000000000 -0700 @@ -627,8 +627,17 @@ void usb_stor_invoke_transport(Scsi_Cmnd int need_auto_sense; int result; + /* + * Grab device's exclusive_access mutex to prevent libusb/usbfs from + * sending out a command in the middle of ours (if libusb sends a + * get_descriptor or something on pipe 0 after our CBW and before + * our CSW, and then we get a stall, we have trouble). + */ + down(&(us->pusb_dev->exclusive_access)); + /* send the command to the transport layer */ result = us->transport(srb, us); + up(&(us->pusb_dev->exclusive_access)); /* if the command gets aborted by the higher layers, we need to * short-circuit all other processing @@ -748,7 +757,9 @@ void usb_stor_invoke_transport(Scsi_Cmnd srb->use_sg = 0; /* issue the auto-sense command */ + down(&(us->pusb_dev->exclusive_access)); temp_result = us->transport(us->srb, us); + up(&(us->pusb_dev->exclusive_access)); /* let's clean up right away */ srb->request_buffer = old_request_buffer; diff -urp -X dontdiff linux-2.4.27-pre2/drivers/usb/usb.c linux-2.4.27-pre2-usb/drivers/usb/usb.c --- linux-2.4.27-pre2/drivers/usb/usb.c 2004-02-26 14:09:59.000000000 -0800 +++ linux-2.4.27-pre2-usb/drivers/usb/usb.c 2004-05-15 23:06:11.000000000 -0700 @@ -989,6 +989,7 @@ struct usb_device *usb_alloc_dev(struct INIT_LIST_HEAD(&dev->filelist); init_MUTEX(&dev->serialize); + init_MUTEX(&dev->exclusive_access); dev->bus->op->allocate(dev); Only in linux-2.4.27-pre2-usb/include/linux: modules diff -urp -X dontdiff linux-2.4.27-pre2/include/linux/usb.h linux-2.4.27-pre2-usb/include/linux/usb.h --- linux-2.4.27-pre2/include/linux/usb.h 2004-04-18 17:23:55.000000000 -0700 +++ linux-2.4.27-pre2-usb/include/linux/usb.h 2004-05-16 00:15:47.000000000 -0700 @@ -828,6 +828,8 @@ struct usb_device { atomic_t refcnt; /* Reference count */ struct semaphore serialize; + struct semaphore exclusive_access; /* prevent driver & proc accesses */ + /* from overlapping cmds at device */ unsigned int toggle[2]; /* one bit for each endpoint ([0] = IN, [1] = OUT) */ unsigned int halted[2]; /* endpoint halts; one bit per endpoint # & direction; */ ------------------------------------------------------- This SF.Net email is sponsored by: SourceForge.net Broadband Sign-up now for SourceForge Broadband and get the fastest 6.0/768 connection for only $19.95/mo for the first 3 months! http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click _______________________________________________ [EMAIL PROTECTED] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel