Skip to content

openvmm: pin microVM restores of handles opened with O_DIRECT - #2150

Merged
Pedro Henrique Penna (ppenna) merged 2 commits into
devfrom
agents/issue-2128-virtiofs-o-direct-restore
Nov 26, 2026
Merged

Pedro Henrique Penna (ppenna) merged 2 commits into
devfrom
agents/issue-2128-virtiofs-o-direct-restore

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Fixes #2128

Stacked on #2148 (agents/issue-2126-virtiofs-empty-symlink), itself stacked on #2147 and the pull requests below it; only the top two commits belong to this pull request (see OpenVMM pin for the landing order).

What does this pull request change?

A microVM guest that holds a file on a virtio-fs share open with O_DIRECT across a snapshot now restores. Before, the capture succeeded, but every restore of the snapshot failed before the guest ran, with saved state is invalid: saved handle has unsupported open flags, such as 0x4002 for a file opened with O_RDWR | O_DIRECT. The restored handle now reopens the host file with O_DIRECT, as the guest opened it, so it keeps the host's direct I/O: on a Linux host filesystem that enforces O_DIRECT's alignment, such as ext4, it serves block-aligned I/O and fails unaligned I/O with EINVAL, as the saved handle did. A Windows host ignores O_DIRECT, before and after the restore.

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

  • virtiofs: reopen a microVM handle with O_DIRECT on restore. reopen_flags (vm/devices/virtio/virtiofs/src/microvm/state.rs), with which the validation of a saved state checks each handle's flags and the restore reopens the handle, now keeps O_DIRECT. One regression test, handles_opened_with_o_direct_restore_with_it, in microvm/fs_tests.rs, and create_with_flags of microvm/policy_tests.rs becomes pub(super) for it.

The NVX commits are the gitlink-only pin and the mapping of the commit, position 393, in the OpenVMM roadmap, as a PR18 fixup. Restore already says that the server "reopens every handle with its saved open flags, except that it drops O_CREAT, O_EXCL, and O_TRUNC", which the fix makes true of O_DIRECT, so no documentation changes. Start with the OpenVMM diff: git diff --submodule=diff origin/agents/issue-2126-virtiofs-empty-symlink...HEAD.

Left out and limitations:

Why is this change needed?

A guest program that keeps a file open with O_DIRECT, as databases and benchmarks do, made every snapshot of its VM unrestorable, although the capture itself succeeded, so the failure appeared only at restore.

Root cause: FUSE_OPEN and FUSE_CREATE accept O_DIRECT (util::open_flags and create_flags), keep it in the flags that the handle records, which the save stores, and pass it to the host open, which Linux performs with it and Windows ignores. reopen_flags refused any saved flag outside its own list, which lacked O_DIRECT since position 083 (6315c16c5, in PR18 of the OpenVMM roadmap) made microVM handles persist.

Alternatives rejected:

  • Dropping O_DIRECT when the restore reopens the handle, or before the host open of every FUSE_OPEN and FUSE_CREATE: either would make the restore pass, but the first would change the handle's behavior across the snapshot, since a reopened handle would then accept, on ext4, unaligned I/O that the saved one failed, and the second would change every live O_DIRECT handle, which upstream's fuse_flags_only_consume_guest_flags (Reject unsafe filesystem opens across virtio-fs and virtio-9p openvmm#4783) expects to keep the flag.
  • The issue's patch, the same allow-list line, is what the fix does; the test also checks reopen_flags directly, so that it fails on any host, and opens the FUSE_CREATE handle too, whose saved flags carry O_CREAT.

How was this change validated?

This branch was restacked onto the rewritten agents/issue-2126-virtiofs-empty-symlink (0415be91945), whose OpenVMM pin, e61fa5326, did not change; its pin and roadmap commits were rebuilt on it, and the checks of the NVX commits below ran again there.

Checks and results. "Before" is OpenVMM 1633b3797, the head of feature/microvm/dev, or the release built from it; "after" is the fix, as 2cb90b693 on 1633b3797 and, after its rebase onto microsoft/openvmm#5284, as the pinned 5af753b17, whose patch git range-diff reports equal but for the context of its one new import.

Check Before After
cargo nextest run --profile agent -p virtiofs -E 'test(handles_opened_with_o_direct_restore_with_it)' (new test), on Windows 11 (NTFS) and Linux (ext4) fails at its first check on both: saved handle has unsupported open flags 0x4002; without that check, the round trip fails at the restore, with 0x4002 on Windows and 0x4041 on Linux passes on both, without skipping, with the fix on 1633b3797 and at 5af753b17
cargo check, cargo clippy --all-targets, and cargo doc --no-deps, each -p virtiofs no warnings on Windows and Linux with the fix on 1633b3797, and clippy again on both at 5af753b17, apart from the linker's LNK4199 notes about unused delay-loaded DLLs, which every Windows build of this workstation prints for build scripts
cargo nextest run --profile agent -p virtiofs Windows: 241 passed, 3 skipped with the fix on 1633b3797, and 244 passed, 3 skipped at 5af753b17; Linux: 242 passed, 1 skipped, and 245 passed, 1 skipped
cargo xtask fmt --fix no changes, at 2cb90b693 and 5af753b17
One-off test through VirtioFs, not committed, on Linux's ext4: reads and writes through a handle opened with O_RDWR | O_DIRECT, then a save, a restore, and reads through the restored handle 4 KiB at offset 0 and 512 bytes at offset 512 read and write; 100 bytes at offsets 0 and 1 fail with EINVAL; after the restore, 4 KiB at offset 0 reads and 100 bytes at offset 1 fail with EINVAL, as before the save
python3 scripts/nvx.py test-microvm --backend kvm --scenario filesystem-snapshot, with filesystem-live.sh changed, not committed, so that two nvx-device-io file ... write 15000 65536 direct writers hold files open with O_DIRECT across the capture, one by FUSE_OPEN (existing) and one by FUSE_CREATE (create) fails at the first restore: saved state is invalid: saved handle has unsupported open flags 0x4002 passes: both restores succeed, and in each, both writers go on writing through their restored handles, flush, and exit 0
python3 scripts/nvx.py test-microvm --backend kvm with the unmodified filesystem-snapshot, filesystem-shares, filesystem-policy, filesystem-owner, denied-filesystem-paths, filesystem-comma-paths, platform-filesystem, and platform-aggregate-export scenarios all pass
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, at 5af753b17: the vectors and CPU profiles that nvx copies are unchanged
python scripts/openvmm_pin.py source 5af753b17035f548039cab531027a3cc635ac4fa --pr 5285 good signature; the pull request's head
python scripts/openvmm_pin.py check-branch --topic --target origin/agents/issue-2126-virtiofs-empty-symlink, python scripts/openvmm_pin.py check-roadmap --worktree, python scripts/check_markdown_links.py, git diff --check, python scripts/nvx.py verify pass; both commits are signed
python scripts/local_gates.py --base origin/agents/issue-2126-virtiofs-empty-symlink --run --only test-changes markdown-links test-layout openvmm-vectors openvmm-cpu-profiles all pass; no change to existing tests

Backend, host OS, host type, and guest: KVM on a Linux test virtual machine (Azure Linux 3, kernel 6.18, x86_64), with its /tmp and the scenarios' shares on ext4, and the Alpine guest and kernel of release v0.1.0-dev.fb28ca4c3f07, whose OpenVMM CI built from 1633b3797, the "before" OpenVMM. The "after" OpenVMM was built there from 2cb90b693 with python3 scripts/nvx.py build-openvmm --backend kvm --skip-restore. The Windows checks ran on a Windows 11 Enterprise (NTFS) workstation, whose host type is not classified, where O_DIRECT changes nothing on the host.

Left to CI: OpenVMM's CI of the pin, which is running; this pull request's CI, with its KVM, MSHV, and WHP microVM jobs, which build OpenVMM from the pin, and its NVX CLI jobs on Linux and Windows; no MSHV host ran here, and WHP microVM runs were left to CI on this shared, loaded workstation; and the nvx-cli and openvmm-ci local gates: the first starts with a pip install and tests the scripts, which this branch does not change, and the second waits for OpenVMM's CI of the pin.

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-2126-virtiofs-empty-symlink lists no change to an existing test, and the OpenVMM pull request adds one test and changes none.

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 recorded for the roadmap update documenting the OpenVMM pin and its O_DIRECT restore fix.

No open issues 🎉

What changed in this PR

This PR pins OpenVMM’s fix for #2128 in NVX, allowing microVM snapshots to restore virtio-fs handles opened with O_DIRECT while preserving their host behavior.

Changes:

  • Updates the roadmap’s recorded pin to 5af753b17, position 393, and adjusts chain counts and the diagram.
  • Documents the restore fix, its dependencies, and why it cannot be upstreamed independently.
File Description
doc/​openvmm-upstream-roadmap.md Maps the new OpenVMM pin and explains the O_DIRECT restore fix.

Review effort: Balanced

A microVM guest that holds a file on a virtio-fs share open with
O_DIRECT could save the VM's state, but not restore it: the restore
refused the saved handle with "saved handle has unsupported open flags
0x4002" for O_RDWR | O_DIRECT, from FUSE_OPEN, and with 0x4041 for
O_WRONLY | O_CREAT | O_DIRECT, from FUSE_CREATE (#2128). OpenVMM's
reopen_flags, which checks a saved handle's flags and gives those with
which a restore reopens it, refused every flag outside a list that
lacked O_DIRECT, although FUSE_OPEN and FUSE_CREATE accept it, keep it
in the handle's flags, and open the host file with it.

Pin microsoft/openvmm 5af753b17035f548039cab531027a3cc635ac4fa, the
head of microsoft/openvmm#5285, one commit on e61fa5326, the head of
microsoft/openvmm#5284, which NVX pins below this commit:

- virtiofs: reopen a microVM handle with O_DIRECT on restore.
  reopen_flags keeps O_DIRECT, so a restore reopens the handle as the
  guest opened it, with the host's O_DIRECT semantics. Its test fails
  without the fix on Windows and Linux and passes with it, and the
  virtiofs tests pass at the pin on both. On KVM, a filesystem-snapshot
  run whose guest held files open with O_DIRECT across the capture
  failed its restore before the fix and restored after it.

No saved-state, protocol, or ABI format, and no version of any of
them, changes; a snapshot that an earlier release saved with such a
handle now restores. The protocol vectors and CPU profiles that nvx
copies are unchanged.

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

Map position 393, the commit of microsoft/openvmm#5285, which NVX now
pins at 5af753b17, 267 commits past the mapped tip, on e61fa5326,
position 392, the head of microsoft/openvmm#5284, as a PR18 fixup:

- 393, virtiofs: reopen a microVM handle with O_DIRECT on restore.
  reopen_flags keeps O_DIRECT, which FUSE_OPEN and FUSE_CREATE accept,
  record, and open the host file with, so that a restore reopens a
  handle that the guest opened with O_DIRECT as the guest opened it,
  rather than refuse the saved state with "saved handle has
  unsupported open flags" (#2128).

Position 393 fixes a defect of PR18's position 083, whose list in
reopen_flags lacked O_DIRECT, and needs nothing that a later position
adds but, for its test, position 164's helpers, position 334's
create_with_flags, and position 335's get_file, so, as position 389
does for position 081, it is a PR18 fixup: fold it into position 083,
where its line applies as it is, and its test into position 335. The
Scope, the DAG, the fold sentences after it, the table, PR18's node,
its row in the PR summary, and its commit mapping count it. Of
positions 372-392, only 385, 389, and 390 change its files: they add
other tests to fs_tests.rs, and position 390 also removes position
083's check of the access mode from reopen_flags, after the list.
Upstream main, 8d4e03132, lacks the microVM's saved state, and
replaying the commit there conflicts in the microVM's state.rs,
fs_tests.rs, and policy_tests.rs, so it cannot go upstream on its own.

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 update documenting the OpenVMM pin for restoring O_DIRECT virtio-fs handles.

No open issues 🎉

Review effort: Balanced

Base automatically changed from agents/issue-2126-virtiofs-empty-symlink to dev November 25, 2026 23:52
@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 25, 2026
Merged via the queue into dev with commit 241a938 Nov 26, 2026
86 of 93 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-2128-virtiofs-o-direct-restore branch November 26, 2026 00:40
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: an open handle with O_DIRECT prevents saved-state restoration

2 participants