Skip to content

[DO NOT REVIEW] fuse: adopt a FUSE_INIT negotiation only once its reply is sent - #5248

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1898-init-reply-failure
Nov 23, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1898-init-reply-failure

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#1898.

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

What and why

fuse::Session::dispatch_init in vm/devices/support/fs/fuse/src/session.rs negotiated FUSE_INIT in the session's own SessionInfo, through the write guard that it holds for the whole request, and marked the session initialized only after it sent the reply. When the reply could not be sent, sender.send_arg(..)? returned early, and the session stayed uninitialized but kept the values of a negotiation that the client never received:

  • Session::save_state() saved them with initialized: false, a state that SessionState::validate() refuses as UninitializedWithInfo, so such a save could not be restored, and a dormant microVM virtio-fs slot, whose save requires the default session state, 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.

A virtio-fs reply fails when the guest's writable descriptors cannot hold it, where write_all fails with WriteZero, or lie outside guest memory, so the guest decides whether this happens.

dispatch_init now negotiates in a SessionInfo of the request's own, built from the defaults and the client's offer alone, with ..SessionInfo::default() for the rest, and stores it in the session, and marks the session initialized, only once send_arg has succeeded. A reply that cannot be sent, like a negotiation that the session refuses, leaves the session as it was: uninitialized, with the default SessionInfo, so save_state() saves the default state, and the next FUSE_INIT negotiates as on a new session. The refusal of unoffered flags no longer resets info, since it no longer touches the session. A FUSE_INIT whose reply is sent negotiates, replies, and saves as before, and the write guard still serializes racing FUSE_INIT requests. Fuse::init documents it.

Left out: when the reply cannot be sent, Fuse::init has already run, and nothing pairs it with Fuse::destroy; microsoft/nvx#1900 defines that cleanup for an init that the session does not complete. Until then, VirtioFs::init, which records its negotiation before the reply, keeps that record after a failed reply, so a microVM save then finds the record and the session's state disagree, as it did before this change.

Upstream main, b50d0c979, negotiates in the session's SessionInfo the same way, so its next FUSE_INIT after a failed reply also inherits max_background and congestion_threshold; it has no saved session state. This commit does not apply there as it is: it changes lines of dispatch_init and of the documentation of Fuse::init that only this branch has, the version cap of the chain's fuse: save and restore negotiated session state and the code of #5200, and its tests use the session's test harness and SessionState.

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

Tests

In session::tests::init, with a sender that fails each reply with WriteZero and counts the replies that the session tries to send, one, and a file system that records the SessionInfo that each init receives and allows more background requests, 64 and 48, when the client offers FUSE_ASYNC_DIO:

  • init_whose_reply_fails_leaves_no_negotiation: after a FUSE_INIT at 7.39 that offers FUSE_ASYNC_READ | FUSE_ASYNC_DIO | FUSE_INIT_EXT and FUSE_DIRECT_IO_ALLOW_MMAP_FLAG2, whose reply fails, the session is uninitialized and saves SessionState::default().
  • init_after_a_failed_reply_negotiates_afresh: a second FUSE_INIT, at 7.31 with only FUSE_ASYNC_READ, replies without background limits, and its reply, the SessionInfo that init receives, and the saved state equal those of a new session that receives only that request.

Validation

With cargo nextest run --profile agent -p fuse on Windows 11, local, with the fix reverted (session.rs and lib.rs of 899dcd63f) and with it:

Without the fix With it
48 pass, 2 fail: init_whose_reply_fails_leaves_no_negotiation saves SessionState { initialized: false, info: SessionInfoState { major: 7, minor: 39, max_readahead: 131072, capable: 1073774593, capable2: 16, want: 1073774593, want2: 0, max_background: 64, congestion_threshold: 48, max_write: 1048576, time_gran: 1 } } instead of the default; init_after_a_failed_reply_negotiates_afresh replies (max_background, congestion_threshold) (64, 48) instead of (0, 0) all 50 pass

At this head, cargo check, cargo clippy --all-targets, and cargo doc --no-deps for fuse are clean, but for the LNK4199 linker message that every linked artifact gets on this machine; cargo xtask fmt --fix changes nothing; and cargo nextest run --profile agent -p virtiofs passes, 230 pass and 3 skipped. The change touches no platform-specific code; this pull request's CI runs the Linux unit 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>
@github-actions github-actions Bot added the release-nvx Targets a branch under feature/microvm/. label Nov 23, 2026
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 23, 2026
…he OpenVMM roadmap

Map position 356, the commit of microsoft/openvmm#5248, which NVX now
pins at b73db6676, 230 commits past the mapped tip:

- 356, fuse: adopt a FUSE_INIT negotiation only once its reply is
  sent. Session::dispatch_init negotiates in a SessionInfo of the
  request's own, from the defaults and the guest's offer alone, and
  stores it in the session, and marks the session initialized, only
  once the reply is sent. It negotiated in the session's own
  SessionInfo, so a reply that could not be sent left the values of a
  negotiation that the guest never received in an uninitialized
  session, whose saved state SessionState::validate refuses, and the
  next FUSE_INIT inherited the failed attempt's max_background and
  congestion_threshold.

