I have a Framework Laptop 13 (Intel 13th gen) and an RTX 3070 sitting in a Thunderbolt 3 eGPU enclosure. On Windows it just works. On Linux, I got this:

NVRM: This PCI I/O region assigned to your NVIDIA device is invalid:
NVRM: BAR1 is 0M @ 0x0 (PCI:0000:04:00.0)

The GPU was right there on the PCI bus, and the driver loaded. Then it gave up, because BAR1 (the 256MB framebuffer aperture the GPU needs to function) had zero bytes allocated.

A 220W GPU, reduced to a very expensive space heater.

Getting it to work took the better part of a weekend. The core of the fix is a bash script that removes and rescans part of the PCI tree before the desktop starts, and the sneakiest problem turned out to be one line in my own initramfs config.

The setup#

  • Laptop: Framework 13, Intel i7-1370P (Raptor Lake), Thunderbolt 4
  • eGPU: RTX 3070 (GA104) in a Thunderbolt 3 enclosure (Intel Titan Ridge)
  • OS: Arch Linux, kernel 6.19, KDE Plasma 6.6 on Wayland
  • Monitor: 4K display plugged into the eGPU’s HDMI port

The eGPU isn’t always connected: sometimes I work from the couch, sometimes from the desk. Whatever fix I came up with could not break the laptop when the GPU isn’t there.

BAR1 gets no address space#

For once I actually read the error, and BAR1 is 0M is pretty explicit. The GPU’s Base Address Register 1 (a 256MB chunk of prefetchable memory that maps the framebuffer) got no address space at all. lspci agrees:

$ sudo lspci -s 04:00.0 -vv | grep -E 'Region|BAR'
Region 0: Memory at 7c000000 (32-bit, non-prefetchable) [size=16M]
Region 1: [virtual] (64-bit, prefetchable)              # ← gone
Region 3: Memory at 6010000000 (64-bit, prefetchable) [size=32M]

BAR0 and BAR3 are fine. BAR1 is just… not there. And dmesg confirms:

pci 0000:04:00.0: BAR 1 [mem size 0x10000000 64bit pref]: can't assign; no space

No space. On a machine with 64 gigs of RAM. Right.

Where the address space went#

PCI devices don’t get addresses on their own. They inherit them from their parent bridge, which inherits from its parent, all the way up to the root port, and every bridge has a “window” that limits how much space it can hand to its children.

I spent a while staring at lspci -vv on every bridge in the chain. This is the Thunderbolt topology:

00:07.0 (Root Port, TB4)               pref window: 512MB
  └─ 02:00.0 (Upstream TB3 Switch)     pref window: 417MB
       ├─ 03:01.0 (Downstream → GPU)   pref window: 161MB  ← NOT ENOUGH
       │    ├─ 04:00.0  RTX 3070       needs: 256+32 = 288MB
       │    └─ 04:00.1  GPU Audio
       ├─ 03:02.0 (Downstream → USB)   USB controller
       └─ 03:04.0 (Downstream → nothing) pref window: 128MB  ← WASTED

The GPU needs 288MB (BAR1 + BAR3), and its bridge has only 161MB. Meanwhile the daisy-chain port (03:04.0, with absolutely nothing connected to it) sits on 128MB of prefetchable space.

The kernel divides the upstream bridge’s window equally among the three downstream ports, so each gets roughly a third of 417MB: mathematically fair, practically useless.

If you’re planning to daisy-chain a second Thunderbolt device, that 128MB reservation makes sense. I’m not. I have one cable going to one box with one GPU in it.

Kernel parameters and BIOS settings that don’t help#

