Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp517771rwe; Fri, 26 Aug 2022 09:06:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Yq3Kd2x2OKM3yu3R9VojbIfcZbV5a5EcvV9cj6cNaHEb0q/dB9KjA7uJbIYpFzYiIFKNo X-Received: by 2002:a17:90a:9907:b0:1f5:2318:ea6d with SMTP id b7-20020a17090a990700b001f52318ea6dmr5062511pjp.163.1661529991333; Fri, 26 Aug 2022 09:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661529991; cv=none; d=google.com; s=arc-20160816; b=DwCZ3/zewT0M0W8DMkX21O9liq5zI53H81Y2kxVMwe0kctPPbr8ciQAl9v/hnbvy8W yYbn4XyE9LC2jkrRSwM8ONjrNEdMNscP5NlGoIKp1fuEE4lBwJI3tmKze18r8Dj4rasa igFf2hvOO0HL5+yOav9lP/P+xvP4EnBl7fqCZSxOAo7mxrLvzjWGHCzxtOZNlDh23Y5y KcBevRE5lQeOqmrSK6tOLyK9EQCcgUTEVYq5EyOphawtHt0crO9fxj2sgKG7Y+LBiABi Ur+m2LgzBRGMQASkWSfPp95ZztnKLDRGbJjikNhMe66up/gJZhqHuRdUUnTuGwTWn8iv xbRw== 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=jFANrZ8eBfVd/R0EjGI/ytNM/VFp1+xJWn9fnTs7zjg=; b=SIT64P+U94wsM2SbmglWpeIRrD0B6R7MnxnOxRsYSSs27ymeNt+FFNnkG1/qZu862p ocwFQ61AfDDuN6nS7uE7qP/JCJgkg+BXOuvccI7yraRdhLE3zf1JzGKOHi1e8OSe2k1c FOYwJHSmYx19OLv6iBvpWYn/Ry7+9y5/IfWMW0+ffahBuuqkmoMdPJOynUbZwJ6q+GzL 9zAN0Mk2OBinpmZpC6P/iBqs1QgG4T9aRCOWPSh23Oh5zCukhuRwRj4nOlYCIC0V1v82 X8DArnfgqQt4Tq7TBx8+1GjAgXc35XcVosjcicW3okgTpiDA8sfWAk/YM0oXs2G/VxRD W3WQ== 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 ng15-20020a17090b1a8f00b001fbb0f2e5ecsi2385363pjb.169.2022.08.26.09.06.18; Fri, 26 Aug 2022 09:06:31 -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 S238049AbiHZOzr (ORCPT + 99 others); Fri, 26 Aug 2022 10:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235525AbiHZOzo (ORCPT ); Fri, 26 Aug 2022 10:55:44 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 7488CA2232 for ; Fri, 26 Aug 2022 07:55:42 -0700 (PDT) Received: (qmail 40232 invoked by uid 1000); 26 Aug 2022 10:55:41 -0400 Date: Fri, 26 Aug 2022 10:55:41 -0400 From: Alan Stern To: Ray Chi Cc: gregkh@linuxfoundation.org, mathias.nyman@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, albertccwang@google.com, badhri@google.com, pumahsu@google.com Subject: Re: [PATCH] usb: core: stop USB enumeration if too many retries Message-ID: References: <20220826075839.292615-1-raychi@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220826075839.292615-1-raychi@google.com> 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 Fri, Aug 26, 2022 at 03:58:39PM +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. Why only to specific ports? > Signed-off-by: Ray Chi > --- > drivers/usb/core/hub.c | 33 +++++++++++++++++++++++++++++++++ > include/linux/usb.h | 3 +++ > 2 files changed, 36 insertions(+) > > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c > index 2633acde7ac1..0f4097440ffb 100644 > --- a/drivers/usb/core/hub.c > +++ b/drivers/usb/core/hub.c > @@ -3081,6 +3081,28 @@ static int hub_port_reset(struct usb_hub *hub, int port1, > return status; > } > > +/* Stop enumerate if the port met errors and quirk is set */ > +static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries) > +{ > + struct usb_port *port_dev = hub->ports[port1 - 1]; > + struct usb_device *hdev = hub->hdev; > + > + if (retries < (PORT_INIT_TRIES - 1) / 2) > + return false; > + > + /* > + * 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. > + */ > + if (port_dev->quirks & USB_PORT_QUIRK_STOP_ENUM) { > + usb_hub_set_port_power(hdev, hub, port1, false); Why turn the port power off? Aren't there better ways to stop the enumeration attempts? When will the power ever get turned back on? Why not use the initial_descriptor_timeout module parameter for this purpose? That's the sort of thing it was meant for. Alan Stern