Position 356 is not yet assigned to a PR. It changes dispatch_init in
session.rs, in lines that PR13's position 047 and position 328 also
change, documents the adoption on Fuse::init in lib.rs after position
328's paragraph, and adds two tests to position 328's tests of
FUSE_INIT, which use the harness of positions 321 and 325 and PR13's
session state. It is no PR13 fixup, although the failed attempt's
values reached position 047's saved state: the in-place negotiation
is upstream's, and the commit changes lines that position 328 adds,
so it follows position 328. Upstream main, b50d0c979, negotiates in
place too, so its next FUSE_INIT after a failed reply inherits the
same two fields, but it saves no session state; replaying the commit
there conflicts in lib.rs, session.rs, and position 328's init.rs, so
it cannot go upstream on its own.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 23, 2026
…he OpenVMM roadmap

Map position 356, the commit of microsoft/openvmm#5248, which NVX now
pins at b73db6676, 230 commits past the mapped tip:

- 356, fuse: adopt a FUSE_INIT negotiation only once its reply is
  sent. Session::dispatch_init negotiates in a SessionInfo of the
  request's own, from the defaults and the guest's offer alone, and
  stores it in the session, and marks the session initialized, only
  once the reply is sent. It negotiated in the session's own
  SessionInfo, so a reply that could not be sent left the values of a
  negotiation that the guest never received in an uninitialized
  session, whose saved state SessionState::validate refuses, and the
  next FUSE_INIT inherited the failed attempt's max_background and
  congestion_threshold.

Position 356 is not yet assigned to a PR. It changes dispatch_init in
session.rs, in lines that PR13's position 047 and position 328 also
change, documents the adoption on Fuse::init in lib.rs after position
328's paragraph, and adds two tests to position 328's tests of
FUSE_INIT, which use the harness of positions 321 and 325 and PR13's
session state. It is no PR13 fixup, although the failed attempt's
values reached position 047's saved state: the in-place negotiation
is upstream's, and the commit changes lines that position 328 adds,
so it follows position 328. Upstream main, b50d0c979, negotiates in
place too, so its next FUSE_INIT after a failed reply inherits the
same two fields, but it saves no session state; replaying the commit
there conflicts in lib.rs, session.rs, and position 328's init.rs, so
it cannot go upstream on its own.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ppenna
Pedro Henrique Penna (ppenna) merged commit b73db66 into feature/microvm/dev Nov 23, 2026
102 of 105 checks passed
aphrody-labs Bot pushed a commit to aphrody-labs/nvx that referenced this pull request Nov 24, 2026
OpenVMM's chipset device builder registered a PCI chipset device's
place, its bus, device, and function, its PCIe downstream port, or its
devfn as an RCiEP, with its bus resolver before it finalized the add,
which can still fail, as with NameInUse when another state unit has
the device's name (microsoft#1904). A failed add thus left the
dropped device in that place when the chipset was built, where it
answered no configuration access, and a device added there instead
failed the build with a PciConflict or PcieConflict that named the
dropped device.

Pin microsoft/openvmm e8324ea31864e90e3486ec89d11f28d15e2c7b67, one
commit on b73db6676, the head of microsoft/openvmm#5248, which NVX
pinned before this commit:

- vmotherboard: claim a device's PCI slot only once its unit spawns.
  The builder's services only record the places that an 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, so a failed add leaves no place behind and touches no other
  device's. Its tests pass with the fix; without it, the chipset build
  fails with a conflict that names the failed device, on Windows.

Every caller of the add, the microVM loader among them, returns its
error, and NVX's microVMs have no PCI bus or device, so they build and
run as before. 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>
syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 24, 2026
…iscards

OpenVMM's FUSE session called the file system's Fuse::init for each
FUSE_INIT and then did not always adopt its negotiation: it failed the
request with EIO when init wanted a flag that the guest did not offer,
and, since microsoft/openvmm#5248, it adopted nothing when it could not
send the reply. In both cases, it called no Fuse::destroy
(microsoft#1900). The guest completes no such FUSE_INIT, and Linux
sends no FUSE_DESTROY for a connection that it did not initialize, so
the next FUSE_INIT called init again over what the first one had set
up. VirtioFs::init records the negotiation that it agrees to, so after
an INIT reply that the device could not send, a microVM capture failed
with "FUSE session and filesystem negotiation state disagree" until the
guest negotiated again.

Pin microsoft/openvmm 9805f89843ee01890f19d47d2f04f6460bd22024, three
commits on be75ab532, the head of microsoft/openvmm#5255, which NVX
pins below this commit:

- fuse: let FUSE_INIT negotiate only once a session has ended.
  Session::destroy takes the session's lock before it marks the session
  uninitialized and calls Fuse::destroy, as dispatch_init does before it
  calls Fuse::init, so a FUSE_INIT that the session dispatches once it
  is uninitialized negotiates only once the session has ended, and the
  session calls init and destroy one at a time. Its test fails without
  the change, on Windows.
- fuse: call destroy after an init that the session does not adopt.
  dispatch_init calls Fuse::destroy right after an init whose
  negotiation it refuses or whose reply it cannot send, under the
  session's lock, and the session's documentation pairs each init with
  one destroy, before the next init. Its four tests that fail without
  the change, among them a microVM save after an INIT reply that
  cannot be sent, pass with it, on Windows.
- fuse: say which FUSE_INIT waits for the end of a session.
  Comments only: a FUSE_INIT that the session dispatches before
  Session::destroy marks it uninitialized fails as a duplicate, as on
  any initialized session, and only a later one waits for the end of
  the session, which Session::destroy and the first commit's test now
  say.

A FUSE_INIT whose reply is sent negotiates, replies, saves, and
restores as before. 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>
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