Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp390591rwd; Wed, 7 Jun 2023 01:05:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ520LovYuYb7TpXQZsT+8qpfkfe2M3FIW6AyOOZe10+GQD17OT7UD348St9Lef/24gvdbLt X-Received: by 2002:a17:902:dac4:b0:1b0:62e2:1f84 with SMTP id q4-20020a170902dac400b001b062e21f84mr17840037plx.5.1686125156346; Wed, 07 Jun 2023 01:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686125156; cv=none; d=google.com; s=arc-20160816; b=eYmm95/QIVRgThqcwZl9DI4pV9rZEMz1BVQWL9c7+VD4EfJR8b+4oqLEMWyUZgJKiK N8E6SAv+up5FBrXIQWlwBE9GjXwBw/5+CBH3XKps0o6AlGS5fpA1GxxYHrnCyQdx3SAD ttzywpFAitRHps3IuY4k2Yal97KqHNHhmSwR2cCtl5rMeG+FzyY4Ty1ZsUi3uWRf9o0E JodZYxCnDeZLnEO9BDo5bXiIZolMxcLBJb51lIYO9mPcQ4YFSL16Uc4n0vi7SHzwNjzE YcyROgwT7SDvcvr/huzuN5cPunG6AjMa6ZCV+kVyRZySnFy2A7Fw5w+IpdBxBGbCBWRy hFAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=axps5vikobkT1mRFE9fglAhCSO+MMypFTxN72eeUtO0=; b=rwCff9rnAAY7wlGLKM9dvP0J/k20ZqadoOuXkrddtzT/1AhLM2K9eWG27ZGud8nlbl ZPs1dSX5Ocim/UeR5uTD+yncLyEWPSlaCGyseQaF4xK+89w2hh7/icuEt4W2yOORC05B PKdSZgUQXACc/orDkyUiRNwCSMFuKw9V5YtbtdV3tukgIZ9P5bT/VFEOlNbjPKkTiBrr 2RHTsqAGGWg7j3VQ0U1O6BsxvixvRioTeqIDvnRhqSjd0RS6GjqF6jzWeoSTURKktDIB PmeMtloiUU5LgaeqNgzINeNwBDOjxGxxQcs3cDsEWZi/FJtw97aE4e8VmF+MNNZpEWed U3Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=kMfyNLOf; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a170902e5c400b001afc438f915si8617281plf.626.2023.06.07.01.05.12; Wed, 07 Jun 2023 01:05:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=@sipsolutions.net header.s=mail header.b=kMfyNLOf; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238041AbjFGH63 (ORCPT + 61 others); Wed, 7 Jun 2023 03:58:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237934AbjFGH61 (ORCPT ); Wed, 7 Jun 2023 03:58:27 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48C8C8E; Wed, 7 Jun 2023 00:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=MIME-Version:Content-Transfer-Encoding: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=axps5vikobkT1mRFE9fglAhCSO+MMypFTxN72eeUtO0=; t=1686124705; x=1687334305; b=kMfyNLOfrR5GeXbEHt9nEXTdQvySSOfXW53hCo+aMiOCKFZ VjaTOmJclP54w5xMxgHhnKHy6ts2JJewj1niaIPBQ8SOsMuDz8mbFEMpgeBciSkaI2sT1FploU07s y398ttaaB2g1e8t0THF45Y05YWT4icEApqNyb7P9i2xcbEa2geG6Ub1ZuwtLiQ1hQZB5aDgp+lqab oujC9r3HMmF9HviLoM6bB9XDBgRFFkes0+9c2LuFWqkPYsUOY/MdpxwjmBJyv29ikkAyd4KTIXL/m nlWw1iby6ECx8WfgFsOv8G/zBljBBagagaXrRSXpkSbv9mjrWHElYcSYIrr/JhUA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1q6o3i-00GSjD-27; Wed, 07 Jun 2023 09:58:22 +0200 Message-ID: Subject: Re: [PATCH v2] PCI/PM: enable runtime PM later during device scanning From: Johannes Berg To: Lukas Wunner Cc: linux-wireless@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org, Bjorn Helgaas Date: Wed, 07 Jun 2023 09:58:21 +0200 In-Reply-To: <20230607074939.GA17700@wunner.de> References: <20230605121621.4259f1be6cd2.Idbaa55b93f780838af44ebccb84c36f60716df04@changeid> <20230605203519.bc4232207449.Idbaa55b93f780838af44ebccb84c36f60716df04@changeid> <20230607074939.GA17700@wunner.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.2 (3.48.2-1.fc38) MIME-Version: 1.0 X-malware-bazaar: not-scanned X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-wireless@vger.kernel.org On Wed, 2023-06-07 at 09:49 +0200, Lukas Wunner wrote: > On Mon, Jun 05, 2023 at 08:35:45PM +0200, Johannes Berg wrote: > > @@ -3139,6 +3139,7 @@ void pci_pm_init(struct pci_dev *dev) > > u16 pmc; > > =20 > > pm_runtime_forbid(&dev->dev); > > + pm_runtime_get_noresume(&dev->dev); > > pm_runtime_set_active(&dev->dev); > > pm_runtime_enable(&dev->dev); > > device_enable_async_suspend(&dev->dev); > > @@ -335,9 +336,12 @@ void pci_bus_add_device(struct pci_dev *dev) > > int retval; > > =20 > > /* > > - * Can not put in pci_device_add yet because resources > > - * are not assigned yet for some devices. > > + * Allow runtime PM only here, since otherwise we may > > + * try to suspend a device that isn't fully configured > > + * yet, which causes problems. > > */ > > + pm_runtime_put_noidle(&dev->dev); > > + > > pcibios_bus_add_device(dev); > > pci_fixup_device(pci_fixup_final, dev); > > pci_create_sysfs_dev_files(dev); >=20 > There seem to be many different callers that end up in pci_pm_init() > and pci_bus_add_device(). >=20 > Is it guaranteed that the two functions are always called in order? > Do callers exist which only invoke the former but not the latter or > vice-versa? Can it happen that a caller of the former errors out, > so the latter is never called, leading to a runtime PM ref imbalance? I did ask myself that too, and honestly, I'm not entirely sure - need somebody more familiar to really understand that, I think. Most places elsewhere _do_ call both, and it feels like you have to call both if you want to do something with the device. However there are a few places that seem to call the first part and then remove the device again immediately after. That also seems harmless though. > It would be easier to ascertain correctness if you could find a > function at a higher level which (indirectly) calls both pci_pm_init() > and pci_bus_add_device() so that you can acquire and release the > runtimw PM ref in that single function. >=20 Unfortunately, there isn't such a place, since the scanning is done by various bus walks. johannes