]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI: Fix alignment calculation for resource size larger than align
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 24 Mar 2026 16:56:33 +0000 (18:56 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 27 Mar 2026 15:19:08 +0000 (10:19 -0500)
The commit bc75c8e50711 ("PCI: Rewrite bridge window head alignment
function") did not use if (r_size <= align) check from pbus_size_mem() for
the new head alignment bookkeeping structure (aligns2[]). In some
configurations, this can result in producing a gap into the bridge window
which the resource larger than its alignment cannot fill.

The old alignment calculation algorithm was removed by the subsequent
commit 3958bf16e2fe ("PCI: Stop over-estimating bridge window size") which
renamed the aligns2[] array leaving only aligns[] array.

Add the if (r_size <= align) check back to avoid this problem.

Fixes: bc75c8e50711 ("PCI: Rewrite bridge window head alignment function")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Closes: https://lore.kernel.org/all/b05a6f14-979d-42c9-924c-d8408cb12ae7@roeck-us.net/
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Xifer <xiferdev@gmail.com>
Link: https://patch.msgid.link/20260324165633.4583-11-ilpo.jarvinen@linux.intel.com
drivers/pci/setup-bus.c

index f853003d3fa65a44f45ade44517bfa469b2151af..4cf120ebe5adfcf1fb0ea09d97af72dfd85f29ee 100644 (file)
@@ -1333,7 +1333,14 @@ static void pbus_size_mem(struct pci_bus *bus, struct resource *b_res,
                        r_size = resource_size(r);
                        size += max(r_size, align);
 
-                       aligns[order] += align;
+                       /*
+                        * If resource's size is larger than its alignment,
+                        * some configurations result in an unwanted gap in
+                        * the head space that the larger resource cannot
+                        * fill.
+                        */
+                       if (r_size <= align)
+                               aligns[order] += align;
                        if (order > max_order)
                                max_order = order;
                }