Repository navigation
[DO NOT REVIEW] virtiofs: fail a microVM save while the guest holds a replaced object - #5254
Merged
Pedro Henrique Penna (ppenna) merged 7 commits intoNov 24, 2026
Conversation
The comment of VirtioFs::insert_inode said that, if the file system supports stable inode numbers and an inode already exists with the device and inode number of the inserted one, the existing inode is returned. That reads as a key over the whole file system, and it leaves out the file type that a match needs and the volumes without stable file IDs. InodeMap's summary still said that the map tracks inodes by their actual inode number. InodeMap indexes the inodes that insertions may reuse by DedupKey: (volume ID, device number, inode number) on a volume with stable file IDs, and (volume ID, path) on any other. Both keys hold the volume ID, so the device and inode numbers identify a candidate only among one volume's inodes, and a host object that two children of an aggregate reach gets a node in each. A candidate takes the inserted inode's name and lookup only if it has the same file type; one of another type leaves the key to the inserted inode, which gets a node of its own. Say so in the comment of insert_inode, without claiming that every file system has stable file IDs: a Linux volume always reports them, and a Windows volume only if its file system can open files by ID. Say in InodeMap's summary that it indexes the inodes that insertions may reuse by DedupKey. No code changes. The comment now states the invariant of section 3.6.4 of NVX's host filesystem design, under which the server matches a volume's objects by host device and inode number, or by name on volumes whose inode numbers are not stable. On Windows, a scratch test, not kept, checked the comment: two aggregate children of one directory looked up its file as two nodes with equal device and inode numbers, while a second lookup through one child kept that child's node. For virtiofs, cargo check, cargo clippy --all-targets, cargo doc --no-deps with warnings denied, with and without private items, and the package's tests pass, and cargo xtask fmt --fix changes nothing. Refs microsoft/nvx#1905 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TestChipset, the MMIO-only chipset on which device unit tests, such as vpci's, build their devices, found the offset of an address in one of its regions by comparing the address with the region's exclusive end, base + len (microsoft/nvx#1902). For a region whose last byte is u64::MAX, that end does not fit the address type, although map accepts the region, since it checks only that the last byte fits. The first lookup in such a region then panicked with "attempt to add with overflow" where overflow checks are on, as in debug builds, and otherwise wrapped to an empty range, so that the region gave no offset for any address. vmotherboard, the production chipset, had the same defect until "vmotherboard: find offsets in an I/O region that ends at the top" (#5168), so a test on TestChipset could disagree with it about such a region. No device that a test builds on TestChipset looks up an offset today, so the defect is latent. Subtract the base instead, with checked_sub, and accept the address when the offset is below the region's length, as vmotherboard does, so that no end address is formed. The result is the same for every other region and address. Test: mmio_region_ending_at_the_top_finds_its_offsets, in test_chipset's tests, applies the boundary cases of #5168 to TestChipset: it maps a 4 KiB region at u64::MAX - 0xfff, and checks the offsets of the byte before it and of its first and last bytes, then again after a remap one byte lower, which ends the region just below the top, and after an unmap. At feature/microvm/dev 899dcd6, it fails with "attempt to add with overflow" in a debug build, and, in a release build, without overflow checks, with no offset for the region's first byte. It passes with the fix in both. The tests now initialize tracing with test_with_tracing, as OpenVMM's unit tests do. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
FuzzChipset, on which the chipset and IDE fuzzers run their devices, found the offset of an address in one of its port I/O or MMIO regions by comparing the address with the region's exclusive end, base + len (microsoft/nvx#1902). For a region whose last byte is the top of its address space, such as 2 ports at 0xfffe or an MMIO region that ends at u64::MAX, that end does not fit the address type, although map accepts the region, since it checks only that the last byte fits. The first lookup in such a region then panicked with "attempt to add with overflow" where overflow checks are on, as in debug builds, and otherwise wrapped to an empty range, so that the region gave no offset for any address. A fuzzed device that looked up an offset there would thus crash, or ignore an access to its own region, where vmotherboard, the production chipset, finds the offset since "vmotherboard: find offsets in an I/O region that ends at the top" (#5168). None of the devices that the fuzzers run today looks up an offset, so the defect is latent. Subtract the base instead, with checked_sub, and accept the address when the offset is below the region's length, as vmotherboard does, so that no end address is formed. The result is the same for every other region and address, for both widths that impl_intercept! generates. Tests, in the crate's new tests module: pio_region_ending_at_the_top_finds_its_offsets and mmio_region_ending_at_the_top_finds_its_offsets apply the boundary cases of #5168 to FuzzChipset: they map a 2-port region at 0xfffe and a 4 KiB MMIO region at u64::MAX - 0xfff, and check the offsets of the byte before each region and of its first and last bytes, then again after a remap one byte lower, which ends the region just below the top, and after an unmap. At feature/microvm/dev 899dcd6, both fail with "attempt to add with overflow" in a debug build, and, in a release build, without overflow checks, with no offset for the region's first byte. Both pass with the fix in both builds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A successful FUSE_LINK reply hands the guest a lookup reference to the target node, but VirtioFs::link took that reference, with inc_lookup, only after its host link, and without the inode map's lock (microsoft/nvx#1897). FORGET removes a node under that lock once its lookup count reaches zero, and the guest sends it on the high-priority queue, whose worker runs independently of the request queue's. A FORGET that dropped the guest's other references to the target while the LINK ran therefore removed the node, and the LINK then counted its reference on the removed inode and replied with the node's ID: every later request about the node failed with EINVAL (request for unknown inode), though the reply had handed the guest a reference to it, and the new name went to an inode that nothing tracked. LOOKUP, CREATE, MKNOD, READDIRPLUS, and the other requests that return a node take their reference in InodeMap::insert or insert_reserved, under the lock, so they either find the node still mapped or map the object anew. LINK now takes its reply's reference when it resolves the target, with VirtioFs::reference_inode, which increments the node's lookup count under the inode map's lock. A FORGET thus either removed the node first, and the LINK fails with EINVAL, as a request about any unknown node does, or leaves the node mapped until the guest forgets the reply's reference too. A LINK that fails afterwards, before or at its host link, releases the reference when its LookupReference drops, as a FORGET of it would: through InodeMap::forget, which FORGET now uses too, and which removes the node if the guest has forgotten it meanwhile. inc_lookup now reports whether it changed the count, so that a failed LINK leaves a count that stopped at u64::MAX there. The microVM profile shares this path and only adds its alias bounds, so it needs no change of its own. Tests, in virtiofs' tests, on a direct and on a microVM share: link_keeps_its_node_through_a_concurrent_forget holds the target's path lock, which a LINK needs to record its new name after its host link, so that the LINK stops there; it then forgets the guest's lookup of the target, lets the LINK finish, and checks that the reply's node answers GETATTR until the guest forgets the reply's reference too. failed_link_retains_no_reference checks that a LINK that fails with ENOTDIR before its host link, or with EEXIST at it, leaves no reference, and released_link_reference_removes_a_forgotten_node, on a direct share, that the release of a LINK's reference that a FORGET overtook removes the node. Without the fix, at 899dcd6, the first test fails on Windows: GETATTR of the reply's node fails with EINVAL. With it, the three tests and the package's other tests pass on Windows. Without the release of a failed LINK's reference, the other two fail. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A microVM save succeeded while the guest held an object whose name the host had given to another object, as host software does when it renames a new file over a file that the guest holds open, and the snapshot then failed to restore (microsoft/nvx#1901). Once the guest had looked the name up again, which gives the new object a node of its own, the held node and the new one both recorded the name, and the restore failed with "saved aliases are duplicated or ambiguous"; without that lookup, it failed with "saved guest inode ID does not match the attachment". The save took the identity that it records for a node from whatever object the node's first name reached at the save, and checked only that the node's other names reached the same object, never that the object was the node's own. So it recorded the held node with the new object's identity, under the guest inode number of the held object, which no restore accepts, and a restore that did would have bound the held node to the new object. The save now records each node's own identity, the device, inode number, and file type of the object that the node got, from which its guest inode number derives, and checks every name of the node against it, as a restore does. A name that reaches another object fails the save, with an error that names the node and its guest inode number and says that the guest must release the object, as a name that is gone already fails it. The held object has no name left by which a restore could reopen it, and a snapshot records nothing else, so no save can keep it; the snapshot format is unchanged. Once the guest releases the object, the save succeeds, and its restore binds the name to the new object. a_held_file_that_the_host_replaces_fails_the_save_until_released holds a file open, has the host rename a new file over it, with and without a lookup of the new file, and checks that the save fails and says why, that the guest's handle still reads the old file, that a snapshot saved before the replacement does not restore, and that once the guest releases the file, the save succeeds and its restore gives the name the new file's node and identity. Without the fix, at 899dcd6, on Windows the save succeeds, and the restore of such a save fails with the errors above. With the fix, the test and the package's other tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A microVM save now fails when a name of a node reaches another object than the node's own (microsoft/nvx#1901), but a restore also rejects two nodes that share a name or the key of one object, and a handle that its node's names do not reopen, which a save still let through. A host makes either when it reuses inode numbers or puts an object back. When it gives the inode number of an object that the guest holds to an object of another type, and then to one of the held object's type again, while the guest looks up each, two nodes name one object; they save, and the restore fails with "saved aliases are duplicated or ambiguous", or, when their names differ, with "saved inode aliases are ambiguous". When the guest opens a node while the host has replaced its object, as Linux does when a program reopens a file through /proc/self/fd, its handle reaches the replacement; once the host gives the node's name its object back, the handle saves, and the restore fails with "reopened handle identity does not match". The save now keys the nodes that it records by their names and by their dedup keys, as a restore does, and fails when two nodes share either, with an error that names both and says that the guest must release one of them. It also checks each handle against its node's identity, and fails with an error that names the handle and its node and says that the guest must close the handle. The snapshot format is unchanged. nodes_that_name_one_object_fail_the_save gives a file's inode number to a directory and then to a file again, at the file's name or at another name of it, as the tests of retyped objects do, and a_handle_of_another_object_than_its_node_fails_the_save opens a node while the host has replaced its object and then puts the object back. Each checks that the save fails with its error, and that it succeeds once the guest releases the extra node or handle. Without this change, on top of the previous commit, on Windows, both saves succeed, and their restores fail with the errors above. With it, both tests and the package's other tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
requested review from
a team and
Anatol Belski (weltling)
as code owners
November 23, 2026 22:48
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
The comments of the microVM save's checks of its nodes said that a restore keys the nodes by their names and objects, so that no two nodes may share either, and that two nodes name one object after the host gives the inode number of an object that the guest holds to another object of its type. A restore, and so the save, keeps apart only the nodes of one volume, since an aggregate gives each child a node of its own for a host object that both children reach, as through a hard link. And a host that gives a held object's inode number to another object of its type gives the guest the held object's node for it, since a lookup reuses that node; two nodes of one object arise only when an object of another type took the number in between, as the tests of the check show. The comments now say so. The code, its errors, and its tests are unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 23, 2026
Pedro Henrique Penna (ppenna)
merged commit Nov 24, 2026
5e0e72d
into
feature/microvm/dev
135 of 139 checks passed
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 24, 2026
…VMM roadmap Map positions 362-364, the commits of microsoft/openvmm#5254, which NVX now pins at 5e0e72d72, 238 commits past the mapped tip: - 362, virtiofs: fail a microVM save while the guest holds a replaced object. The save records each node's own identity, the device, inode number, and file type of the object that the node got, and checks every name of the node against it, as the restore does. It took the identity from the object that the node's first name reached, so once host software had renamed a new file over a file that the guest held open, it saved a snapshot that failed to restore. - 363, virtiofs: fail a microVM save of nodes or handles that a restore rejects. The save also fails when two nodes of one volume share a name or a dedup key, or when a handle reaches another object than its node, which the restore rejects too. - 364, virtiofs: say which nodes a microVM save keeps apart. Two comments of position 363's checks now say that they keep apart only the nodes of one volume, and how two nodes of one object arise. Positions 362-364 are not yet assigned to a PR. They change the node and handle loops of save_microvm_state, in lines that PR18's position 083 adds, remove position 083's validate_saved_identity, add VirtioFsInode::object_identity after position 083's from_saved, and add three tests after position 083's test of hard link aliases, which call the policy tests' helpers that position 160 adds and position 164 exports. They fix defects of position 083's save, but position 362 compares by the device that position 329 records, through position 330's device_nr, and their tests need position 164's export, so they are no PR18 fixups, and they follow position 330. Upstream main, 5d6ab1cfa, lacks the microVM's snapshots; replaying the commits there conflicts in the microVM's files and in the Guide's virtio-fs page, which it lacks, so they cannot go upstream on their own. 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
OpenVMM's FUSE session did not know FUSE_COPY_FILE_RANGE_64, opcode 53, which Linux 6.18 sends first for each copy_file_range(2) on a virtio-fs share, whatever protocol version the session negotiated (microsoft#1899). Its catch-all for unknown opcodes failed the request with EINVAL, so the system call failed in NVX's 6.18.38 guests, whereas only ENOSYS makes Linux resend the copy as FUSE_COPY_FILE_RANGE and, after ENOSYS to that one too, copy the data itself. Pin microsoft/openvmm be75ab532b77ce90fa46371f2ced3cb547fd00c7, one commit on 5e0e72d72, the head of microsoft/openvmm#5254, which NVX pins below this commit: - fuse: fail FUSE_COPY_FILE_RANGE_64 with ENOSYS, not EINVAL. The session decodes opcode 53 as it decodes FUSE_COPY_FILE_RANGE and fails it with ENOSYS without calling the file system, which keeps answering FUSE_COPY_FILE_RANGE alone, as Fuse::copy_file_range now documents. A short request still fails with EINVAL. Its two tests fail without the fix, with EINVAL instead of ENOSYS, and pass with it, on Windows. Two copy_file_range(2) calls of 1 MiB in a 6.18.38 guest on WHP failed with EINVAL before the fix and copied the file after it, with the guest's own copy once both variants had failed with ENOSYS. The session still negotiates protocol 7.39. 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>
Aaqibhafeez Khan (Aaqibhafeezkhan)
pushed a commit
to Aaqib-OSS/nvx
that referenced
this pull request
Nov 24, 2026
… roadmap Map position 369, the commit of microsoft/openvmm#5260, which NVX now pins at 8c1204c68, 243 commits past the mapped tip: - 369, virt_support_apic: select a reserved DFR model by bit 31. cluster_mode selects the flat model for a reserved model of the xAPIC DFR whose bit 31 is set and the cluster model for one whose bit 31 is clear, as in Hyper-V's APIC, rather than reach unreachable!, for a guest's write and a restore alike, which aborted the VMM of WHP's user-mode APIC and of OpenHCL's SNP and TDX backends. Position 369 is not yet assigned to a PR. It changes lib.rs of virt_support_apic, where PR10's position 026 makes TIMER_FREQUENCY public, none of the lines that it changes. It is not a fixup: the unreachable! is upstream's. It applies to upstream main, efe0b08df, as it is, and virt_support_apic type-checks and passes its tests on the merged tree, so it can go upstream on its own. microsoft/openvmm#5247 proposes another fix of the same panic upstream, which ignores such a write; replaying the commit on it conflicts in lib.rs, which the remarks record for the next rebase. The Scope now names 9805f8984, position 368, as the head of feature/microvm/dev, since microsoft/openvmm#5254, microsoft/openvmm#5255, and microsoft/openvmm#5257 landed positions 362-368 there. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Refs microsoft/nvx#1901.
Stacked on #5253; only the top 3 commits belong to this PR.
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/devto that exact commit, after #5253 and the pull requests below it, not with the merge button, which squashes.What and why
VirtioFs::save_microvm_state, invm/devices/virtio/virtiofs/src/microvm/fs.rs, saved a microVM's virtio-fs state while the guest held an object whose name the host had given to another object, as host software does when it renames a new file over a file that the guest holds open, and the snapshot then failed to restore:The save took the identity that it records for a node from whatever object the node's first name reached at the save, and checked only that the node's other names reached the same object, never that the object was the node's own. So it recorded the held node with the new object's identity, under the guest inode number of the held object, which no restore accepts; a restore that accepted it would have bound the held node to the new object.
The first commit has the save record each node's own identity, the device, inode number, and file type of the object that the node got, from which its guest inode number derives (the new
VirtioFsInode::object_identity), and check every name of the node against it, as a restore does. A name that reaches another object fails the save, with an error that names the node and its guest inode number and says that the guest must release the object, as a name that is gone already fails it. The held object has no name left by which a restore could reopen it, and a snapshot records nothing else, so no save can keep it. Once the guest releases it, as a Linux guest does when it closes the file, since the microVM profile's entry timeout is zero, the save succeeds, and its restore binds the name to the new object.validate_saved_identity, which only compared a node's names with each other, is removed. The Guide's "Snapshot attachments" section documents the capture failure.The second commit has the save refuse the other states that a restore rejects, which a host makes when it reuses inode numbers or puts an object back:
InodeMap::dedup_entrygives each a node of its own); their restore failed with "saved aliases are duplicated or ambiguous", or, when their names differ, with "saved inode aliases are ambiguous";/proc/self/fd, and the host then gives the node's name its object back; its restore failed with "reopened handle identity does not match".The save now keys the nodes that it records by their names and by their dedup keys, as a restore does, and fails when two nodes share either, with an error that names both and says that the guest must release one of them; and it checks each handle against its node's identity, with an error that names the handle and its node and says that the guest must close the handle.
The third commit corrects two comments of the second's checks, which said that no two nodes may share a name or an object, and that two nodes of one object arise when the host gives a held object's inode number to another object of its type: a restore, and so the save, keeps apart only the nodes of one volume, since an aggregate gives each child a node of its own for a host object that both reach, and a lookup of an object of the held object's type with its inode number reuses the held node, so two nodes of one object arise only when an object of another type took the number in between. It changes no code.
Each new check refuses only a state that the restore rejects, or, for a name that now reaches an object with the node's device and inode number but another file type, one that it would have restored as that type. No other snapshot that restored before is refused, and the restore is unchanged.
A limit remains: a replacement with the device, inode number, and file type of the object that a node holds, as when the host removes a file that the guest holds only through a lookup and creates one that reuses its inode number, passes every check, and a restore binds the node to the replacement. The running device already resolves the node to the replacement, since it keys nodes by that identity, and nodes hold no host descriptor; telling the two apart would need a host reference per node or a generation number in the snapshot, a format change. An open handle keeps its object, so its inode number cannot be reused while the guest holds the handle.
Upstream main has no microVM profile, so these commits, which change only the microVM save, cannot go upstream on their own.
No saved-state, protocol, or ABI format, and no version of any of them, changes.
Tests
In
microvm/fs_tests.rs:a_held_file_that_the_host_replaces_fails_the_save_until_releasedholds a file open and has the host rename a new file over it, with and without a lookup of the new file, and checks that the save fails and says why, that the guest's handle still reads the old file, that a snapshot saved before the replacement does not restore, and that once the guest releases the file, the save succeeds and its restore gives the name the new file's node and identity.nodes_that_name_one_object_fail_the_savegives a file's inode number to a directory and then to a file again, at the file's name or at a hard link of it, as the tests of retyped objects do, and checks that the save fails until the guest forgets the extra node.a_handle_of_another_object_than_its_node_fails_the_saveopens a node while the host has replaced its object, then puts the object back, and checks that the save fails until the guest closes the handle.Validation
With Rust 1.97.1,
cargo nextest run --profile agent -p virtiofson Windows 11, local, without each fix and at the second commit,b2ac1073d:09966aa63, the head of #5253, with this PR's tests)At
899dcd63f, below the stack, a scratch probe that was not committed restored such saves and got the errors above: "saved aliases are duplicated or ambiguous" for the held file after a lookup of the new file, the error of microsoft/nvx#1901, and for two nodes under one name; "saved guest inode ID does not match the attachment" without that lookup; "saved inode aliases are ambiguous" for two nodes under different names; and "reopened handle identity does not match" for the handle.At each of the two commits,
cargo check,cargo clippy --all-targets, andcargo doc --no-depsforvirtiofsare clean, apart from theLNK4199linker message that every linked artifact gets on this machine, andcargo nextest run --profile agent -p virtiofspasses: 234 pass and 3 skipped at the first, 236 pass and 3 skipped at the second, and the same at the third, this head, where the four checks are clean too.cargo xtask fmt --fixchanges nothing at any of them. Before the rebase onto #5253, the same two commits on899dcd63falso passedcargo clippy --all-targets --target x86_64-unknown-linux-gnu -p virtiofs. The change has no platform-specific code; the shared Linux test hosts were unreachable, so this pull request's CI ran the Linux unit tests: run 45287652986, at this head, passedunit tests [x64-linux],unit tests [x64-windows],quick check [fmt, clippy x64-linux], andrun vmm-testsonx64-linux-amd-kvm,x64-linux-intel-mshv,x64-windows-intel, andx64-windows-amd, the last of them after one rerun ofbuild artifacts (for VMM tests) [aarch64-linux], whose runner had shut down. Itsx64-windows-amd-snpVMM tests failed, and with themopenvmm checkin gates. NVX's pin of this head, microsoft/nvx#2068, passed its microVM tests on KVM, MSHV, and WHP in run 45290465963.