virtio: sparse-align initial BAR placement to avoid Windows PnP rebalance deadlock - #8205
Merged
rbradford merged 1 commit intoMay 19, 2026
Merged
Conversation
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
from
May 13, 2026 07:36
41709f3 to
2586f8b
Compare
phip1611
reviewed
May 13, 2026
phip1611
previously approved these changes
May 13, 2026
phip1611
left a comment
Member
There was a problem hiding this comment.
Very nice write-up and investigation of the issue! Code wise LGTM. I’m a little hesitant to approve this without input from someone with more PCI experience than me.
phip1611
dismissed
their stale review
May 13, 2026 07:49
hit wrong button - didn't want to approve...
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
2 times, most recently
from
May 13, 2026 08:01
51d9655 to
587daf8
Compare
phip1611
reviewed
May 13, 2026
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
3 times, most recently
from
May 13, 2026 09:59
0c18f57 to
4c2d97f
Compare
rbradford
requested changes
May 14, 2026
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
2 times, most recently
from
May 14, 2026 02:17
5b7b907 to
74ed43f
Compare
Member
|
Please rebase feature branches in CH, never update a branch using the |
Contributor
Author
rebased, thanks |
Member
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
from
May 15, 2026 12:10
7b4c623 to
d50a481
Compare
Contributor
Author
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
from
May 15, 2026 17:34
d50a481 to
8087691
Compare
rbradford
approved these changes
May 16, 2026
rbradford
requested changes
May 16, 2026
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
from
May 16, 2026 04:48
8087691 to
d959290
Compare
rbradford
reviewed
May 16, 2026
rbradford
requested changes
May 16, 2026
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
2 times, most recently
from
May 16, 2026 16:40
02b3a06 to
fe627c2
Compare
rbradford
reviewed
May 18, 2026
rbradford
left a comment
Member
There was a problem hiding this comment.
Great - please just squash the comment into the first commit. FWIW I think there is the right amount of detail in the comment message.
Windows 11 PnP rebalance rewrites peer BARs into the same range CH packed the initial layout at, causing move_bar() failures and boot deadlock. Pack Mmio64 BARs at 8 MiB stride. Mmio32 isn't wide enough for the same stride, but its BARs don't participate in guest BAR rebalancing. On restore, pin the BAR to the snapshot address (alignment=None) so a guest-relocated BAR with smaller alignment is accepted. Signed-off-by: CMGS <[email protected]>
CMGS
force-pushed
the
fix/win-bar-rebalance
branch
from
May 19, 2026 02:55
fe627c2 to
f8c6675
Compare
rbradford
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes #8202.
Windows 11 25H2's PnP arbiter (
pci.sys) rewrites peer BAR addresses on resource rebalance and frequently picks targets that overlap another live device's BAR — see #8202 for the full Microsoft documentation references and the deadlock failure mode. With the default 512 KiB-aligned packed layout, three or four adjacent virtio device BARs at the top of MMIO64 are within Windows' preferred-address window, so the rebalance collides with non-trivial probability (~50% in our reproducer) andmove_bar()correctly refuses the conflicting allocation. The guest, having committed the new address to its own state, never reconciles with the rolled-back config register and wedges early boot.This PR takes the low-risk
option #1from the issue: bump the virtio capability BAR allocator alignment to 8 MiB so initial devices land at well-separated offsets (each 512 KiB BAR consumes 8 MiB of address slack). Windows-side BAR moves now have room to succeed without colliding with other CH-managed devices. On phys_bits=46, the alignment-induced waste is ~64 TiB of unused address space — negligible.Verified on our testbed: Win11 25H2 boot +
vm net --nics 1→2→4→2→1→0resize chain + 0-NIC snapshot + clone-with-override + chain clone all pass deterministically.Two commits:
virtio: 8 MiB-aligned initial BAR placement — applies to fresh allocation in
VirtioPciDevice::allocate_bars(). Both the Memory*BitRegion and the optional shm BAR paths are bumped to 8 MiB alignment.virtio: relax BAR alignment on restore — needed because the guest may have reprogrammed a BAR to a 512 KiB-aligned (but not 8 MiB-aligned) address while running;
move_bar()usesCAPABILITY_BAR_SIZE(512 KiB) as its alignment, so any address the guest had settled on must remain valid through snapshot/restore. Without this, every restore from a snapshot of a guest that had moved any BAR fails withAllocating space for an IO BAR failed. Fresh allocation continues to use the sparse 8 MiB alignment.This is independent of #8203 / #8204 (allocator state leak in
move_bar()): even with PR #8204 keeping host-side state consistent, the rebalance attempt still fails when the target overlaps, leaving the guest with an invalid view of the BAR. Sparse layout prevents the rebalance from ever needing to land on an occupied range in the first place.The issue mentions two alternative fixes (#2 coordinated swap, #3 QEMU-style accept-and-stomp). Both would be more invasive — happy to follow up with those if upstream prefers a deeper fix.
Signed-off-by: CMGS [email protected]