Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1139688rdb; Fri, 20 Oct 2023 09:24:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDbxM2tgh+Cd7EB6vwAO9Bha29bKe8LN+veuUS8IOO623i0tTt7F7LfaIi98Ltw2SKmPze X-Received: by 2002:a05:6a00:15cf:b0:6b1:b5c4:a8b0 with SMTP id o15-20020a056a0015cf00b006b1b5c4a8b0mr2613077pfu.23.1697819049776; Fri, 20 Oct 2023 09:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697819049; cv=none; d=google.com; s=arc-20160816; b=I7CNchC5wgJbsILBfRDHqE61XVboSsryEOgDn5pdaCJlmC7tNs+xtvmBKGmFKf4kHH jo1BQOXJnHqIPcujAHySvyVpdbrGTNwY8LQ/i/rPFppO9JdpshlxAWBVLysLCyptQYlA IrUkRsE9jsnLiLblIs0kCHYh/c2JGSi0Cc2qMS3K007pnPiIoSHNtrWinhlPAWvfPxiQ q4JCKWsJzDXe/fELTqDwSYa4etxx84A5XYP6TdiW/OiKuCqu0PiWdU70k00SNSau5vEJ Nol/IiaqJuZ8Ob/rYX9o2WDGx9UKvL8vGQz55kwJ1N8lfu23hHPZTd5iwfsfaeUq/r2+ iCfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=2dwtVxF/4al1Kj9KZRT8dvBcLiyD4iWBOZOrfoZyKUs=; fh=v4QtMduwf+Xaw8Ivf3DvAZJQl82XX3MCCo93xkR+XtY=; b=jkFNWlo/7/D+X2lLKj0D52QLeO9sB2HCBbJ5clWjFiGOw2dwc3IorzWUICymK8MU/a 1mBRR56IkIuWo/6npdHJF8UAdDzunNgW36/X3o8UYXxnLGxzNlS81rhdgGS9YW0uqCQJ EYkxaWOkGBP478LnLno+zes95oKMcdm7TBep/wdrPWlXhTy9I2+BJMb0zMENF9JAtKFI 2JQBFMnO/YgNMQzxtdZReisXIuX2Zv8/P+C+PpJOBC5adbIkvkj0Qolz76qlYKPXEnTs 0gavi2EaS2Rpf098fILoBZqz2HshXv64pj3l+C3ZenOGX49kWmbj9/btjbWde0FgXxza xZ+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id o7-20020a056a0015c700b0068fb5ca50cdsi2330925pfu.126.2023.10.20.09.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:24:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9C5A780725A7; Fri, 20 Oct 2023 09:24:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbjJTQX6 (ORCPT + 99 others); Fri, 20 Oct 2023 12:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377864AbjJTQX5 (ORCPT ); Fri, 20 Oct 2023 12:23:57 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id B4C051A4 for ; Fri, 20 Oct 2023 09:23:54 -0700 (PDT) Received: (qmail 302116 invoked by uid 1000); 20 Oct 2023 12:23:53 -0400 Date: Fri, 20 Oct 2023 12:23:53 -0400 From: Alan Stern To: Doug Anderson Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Grant Grundler , Hayes Wang , Bastien Nocera , Benjamin Tissoires , Flavio Suligoi , Hans de Goede , Heikki Krogerus , Ivan Orlov , Marc Kleine-Budde , "Rafael J. Wysocki" , Ray Chi , Ricardo =?iso-8859-1?Q?Ca=F1uelo?= , Rob Herring , Roy Luo , Stanley Chang , Vincent Mailhol , linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: core: Prevent infinite loops when usb_reset_device() unbinds/binds Message-ID: <2b6352b1-e192-47d6-bdce-b63216ab674b@rowland.harvard.edu> References: <20231020083125.1.I3e5f7abcbf6f08d392e31a5826b7f234df662276@changeid> <60a358c9-b44b-4d25-9a20-aa9e00c65ab6@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 20 Oct 2023 09:24:07 -0700 (PDT) On Fri, Oct 20, 2023 at 08:59:42AM -0700, Doug Anderson wrote: > Hi, > > On Fri, Oct 20, 2023 at 8:46 AM Alan Stern wrote: > > > > On Fri, Oct 20, 2023 at 08:31:38AM -0700, Douglas Anderson wrote: > > > When we call usb_reset_device() and a driver doesn't implement > > > pre_reset() and post_reset() methods then the USB core will attempt to > > > unbind and rebind the driver in order to make reset work. This is a > > > great general solution, but it has the potential to loop forever. > > > Specifically, if the USB device is in a state that the USB device > > > driver issues another usb_reset_device() after each rebind then we'll > > > just continually unbind and rebind with no end. > > > > > > It's difficult to address this condition in a USB device driver > > > because it's hard for the driver to keep state across each > > > unbind/bind. > > > > How about just adding appropriate pre_reset() and post_reset() methods? > > This is precisely what they are meant for. Then the the unbind/rebind > > loop wouldn't ever get started. > > Right, and we have pre_reset() and post_reset() in the r1852 driver. > The issue is that we are seeing occasional control transfer errors > while the r8152 driver is still running its probe() routine and we > want to reset in response to those. It is relatively difficult to have > the pre_reset() and post_reset() methods work properly if failures > happen and probe() hasn't finished yet. Why is that? > The current proposal I have > for the r8152 driver is to have the pre_reset() routine return -EIO if > we saw errors during probe, which tells the USB core to unbind/rebind > us. This gets us to a known good state. Don't you also get to a known good state if pre_reset() and post_reset() both return 0? Then there's no unbinding, so the driver can just jump back to the start of its probe() routine. Or fail the probe, if there have been too many errors. > If we need to do a reset later > on (after probe finished successfully) then pre_reset() and > post_reset() can avoid the unbind/bind. > > The worry was that this could cause an infinite loop. Hence this patch. ;-) With no unbinding/rebinding, any loops that occur will be entirely under the driver's control. Then it should easily be able to avoid looping forever. Alan Stern