Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3596616ioo; Wed, 25 May 2022 04:16:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykRtfeIPrtVsvsNlLCPoDzhpeTOoeAOsqkG6pldK+h3/ZkFKGPG8R1RmucFACOPLVZ//Cd X-Received: by 2002:a05:6402:40c4:b0:42b:5745:ca2 with SMTP id z4-20020a05640240c400b0042b57450ca2mr18859775edb.387.1653477365239; Wed, 25 May 2022 04:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653477365; cv=none; d=google.com; s=arc-20160816; b=NufqH0DuFB1DF+EiKPbhgKzcNvBvXHGpyfZTR+ku7T4Uft9Cwy/mCe7pT1KdY+cTQi 9wu2D4v9GrPRa/RZQi8zOouJH3LMOR/nD1Cx6r4VnkVkS+NULXkUKzpThrYFx1zV3Tm7 d4BSvQwW954UjvtEIdme9TqYboOUezNTsn7pLTNcIndh00S93ug73A4sQQ0DYzVqB246 VR8GaaCT8187YWoMWGfvzOv8ZDFDs094bvWz12vlTBFK1nBbpAax9OKEf38JkQFbX5dx 65E7ZQqs2iZdY+ctmQ9HNNxwtHiR8WMpLiMfznajUBkGGtwYTa9r6jLRThXUXnpA3Y5v 6zLQ== 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 :message-id:subject:cc:to:from:date:dkim-signature; bh=fXGqC55ZHjx5pR5Eq7TBqNj2R2xVYqFFffwF2ilcz0U=; b=YYI2j+d0Onl8kgnP784Wre8k6vpsh95b0jdN2Vh96cbiAT54UfYnghRIXqyYiUz891 wm0atPryw8wUpPk9kzFFqV9WvEVEOSiDEqVxpCTm0KDvFtCqzXm1B9eDDZcZJLaWGDTM P8b9VWNHB9MMhyQ3dSQG+ly2WzBXwAZOyJZlxiomD6ESLr8j02TOJYoMRkaitoGh1GIX owOmW5skxgP6xp8mfQto9YcMmIPIcKkfPkz/Qz8uK5EQr5s9cX1MXiC9s03vDg18AtWP 9YtP0AXe+FdmvDeDfq7qo8657NsAZqY5yIVtfoTc99rWW3iogJG/YxgI4sU/NDgVpk/J oFdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="qxov/uCE"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020aa7d643000000b0042abfb56b26si3827095edr.136.2022.05.25.04.15.37; Wed, 25 May 2022 04:16:05 -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=@kernel.org header.s=k20201202 header.b="qxov/uCE"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241809AbiEXU6w (ORCPT + 99 others); Tue, 24 May 2022 16:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241776AbiEXU6t (ORCPT ); Tue, 24 May 2022 16:58:49 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EA334AE2D; Tue, 24 May 2022 13:58:48 -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 sin.source.kernel.org (Postfix) with ESMTPS id 954D2CE1D57; Tue, 24 May 2022 20:58:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97DA6C34100; Tue, 24 May 2022 20:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653425925; bh=co8rmso/X/9KSryJdR6dHk17tc5T5WiA0FcvA4bAgWo=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=qxov/uCEnvuyYCwQB6yKH37c+PrG3ORg97DLE/3mRnqtSs68wwRDShxraD4nkZDqw GEpL/5SYaiSzFvdam6vNCn0EI9qAIOwDlSyf2Op4PwxznHdshGcNEuKD5FemBcT3sx qzZO8Ho4rnWPtv4STbswUgAkqFLr75SNrKEsPfwnLT++mqyAbrOThenAdUEOZaGu6l EqlegieAVBuyv94I8FuakXb2EuB0YgHwuJIrtwWE5JYDKklbxzB8bHbj7A3ims7SAk VMy/K3PQ4WG4icmqgOx9vqPzhIrUGmxkC8CFg/5EOmWqkq7xGpcStMq8V4YGElcFM/ lybtYoq5kHB/w== Date: Tue, 24 May 2022 15:58:42 -0500 From: Bjorn Helgaas To: Yicong Yang Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J . Wysocki" , Mika Westerberg , "Rafael J . Wysocki" Subject: Re: [RESEND PATCH v5] PCI: Make sure the bus bridge powered on when scanning bus Message-ID: <20220524205842.GA269611@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220517124319.47125-1-yangyicong@hisilicon.com> X-Spam-Status: No, score=-7.8 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 On Tue, May 17, 2022 at 08:43:19PM +0800, Yicong Yang wrote: > When the bus bridge is runtime suspended, we'll fail to rescan > the devices through sysfs as we cannot access the configuration > space correctly when the bridge is in D3hot. Is the "D3hot" above a typo? I think devices are supposed to respond to config accesses when in D3hot. PCIe r6.0, sec 5.3.1.4.1: Configuration and Message requests are the only TLPs accepted by a Function in the D3Hot state. ... Functions that are in D3Hot are permitted to be transitioned by software (writing to their PMCSR PowerState field) to the D0active state or the D0uninitialized state. Functions that are in D3Hot must respond to Configuration Space accesses as long as power and clock are supplied so that they can be returned to D0 by software. > It can be reproduced like: > > $ echo 1 > /sys/bus/pci/devices/0000:80:00.0/0000:81:00.1/remove > $ echo 1 > /sys/bus/pci/devices/0000:80:00.0/pci_bus/0000:81/rescan > > 0000:80:00.0 is a Root Port and it is runtime-suspended, so > 0000:81:00.1 is unreachable after a rescan. > > Power up the bridge when scanning the child bus and allow it to > suspend again by adding pm_runtime_get_sync()/pm_runtime_put() > in pci_scan_child_bus_extend(). > > Cc: Rafael J. Wysocki > Cc: Mika Westerberg > Cc: Bjorn Helgaas > Signed-off-by: Yicong Yang > Reviewed-by: Rafael J. Wysocki > --- > drivers/pci/probe.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c > index 17a969942d37..b108e72b6586 100644 > --- a/drivers/pci/probe.c > +++ b/drivers/pci/probe.c > @@ -2859,11 +2859,20 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, > unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0; > unsigned int start = bus->busn_res.start; > unsigned int devfn, fn, cmax, max = start; > + struct pci_dev *bridge = bus->self; > struct pci_dev *dev; > int nr_devs; > > dev_dbg(&bus->dev, "scanning bus\n"); > > + /* > + * Make sure the bus bridge is powered on, otherwise we may not be > + * able to scan the devices as we may fail to access the configuration > + * space of subordinates. > + */ > + if (bridge) > + pm_runtime_get_sync(&bridge->dev); > + > /* Go find them, Rover! */ > for (devfn = 0; devfn < 256; devfn += 8) { > nr_devs = pci_scan_slot(bus, devfn); > @@ -2976,6 +2985,9 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, > } > } > > + if (bridge) > + pm_runtime_put(&bridge->dev); > + > /* > * We've scanned the bus and so we know all about what's on > * the other side of any bridges that may be on this bus plus > -- > 2.24.0 >