Before I understood the topology, I tried everything I could find on the Arch Wiki, the eGPU.io forums and random Reddit threads:

  • pci=realloc: the internet says this fixes BAR allocation. It does, but only during boot. Thunderbolt hotplug is a different code path, and realloc does not apply there.
  • pci=hpmmioprefsize=2G: reserves more prefetchable space for hotplug bridges. Great idea, except the root port’s firmware window is only 512MB and this parameter cannot make it bigger. I tried 2G, 4G and 32G, with the same result.
  • pci=hpmemsize=128M: the same thing for non-prefetchable memory, so irrelevant here.

I also went through every BIOS setting on the Framework. There is no PCIe MMIO size option, no Resizable BAR toggle and no Thunderbolt memory allocation knob. The firmware enables Above 4G Decoding (you can tell because the addresses are at 0x6000000000), but you can’t change it. Framework’s Insyde BIOS is not exactly a playground for PCI tuning.

The remove-and-rescan trick#

Once I understood the problem, the fix was crude but effective: remove the empty bridges from the PCI bus, remove the GPU’s bridge, then rescan from the root port. On the rescan the kernel sees only one downstream bridge that needs prefetchable space, so it gives that bridge everything: 288MB, exactly what the GPU needs.

I wrote a quick script, ran it by hand, and… nvidia-smi worked, for the first time in two days. Then I rebooted and it stopped working again.

The initramfs trap (another half day gone)#

The script ran, did the remove and rescan, and the BAR allocation succeeded. Then, about 16 seconds later, something reset everything. I could see it in dmesg:

[  0.87] pci 0000:04:00.0: BAR 1 [mem 0x6000000000-0x600fffffff 64bit pref]  ← OK!
[ 16.72] pci 0000:02:00.0: bridge configuration invalid ([bus 00-00]), reconfiguring
[ 16.73] pci 0000:04:00.0: BAR 1 [mem size 0x10000000 64bit pref]: can't assign  ← GONE

Something at second 16 was re-enumerating the entire Thunderbolt bus. The bridge windows went back to zero and the kernel redid the allocation from scratch, badly, again.

I spent hours on this before I looked at my own mkinitcpio.conf:

MODULES=(thunderbolt)

I had put thunderbolt in the initramfs modules at some point (I honestly don’t remember why, probably something about the Thunderbolt dock I used to have). With it there, the TB controller initialized very early in the boot, enumerated the PCI bus and allocated everything correctly. Then, 16 seconds later, the Thunderbolt hotplug system kicked in and did it all over again, resetting the bridge windows.

So there were two enumerations, one good and one bad, and my script ran before, between or after them depending on how fast systemd felt like starting things. That’s a timing race I could not win. The fix:

# /etc/mkinitcpio.conf
MODULES=()

Remove thunderbolt, rebuild the initramfs with mkinitcpio -P and reboot. Now the TB module loads once through udev, the enumeration happens once, and the script always finds the same state.

I felt stupid for not checking this earlier. But honestly, who looks at their initramfs module list when debugging PCI BAR allocation?

The script and the service#

With the double enumeration gone, this is the full setup. First, blacklist nvidia so it doesn’t load before the fix runs (it would see BAR1 at zero and give up for good):

# /etc/modprobe.d/nvidia-egpu.conf
blacklist nvidia
blacklist nvidia_drm
blacklist nvidia_modeset
blacklist nvidia_uvm

Then a systemd service runs the fix before SDDM:

# /etc/systemd/system/egpu-bar-fix.service
[Unit]
Description=Fix NVIDIA eGPU BAR1 allocation after Thunderbolt hotplug
After=bolt.service systemd-udevd.service
Before=display-manager.service
Wants=bolt.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/egpu-bar-fix.sh
RemainAfterExit=yes
TimeoutStartSec=90

[Install]
WantedBy=display-manager.service

The script itself finds the GPU and its bridges at runtime instead of relying on hardcoded PCI addresses (the only fixed one is a fallback for the Thunderbolt root port, 00:07.x on my Framework), so it should work on other hardware with other topologies:

#!/bin/bash
#
# egpu-bar-fix - Fix NVIDIA eGPU BAR1 allocation on Thunderbolt

