Skip to content

openvmm: pin microVM restores of handles opened with access mode 3 - #2146

Merged
Pedro Henrique Penna (ppenna) merged 3 commits into
devfrom
agents/issue-2125-virtiofs-access-mode-3
Nov 25, 2026
Merged

Pedro Henrique Penna (ppenna) merged 3 commits into
devfrom
agents/issue-2125-virtiofs-access-mode-3

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Fixes #2125

Stacked on #2144 (agents/issue-2135-virtiofs-last-node-id), which has merged, so GitHub retargeted this pull request to dev, where only its three commits remain (see OpenVMM pin for the landing order).

What does this pull request change?

A microVM guest that opened a file on a virtio-fs share with access mode 3 (O_ACCMODE == 3), which Linux's open(2) reserves to check for read and write permission and return a descriptor that can neither read nor write, and held it open, could save the VM's state, but restoring that snapshot failed with "saved handle has invalid access mode", on read-write and read-only shares alike, and outside a share's writable paths too. Now a restore reopens such a handle with the same access mode, so it still neither reads nor writes, and the snapshot restores. A restore still refuses a handle whose access mode is O_WRONLY or O_RDWR on a read-only share or child or outside the writable paths.

The fix is in OpenVMM, microsoft/openvmm#5282, which this pull request pins:

  • virtiofs: restore microVM handles opened with access mode 3. In vm/devices/virtio/virtiofs/src/microvm/state.rs, reopen_flags no longer rejects access mode 3, and validate_microvm_state decides whether a saved handle writes with opens_for_writing, the rule with which FUSE_OPEN refuses opens of read-only nodes, applied to the flags that reopen the handle, which drop O_TRUNC: only O_WRONLY and O_RDWR need a writable node. One regression test in microvm/fs_tests.rs.

The NVX commits are the gitlink-only pin; the mapping of the commit, position 390, in the OpenVMM roadmap; and two sentences of Restore that say which handles a restore treats as open for writing, those whose access mode is O_WRONLY or O_RDWR, as OPEN requires, and that a restored handle keeps its access mode, even access mode 3. Start with the OpenVMM diff: git diff --submodule=diff origin/dev...HEAD.

Left out and limitations:

Why is this change needed?

A guest that held such a handle, which FUSE_OPEN gives on any share, made snapshots that saved but never restored.

Root cause: FUSE_OPEN accepts access mode 3, as upstream's does: util::open_flags keeps the access mode, and check_open_readonly refuses on a read-only node only the opens that opens_for_writing names, those for O_WRONLY or O_RDWR, or with O_TRUNC. Position 083 of the microVM chain (6315c16c5, PR18 of the OpenVMM roadmap), which made the microVM's virtio-fs state persistent, saves a handle's open flags as they are, but its reopen_flags rejected access mode 3, and its restore refused on a read-only share every handle whose access mode is not O_RDONLY, a rule that position 160 (2ea6f1e0b) extended to the writable paths. So even without that rejection, a read-only share or child, or a node outside the writable paths, would have refused the handle.

Alternatives rejected:

  • Refusing access mode 3 at FUSE_OPEN, which the issue mentions: it would refuse a valid Linux open that the device already serves, and change live behavior to fix a restore.
  • The issue's patch, which compares the access mode with O_WRONLY and O_RDWR in the validation, is the approach taken, except that the validation calls opens_for_writing, the rule that FUSE_OPEN applies, on the flags that reopen the handle, so that the open and the restore cannot disagree again.
  • Reopening a handle of access mode 3 as O_RDONLY: the restored handle could then read, which the guest's could not.

How was this change validated?

Checks and results. "Before" is OpenVMM 1633b3797, the head of feature/microvm/dev and NVX's pin on dev, with the new test; "after" is the fix on 1633b3797 (ab986fcb3) and, after its rebase onto microsoft/openvmm#5281, the pin, 770bc61e7, whose patch git range-diff reports equal apart from the imports' context. Hosts: Windows 11 Enterprise (local workstation, build 26300, NTFS) and a Linux KVM test VM (Azure Linux 3, kernel 6.18, x86_64, tmpfs).

