Skip to content

[DO NOT REVIEW] vmotherboard: claim a device's PCI slot only once its unit spawns - #5249

Merged
Pedro Henrique Penna (ppenna) merged 2 commits into
feature/microvm/devfrom
copilot/nvx-issue-1904-pci-slot-rollback
Nov 23, 2026
Merged

Pedro Henrique Penna (ppenna) merged 2 commits into
feature/microvm/devfrom
copilot/nvx-issue-1904-pci-slot-rollback

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#1904.

Stacked on #5248; only the top 1 commit belongs to this PR. #5248 has since landed: feature/microvm/dev is at its head, b73db6676, so this commit is the only one that the branch lacks.

NVX pins the head of this branch, so this is a prerequisite of the NVX change that pins it, microsoft/nvx#2061, and it lands by fast-forwarding feature/microvm/dev to that exact commit, not with the merge button, which squashes.

What and why

ArcMutexChipsetDeviceBuilder::inner_add in vmm_core/vmotherboard/src/chipset/backing/arc_mutex/device.rs registered a PCI chipset device's place with the builder's bus resolver before ArcMutexChipsetServices::finalize, which can still fail, for example with NameInUse when another state unit has the device's name. The place is its bus, device, and function on a PCI bus, its PCIe downstream port, or its devfn as an RCiEP. Nothing took the registration back, so when the add failed in finalize:

  • The resolver kept the dropped device's Weak in that place, and ChipsetBuilder::build attached it to the bus, where configuration accesses find no device.
  • A device added in the same place afterwards failed the build with a PciConflict, or a PcieConflict for a downstream port or an RCiEP, that named the dropped device.

No caller goes on after a failed add: each, such as the base chipset and the microVM loader, returns its error. So this is a latent lifecycle hazard of the builder, which microsoft/nvx#1904 found by code reading, rather than a reachable failure.