set -euo pipefail

log() { logger -t egpu-bar-fix "$*"; echo "$*"; }
die() { log "FATAL: $*"; exit 1; }

find_nvidia_gpu() {
    local dir
    for dir in /sys/bus/pci/devices/*/; do
        [ "$(cat "$dir/vendor" 2>/dev/null)" = "0x10de" ] \
            && [ "$(cat "$dir/class" 2>/dev/null | cut -c1-6)" = "0x0300" ] \
            && basename "$dir" && return
    done
    return 1
}

pci_class() { cat "/sys/bus/pci/devices/$1/class" 2>/dev/null | cut -c1-6; }
is_bridge() { [ "$(pci_class "$1")" = "0x0604" ]; }

parent_bridge() {
    local real=$(readlink -f "/sys/bus/pci/devices/$1")
    local parent=$(basename "$(dirname "$real")")
    is_bridge "$parent" 2>/dev/null && echo "$parent"
}

sibling_bridges() {
    local real=$(readlink -f "/sys/bus/pci/devices/$1")
    local bdf child
    for child in "$(dirname "$real")"/0000:*; do
        bdf=$(basename "$child")
        [ "$bdf" != "$1" ] && is_bridge "$bdf" 2>/dev/null && echo "$bdf"
    done
}

bridge_is_empty() {
    local f
    for f in "/sys/bus/pci/devices/$1"/0000:*/class; do
        [ -f "$f" ] && [ "$(cat "$f" | cut -c1-6)" != "0x0604" ] && return 1
    done
    return 0
}

bar1_ok() {
    local bar1=$(sed -n '2p' "/sys/bus/pci/devices/$1/resource" 2>/dev/null)
    ! echo "$bar1" | grep -q '^0x0000000000000000'
}

# --- Main ---

log "looking for NVIDIA eGPU..."

gpu=$(find_nvidia_gpu) || gpu=""
if [ -z "$gpu" ]; then
    for _ in $(seq 1 5); do sleep 1; gpu=$(find_nvidia_gpu) && break; done
fi
[ -z "$gpu" ] && { log "no NVIDIA GPU found - nothing to do"; exit 0; }

log "found GPU at $gpu"

if bar1_ok "$gpu"; then
    log "BAR1 already assigned - loading driver"
    modprobe nvidia_drm modeset=1
    exit 0
fi

log "BAR1 is unassigned - fixing..."

gpu_bridge=$(parent_bridge "$gpu") || die "cannot find GPU parent bridge"

for sib in $(sibling_bridges "$gpu_bridge"); do
    bridge_is_empty "$sib" && {
        log "removing empty bridge $sib"
        echo 1 > "/sys/bus/pci/devices/$sib/remove" 2>/dev/null || true
    }
done

log "removing GPU bridge $gpu_bridge"
echo 1 > "/sys/bus/pci/devices/$gpu_bridge/remove"
sleep 1

upstream=$(parent_bridge "$gpu_bridge") || true
root=${upstream:+$(parent_bridge "$upstream")}
if [ -z "$root" ]; then
    for rp in /sys/bus/pci/devices/0000:00:07.?; do
        [ -d "$rp" ] && root=$(basename "$rp") && break
    done
fi
[ -z "$root" ] && die "cannot find root port"

log "rescanning from $root"
echo 1 > "/sys/bus/pci/devices/$root/rescan"
sleep 3

gpu=$(find_nvidia_gpu) || die "GPU not found after rescan"
bar1_ok "$gpu"           || die "BAR1 still unassigned after fix"

log "BAR1 OK for $gpu - loading driver"
modprobe nvidia_drm modeset=1
log "done"

When the eGPU is not connected, the script exits in about 5 seconds (“no NVIDIA GPU found”) and SDDM starts normally on the Intel GPU. When it is connected, the full fix (remove the bridges, rescan, load nvidia) takes about 9 seconds, and then SDDM starts with the GPU ready.

