Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp68060rwb; Fri, 2 Sep 2022 10:16:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR4UsTxdQaGLLKDE5gryZy3nESeYeKOtgBn9eM4m0oSTVEof6TbcBHYrHXuz8lH0ZwmdWx72 X-Received: by 2002:a17:902:bb95:b0:16e:e3f4:8195 with SMTP id m21-20020a170902bb9500b0016ee3f48195mr35964823pls.130.1662139015937; Fri, 02 Sep 2022 10:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662139015; cv=none; d=google.com; s=arc-20160816; b=EkegqPtq7uYej1JT5fWoTDsEUaxmDuThQ0Dfywb+JlD9pHlK0Fr8kXZwt1JFzv5Rxo RuzK4Uipxf4EitcM4QdHzYoJ1Ln0zMGEeYvWfra6eG95Q7P9qc6vzhIv1530OGiw5a8h QmvmUREsT8oPm2JE6r6YcPzyflA4pYoXoKVs7hXvyJk1aB6pNs7UHzSOSPcn9oDm8jTU l/0MJHwTb5DwJ1gaBQ8s9nE9cS30vhDH+BmqPKoloRaL9ITzSvlzBMtYN4YNrj9X9+PU wm3soXPCGyZBqCGTLccKTfm62p1GkXT2nwibXtkyVNZN5h5MqmrWOQL/esIb4DRqyawM DpKw== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=bNJFFNPm8HEI9QyeD5EMtanQINtNzHDSiOiUIZRTzbY=; b=A0QUd7UdlFqq9y77MQXWPt78Xmab1sEGPQBHu44HaVR+L6GyHMThL+didQohKJqpWR zjY2L2VZ11IuWOLlouBiZaqUTzYWgrdrHF3hS70zw0Kv7Ba9A36S2N9Oh8VMyjbxI1QQ FT9Pn8H0VLm75cKgaH1Tdmy+n84dfuWy2FmCehz4/uELYHCFj4kEA8tUeKphCy5muhGv DGUI2COV13j14o61VBIc+kypH8DAAiyb3CeuyiE1z3NeNYCwywmqJEIc7grG8DJI3Tw4 alrEigthPHgT4heBNoJH9fD9Xh8DpXrypVV3eGRTVugU91WMrZT9+D9n7+s0Dr5GTqMF yNVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a170902cecb00b001753c45cb46si3028015plg.209.2022.09.02.10.16.44; Fri, 02 Sep 2022 10:16:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236342AbiIBRH5 (ORCPT + 99 others); Fri, 2 Sep 2022 13:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233264AbiIBRHw (ORCPT ); Fri, 2 Sep 2022 13:07:52 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 6640C110D85 for ; Fri, 2 Sep 2022 10:07:50 -0700 (PDT) Received: (qmail 278413 invoked by uid 1000); 2 Sep 2022 13:07:49 -0400 Date: Fri, 2 Sep 2022 13:07:49 -0400 From: Alan Stern To: Ray Chi Cc: Greg KH , mathias.nyman@linux.intel.com, Albert Wang , Badhri Jagan Sridharan , Puma Hsu , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [Patch v2] usb: core: stop USB enumeration if too many retries Message-ID: References: <20220902091535.3572333-1-raychi@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 03, 2022 at 12:08:04AM +0800, Ray Chi wrote: > On Fri, Sep 2, 2022 at 10:49 PM Alan Stern wrote: > > > > On Fri, Sep 02, 2022 at 05:15:35PM +0800, Ray Chi wrote: > > > If a broken accessory connected to a USB host, usbcore might > > > keep doing enumeration retries and it will take a long time to > > > cause system unstable. > > > > > > This patch provides a quirk to specific USB ports of the hub to > > > stop USB enumeration if needed. > > > > This seems very awkward. Why not have a quirk that prevents USB > > enumeration completely, instead of after some number of retries? After > > all, if the port is connected to a broken accessory, there's no reason > > to try enumerating it even once. > > > > For that matter, have you tried using the existing "disabled" port > > attribute instead of adding a new quirk? Does it already solve your > > problem? > > > > Since we don't know if the connected accessory is normal or broken, doing port > initialization is necessary. I don't understand. If you don't know whether the accessory is broken, how do you know whether to set the quirk? On the other hand, if you always set the quirk even before you know whether the accessory is broken, why make it a quirk at all? Why not make it the normal behavior of the driver? > > > + * Some USB hosts can't take a long time to keep doing enumeration > > > + * retry. After doing half of the retries, we would turn off the port > > > + * power to stop enumeration if the quirk is set. > > > > What made you decide that half of the retries was the right place to > > stop? Why not do all the retries? > > Since some normal devices will be timeout in the first attempt, I set > the condition to half > of the retries. All the retries will take 12*timeout seconds. It is > too long so that a watchdog > timeout problem may happen. Why not set CONFIG_USB_FEW_INIT_RETRIES instead? > > If the quirk prevented enumeration completely then this function > > wouldn't be needed. > > The enumeration is still needed as above. > > > > > > + > > > /* Check if a port is power on */ > > > int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) > > > { > > > @@ -4855,6 +4879,11 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, > > > buf->bMaxPacketSize0; > > > kfree(buf); > > > > > > + if (r < 0 && (port_dev->quirks & USB_PORT_QUIRK_STOP_ENUM)) { > > > > How come this line tests the quirk but doesn't call > > hub_port_stop_enumerate()? > > Since the quirk is used to stop enumeration and reduce the total time. > If the port has the quirk, I think the port doesn't need to do > set_address after the port gets > failures in the new scheme. It will add 2 attempts * timeout (defined > in hc_driver) seconds. I still can't tell what you're trying to accomplish. You need to do a much better job of explaining the point of this. For instance, you might describe in detail a situation where the quirk is needed, explaining what sort of behavior of the system would lead you to set the quirk, and why. Alan Stern