Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: manivannan.sadhasivam@linaro.org
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Brian Norris <briannorris@chromium.org>,
	Hsin-Yi Wang <hsinyi@chromium.org>, Lizhi Hou <lizhi.hou@amd.com>
Subject: Re: [PATCH v3 2/5] PCI/pwrctrl: Move pci_pwrctrl_unregister() to pci_destroy_dev()
Date: Sun, 13 Apr 2025 23:08:31 +0200	[thread overview]
Message-ID: <Z_wnz1SyIWjnhJJt@wunner.de> (raw)
In-Reply-To: <20250116-pci-pwrctrl-slot-v3-2-827473c8fbf4@linaro.org>

On Thu, Jan 16, 2025 at 07:39:12PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> PCI core will try to access the devices even after pci_stop_dev() for
> things like Data Object Exchange (DOE), ASPM etc... So move
> pci_pwrctrl_unregister() to the near end of pci_destroy_dev() to make sure
> that the devices are powered down only after the PCI core is done with
> them.
[...]
> --- a/drivers/pci/remove.c
> +++ b/drivers/pci/remove.c
> @@ -41,7 +41,6 @@ static void pci_stop_dev(struct pci_dev *dev)
>  	if (!pci_dev_test_and_clear_added(dev))
>  		return;
>  
> -	pci_pwrctrl_unregister(&dev->dev);
>  	device_release_driver(&dev->dev);
>  	pci_proc_detach_device(dev);
>  	pci_remove_sysfs_dev_files(dev);
> @@ -64,6 +63,7 @@ static void pci_destroy_dev(struct pci_dev *dev)
>  	pci_doe_destroy(dev);
>  	pcie_aspm_exit_link_state(dev);
>  	pci_bridge_d3_update(dev);
> +	pci_pwrctrl_unregister(&dev->dev);
>  	pci_free_resources(dev);
>  	put_device(&dev->dev);
>  }

The above is now commit 2d923930f2e3 ("PCI/pwrctrl: Move
pci_pwrctrl_unregister() to pci_destroy_dev()"), which went
into v6.15-rc1.

While inspecting the code for an unrelated issue, I noticed a
potential ordering problem here:

Prior to 2d923930f2e3, pci_pwrctrl_unregister() was called before
of_pci_remove_node().  The order is reversed now.

So if the of_node of a PCI device was created dynamically (note the
OF_DYNAMIC check in of_pci_remove_node()), the of_node may now be
destroyed and pdev->dev.of_node may be set to NULL.

Afterwards pci_pwrctrl_unregister() bails out for lack of an of_node.

It's a change of behavior vis-à-vis what the code did prior to
2d923930f2e3.

I don't have a board using a power controller for a PCI device,
so I'm not really sure if this is an issue in practice and if so,
how it should be solved.  One obvious solution would be to move the
invocation of of_pci_remove_node() to pci_destroy_dev(), after the
invocation of pci_pwrctrl_unregister().

However I'm confused that of_pci_remove_node() is currently gated by
the PCI_DEV_ADDED flag.  Well I guess the reason is that the counterpart,
of_pci_make_dev_node(), is gated by the flag as well.  But why?
And why is the latter additionally gated by pci_is_bridge() but the
former is not?

Thanks,

Lukas

  reply	other threads:[~2025-04-13 21:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16 14:09 [PATCH v3 0/5] PCI/pwrctrl: Rework pwrctrl driver integration and add driver for PCI slot Manivannan Sadhasivam via B4 Relay
2025-01-16 14:09 ` [PATCH v3 1/5] PCI/pwrctrl: Move creation of pwrctrl devices to pci_scan_device() Manivannan Sadhasivam via B4 Relay
2025-01-16 14:09 ` [PATCH v3 2/5] PCI/pwrctrl: Move pci_pwrctrl_unregister() to pci_destroy_dev() Manivannan Sadhasivam via B4 Relay
2025-04-13 21:08   ` Lukas Wunner [this message]
2025-01-16 14:09 ` [PATCH v3 3/5] PCI/pwrctrl: Skip scanning for the device further if pwrctrl device is created Manivannan Sadhasivam via B4 Relay
2025-02-20 23:24   ` Bjorn Helgaas
2025-02-21 17:38     ` Manivannan Sadhasivam
2025-02-20 23:35   ` Bjorn Helgaas
2025-02-21 17:40     ` Manivannan Sadhasivam
2025-03-21  2:59   ` Wei Fang
2025-03-21  4:42     ` Manivannan Sadhasivam
2025-03-21  7:04       ` Wei Fang
2025-03-22  3:23         ` Manivannan Sadhasivam
2025-03-22 11:39           ` Wei Fang
2025-03-24  8:15             ` Manivannan Sadhasivam
2025-03-27  6:02               ` Wei Fang
2025-04-02  8:14                 ` Manivannan Sadhasivam
2025-01-16 14:09 ` [PATCH v3 4/5] dt-bindings: vendor-prefixes: Document the 'pciclass' prefix Manivannan Sadhasivam via B4 Relay
2025-01-16 14:09 ` [PATCH v3 5/5] PCI/pwrctrl: Add pwrctrl driver for PCI Slots Manivannan Sadhasivam via B4 Relay
2025-02-20 14:24 ` [PATCH v3 0/5] PCI/pwrctrl: Rework pwrctrl driver integration and add driver for PCI slot Krzysztof Wilczyński

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=Z_wnz1SyIWjnhJJt@wunner.de \
    --to=lukas@wunner.de \
    --cc=bhelgaas@google.com \
    --cc=brgl@bgdev.pl \
    --cc=briannorris@chromium.org \
    --cc=hsinyi@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=manivannan.sadhasivam@linaro.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