Warning: during the remove phase, do NOT remove the upstream bridge (02:00.0). I made this mistake early on and my external monitor went black instantly: the monitor uses Intel’s DisplayPort tunneling through the Thunderbolt chain, and removing the upstream bridge kills the tunnel. I had to hard-reboot. Only remove the GPU’s direct parent bridge and its empty siblings.

Getting KDE to composite on the right GPU#

With nvidia-smi working, the desktop still felt sluggish. It wasn’t terrible, but it wasn’t the smoothness I expected from a 3070 driving a single 4K display. I checked what KWin was actually using:

$ qdbus org.kde.KWin /KWin org.kde.KWin.supportInformation | grep renderer
OpenGL renderer string: Mesa Intel(R) Iris(R) Xe Graphics (RPL-P)

Intel. KWin was rendering every frame on the integrated GPU and then copying it to the NVIDIA card for display output, so every single frame crossed the Thunderbolt link twice. No wonder it felt off.

The fix is a small env script that KDE sources at login:

# ~/.config/plasma-workspace/env/kwin-gpu.sh
if [ -e /dev/dri/card0 ] && \
   [ "$(cat /sys/class/drm/card0/device/vendor 2>/dev/null)" = "0x10de" ]; then
    export KWIN_DRM_DEVICES=/dev/dri/card0:/dev/dri/card1
fi

KWIN_DRM_DEVICES tells KWin which GPU to render on, and the first device in the list wins. The if checks that card0 really is the NVIDIA card, so when the eGPU is disconnected and card0 is Intel, the variable is never set and KWin does its default thing.

After logging in again:

OpenGL renderer string: NVIDIA GeForce RTX 3070/PCIe/SSE2

That’s more like it. KWin now composites the 4K desktop on the discrete GPU, and frames go straight from render to display without the extra copies.

What I haven’t tested#

  • Suspend and resume. I have no idea if the BAR allocation survives a suspend cycle. It almost certainly doesn’t. If you suspend by closing the lid, you might need extra udev rules or a resume hook. I always shut down when I unplug the eGPU.
  • Hot-unplug. Pulling the Thunderbolt cable while the GPU is active is a gamble on Linux. KWin handles it somewhat gracefully (it falls back to Intel), but I wouldn’t rely on it. I stop KDE, unload nvidia, then disconnect.
  • Other enclosures. The script discovers the topology at runtime, so it should work with other TB enclosures and GPUs, but I’ve only tested my Titan Ridge and RTX 3070.

The files#

FileWhat it does
/etc/mkinitcpio.confMODULES=(), removed thunderbolt
/etc/modprobe.d/nvidia-egpu.confBlacklists nvidia (loaded by the script instead)
/usr/local/bin/egpu-bar-fix.shThe remove+rescan fix
/etc/systemd/system/egpu-bar-fix.serviceRuns before SDDM
~/.config/plasma-workspace/env/kwin-gpu.shTells KWin to render on NVIDIA
/boot/refind_linux.confpci=realloc in kernel params

After creating these:

sudo mkinitcpio -P
sudo systemctl daemon-reload
sudo systemctl enable egpu-bar-fix.service

Is this a kernel bug?#

Probably, yes. The hotplug code (pci_bus_distribute_available_resources() in drivers/pci/setup-bus.c, if you want to look) divides the space equally among child bridges without checking whether any of them has devices behind it. That’s conservative, since a device could appear on any port later, but in the common eGPU case, where only one port has anything connected, it wastes too much space.

There are discussions on the kernel mailing list about smarter resource allocation for hotplug, but Thunderbolt eGPUs are niche enough that nobody has pushed a fix upstream. So for now, about 100 lines of bash will have to do.


The script and config files are on GitHub. If you’re fighting the same problem or a variation of it, find me on LinkedIn, always happy to compare dmesg output with fellow eGPU masochists.