From owner-svn-src-stable-8@freebsd.org Mon Sep 12 10:23:26 2016 Return-Path: Delivered-To: svn-src-stable-8@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A25D2BD800C; Mon, 12 Sep 2016 10:23:26 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 701519AE; Mon, 12 Sep 2016 10:23:26 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8CANPE1019201; Mon, 12 Sep 2016 10:23:25 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8CANOhq019191; Mon, 12 Sep 2016 10:23:24 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201609121023.u8CANOhq019191@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 12 Sep 2016 10:23:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r305736 - in stable/8/sys: dev/usb dev/usb/template sys X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Sep 2016 10:23:26 -0000 Author: hselasky Date: Mon Sep 12 10:23:24 2016 New Revision: 305736 URL: https://svnweb.freebsd.org/changeset/base/305736 Log: MFC r305421: Resolve deadlock between device_detach() and usbd_do_request_flags() by reviving the SX control request lock and refining which lock protects the common scratch area in "struct usb_device". The SX control request lock was removed by r246759 because it caused a lock order reversal with the USB enumeration lock inside usbd_transfer_setup() as a function of r246616. It was thought that reducing the number of locks would resolve the LOR, but because some USB device drivers use usbd_do_request_flags() inside callback functions, like in taskqueues, a deadlock may occur when these are drained from device_detach(). By restoring the SX control request lock usbd_do_request_flags() is allowed to complete its execution when a USB device driver is detaching. By using the SX control request lock to protect the scratch area, the LOR introduced by r246616 is also resolved. Bump the FreeBSD version while at it to force recompilation of all USB kernel modules. Found by: avos@ Modified: stable/8/sys/dev/usb/template/usb_template.c stable/8/sys/dev/usb/usb_device.c stable/8/sys/dev/usb/usb_device.h stable/8/sys/dev/usb/usb_generic.c stable/8/sys/dev/usb/usb_request.c stable/8/sys/dev/usb/usb_transfer.c stable/8/sys/dev/usb/usb_util.c stable/8/sys/sys/param.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/dev/ (props changed) stable/8/sys/dev/usb/ (props changed) stable/8/sys/sys/ (props changed) Modified: stable/8/sys/dev/usb/template/usb_template.c ============================================================================== --- stable/8/sys/dev/usb/template/usb_template.c Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/dev/usb/template/usb_template.c Mon Sep 12 10:23:24 2016 (r305736) @@ -1240,7 +1240,7 @@ usb_temp_setup(struct usb_device *udev, return (0); /* Protect scratch area */ - do_unlock = usbd_enum_lock(udev); + do_unlock = usbd_ctrl_lock(udev); uts = udev->scratch.temp_setup; @@ -1319,7 +1319,7 @@ done: if (error) usb_temp_unsetup(udev); if (do_unlock) - usbd_enum_unlock(udev); + usbd_ctrl_unlock(udev); return (error); } Modified: stable/8/sys/dev/usb/usb_device.c ============================================================================== --- stable/8/sys/dev/usb/usb_device.c Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/dev/usb/usb_device.c Mon Sep 12 10:23:24 2016 (r305736) @@ -1550,6 +1550,7 @@ usb_alloc_device(device_t parent_dev, st /* initialise our SX-lock */ sx_init_flags(&udev->enum_sx, "USB config SX lock", SX_DUPOK); sx_init_flags(&udev->sr_sx, "USB suspend and resume SX lock", SX_NOWITNESS); + sx_init_flags(&udev->ctrl_sx, "USB control transfer SX lock", SX_DUPOK); cv_init(&udev->ctrlreq_cv, "WCTRL"); cv_init(&udev->ref_cv, "UGONE"); @@ -1735,7 +1736,7 @@ usb_alloc_device(device_t parent_dev, st */ /* Protect scratch area */ - do_unlock = usbd_enum_lock(udev); + do_unlock = usbd_ctrl_lock(udev); scratch_ptr = udev->scratch.data; @@ -1786,7 +1787,7 @@ usb_alloc_device(device_t parent_dev, st } if (do_unlock) - usbd_enum_unlock(udev); + usbd_ctrl_unlock(udev); /* assume 100mA bus powered for now. Changed when configured. */ udev->power = USB_MIN_POWER; @@ -2148,6 +2149,7 @@ usb_free_device(struct usb_device *udev, sx_destroy(&udev->enum_sx); sx_destroy(&udev->sr_sx); + sx_destroy(&udev->ctrl_sx); cv_destroy(&udev->ctrlreq_cv); cv_destroy(&udev->ref_cv); @@ -2311,7 +2313,7 @@ usbd_set_device_strings(struct usb_devic uint8_t do_unlock; /* Protect scratch area */ - do_unlock = usbd_enum_lock(udev); + do_unlock = usbd_ctrl_lock(udev); temp_ptr = (char *)udev->scratch.data; temp_size = sizeof(udev->scratch.data); @@ -2371,7 +2373,7 @@ usbd_set_device_strings(struct usb_devic } if (do_unlock) - usbd_enum_unlock(udev); + usbd_ctrl_unlock(udev); } /* @@ -2853,6 +2855,40 @@ usbd_enum_is_locked(struct usb_device *u } /* + * The following function is used to serialize access to USB control + * transfers and the USB scratch area. If the lock is already grabbed + * this function returns zero. Else a value of one is returned. + */ +uint8_t +usbd_ctrl_lock(struct usb_device *udev) +{ + if (sx_xlocked(&udev->ctrl_sx)) + return (0); + sx_xlock(&udev->ctrl_sx); + + /* + * We need to allow suspend and resume at this point, else the + * control transfer will timeout if the device is suspended! + */ + if (usbd_enum_is_locked(udev)) + usbd_sr_unlock(udev); + return (1); +} + +void +usbd_ctrl_unlock(struct usb_device *udev) +{ + sx_xunlock(&udev->ctrl_sx); + + /* + * Restore the suspend and resume lock after we have unlocked + * the USB control transfer lock to avoid LOR: + */ + if (usbd_enum_is_locked(udev)) + usbd_sr_lock(udev); +} + +/* * The following function is used to set the per-interface specific * plug and play information. The string referred to by the pnpinfo * argument can safely be freed after calling this function. The Modified: stable/8/sys/dev/usb/usb_device.h ============================================================================== --- stable/8/sys/dev/usb/usb_device.h Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/dev/usb/usb_device.h Mon Sep 12 10:23:24 2016 (r305736) @@ -162,7 +162,7 @@ struct usb_temp_setup { /* * The scratch area for USB devices. Access to this structure is - * protected by the enumeration SX lock. + * protected by the control SX lock. */ union usb_device_scratch { struct usb_hw_ep_scratch hw_ep_scratch[1]; @@ -183,6 +183,7 @@ struct usb_device { struct usb_udev_msg cs_msg[2]; struct sx enum_sx; struct sx sr_sx; + struct sx ctrl_sx; struct mtx device_mtx; struct cv ctrlreq_cv; struct cv ref_cv; @@ -309,6 +310,8 @@ uint8_t usbd_enum_lock_sig(struct usb_de void usbd_enum_unlock(struct usb_device *); void usbd_sr_lock(struct usb_device *); void usbd_sr_unlock(struct usb_device *); +uint8_t usbd_ctrl_lock(struct usb_device *); +void usbd_ctrl_unlock(struct usb_device *); uint8_t usbd_enum_is_locked(struct usb_device *); #if USB_HAVE_TT_SUPPORT Modified: stable/8/sys/dev/usb/usb_generic.c ============================================================================== --- stable/8/sys/dev/usb/usb_generic.c Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/dev/usb/usb_generic.c Mon Sep 12 10:23:24 2016 (r305736) @@ -706,16 +706,16 @@ ugen_get_cdesc(struct usb_fifo *f, struc return (error); } -/* - * This function is called having the enumeration SX locked which - * protects the scratch area used. - */ static int ugen_get_sdesc(struct usb_fifo *f, struct usb_gen_descriptor *ugd) { void *ptr; uint16_t size; int error; + uint8_t do_unlock; + + /* Protect scratch area */ + do_unlock = usbd_ctrl_lock(f->udev); ptr = f->udev->scratch.data; size = sizeof(f->udev->scratch.data); @@ -736,6 +736,9 @@ ugen_get_sdesc(struct usb_fifo *f, struc error = copyout(ptr, ugd->ugd_data, size); } + if (do_unlock) + usbd_ctrl_unlock(f->udev); + return (error); } Modified: stable/8/sys/dev/usb/usb_request.c ============================================================================== --- stable/8/sys/dev/usb/usb_request.c Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/dev/usb/usb_request.c Mon Sep 12 10:23:24 2016 (r305736) @@ -453,16 +453,9 @@ usbd_do_request_flags(struct usb_device } /* - * Grab the USB device enumeration SX-lock serialization is - * achieved when multiple threads are involved: + * Serialize access to this function: */ - do_unlock = usbd_enum_lock(udev); - - /* - * We need to allow suspend and resume at this point, else the - * control transfer will timeout if the device is suspended! - */ - usbd_sr_unlock(udev); + do_unlock = usbd_ctrl_lock(udev); hr_func = usbd_get_hr_func(udev); @@ -706,10 +699,8 @@ usbd_do_request_flags(struct usb_device USB_XFER_UNLOCK(xfer); done: - usbd_sr_lock(udev); - if (do_unlock) - usbd_enum_unlock(udev); + usbd_ctrl_unlock(udev); if ((mtx != NULL) && (mtx != &Giant)) mtx_lock(mtx); Modified: stable/8/sys/dev/usb/usb_transfer.c ============================================================================== --- stable/8/sys/dev/usb/usb_transfer.c Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/dev/usb/usb_transfer.c Mon Sep 12 10:23:24 2016 (r305736) @@ -872,7 +872,7 @@ usbd_transfer_setup(struct usb_device *u return (error); /* Protect scratch area */ - do_unlock = usbd_enum_lock(udev); + do_unlock = usbd_ctrl_lock(udev); refcount = 0; info = NULL; @@ -1170,7 +1170,7 @@ done: error = parm->err; if (do_unlock) - usbd_enum_unlock(udev); + usbd_ctrl_unlock(udev); return (error); } Modified: stable/8/sys/dev/usb/usb_util.c ============================================================================== --- stable/8/sys/dev/usb/usb_util.c Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/dev/usb/usb_util.c Mon Sep 12 10:23:24 2016 (r305736) @@ -119,7 +119,7 @@ device_set_usb_desc(device_t dev) } /* Protect scratch area */ - do_unlock = usbd_enum_lock(udev); + do_unlock = usbd_ctrl_lock(udev); temp_p = (char *)udev->scratch.data; @@ -136,7 +136,7 @@ device_set_usb_desc(device_t dev) } if (do_unlock) - usbd_enum_unlock(udev); + usbd_ctrl_unlock(udev); device_set_desc_copy(dev, temp_p); device_printf(dev, "<%s> on %s\n", temp_p, Modified: stable/8/sys/sys/param.h ============================================================================== --- stable/8/sys/sys/param.h Mon Sep 12 10:20:44 2016 (r305735) +++ stable/8/sys/sys/param.h Mon Sep 12 10:23:24 2016 (r305736) @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 804508 /* Master, propagated to newvers */ +#define __FreeBSD_version 804509 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, From owner-svn-src-stable-8@freebsd.org Thu Sep 15 08:38:54 2016 Return-Path: Delivered-To: svn-src-stable-8@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C9B9ABDC5D9; Thu, 15 Sep 2016 08:38:54 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9BEE71139; Thu, 15 Sep 2016 08:38:54 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8F8crGX079383; Thu, 15 Sep 2016 08:38:53 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8F8cr6L079382; Thu, 15 Sep 2016 08:38:53 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201609150838.u8F8cr6L079382@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 15 Sep 2016 08:38:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r305831 - stable/8/sys/dev/usb/input X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Sep 2016 08:38:54 -0000 Author: hselasky Date: Thu Sep 15 08:38:53 2016 New Revision: 305831 URL: https://svnweb.freebsd.org/changeset/base/305831 Log: MFC r305590: Correctly map the USB mouse tilt delta values into buttons 5 and 6 instead of 3 and 4 which is used for the scroll wheel, according to X.org. PR: 170358 Modified: stable/8/sys/dev/usb/input/ums.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/dev/ (props changed) stable/8/sys/dev/usb/ (props changed) Modified: stable/8/sys/dev/usb/input/ums.c ============================================================================== --- stable/8/sys/dev/usb/input/ums.c Thu Sep 15 08:37:20 2016 (r305830) +++ stable/8/sys/dev/usb/input/ums.c Thu Sep 15 08:38:53 2016 (r305831) @@ -288,9 +288,9 @@ ums_intr_callback(struct usb_xfer *xfer, /* translate T-axis into button presses until further */ if (dt > 0) - buttons |= 1UL << 3; + buttons |= 1UL << 5; else if (dt < 0) - buttons |= 1UL << 4; + buttons |= 1UL << 6; sc->sc_status.button = buttons; sc->sc_status.dx += dx;