[PATCH 00/11] PCI: pci_resource_alignment() improvement + cleanups

Ilpo Järvinen posted 11 patches 1 month, 2 weeks ago
arch/powerpc/include/asm/machdep.h         |  2 +-
arch/powerpc/kernel/pci-common.c           |  2 +-
arch/powerpc/platforms/powernv/pci-sriov.c |  4 +-
arch/powerpc/platforms/powernv/pci.h       |  5 ++-
arch/powerpc/platforms/pseries/setup.c     |  5 ++-
drivers/pci/iov.c                          |  7 +--
drivers/pci/pci.h                          | 24 ++++-------
drivers/pci/setup-bus.c                    | 50 ++++++++++++----------
drivers/pci/setup-cardbus.c                |  2 +-
drivers/pci/setup-res.c                    | 37 ++++++++++++++++
include/linux/ioport.h                     |  2 +-
include/linux/pci.h                        |  8 ++--
kernel/resource.c                          |  2 +-
13 files changed, 94 insertions(+), 56 deletions(-)
[PATCH 00/11] PCI: pci_resource_alignment() improvement + cleanups
Posted by Ilpo Järvinen 1 month, 2 weeks ago
pci_resource_alignment() returns 0 when resource is already assigned
and in case of disabled bridge windows. This has caused problems to
calculations relying on pci_resource_alignment():

https://lore.kernel.org/linux-pci/LV8P221MB1472A24B9975F7C8E8D6BF929947A@LV8P221MB1472.NAMP221.PROD.OUTLOOK.COM/

This series reworks pci_resource_alignment() interface to return always
non-zero alignment if the resource exists. For assigned bridge windows,
the calculation is using heuristic based on size and start address
alignment as calculating the alignment again is costly (would require
sizing the entire sub-hierarchy).

As pci_resource_alignment() is becoming more complicated, it's also
moved to setup-res.c. While moving pci_resource_alignment()'s arguments
are converted into const to tell compiler it can rely on resource
remaining the same across the call.

This was intended to be part of a larger series that addresses some
shortcomings in pci=realloc. The pci=realloc changes will recalculate
bridge window sizes considering also assigned resources which required
making these changes to pci_resource_alignment().

As this also relates to the issue linked above, I'm sending it already
now without pci=realloc changes that are still incomplete. The first
patches originate from the large pci=realloc work but seem generally
useful even if independent of the alignment improvements so I've
included them here without reorganizing the series to contain only
alignment related changes.

Ilpo Järvinen (11):
  PCI: Log all resource claims
  PCI: Rename added to add_list
  PCI: Consolidate add_list (aka realloc_head) empty sanity checks
  PCI: Remove const removal cast
  resource: Make resource_alignment() input const resource
  powerpc/pseries: Make pseries_get_iov_fw_value() & pnv_iov_get()
    pci_dev const
  PCI: Make pci_sriov_resource_alignment() pci_dev const
  PCI: Convert pci_resource_alignment() input parameters to const
  PCI: Move pci_resource_alignment() to setup-res.c file
  PCI: Lower bound bridge windown alignment
  PCI: Return valid alignment for assigned resources

 arch/powerpc/include/asm/machdep.h         |  2 +-
 arch/powerpc/kernel/pci-common.c           |  2 +-
 arch/powerpc/platforms/powernv/pci-sriov.c |  4 +-
 arch/powerpc/platforms/powernv/pci.h       |  5 ++-
 arch/powerpc/platforms/pseries/setup.c     |  5 ++-
 drivers/pci/iov.c                          |  7 +--
 drivers/pci/pci.h                          | 24 ++++-------
 drivers/pci/setup-bus.c                    | 50 ++++++++++++----------
 drivers/pci/setup-cardbus.c                |  2 +-
 drivers/pci/setup-res.c                    | 37 ++++++++++++++++
 include/linux/ioport.h                     |  2 +-
 include/linux/pci.h                        |  8 ++--
 kernel/resource.c                          |  2 +-
 13 files changed, 94 insertions(+), 56 deletions(-)


base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
-- 
2.39.5

Re: [PATCH 00/11] PCI: pci_resource_alignment() improvement + cleanups
Posted by Bjorn Helgaas 1 month, 1 week ago
On Wed, Apr 29, 2026 at 03:26:06PM +0300, Ilpo Järvinen wrote:
> pci_resource_alignment() returns 0 when resource is already assigned
> and in case of disabled bridge windows. This has caused problems to
> calculations relying on pci_resource_alignment():
> 
> https://lore.kernel.org/linux-pci/LV8P221MB1472A24B9975F7C8E8D6BF929947A@LV8P221MB1472.NAMP221.PROD.OUTLOOK.COM/
> 
> This series reworks pci_resource_alignment() interface to return always
> non-zero alignment if the resource exists. For assigned bridge windows,
> the calculation is using heuristic based on size and start address
> alignment as calculating the alignment again is costly (would require
> sizing the entire sub-hierarchy).
> 
> As pci_resource_alignment() is becoming more complicated, it's also
> moved to setup-res.c. While moving pci_resource_alignment()'s arguments
> are converted into const to tell compiler it can rely on resource
> remaining the same across the call.
> 
> This was intended to be part of a larger series that addresses some
> shortcomings in pci=realloc. The pci=realloc changes will recalculate
> bridge window sizes considering also assigned resources which required
> making these changes to pci_resource_alignment().
> 
> As this also relates to the issue linked above, I'm sending it already
> now without pci=realloc changes that are still incomplete. The first
> patches originate from the large pci=realloc work but seem generally
> useful even if independent of the alignment improvements so I've
> included them here without reorganizing the series to contain only
> alignment related changes.
> 
> Ilpo Järvinen (11):
>   PCI: Log all resource claims
>   PCI: Rename added to add_list
>   PCI: Consolidate add_list (aka realloc_head) empty sanity checks
>   PCI: Remove const removal cast
>   resource: Make resource_alignment() input const resource
>   powerpc/pseries: Make pseries_get_iov_fw_value() & pnv_iov_get()
>     pci_dev const
>   PCI: Make pci_sriov_resource_alignment() pci_dev const
>   PCI: Convert pci_resource_alignment() input parameters to const
>   PCI: Move pci_resource_alignment() to setup-res.c file
>   PCI: Lower bound bridge windown alignment
>   PCI: Return valid alignment for assigned resources
> 
>  arch/powerpc/include/asm/machdep.h         |  2 +-
>  arch/powerpc/kernel/pci-common.c           |  2 +-
>  arch/powerpc/platforms/powernv/pci-sriov.c |  4 +-
>  arch/powerpc/platforms/powernv/pci.h       |  5 ++-
>  arch/powerpc/platforms/pseries/setup.c     |  5 ++-
>  drivers/pci/iov.c                          |  7 +--
>  drivers/pci/pci.h                          | 24 ++++-------
>  drivers/pci/setup-bus.c                    | 50 ++++++++++++----------
>  drivers/pci/setup-cardbus.c                |  2 +-
>  drivers/pci/setup-res.c                    | 37 ++++++++++++++++
>  include/linux/ioport.h                     |  2 +-
>  include/linux/pci.h                        |  8 ++--
>  kernel/resource.c                          |  2 +-
>  13 files changed, 94 insertions(+), 56 deletions(-)

Applied to pci/resource for v7.2, thanks!

Powerpc folks, the arch/powerpc changes here are minor (just adding
const), but heads up in case you see any issue.