From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDBC9C072B5 for ; Tue, 21 May 2019 20:47:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3DEB217D7 for ; Tue, 21 May 2019 20:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728018AbfEUUrG convert rfc822-to-8bit (ORCPT ); Tue, 21 May 2019 16:47:06 -0400 Received: from shards.monkeyblade.net ([23.128.96.9]:45050 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727350AbfEUUrF (ORCPT ); Tue, 21 May 2019 16:47:05 -0400 Received: from localhost (unknown [IPv6:2601:601:9f80:35cd::3d8]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id B282E14CEC900; Tue, 21 May 2019 13:47:04 -0700 (PDT) Date: Tue, 21 May 2019 13:47:04 -0700 (PDT) Message-Id: <20190521.134704.1456978856134153782.davem@davemloft.net> To: Jan.Kloetzke@preh.de Cc: oneukum@suse.com, jan@kloetzke.net, netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH v3] usbnet: fix kernel crash after disconnect From: David Miller In-Reply-To: <20190521131826.30475-1-Jan.Kloetzke@preh.de> References: <1558438944.12672.13.camel@suse.com> <20190521131826.30475-1-Jan.Kloetzke@preh.de> X-Mailer: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 21 May 2019 13:47:04 -0700 (PDT) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Kloetzke Jan Date: Tue, 21 May 2019 13:18:40 +0000 > When disconnecting cdc_ncm the kernel sporadically crashes shortly > after the disconnect: ... > The crash happens roughly 125..130ms after the disconnect. This > correlates with the 'delay' timer that is started on certain USB tx/rx > errors in the URB completion handler. > > The problem is a race of usbnet_stop() with usbnet_start_xmit(). In > usbnet_stop() we call usbnet_terminate_urbs() to cancel all URBs in > flight. This only makes sense if no new URBs are submitted > concurrently, though. But the usbnet_start_xmit() can run at the same > time on another CPU which almost unconditionally submits an URB. The > error callback of the new URB will then schedule the timer after it was > already stopped. > > The fix adds a check if the tx queue is stopped after the tx list lock > has been taken. This should reliably prevent the submission of new URBs > while usbnet_terminate_urbs() does its job. The same thing is done on > the rx side even though it might be safe due to other flags that are > checked there. > > Signed-off-by: Jan Klötzke Applied.