linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Lukas Wunner <lukas@wunner.de>
Cc: linux-wireless@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-pm@vger.kernel.org, rafael@kernel.org,
	Bjorn Helgaas <bhelgaas@google.com>
Subject: Re: [PATCH v2] PCI/PM: enable runtime PM later during device scanning
Date: Wed, 07 Jun 2023 09:58:21 +0200	[thread overview]
Message-ID: <c2b6599182b2f543da2d5fee17dce4b3a094535a.camel@sipsolutions.net> (raw)
In-Reply-To: <20230607074939.GA17700@wunner.de>

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;
> >  
> >  	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;
> >  
> >  	/*
> > -	 * 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);
> 
> There seem to be many different callers that end up in pci_pm_init()
> and pci_bus_add_device().
> 
> 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.
> 

Unfortunately, there isn't such a place, since the scanning is done by
various bus walks.

johannes

      reply	other threads:[~2023-06-07  7:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230605121621.4259f1be6cd2.Idbaa55b93f780838af44ebccb84c36f60716df04@changeid>
2023-06-05 18:35 ` [PATCH v2] PCI/PM: enable runtime PM later during device scanning Johannes Berg
2023-06-05 20:50   ` Lukas Wunner
2023-06-06  7:22     ` Johannes Berg
2023-06-07  7:49   ` Lukas Wunner
2023-06-07  7:58     ` Johannes Berg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c2b6599182b2f543da2d5fee17dce4b3a094535a.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).