Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp588062iog; Mon, 13 Jun 2022 08:40:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/moQJxxCJCEEJiYW1iBoY1cSlg5k4T91UVY1eMnytjQSSxcty0W5g01eKKXloO3P9bq9h X-Received: by 2002:a17:90b:3e8b:b0:1e8:66c2:c61c with SMTP id rj11-20020a17090b3e8b00b001e866c2c61cmr16242071pjb.181.1655134824569; Mon, 13 Jun 2022 08:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134824; cv=none; d=google.com; s=arc-20160816; b=Uyv3oxIZ56knjz0/7a0uII0cc6T10MQOC/5mItAl3SjqpCpDHwivfuOUpDLq6ft6E4 ztRoY+xfBhTmTPAUxEUI8MxVeQswzDmut32UPlriXHL7LqP1jlkJMMckzEk8S0gEGkH8 q6AhHwKx1SVyu+rF7e1+x9lsju7FxLR0Zk/wfTkB87+4lmufdtGqSg5905slqf75jjxF 1itHhS9d3yArGFza+uf/5Lcvk/PCA/NNh+THpgBO9gqO0WA2MMVOilvnMCPLSlZVjjTK iIph1zC+TnQ90TRWSDsqFsPCnVpWezjEHDLnMJZvdFVwWVbIvbcbaABBs2YiR7fKUvGO fxEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LxdQBQ4VxjoW5+zX11sqJybcVqdLe/oQj6Xf4UnhrPU=; b=GU8dNbd8bWPIOhGEWmNNB9yDohR6oNdfEGsfP5OGo6Pal69IX1dfz23SVY5JOyKjt1 TBDVQBYk3LkxpPlZu+/UfdEtimNSJ2wxu/KunWyCkIdJyYrCDxoJjyToyBb6iAEvz2Kq duoVFcgaMKDbx4Hs0B8g5H6hlwxEI0oQ+waIydesrUjb6LUxClGkPqjNCoK+4RWIzM4i c9A0CjgNTWz1cxvEgeClszuEDbD+pilXMTABbdTd7gyzf6gajn8pP0+RxCqTV58dqcx2 oIF9WAyt9uk4mImdRGJZq5uWWs6e0TOsAJLr0UkNd1brxv5e16I7DfMd/ZhdnwRKakZW XJ2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z+obmfTL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g67-20020a636b46000000b004051d974ce4si9296547pgc.458.2022.06.13.08.40.13; Mon, 13 Jun 2022 08:40:24 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z+obmfTL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351301AbiFMLDz (ORCPT + 99 others); Mon, 13 Jun 2022 07:03:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348209AbiFMKxt (ORCPT ); Mon, 13 Jun 2022 06:53:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE6272EA2D; Mon, 13 Jun 2022 03:27:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2EF8B60AEB; Mon, 13 Jun 2022 10:27:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40F5DC34114; Mon, 13 Jun 2022 10:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116061; bh=u1KKuXTSOS7VEj/FGapEtDlbpPzhB1wBn88enMYS2aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z+obmfTLG3Vb4mdHnPbOONTQMrVx9d0A9VRa/JfYzix6HYegQBTN7qmYQTn1eckEU qLuzc4ZP9dlea0iBaIZSvHOpyeHKJ7aBCmIATBNA5BPuzk6pelvYBRZ4qMpyIhkIrH PVB+6VDJcVgo5wHyUKZ7ZuwiX0vIGHgB0gJayy2M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Chris Chiu , Alan Stern , Kishon Vijay Abraham I Subject: [PATCH 5.4 005/411] usb: core: hcd: Add support for deferring roothub registration Date: Mon, 13 Jun 2022 12:04:38 +0200 Message-Id: <20220613094928.653186873@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Kishon Vijay Abraham I commit a44623d9279086c89f631201d993aa332f7c9e66 upstream. It has been observed with certain PCIe USB cards (like Inateck connected to AM64 EVM or J7200 EVM) that as soon as the primary roothub is registered, port status change is handled even before xHC is running leading to cold plug USB devices not detected. For such cases, registering both the root hubs along with the second HCD is required. Add support for deferring roothub registration in usb_add_hcd(), so that both primary and secondary roothubs are registered along with the second HCD. This patch has been added and reverted earier as it triggered a race in usb device enumeration. That race is now fixed in 5.16-rc3, and in stable back to 5.4 commit 6cca13de26ee ("usb: hub: Fix locking issues with address0_mutex") commit 6ae6dc22d2d1 ("usb: hub: Fix usb enumeration issue due to address0 race") CC: stable@vger.kernel.org # 5.4+ Suggested-by: Mathias Nyman Tested-by: Chris Chiu Acked-by: Alan Stern Signed-off-by: Kishon Vijay Abraham I Link: https://lore.kernel.org/r/20220510091630.16564-2-kishon@ti.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd.c | 29 +++++++++++++++++++++++------ include/linux/usb/hcd.h | 2 ++ 2 files changed, 25 insertions(+), 6 deletions(-) --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2657,6 +2657,7 @@ int usb_add_hcd(struct usb_hcd *hcd, { int retval; struct usb_device *rhdev; + struct usb_hcd *shared_hcd; if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); @@ -2813,13 +2814,26 @@ int usb_add_hcd(struct usb_hcd *hcd, goto err_hcd_driver_start; } + /* starting here, usbcore will pay attention to the shared HCD roothub */ + shared_hcd = hcd->shared_hcd; + if (!usb_hcd_is_primary_hcd(hcd) && shared_hcd && HCD_DEFER_RH_REGISTER(shared_hcd)) { + retval = register_root_hub(shared_hcd); + if (retval != 0) + goto err_register_root_hub; + + if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd)) + usb_hcd_poll_rh_status(shared_hcd); + } + /* starting here, usbcore will pay attention to this root hub */ - retval = register_root_hub(hcd); - if (retval != 0) - goto err_register_root_hub; + if (!HCD_DEFER_RH_REGISTER(hcd)) { + retval = register_root_hub(hcd); + if (retval != 0) + goto err_register_root_hub; - if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) - usb_hcd_poll_rh_status(hcd); + if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) + usb_hcd_poll_rh_status(hcd); + } return retval; @@ -2862,6 +2876,7 @@ EXPORT_SYMBOL_GPL(usb_add_hcd); void usb_remove_hcd(struct usb_hcd *hcd) { struct usb_device *rhdev = hcd->self.root_hub; + bool rh_registered; dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); @@ -2872,6 +2887,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); spin_lock_irq (&hcd_root_hub_lock); + rh_registered = hcd->rh_registered; hcd->rh_registered = 0; spin_unlock_irq (&hcd_root_hub_lock); @@ -2881,7 +2897,8 @@ void usb_remove_hcd(struct usb_hcd *hcd) cancel_work_sync(&hcd->died_work); mutex_lock(&usb_bus_idr_lock); - usb_disconnect(&rhdev); /* Sets rhdev to NULL */ + if (rh_registered) + usb_disconnect(&rhdev); /* Sets rhdev to NULL */ mutex_unlock(&usb_bus_idr_lock); /* --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -124,6 +124,7 @@ struct usb_hcd { #define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */ #define HCD_FLAG_DEAD 6 /* controller has died? */ #define HCD_FLAG_INTF_AUTHORIZED 7 /* authorize interfaces? */ +#define HCD_FLAG_DEFER_RH_REGISTER 8 /* Defer roothub registration */ /* The flags can be tested using these macros; they are likely to * be slightly faster than test_bit(). @@ -134,6 +135,7 @@ struct usb_hcd { #define HCD_WAKEUP_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_WAKEUP_PENDING)) #define HCD_RH_RUNNING(hcd) ((hcd)->flags & (1U << HCD_FLAG_RH_RUNNING)) #define HCD_DEAD(hcd) ((hcd)->flags & (1U << HCD_FLAG_DEAD)) +#define HCD_DEFER_RH_REGISTER(hcd) ((hcd)->flags & (1U << HCD_FLAG_DEFER_RH_REGISTER)) /* * Specifies if interfaces are authorized by default