Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/3] PCI: Improve devres documentation
@ 2026-12-03 12:53 Philipp Stanner
  2026-12-03 12:53 ` [PATCH v2 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-03 12:53 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Philipp Stanner

Changes in v2:
  - Remove mention of forgotten / non-existent functions.
  - Improve commit messages

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/

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

 drivers/pci/devres.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

-- 
2.56.0


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

* [PATCH v2 1/3] PCI: Deprecate public devres reversal functions
  2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
@ 2026-12-03 12:53 ` Philipp Stanner
  2026-12-03 13:11   ` sashiko-bot
  2026-12-03 12:53 ` [PATCH v2 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-03 12:53 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 manual 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 | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index f075e7881c3a..48451581516a 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -522,8 +522,7 @@ static void pcim_remove_bar_from_legacy_table(struct pci_dev *pdev, int bar)
  *
  * Returns: __iomem pointer on success, NULL on failure.
  *
- * Managed pci_iomap(). Map is automatically unmapped on driver detach. If
- * desired, unmap manually only with pcim_iounmap().
+ * Managed pci_iomap(). Map is automatically unmapped on driver detach.
  *
  * This SHOULD only be used once per BAR.
  *
@@ -565,12 +564,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 +643,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 with unmanaged pci_ interfaces.
  */
 void pcim_iounmap_region(struct pci_dev *pdev, int bar)
 {
@@ -825,8 +832,7 @@ EXPORT_SYMBOL(pcim_request_all_regions);
  * Creates a new IO-Mapping within the specified @bar, ranging from @offset to
  * @offset + @len.
  *
- * The mapping will automatically get unmapped on driver detach. If desired,
- * release manually only with pcim_iounmap().
+ * The mapping will automatically get unmapped on driver detach.
  */
 void __iomem *pcim_iomap_range(struct pci_dev *pdev, int bar,
 		unsigned long offset, unsigned long len)
-- 
2.56.0


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

* [PATCH v2 2/3] PCI: Better document pcim_enable_device()
  2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
  2026-12-03 12:53 ` [PATCH v2 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
@ 2026-12-03 12:53 ` Philipp Stanner
  2026-12-03 12:53 ` [PATCH v2 3/3] PCI: Deprecate pcim_pin_device() Philipp Stanner
  2026-12-03 13:11 ` [PATCH v2 0/3] PCI: Improve devres documentation sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-12-03 12:53 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 on driver detach. 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 48451581516a..3e49017bb717 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 v2 3/3] PCI: Deprecate pcim_pin_device()
  2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
  2026-12-03 12:53 ` [PATCH v2 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
  2026-12-03 12:53 ` [PATCH v2 2/3] PCI: Better document pcim_enable_device() Philipp Stanner
@ 2026-12-03 12:53 ` Philipp Stanner
  2026-12-03 13:11 ` [PATCH v2 0/3] PCI: Improve devres documentation sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: Philipp Stanner @ 2026-12-03 12:53 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 3e49017bb717..a96fa984b315 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 v2 1/3] PCI: Deprecate public devres reversal functions
  2026-12-03 12:53 ` [PATCH v2 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
@ 2026-12-03 13:11   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-03 13:11 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_iomap_region() kernel-doc still recommends deprecated
  unmap helper
- [Low] PCI: unescaped trailing underscore in pci_ breaks Sphinx
  kernel-doc build
--

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

PCI: Deprecate public devres reversal functions

This commit marks pcim_iounmap() and pcim_iounmap_region() as deprecated
in their kernel-doc comments and removes manual-release instructions from
pcim_iomap() and pcim_iomap_range().

> diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
> index f075e7881c3a6..48451581516a1 100644
> --- a/drivers/pci/devres.c
> +++ b/drivers/pci/devres.c

[ ... ]

> @@ -640,12 +643,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)

[Severity: Low]
Should the kernel-doc for pcim_iomap_region() right above this also be
updated?  It still advises releasing manually with pcim_iounmap_region(),
which contradicts this deprecation notice in the generated documentation
from Documentation/driver-api/pci/pci.rst.

>   * @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 with unmanaged pci_ interfaces.

[Severity: Low]
Does the trailing underscore in "pci_" break the Sphinx kernel-doc build?

Documentation/driver-api/pci/pci.rst includes exported kernel-doc from
drivers/pci/devres.c, and reStructuredText parses a bare word ending in
an underscore as a hyperlink reference, failing with an unknown target
name error for "pci".  Writing "pci_*" avoids the error.

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

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

* Re: [PATCH v2 0/3] PCI: Improve devres documentation
  2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
                   ` (2 preceding siblings ...)
  2026-12-03 12:53 ` [PATCH v2 3/3] PCI: Deprecate pcim_pin_device() Philipp Stanner
@ 2026-12-03 13:11 ` sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-03 13:11 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/20261203125328.2421736-3-phasta@kernel.org

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

end of thread, other threads:[~2026-12-03 13:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 12:53 [PATCH v2 0/3] PCI: Improve devres documentation Philipp Stanner
2026-12-03 12:53 ` [PATCH v2 1/3] PCI: Deprecate public devres reversal functions Philipp Stanner
2026-12-03 13:11   ` sashiko-bot
2026-12-03 12:53 ` [PATCH v2 2/3] PCI: Better document pcim_enable_device() Philipp Stanner
2026-12-03 12:53 ` [PATCH v2 3/3] PCI: Deprecate pcim_pin_device() Philipp Stanner
2026-12-03 13:11 ` [PATCH v2 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