From owner-freebsd-usb@freebsd.org Sun Sep 4 21:29:00 2016 Return-Path: Delivered-To: freebsd-usb@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 F147DB761D3; Sun, 4 Sep 2016 21:29:00 +0000 (UTC) (envelope-from andriyvos@gmail.com) Received: from mail-lf0-f42.google.com (mail-lf0-f42.google.com [209.85.215.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6C6199C2; Sun, 4 Sep 2016 21:28:57 +0000 (UTC) (envelope-from andriyvos@gmail.com) Received: by mail-lf0-f42.google.com with SMTP id g62so115381181lfe.3; Sun, 04 Sep 2016 14:28:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:to:subject:cc:mime-version :content-transfer-encoding:from:message-id:user-agent; bh=4K3qBq4JOFZClFoxL5mpmORZ4PdTZDK7HfqDzZLje+A=; b=km03it4Ohf9SK3Dx38KJ2nZp/X7iw3ZsL5kB+4ApDGhHNiuhyloNQyHkbLbYuUZqtZ bREOGW7ovfpZEv3t6HtXpDJtGIs0mYZY4kUKex/ZX8UhZ/NLjLC3ItuADF4QbYEKMPMZ RjXmuh77qf/+LeDevC9s34izpnvmJ+2vEkvI9BJLamPu5jmqtXavX7mmjtSnDVk+j0Y9 /gJogk2PrGvSeDcy8pRZT2+x+kXSR++MaeU8zdOrSxEPHrXyV8JeTqwCbN5E/KQQ3ZqC EZnggHkp6Ry7kC8Tk5BkdiimvgpZS2fFrHROfQOoLTpAVjHUTv28hsa9M8ZUKXNHIncx 9DUQ== X-Gm-Message-State: AE9vXwOYLyMMHaZe2/BxGILlbvzkj98D5ScZ/18kIqa0DhB5QULno1+I25HjqtWUs6v/FQ== X-Received: by 10.25.83.198 with SMTP id h189mr9683728lfb.130.1473024042233; Sun, 04 Sep 2016 14:20:42 -0700 (PDT) Received: from localhost (host-176-37-109-22.la.net.ua. [176.37.109.22]) by smtp.gmail.com with ESMTPSA id s82sm4212181lja.14.2016.09.04.14.20.41 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 04 Sep 2016 14:20:41 -0700 (PDT) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Date: Mon, 05 Sep 2016 00:20:25 +0300 To: "Adrian Chadd" , "Hans Petter Selasky" Subject: Deadlock between device_detach() and usbd_do_request_flags() Cc: "freebsd-wireless@freebsd.org" , "freebsd-usb@freebsd.org" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Andriy Voskoboinyk" Message-ID: User-Agent: Opera Mail/12.16 (FreeBSD) X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Sep 2016 21:29:01 -0000 There is a rare, but reproducible deadlock for wlan(4) drivers: Thread 1: * uhub_explore_handle_re_enumerate() (obtains enum_sx lock) * usbd_set_config_index() * usb_unconfigure() * usb_detach_device() * usb_detach_device_sub() * typically is executed here (prevents another possible deadlock?) * ieee80211_ifdetach() * ieee80211_vap_destroy() * ic_vap_delete> * ieee80211_vap_detach() here it calls ieee80211_stop() and waits for -> INIT state transition Thread 2 (started from thread 1): * ieee80211_newstate_cb() * vap->iv_newstate() here: if the driver will try to call usbd_do_request_flags() (typically via / ) it will hang (because enum_sx lock is already held by thread 1). Another way: execute some periodical task that will try to access some registers (urtwn_temp_calib(), rum_ratectl_task(), run_ratectl_cb()) while thread 1 is running - deadlock is here too, since will wait for them indefinitely (via ieee80211_draintask()) Right now the most obvious (and, probably, wrong) way is to just detect & release all locks (usbd_enum_unlock()) for ieee80211_ifdetach() / ieee80211_draintask() and re-acquire them later (not tested yet). Any ideas?