Check Before After
cargo nextest run --profile agent -p virtiofs -E 'test(a_handle_that_neither_reads_nor_writes_survives_save_and_restore)' (new test), on Windows and Linux fails: "saved handle has invalid access mode" for the read-write share passes on both, at ab986fcb3 and at the pin
The new test with only the reopen_flags change, not committed, on Windows fails: "read-only microVM profile cannot restore a writable handle" for the read-only share, and, with that case left out, "microVM access policy cannot restore a writable handle outside its writable paths" outside the writable paths
cargo check, cargo clippy --all-targets, and cargo doc --no-deps, each -p virtiofs no warnings on Windows and Linux at ab986fcb3; at the pin, clippy on Windows and all three on Linux
cargo nextest run --profile agent -p virtiofs Windows: 241 passed, 3 skipped (ab986fcb3), 242 passed, 3 skipped (pin); Linux: 242 passed, 1 skipped (ab986fcb3), 243 passed, 1 skipped (pin)
cargo xtask fmt --fix no changes, at ab986fcb3 and at the pin
cargo test --locked --manifest-path nvx/Cargo.toml --no-default-features --test openvmm_vectors -- --ignored, and the same with --test openvmm_cpu_profiles pass, 4 and 1 tests: the vectors and CPU profiles that nvx copies are unchanged
python scripts/openvmm_pin.py check-branch --topic --target origin/agents/issue-2135-virtiofs-last-node-id, python scripts/openvmm_pin.py check-roadmap --worktree, python scripts/check_markdown_links.py, git diff --check pass; the three commits are signed
python scripts/local_gates.py --base origin/agents/issue-2135-virtiofs-last-node-id --run --only test-changes markdown-links test-layout openvmm-vectors openvmm-cpu-profiles all pass; no change to existing tests
python scripts/nvx.py check-openvmm-ci --revision 770bc61e7b2c683b092bffb5c8cd83b8696cf54a the six required jobs pass, in run 45657379614

Backend, host OS, host type, and guest: no microVM run. No scenario opens a file with access mode 3, which takes a guest program that calls open(2) with it, and the new test drives the same FUSE_OPEN, save, and restore code that such a guest's requests reach.

OpenVMM's CI of the pin, run 45657379614, passed the six jobs that NVX requires on its second attempt. The first lost build artifacts (for VMM tests) [x64-linux] when its runner received a shutdown signal while it restored a cache, which skipped every x64 run vmm-tests job; one rerun of the failed jobs passed them. The first NVX CI run of this branch, 45660293267, failed only its OpenVMM CI of the pinned revision job for that reason, and the run of the current head, after the rebuild on #2144's amended roadmap commit, is 45670203389.

Left to CI: the microVM scenarios on KVM, MSHV, and WHP, filesystem-snapshot among them, which check that the restores of other handles still work; the NVX CLI jobs, including the nvx-cli gate's Python tests, which this branch does not change and which install Python packages, so they did not run here; and OpenVMM's CI of the pin, which openvmm-ci checks.

Checklist

  • Tests cover the new or fixed behavior, in the layout that
    python3 scripts/check_test_layout.py checks.
  • python3 scripts/check_test_changes.py --base origin/dev lists no change
    to an existing test, or a Changes to existing tests section below
    explains each one.
  • The documentation that the change affects is updated, including
    .github/copilot-instructions.md and the skills when a convention or
    workflow changes.
  • A change to the public API of nvx updates nvx/public-api/ with
    python3 scripts/public_api.py --update.
  • Snapshots, protocols, and on-disk formats stay compatible, or the
    description says how the change versions or migrates them.

Changes to existing tests

None: python scripts/check_test_changes.py --base origin/agents/issue-2135-virtiofs-last-node-id lists no change to an existing test, and the OpenVMM pull request adds one test, and the four imports that it uses, to microvm/fs_tests.rs, and changes no test.

OpenVMM pin

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the OpenVMM revision pin and restore-semantics documentation updates.

No open issues 🎉

What changed in this PR

