Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] PCI: Improve devres documentation
@ 2026-12-01 12:29 Philipp Stanner
  2026-12-01 12:29 ` [PATCH 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-12-01 12:29 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner

Recent discussions and bugs [1, 2] related to my past PCI devres rework
have revealed that drivers have a hard time understanding the purpose of
the managed pcim_ API. This series deprecates the most confusing /
inconsistent functions and adds advice on which functions to use.

Based on master.

[1] https://lore.kernel.org/all/20261201-s2p-d60-v1-1-d88cf22132ab@mbzuai.ac.ae/
[2] https://lore.kernel.org/netdev/7ca512d133f7a3bcfe00e9b0b2af5fe5f147ad77.camel@mailbox.org/

(sorry for the resend, Bjorn. I messed up the PCI list when
copy-pasting)

Philipp Stanner (3):
  PCI: Deprecate public devres reversal functions
  PCI: Better document pcim_enable_device()
  PCI: Deprecate pcim_pin_device()

 drivers/pci/devres.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)


base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
-- 
2.56.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] PCI: Deprecate public devres reversal functions
  2026-12-01 12:29 [PATCH 0/3] PCI: Improve devres documentation Philipp Stanner
@ 2026-12-01 12:29 ` Philipp Stanner
  2026-12-01 12:40   ` sashiko-bot
  2026-12-01 12:29 ` [PATCH 2/3] PCI: Better document pcim_enable_device() Philipp Stanner
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Philipp Stanner @ 2026-12-01 12:29 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner

The PCI devres API has become a bit inconsistent. Devres is intended to
fully manage the device resources automatically, i.e., they get released
on driver unbind.

However, APIs were added to PCI devres that allow to revert another's
actions. For example, pcim_iomap() creates an automatically released
mapping, and yet pcim_iounmap() exists to *manually* release it.

This has confused users in the past. Some ended up freeing resources
with said interfaces manually in their remove() implementation, despite
the entire point being that exactly this is done automatically by
devres.

Nevertheless, sometimes users want or need manually resource management,
for example in suspend() and resume() paths. In these cases, they should
fully manage their resources manually.

