On Thu, 3 Jun 2004 22:06:06 +0200
Vojtech Pavlik <[EMAIL PROTECTED]> wrote:

> The deadlocks might actually be my fault, as I re-used the serialize
> semaphore, while the original 2.4 patch used it's own.

Et tu Brut :-)  I tried that as well, but the root problem is how
dev->serialize is taken across a probe, which involves SCSI probing.

Appended is a 2.4 patch I have in my tree and thinking about forwarding
to Marcelo. If both Red Hat and SuSE suffer from it (on sharply different
installers), the patch probably deserves to be upstream. If nobody
objects, to Marcelo it goes.

But to the best of my knowledge, 2.6 should not be affected!

-- Pete

diff -urN -X dontdiff linux-2.4.26/drivers/usb/devio.c 
linux-2.4.26-nip/drivers/usb/devio.c
--- linux-2.4.26/drivers/usb/devio.c    2003-11-29 18:53:02.000000000 -0800
+++ linux-2.4.26-nip/drivers/usb/devio.c        2004-05-03 17:36:31.000000000 -0700
@@ -1157,6 +1157,13 @@
                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 @@
                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 -urN -X dontdiff linux-2.4.26/drivers/usb/storage/transport.c 
linux-2.4.26-nip/drivers/usb/storage/transport.c
--- linux-2.4.26/drivers/usb/storage/transport.c        2004-02-26 14:09:59.000000000 
-0800
+++ linux-2.4.26-nip/drivers/usb/storage/transport.c    2004-05-03 17:38:53.000000000 
-0700
@@ -627,8 +627,17 @@
        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 @@
                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 -urN -X dontdiff linux-2.4.26/drivers/usb/usb.c linux-2.4.26-nip/drivers/usb/usb.c
--- linux-2.4.26/drivers/usb/usb.c      2004-02-26 14:09:59.000000000 -0800
+++ linux-2.4.26-nip/drivers/usb/usb.c  2004-05-03 17:35:11.000000000 -0700
@@ -989,6 +989,7 @@
        INIT_LIST_HEAD(&dev->filelist);
 
        init_MUTEX(&dev->serialize);
+       init_MUTEX(&dev->exclusive_access);
 
        dev->bus->op->allocate(dev);
 
diff -urN -X dontdiff linux-2.4.26/include/linux/usb.h 
linux-2.4.26-nip/include/linux/usb.h
--- linux-2.4.26/include/linux/usb.h    2004-04-18 17:23:55.000000000 -0700
+++ linux-2.4.26-nip/include/linux/usb.h        2004-05-03 17:40:15.000000000 -0700
@@ -828,6 +828,8 @@
 
        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 the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to