{"slug": "fitting-four-32-gb-resizable-bars-behind-a-pcie-switch-on-linux", "title": "Fitting Four 32 GB Resizable BARs Behind a PCIe Switch on Linux", "summary": "A Linux 7.0 bridge-window sizing bug in pbus_size_mem() in drivers/pci/setup-bus.c prevents the kernel from assigning 32 GB Resizable BARs to four AMD Radeon AI PRO R9700 GPUs behind a Broadcom PEX88096 PCIe switch, because the kernel sums child window sizes without leaving the nearly 32 GB gap between one card's 2 MB doorbell BAR and the next card's start. The bug, reported by Nikolas Britton on linux-pci in September, gave the switch a window of about 128.6 GB while the four cards' windows span 224 GB, so only two R9700s received BARs and the rest got nothing on kernel 7.0.6; an unpatched v7.4-rc1 kernel placed three of the four. Ilpo Järvinen, who maintains the code, has a fix in a 14-patch series of resource placement fixes, and author Doug Calobrisi published a gpu-rebar-layout kernel module on GitHub that performs the resize and rescan, with padding disabled (pad=0), until the patch lands.", "body_md": "# Fitting Four 32 GB Resizable BARs Behind a PCIe Switch on Linux\n\nMy [PCIe switch](https://doug.sh/posts/pcie-bifurcation-switches-retimers/) is a Broadcom PEX88096 in the board’s one x16 slot, with four AMD Radeon AI PRO R9700s and the two RTX 3090s\nfrom [my PCIe splitter post](https://doug.sh/posts/pcie-splitter-rtx-3090/) behind it, and\n[the build post](https://doug.sh/posts/six-gpus-one-x16-slot/) has the whole box.\n\nThe switch gives each card eight lanes and lets the cards copy to each other without going through the CPU. AMD’s ROCm calls that peer-to-peer (P2P), and it only turns it on when each card’s whole 32 GB is mapped. On Linux, that means a 32 GB Resizable BAR on every card. A base address register, or BAR, maps a range of the CPU’s address space onto a device’s memory. Resizable BAR is the BIOS option that lets a card’s BAR be the full 32 GB instead of the default 256 MB.\n\nA few people asked for the module after the build post, so it’s on GitHub as\n[gpu-rebar-layout](https://github.com/dougcalobrisi/gpu-rebar-layout). It leans on kernel internals that\ncould change in any release, so read the README before you load it. A patch series on the mailing\nlist fixes the sizing bug, but this board will still need the module’s resize and rescan after it lands,\nwith its padding turned off (`pad=0`).\n\n## Why the BIOS can’t map six 32 GB BARs [🔗](#why-the-bios-cant-map-six-32-gb-bars)\n\nWith the 3090s added, the board stopped at the white VGA light on its POST LEDs, because every 32 GB BAR\ntakes up 64 GB of the BIOS’s address space. [The address space post](https://doug.sh/posts/pci-address-space-six-gpus/)\nhas the math.\n\n## Linux 7.0’s bridge window sizing bug: can’t assign; no space [🔗](#linux-70s-bridge-window-sizing-bug-cant-assign-no-space)\n\nThis board’s BIOS has no per-card Resizable BAR setting. Linux can give large BARs to some cards and leave others small, as long as it does it before any GPU driver loads. With all six cards in and Resizable BAR off, I wanted Linux to do the allocation. The plan was to set each R9700’s BAR size register to 32 GB, remove the CPU port the switch hangs off, and rescan, so the kernel lays out the whole switch again from the new sizes.\n\nEach R9700’s 32 GB BAR is followed by a doorbell BAR, for registers the driver writes to tell the card there’s new work. With Resizable BAR on, the BIOS makes it 256 MB. Linux leaves it at 2 MB.\n\nThe kernel gave the switch a window of about 128.6 GB. With the doorbell placed after each BAR, the way Linux 7.0 lays them out, the four windows span 224 GB (three 64 GB slots plus the last card’s 32 GB and its doorbell). Two R9700s got their BARs, and the rest of the switch got nothing.\n\n```\npci 0000:1b:00.0: bridge window [mem size 0x800200000 64bit pref]: can't assign; no space\n```\n\nThat was on 7.0.6. The unpatched v7.4-rc1 kernel placed three of the four in the control run that the Linux kernel patch-testing post (coming soon) covers.\n\n`0x800200000` is 32 GB plus 2 MB, one card’s window. The kernel had sized the switch’s window as the plain\nsum of its children: four of those plus the two 3090s’ 288 MB windows.\n\nThe function is `pbus_size_mem()` in `drivers/pci/setup-bus.c`. For each child of a bridge it adds the\nchild’s size, or its alignment if that’s bigger, to the total.\n\n```\nr_size = resource_size(r);\nsize += max(r_size, align);\n```\n\nThat leaves no gap when every child’s size is a multiple of its alignment, which is true for ordinary BARs because they’re powers of two. A GPU’s window here is 32 GB plus 2 MB with a 32 GB alignment, so the sum leaves out the gap of almost 32 GB between one card’s doorbell and the next card’s start.\n\nIt’s a known regression. Nikolas Britton [reported it on linux-pci in September](https://lore.kernel.org/linux-pci/20260903063124.9316-1-nbritton@exabit.io/),\nand the thread’s title describes my problem almost word for word.\n\nIlpo Järvinen, who maintains this code, has a fix in\n[a 14-patch series of resource placement fixes](https://lore.kernel.org/r/20261106134341.39493-1-ilpo.jarvinen@linux.intel.com),\nat v5 as of November 6 and not merged yet. I tested it and sent a Tested-by to the linux-pci mailing\nlist. With it, all four R9700s get their 32 GB.\n\nEven with the fix, this board still needs something to set the BAR sizes and rescan before the GPU drivers load, because amdgpu’s resize at load time can’t grow a window that other cards already sit in.\n\n## A kernel module that pads the BARs [🔗](#a-kernel-module-that-pads-the-bars)\n\nThe kernel already knows how to raise a BAR’s alignment without changing its size, but naming a device\nin the `pci=resource_alignment=` boot option uses the resizing mode instead. Asking for 32 GB alignment\non an R9700 would also grow its small BARs, including the 512 KB register BAR, which can’t be aligned to\n32 GB below 4 GB.\n\nThe workaround is [an out-of-tree module](https://github.com/dougcalobrisi/gpu-rebar-layout) that runs\nfrom the initramfs, the tiny early-boot filesystem\nthe kernel starts from, before any GPU driver loads. For each matching card it sets\nthe BAR size register, then it removes the root port above the switch and rescans.\n\nBetween the scan and the address assignment it walks every bus segment under the switch. It raises each smaller 64-bit prefetchable BAR’s alignment to the size of the largest 64-bit prefetchable BAR on that segment, and does the same for the other memory BARs as a separate group. Each R9700 window becomes exactly 64 GB and each 3090 window exactly 512 MB. Once every window is a multiple of its alignment, the kernel’s allocator does the rest.\n\nAfter a reboot the R9700s sat at 160, 224, 288, and 352 GB, the 3090s just above them, and amdgpu reported the whole card.\n\n```\namdgpu 0000:14:00.0: [drm] Detected VRAM RAM=32624M, BAR=32768M\n```\n\nWith the [ACS redirect setting](https://doug.sh/posts/six-gpus-one-x16-slot/#kernel-command-line-bars-gpu-unlock-baco-and-acs)\nthe box already had (`pci=disable_acs_redir=` on the R9700 switch ports), P2P between the R9700s ran\nat 14.0 GB/s for every pair, which is what an eight-lane gen4 link delivers in practice, and all four\ncopying in a ring at once moved 54.7 GB/s.\n\n## If your GPUs won’t all get their BARs [🔗](#if-your-gpus-wont-all-get-their-bars)\n\n1. Search the linux-pci mailing list for your `can't assign` error first. Someone may have already\nreported it, or even fixed it.\n2. Resize the BARs and rescan before the GPU drivers load, which means doing it from the initramfs.\n3. Don’t remove or rescan a GPU that already has its driver loaded. That locked up my box.\n4. If one card gets its BARs and the next one doesn’t, look at the small BARs next to the big ones.\n5. Check the cards again a few minutes after boot, in case they go to sleep and don’t wake back up.\n\n*I had help with this one. Claude wrote the module with me, ran the commands and tests on the box over\nSSH, and helped me draft this post. I did the physical work, read all the words, checked the numbers, and\nrewrote anything that sounded like a chatbot, so the mistakes are mine.*\n\n## Sources [🔗](#sources)\n\n- [gpu-rebar-layout](https://github.com/dougcalobrisi/gpu-rebar-layout) , the module’s source and README\n- [PCI: bridge window undersized when child bridge windows are larger than their alignment](https://lore.kernel.org/linux-pci/20260903063124.9316-1-nbritton@exabit.io/) , the linux-pci thread with the regression report and Ilpo Järvinen’s reply\n- [PCI: Resource placement algorithm fixes (v5)](https://lore.kernel.org/r/20261106134341.39493-1-ilpo.jarvinen@linux.intel.com) , Ilpo’s series, including “PCI: Fix composite resource sizing” and “PCI: Place resources to either edge of the window”\n- [`drivers/pci/setup-bus.c`](https://github.com/torvalds/linux/blob/v7.0/drivers/pci/setup-bus.c) ,`pbus_size_mem()`\n- [`pci_request_resource_alignment()`](https://github.com/torvalds/linux/blob/v7.0/drivers/pci/pci.c) , the two alignment modes behind`pci=resource_alignment=`", "url": "https://wpnews.pro/news/fitting-four-32-gb-resizable-bars-behind-a-pcie-switch-on-linux", "canonical_source": "https://doug.sh/posts/gpu-bars-behind-a-pcie-switch/", "published_at": "2026-11-09 22:00:00+00:00", "updated_at": "2026-11-24 01:48:26.756379+00:00", "lang": "en", "topics": ["ai-infrastructure", "ai-chips", "mlops"], "entities": ["Broadcom PEX88096", "AMD Radeon AI PRO R9700", "Nvidia RTX 3090", "Linux 7.0", "Nikolas Britton", "Ilpo Järvinen", "gpu-rebar-layout", "ROCm"], "also_reported_by": [], "takeaway": "When a PCIe bridge's children have windows larger than their alignment (a 32 GB BAR plus a 2 MB doorbell at 32 GB alignment), the kernel's max(size, align) sum omits the gap, so force a resize and rescan with the gpu-rebar-layout module and pad=0 until the 14-patch linux-pci fix lands.", "recommendation": {"advice": "If ROCm P2P fails to enable across GPUs behind a PCIe switch, set each card's BAR to 32 GB and rescan the switch with the gpu-rebar-layout module using pad=0, since Linux 7.0's pbus_size_mem() under-sizes the bridge window.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/fitting-four-32-gb-resizable-bars-behind-a-pcie-switch-on-linux", "markdown": "https://wpnews.pro/news/fitting-four-32-gb-resizable-bars-behind-a-pcie-switch-on-linux.md", "text": "https://wpnews.pro/news/fitting-four-32-gb-resizable-bars-behind-a-pcie-switch-on-linux.txt", "jsonld": "https://wpnews.pro/news/fitting-four-32-gb-resizable-bars-behind-a-pcie-switch-on-linux.jsonld"}}