Mark all manual release functions as deprecated and tell users what they
should do instead.

Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 drivers/pci/devres.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index f075e7881c3a..9a085fb18100 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -565,12 +565,16 @@ void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
 EXPORT_SYMBOL(pcim_iomap);
 
 /**
- * pcim_iounmap - Managed pci_iounmap()
+ * pcim_iounmap - Managed pci_iounmap() (DEPRECATED)
  * @pdev: PCI device to iounmap for
  * @addr: Address to unmap
  *
  * Managed pci_iounmap(). @addr must have been mapped using a pcim_* mapping
  * function.
+ *
+ * This function is deprecated (at least for external users). If you're ever in
+ * a position where it seems useful, you should manage your IO-mappings fully
+ * manually, e.g., with pci_iomap().
  */
 void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr)
 {
@@ -640,12 +644,16 @@ void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
 EXPORT_SYMBOL(pcim_iomap_region);
 
 /**
- * pcim_iounmap_region - Unmap and release a PCI BAR
+ * pcim_iounmap_region - Unmap and release a PCI BAR (DEPRECATED)
  * @pdev: PCI device to operate on
  * @bar: Index of BAR to unmap and release
  *
  * Unmap a BAR and release its region manually. Only pass BARs that were
  * previously mapped by pcim_iomap_region().
+ *
+ * This function is deprecated (at least for external users). If you're ever in
+ * a position where it seems useful, you should manage your regions fully
+ * manually, e.g., with pci_iomap_region().
  */
 void pcim_iounmap_region(struct pci_dev *pdev, int bar)
 {
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] PCI: Better document pcim_enable_device()
  2026-12-01 12:29 [PATCH 0/3] PCI: Improve devres documentation Philipp Stanner
  2026-12-01 12:29 ` [PATCH 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
@ 2026-12-01 12:29 ` Philipp Stanner
  2026-12-01 12:29 ` [PATCH 3/3] PCI: Deprecate pcim_pin_device() Philipp Stanner
  2026-12-01 12:40 ` [PATCH 0/3] PCI: Improve devres documentation sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-12-01 12:29 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner

pcim_enable_device() enables a PCI device and registers a devres action
which will automatically disable the device in remove(). Users should
only use it if they want to fully rely on automatic resource management.

Unfortunately, users often get the function's purpose wrong and
intermingle it with manual calls to pci_disable_device() et al.

Better document what pcim_enable_device() is intended for and when it
should be used.

Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 drivers/pci/devres.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index 9a085fb18100..afc7e966bb32 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -365,7 +365,11 @@ static void pcim_disable_device(void *pdev_raw)
  * Returns: 0 on success, negative error code on failure.
  *
  * Managed pci_enable_device(). Device will automatically be disabled on
- * driver detach.
+ * driver detach. You should only use this function in probe(), not in, e.g.,
+ * resume().
+ *
+ * If you need manual enabling and disabling, use pci_enable_device() paired
+ * with pci_disable_device(). Do not mix them with pcim_enable_device().
  */
 int pcim_enable_device(struct pci_dev *pdev)
 {
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] PCI: Deprecate pcim_pin_device()
  2026-12-01 12:29 [PATCH 0/3] PCI: Improve devres documentation Philipp Stanner
  2026-12-01 12:29 ` [PATCH 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
  2026-12-01 12:29 ` [PATCH 2/3] PCI: Better document pcim_enable_device() Philipp Stanner
@ 2026-12-01 12:29 ` Philipp Stanner
  2026-12-01 12:40 ` [PATCH 0/3] PCI: Improve devres documentation sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-12-01 12:29 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner

pcim_pin_device() reverts the action set up by pcim_enable_device(),
namely that the device gets disabled on driver unload.

This makes the PCI devres API inconsistent and confusing. Who does not
want automatic disablement of the device, should not use a function that
sets up automatic disablement. In other words, whoever needs
pcim_pin_device() just should use pci_enable_device() over
pcim_enable_device().

Mark pcim_pin_device() as deprecated.

Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 drivers/pci/devres.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index afc7e966bb32..b6e81ee72943 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -397,11 +397,15 @@ int pcim_enable_device(struct pci_dev *pdev)
 EXPORT_SYMBOL(pcim_enable_device);
 
 /**
- * pcim_pin_device - Pin managed PCI device
+ * pcim_pin_device - Pin managed PCI device (DEPRECATED)
  * @pdev: PCI device to pin
  *
  * Pin managed PCI device @pdev. Pinned device won't be disabled on driver
  * detach. @pdev must have been enabled with pcim_enable_device().
+ *
+ * This function is deprecated and should be removed. If you're ever in a
+ * position where it seems useful, you should manage your device enablement
+ * fully manually, with pci_enable_device() and pci_disable_device().
  */
 void pcim_pin_device(struct pci_dev *pdev)
 {
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] PCI: Deprecate public devres reversal functions
  2026-12-01 12:29 ` [PATCH 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
@ 2026-12-01 12:40   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-01 12:40 UTC (permalink / raw)
  To: Philipp Stanner; +Cc: linux-pci

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] PCI: pcim_iounmap_region() comment recommends nonexistent
  pci_iomap_region()
- [Low] PCI: pcim_iomap*() kernel-doc still recommends deprecated unmap
  helpers
--

commit eedf46bf67042e29b89e345ad6de41d2b256ef4c
Author: Philipp Stanner <phasta@kernel.org>

PCI: Deprecate public devres reversal functions

This commit marks the pcim_iounmap() and pcim_iounmap_region() manual
release functions as deprecated in their kernel-doc comments and directs
callers needing manual management to use unmanaged PCI helpers instead.

> diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
> index f075e7881c3a6..9a085fb18100a 100644
> --- a/drivers/pci/devres.c
> +++ b/drivers/pci/devres.c
> @@ -565,12 +565,16 @@ void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
>  EXPORT_SYMBOL(pcim_iomap);
>  
>  /**
> - * pcim_iounmap - Managed pci_iounmap()
> + * pcim_iounmap - Managed pci_iounmap() (DEPRECATED)
>   * @pdev: PCI device to iounmap for
>   * @addr: Address to unmap
>   *
>   * Managed pci_iounmap(). @addr must have been mapped using a pcim_* mapping
>   * function.
> + *
> + * This function is deprecated (at least for external users). If you're ever in
> + * a position where it seems useful, you should manage your IO-mappings fully
> + * manually, e.g., with pci_iomap().
>   */
>  void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr)
>  {

[Severity: Low]
Should the kernel-doc comments on pcim_iomap(), pcim_iomap_region(), and
pcim_iomap_range() also be updated now that pcim_iounmap() and
pcim_iounmap_region() are deprecated?  Those comments still tell callers
to manually unmap or release mappings using pcim_iounmap() and
pcim_iounmap_region().

> @@ -640,12 +644,16 @@ void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
>  EXPORT_SYMBOL(pcim_iomap_region);
>  
>  /**
> - * pcim_iounmap_region - Unmap and release a PCI BAR
> + * pcim_iounmap_region - Unmap and release a PCI BAR (DEPRECATED)
>   * @pdev: PCI device to operate on
>   * @bar: Index of BAR to unmap and release
>   *
>   * Unmap a BAR and release its region manually. Only pass BARs that were
>   * previously mapped by pcim_iomap_region().
> + *
> + * This function is deprecated (at least for external users). If you're ever in
> + * a position where it seems useful, you should manage your regions fully
> + * manually, e.g., with pci_iomap_region().
>   */
>  void pcim_iounmap_region(struct pci_dev *pdev, int bar)
>  {

[Severity: Low]
Should this comment recommend pci_request_region() and pci_iomap()
instead of pci_iomap_region()?  There is no unmanaged pci_iomap_region()
helper in the kernel.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201122951.904104-2-phasta@kernel.org?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] PCI: Improve devres documentation
  2026-12-01 12:29 [PATCH 0/3] PCI: Improve devres documentation Philipp Stanner
                   ` (2 preceding siblings ...)
  2026-12-01 12:29 ` [PATCH 3/3] PCI: Deprecate pcim_pin_device() Philipp Stanner
@ 2026-12-01 12:40 ` sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-01 12:40 UTC (permalink / raw)
  To: Philipp Stanner; +Cc: linux-pci

Sashiko has finished reviewing this 3-patch series:

- Patches 2 and 3: no issues found.
- Patch 1 ("PCI: Deprecate public devres reversal functions"): 2
  potential issues (2 Low)

A detailed review has been sent as a separate reply to patch 1.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201122951.904104-2-phasta@kernel.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-01 12:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 12:29 [PATCH 0/3] PCI: Improve devres documentation Philipp Stanner
2026-12-01 12:29 ` [PATCH 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
2026-12-01 12:40   ` sashiko-bot
2026-12-01 12:29 ` [PATCH 2/3] PCI: Better document pcim_enable_device() Philipp Stanner
2026-12-01 12:29 ` [PATCH 3/3] PCI: Deprecate pcim_pin_device() Philipp Stanner
2026-12-01 12:40 ` [PATCH 0/3] PCI: Improve devres documentation sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox