[PATCH 09/10] PCI: Align head space better

Ilpo Järvinen ilpo.jarvinen at linux.intel.com
Wed Mar 25 23:04:03 AEDT 2026


On Tue, 24 Mar 2026, Ilpo Järvinen wrote:

> When a bridge window contains big and small resource(s), the small
> resource(s) may not amount to the half of the size of the big resource
> which would allow calculate_head_align() to shrink the head alignment.
> This results in always placing the small resource(s) after the big
> resource.
> 
> In general, it would be good to be able to place the small resource(s)
> before the big resource to achieve better utilization of the address
> space. In the cases where the large resource can only fit at the end
> of the window, it is even required.
> 
> However, carrying the information over from pbus_size_mem() and
> calculate_head_align() to __pci_assign_resource() and
> pcibios_align_resource() is not easy with the current data structures.
> 
> A somewhat hacky way to move the non-aligning tail part to the head is
> possible within pcibios_align_resource(). The free space between the
> start of the free space span and the aligned start address can be
> compared with the non-aligning remainder of the size. If the free space
> is larger than the remainder, placing the remainder before the start
> address is possible. This relocation should generally work, because PCI
> resources consist only power-of-2 atoms.
> 
> Various arch requirements may still need to override the relocation, so
> the relocation is only applied selectively in such cases.
> 
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221205
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen at linux.intel.com>
> ---
>  arch/arm/kernel/bios32.c         |  3 +++
>  arch/m68k/kernel/pcibios.c       |  4 ++++
>  arch/mips/pci/pci-generic.c      |  3 +++
>  arch/mips/pci/pci-legacy.c       |  2 ++
>  arch/parisc/kernel/pci.c         |  3 +++
>  arch/powerpc/kernel/pci-common.c |  2 ++
>  arch/sh/drivers/pci/pci.c        |  2 ++
>  arch/x86/pci/i386.c              |  2 ++
>  arch/xtensa/kernel/pci.c         |  2 ++
>  drivers/pci/setup-res.c          | 39 +++++++++++++++++++++++++++++++-
>  include/linux/pci.h              |  5 ++++
>  kernel/resource.c                |  2 +-
>  12 files changed, 67 insertions(+), 2 deletions(-)

> diff --git a/arch/sh/drivers/pci/pci.c b/arch/sh/drivers/pci/pci.c
> index 7a0522316ee3..994c3bd36ef2 100644
> --- a/arch/sh/drivers/pci/pci.c
> +++ b/arch/sh/drivers/pci/pci.c
> @@ -185,6 +185,8 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res,
>  		 */
>  		if (start & 0x300)
>  			start = (start + 0x3ff) & ~0x3ff;
> +	} else (res->flags & IORESOURCE_MEM) {

I'll be adding the missing if into this in v2 (found by sashiko). It seems 
lkp didn't test this so it was not caught earlier.

> +		start = pci_align_resource(dev, res, empty_res, size, align);
>  	}
>  
>  	return start;

-- 
 i.


More information about the Linuxppc-dev mailing list