This PR pins the OpenVMM fix for #2125, allowing microVM snapshots to restore virtio-fs handles opened with Linux access mode 3 while preserving their access restrictions and the saved-state format.

Changes:

  • Records OpenVMM revision 770bc61e7 at roadmap position 390, including its dependencies and upstream mapping.
  • Clarifies that restore preserves handle access modes and requires writable nodes for O_WRONLY and O_RDWR handles.
File Description
doc/​openvmm-upstream-roadmap.md Updates the pinned revision, chain counts, and mapping for the restore fix.
doc/​design/​3.6-host-filesystem.md Documents writable-handle validation and preservation of access mode 3 during restore.

Review effort: Balanced

A microVM guest that opened a virtio-fs file with access mode 3, which
neither reads nor writes, and held it open could save the VM's state,
but its restore failed with "saved handle has invalid access mode", on
read-write and read-only shares alike (#2125). FUSE_OPEN accepts that
access mode, but the restore's validation rejected it, and also took
every access mode other than O_RDONLY for one that writes.

Pin microsoft/openvmm 770bc61e7b2c683b092bffb5c8cd83b8696cf54a, the head
of microsoft/openvmm#5282, one commit on 350018ce4, the head of
microsoft/openvmm#5281, which NVX pins below this commit:

- virtiofs: restore microVM handles opened with access mode 3. A
  restore keeps every access mode, and needs a writable node only for a
  handle whose access mode is O_WRONLY or O_RDWR, as FUSE_OPEN does. Its
  test fails without the fix, on a read-write share, on a read-only
  share, and outside the writable paths, and passes with it, on Windows
  and on Linux, and the virtiofs package's tests pass at the pin on
  both.

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>
… OpenVMM roadmap

Map position 390, the commit of microsoft/openvmm#5282, which NVX now
pins at 770bc61e7, 264 commits past the mapped tip, on 350018ce4,
position 389, the head of microsoft/openvmm#5281:

- 390, virtiofs: restore microVM handles opened with access mode 3. A
  restore reopens a handle that the guest opened with access mode 3,
  which neither reads nor writes, rather than reject it, and needs a
  writable node only for a handle whose access mode is O_WRONLY or
  O_RDWR, as FUSE_OPEN does, so that a snapshot of a guest that holds
  such a handle on a read-only share or outside the writable paths
  restores (#2125).

Position 390 is not yet assigned to a PR. It fixes a defect of PR18's
position 083, whose reopen_flags rejected access mode 3 and whose
restore took every access mode but O_RDONLY for a writable one, as
position 160 kept doing for its writable paths, but its code changes
position 160's line and calls position 334's opens_for_writing, and
its test needs positions 160, 164, and 352, so it is not a PR18
fixup. Of positions 372-389, only 385 and 389 change one of its files,
fs_tests.rs. Upstream main, 8d4e03132, lacks the defect, since it
lacks the microVM's saved state, and replaying the commit there
conflicts in the microVM's state.rs and fs_tests.rs, so it cannot go
upstream on its own.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The host filesystem's design said that a restore validates writable
handles only where the export or child is read-write and every name of
the node is writable, and that it reopens every handle with its saved
open flags. OpenVMM rejected handles with Linux's access mode 3, which
neither reads nor writes, and took them for writable ones, so a guest
that held such a handle, which OPEN gives on any share, could save but
not restore the VM (#2125). With the OpenVMM fix, only handles whose
access mode is O_WRONLY or O_RDWR need writable nodes, as OPEN
requires, and a restored handle keeps its access mode, so say both.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the roadmap and filesystem documentation updates.

No open issues 🎉

Review effort: Balanced

Base automatically changed from agents/issue-2135-virtiofs-last-node-id to dev November 25, 2026 18:39
@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 25, 2026
@ppenna
Pedro Henrique Penna (ppenna) removed this pull request from the merge queue due to a manual request Nov 25, 2026
@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 25, 2026
Merged via the queue into dev with commit bf0ca41 Nov 25, 2026
53 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-2125-virtiofs-access-mode-3 branch November 25, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

virtio-fs microVM: restoring a saved state fails for handles opened with access mode 3

2 participants