register_static_pci, register_static_pcie, and register_static_pcie_rciep now only record the places that the add asks for, and finalize registers them with the resolver after the spawn of the device's unit, its last step that can fail, under the builder's lock. That is where it already makes the device the chipset's EOI handler, PIC, and line target since the chain's vmotherboard: wire a chipset device only once its unit spawns (#5170). A failed add leaves no place behind and touches no other device's. A successful add registers the same places as before, which the resolver attaches to the buses as the chipset is built. The resolver's three registration methods move from ChipsetBuilder, whose methods take the builder's lock, to BusResolver, which finalize reaches under the lock that it holds.

Upstream main, b50d0c979, registers the place before finalize the same way. This commit does not apply there on its own: it extends the ordering of finalize and the test module that the chain's #5170 commit adds.

No saved state, protocol, ABI, or format, and no version of any of them, changes.

Tests

In services::tests of vmotherboard, each test fails an add by giving its unit's name to another unit first:

  • failed_add_leaves_the_pci_slot_free: on a GenericPciBus, adds a function at 00:05.1, fails the add of one at 00:05.0, adds another at 00:05.0, builds the chipset, and reads the vendor and device IDs of both functions through the bus's configuration ports, 0xCF8 and 0xCFC.
  • failed_add_leaves_the_pcie_port_and_rciep_free: on a root complex that, as a real one does, takes one device at each devfn, adds a device on one downstream port and an RCiEP, fails the add of a device on the other port and of another RCiEP, adds devices in their places, builds the chipset, and checks that the root complex attaches exactly the four live devices.

Validation

With cargo nextest run --profile agent -p vmotherboard on Windows 11, local, with the fix reverted (the production code of 899dcd63f, whose vmotherboard equals that of #5248's head, b73db6676, which changes only fuse) and with it:

Without the fix With it
17 pass, 2 fail as the chipset is built: failed_add_leaves_the_pci_slot_free with PciConflict { bdf: (0, 5, 0), conflict_dev: "replacement", reason: ExistingDev("device") }; failed_add_leaves_the_pcie_port_and_rciep_free with PcieConflict { conflict_dev: "rciep replacement", reason: ExistingDev("rciep") } and PcieConflict { conflict_dev: "endpoint replacement", reason: ExistingDev("endpoint") } all 19 pass

At this head, cargo check, cargo clippy --all-targets, and cargo doc --no-deps for vmotherboard are clean, but for the LNK4199 linker message that every linked artifact gets on this machine, and cargo xtask fmt --fix changes nothing. The change touches no platform-specific code; this pull request's CI runs the Linux unit tests and the VMM tests, whose VMs build their chipsets through this path.

In this pull request's CI, run 45261953268, the unit tests passed on x64 Linux, with the four failed_add_leaves_* tests, and on x64 Windows, and the VMM tests passed on x64-linux-intel-mshv, x64-windows-intel, and x64-windows-amd. On x64-linux-amd-kvm, multiarch::pcie::openvmm_uefi_x64_windows_datacenter_core_2025_x64_virtio_net_kdnet_windows timed out at the guest's power-off after virtio_net logged descriptor 0 is already outstanding, the intermittent failure that #5161 describes. It had found its virtio-net device on the PCI bus and got a DHCP address through it first. The job passed on its one rerun, with all 150 tests.

Session::dispatch_init negotiated in the session's own SessionInfo,
under its write lock, and marked the session initialized only after it
sent the reply (microsoft/nvx#1898). When the reply could not be sent,
as when a virtio-fs client's buffers cannot hold it, the session stayed
uninitialized but kept the values of the attempt that the client never
received. save_state then saved them with initialized false, which
SessionState::validate refuses as UninitializedWithInfo, so such a save
could not be restored, and a dormant microVM virtio-fs slot refused to
save at all. A later FUSE_INIT reset only the fields that dispatch_init
sets before Fuse::init, so the failed attempt's max_background and
congestion_threshold reached the file system's init, the reply, and
the saved state of the next negotiation.

dispatch_init now negotiates in a SessionInfo of the request's own,
built from the defaults and the client's offer alone, and stores it in
the session, and marks the session initialized, only once the reply is
sent. A reply that cannot be sent, like a negotiation that the session
refuses, leaves the session as it was: uninitialized, without a
negotiation. A FUSE_INIT whose reply is sent negotiates, replies, and
saves as before. Fuse::init documents it.

Tests, in fuse's session tests of init, with a sender that fails each
reply with WriteZero, and a file system that records what each init
receives and allows more background requests when the client offers
FUSE_ASYNC_DIO:

- init_whose_reply_fails_leaves_no_negotiation fails at
  feature/microvm/dev 899dcd6: the uninitialized session saves the
  failed attempt's version 7.39, capabilities, and background limits.
- init_after_a_failed_reply_negotiates_afresh, whose second FUSE_INIT
  offers only FUSE_ASYNC_READ at 7.31, fails there: that reply carries
  the failed attempt's background limits, (64, 48) instead of (0, 0).
  With the fix, its reply, what init receives, and the saved state
  match those of a new session.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When the add of a PCI chipset device failed after the device had been
given its place on a bus, as with NameInUse when another state unit
had the device's name, the bus resolver kept that place. The built
chipset had the dropped device's weak reference at its bus, device,
and function, where configuration accesses found no device, and a
device added there in its place failed the build with a PciConflict
that named the dropped device. A device on a PCIe downstream port or
an RCiEP kept its port or devfn the same way. No caller goes on after
a failed add, since each, such as the base chipset and the microVM
loader, returns its error, so this was a latent lifecycle hazard
rather than a reachable failure.

ArcMutexChipsetDeviceBuilder's add registered the device's place with
the bus resolver before ArcMutexChipsetServices::finalize, which can
still fail, and nothing took the registration back. The services now
only record the places that the add asks for, and finalize registers
them with the resolver after the spawn of the device's unit, its last
step that can fail, as it does the EOI handler, PIC, and line targets,
under the builder's lock. A failed add then leaves no place behind and
touches no other device's, and a successful add registers the same
places as before, which the resolver attaches to the buses as the
chipset is built. The resolver's registration methods move from
ChipsetBuilder, whose methods take the builder's lock, to BusResolver,
which finalize reaches under the lock that it holds.

Tests: failed_add_leaves_the_pci_slot_free fails the add of a PCI
function at 00:05.0 whose unit name is taken, adds another there, and
reads the IDs of both it and the function added at 00:05.1 before the
failure through the configuration ports of a GenericPciBus. The test
failed_add_leaves_the_pcie_port_and_rciep_free does the same with a
device on a downstream port and one as an RCiEP of a root complex
that, as a real one does, takes one device at each devfn, and checks
that it attaches the two live devices added in their places and the
two added beside them, on another port and devfn, before the failures.
At 899dcd6, without this change, both fail as the chipset is built,
with a PciConflict for 00:05.0 and a PcieConflict for the port and for
the RCiEP, each naming the failed device. Both pass with the fix, on
Windows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the release-nvx Targets a branch under feature/microvm/. label Nov 23, 2026
@ppenna
Pedro Henrique Penna (ppenna) merged commit e8324ea into feature/microvm/dev Nov 23, 2026
135 of 139 checks passed
aphrody-labs Bot pushed a commit to aphrody-labs/nvx that referenced this pull request Nov 24, 2026
…the OpenVMM roadmap

Map position 357, the commit of microsoft/openvmm#5249, which NVX now
pins at e8324ea31, 231 commits past the mapped tip:

- 357, vmotherboard: claim a device's PCI slot only once its unit
  spawns. ArcMutexChipsetServices::finalize registers a chipset
  device's places, on its PCI bus, on its PCIe downstream port, or at
  its devfn as an RCiEP, with the builder's bus resolver only once the
  device's state unit has spawned, the last step of the add that can
  fail. The add registered them before finalize, so an add that failed
  there, as with NameInUse when another unit had the device's name,
  left the dropped device's weak reference in its places, where the
  built chipset attached it, and a device added in its place failed
  the build with a PciConflict or a PcieConflict that named the
  dropped device.

Position 357 is not yet assigned to a PR. In services.rs, it extends
the order of finalize, and the tests module, that position 316 adds,
and PR10's position 015 and position 315 also change the file; in
builder/mod.rs, it moves the resolver's three registration methods
from ChipsetBuilder to BusResolver, and position 015 also changes the
file. It changes none of the code that a mapped PR adds, so it is no
fixup, and it follows position 316. Upstream main, 5d6ab1cfa,
registers the places before finalize the same way; replaying the
commit there conflicts in services.rs, whose code of position 316 it
changes, so it cannot go upstream on its own.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aphrody-labs Bot pushed a commit to aphrody-labs/nvx that referenced this pull request Nov 24, 2026
The comment of OpenVMM's VirtioFs::insert_inode said that, on a file
system with stable inode numbers, an inode that already existed with
the inserted inode's device and inode number was returned instead
(microsoft#1905). That reads as a key over the whole file system,
while the virtio-fs server matches a host object only among the inodes
of one volume, by its device and inode numbers on a volume with stable
file IDs and by its path on any other, and reuses only an inode of the
same file type. Section 3.6.4 of the host filesystem design already
says so, since microsoft#1875.

Pin microsoft/openvmm 7e94a090a80de4f5ac08a1ab74d1726da4dcf08b, one
commit on e8324ea31, the head of microsoft/openvmm#5249, which NVX
pinned before this commit:

- virtiofs: say that inodes deduplicate only within a volume. The
  comment of insert_inode says that an inode already in the map is a
  candidate for the inserted inode's host object only within its
  volume, so a host object that two children of an aggregate reach
  gets a node in each, and that only a candidate of the same file type
  is reused; InodeMap's summary says that it indexes the inodes that
  insertions may reuse by DedupKey. It changes comments only.

Nothing that NVX runs changes. No saved-state, protocol, or ABI
format, and no version of any of them, changes. The protocol vectors
and CPU profiles that nvx copies are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aphrody-labs Bot pushed a commit to aphrody-labs/nvx that referenced this pull request Nov 24, 2026
…m in the OpenVMM roadmap

Map position 361, the commit of microsoft/openvmm#5253, which NVX now
pins at 09966aa63, 235 commits past the mapped tip:

- 361, virtiofs: keep the node that a LINK returns until the guest
  forgets it. FUSE_LINK takes the lookup reference that its reply
  hands the guest when it resolves its target node, under the inode
  map's lock, with a new VirtioFs::reference_inode, and a LINK that
  fails releases it through a new InodeMap::forget, which FORGET uses
  too. Upstream's link counted the reference only after its host link,
  outside that lock, so a FORGET that raced it on the high-priority
  queue could remove the node, and the LINK then replied with an ID
  that every later request failed with EINVAL.

Position 361 is not yet assigned to a PR. In lib.rs, it changes
upstream's link and forget, and in link the argument of the alias
preflight that PR18's position 081 adds, and it adds reference_inode,
LookupReference, and InodeMap::forget; in inode.rs, it has
inc_lookup, which position 331 saturates, report whether it changed
the count. It adds three tests to the tests of lib.rs. It is no
fixup: the race is upstream's, since microsoft/openvmm#2661. Upstream
main, 5d6ab1cfa, has the race too; replaying the commit there
conflicts in inode.rs and lib.rs, so it cannot go upstream on its
own.

The Scope now also says that feature/microvm/dev is at e8324ea31,
since microsoft/openvmm#5248 and microsoft/openvmm#5249 landed
positions 356 and 357.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-nvx Targets a branch under feature/microvm/.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant