Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1650627ioo; Sun, 22 May 2022 23:02:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5wu07vjVc2LjNUcd3CDRxZduLIzSHFMpZQcDbJNLpqJb//6mr1MoLZJzCAXNqWGj8AMr8 X-Received: by 2002:a63:df53:0:b0:3f5:f0a4:d7e2 with SMTP id h19-20020a63df53000000b003f5f0a4d7e2mr19083790pgj.313.1653285747562; Sun, 22 May 2022 23:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653285747; cv=none; d=google.com; s=arc-20160816; b=IVhKxaAUjmc/l+ZklMRcqT5CooQ5tAjVmxfX1aR0dUTPJPcuQ+r5Td+GYFWpT0mFdt U4gqLEvwdJylkbsmEr6tguyhuv4PB2v6qAo4za2PWeSSzvaMMNYPp9aJrDDSHq1Nyfak kSuZ/Pbva85GZkeKmve2di6sv73AhgasiMoBCYJup1wTsP3r+hdllErEEsVXvVG+6Hoa gjtf467jVqszI8MaHFSr35tuPiumtIattSuxrrINchXju6B2eyIGrOJZOClFsxcdtL3Y pAgyCNylzAhlFCRPOXr01xCOR+iBku9OQvEEOK0OTLbXOe4LvkgpA7sk4tPU55Nl5NbA p2FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ELzg/MFmWyGU27E2R7eMgZHjaWwGy4nChFDuRz9PKFY=; b=EIc+FDcdmKigeuBl5fQYsh8IwRS/sc5ve8Wm/lwLtay/joa6yKdPEOM4Uae25WV2PZ 3MR+q610lY5ua3OrWV+bdbAgl7n914uDOfQGb3h40zr7ou7hok+LV5lljLlTtdKDmPEi dDaVD4+45j14Wps9mMfLORE6KAduxwyCSVEGkeKUPiZVE9AFduTeDUOIh+BVaZyoeWjS BpKvAUeBVJV4ElXuk4GeSUyvKQYle0+XPAluLx+vNXYQJeg2MwSpGbFuis0I3KF4gMFh /Yt4Wa77pqyQTmTGLqJeDpqnsqKyyQQYT7kc8b5Azfx8Hmd/h/pFiAjJJk4a2M71dCme mO0g== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k3-20020a17090aaa0300b001cb8365e641si4288418pjq.52.2022.05.22.23.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 23:02:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9D67036B53; Sun, 22 May 2022 22:55:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345930AbiETGmB (ORCPT + 99 others); Fri, 20 May 2022 02:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235792AbiETGly (ORCPT ); Fri, 20 May 2022 02:41:54 -0400 Received: from bmailout3.hostsharing.net (bmailout3.hostsharing.net [IPv6:2a01:4f8:150:2161:1:b009:f23e:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B111C6D948 for ; Thu, 19 May 2022 23:41:53 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS DV RSA Mixed SHA256 2020 CA-1" (verified OK)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id A9EF8100E416C; Fri, 20 May 2022 08:41:48 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 8C1B0127487; Fri, 20 May 2022 08:41:48 +0200 (CEST) Date: Fri, 20 May 2022 08:41:48 +0200 From: Lukas Wunner To: Sheng Bi Cc: helgaas@kernel.org, alex.williamson@redhat.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] PCI: Fix no-op wait after secondary bus reset Message-ID: <20220520064148.GA20418@wunner.de> References: <20220516165740.6256af51.alex.williamson@redhat.com> <20220518115432.76183-1-windy.bi.enflame@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220518115432.76183-1-windy.bi.enflame@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 Wed, May 18, 2022 at 07:54:32PM +0800, Sheng Bi wrote: > +static int pci_bridge_secondary_bus_wait(struct pci_dev *bridge, int timeout) > +{ > + struct pci_dev *dev; > + int delay = 0; > + > + if (!bridge->subordinate || list_empty(&bridge->subordinate->devices)) > + return 0; > + > + list_for_each_entry(dev, &bridge->subordinate->devices, bus_list) { > + while (!pci_device_is_present(dev)) { > + if (delay > timeout) { > + pci_warn(dev, "not ready %dms after secondary bus reset; giving up\n", > + delay); > + return -ENOTTY; > + } > + > + msleep(20); > + delay += 20; > + } > + > + if (delay > 1000) > + pci_info(dev, "ready %dms after secondary bus reset\n", > + delay); > + } > + > + return 0; > +} An alternative approach you may want to consider is to call pci_dev_wait() in the list_for_each_entry loop, but instead of passing it a constant timeout you'd pass the remaining time. Get the current time before and after each pci_dev_wait() call from "jiffies", calculate the difference, convert to msecs with jiffies_to_msecs() and subtract from the "timeout" parameter passed in by the caller, then simply pass "timeout" to each pci_dev_wait() call. As a side note, traversing the bus list normally requires holding the pci_bus_sem for reading. But it's probably unlikely that devices are added/removed concurrently to a bus reset and we're doing it wrong pretty much everywhere in the PCI reset code, so... (I fixed up one of the reset functions with 10791141a6cf, but plenty of others remain...) Thanks, Lukas