Skip to content

openvmm: pin the reserved DFR models of the user-mode APIC - #2092

Merged
Pedro Henrique Penna (ppenna) merged 2 commits into
devfrom
agents/issue-1473-apic-dfr-reserved-model
Nov 24, 2026
Merged

Pedro Henrique Penna (ppenna) merged 2 commits into
devfrom
agents/issue-1473-apic-dfr-reserved-model

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #1473

What does this pull request change?

It pins microsoft/openvmm 8c1204c68381d11d90e58c4ee710a879f71fb601
(microsoft/openvmm#5260), one commit on feature/microvm/dev, which
makes OpenVMM's local APIC emulator, virt_support_apic, select the model of a
reserved xAPIC DFR value by bit 31 instead of reaching unreachable! and
aborting the VMM, and maps that commit in the OpenVMM roadmap as position 369.

  • Before: a guest write of a reserved DFR model (bits 31:28 other than
    0b1111 or 0b0000) panicked with entered unreachable code: Unknown DFR value, which aborted the VMM. Examples are
    mov dword [0xfee000e0], 0x7fffffff and a one-byte write of 0x70 at
    0xfee000e3. A restore of a saved state whose DFR held a reserved model
    panicked in the same way.
  • After: a reserved model selects the flat model when bit 31 is set and the
    cluster model when bit 31 is clear, and the emulator logs a rate-limited
    warning. The DFR reads back the selected model (0xffffffff or
    0x0fffffff), and a save stores that model, so no saved state holds a
    reserved model. A restore decodes a saved DFR in the same way.

Start the review at cluster_mode in
openvmm/vmm_core/virt_support_apic/src/lib.rs, then read the new test,
dfr_reserved_model_follows_bit_31, at the end of that file.

Commits:

  1. openvmm: pin the reserved DFR models of the user-mode APIC changes only the
    gitlink.
  2. doc: map the reserved DFR models of the user-mode APIC in the OpenVMM roadmap changes only doc/openvmm-upstream-roadmap.md.

Scope and limitations:

  • NVX's microVMs use the APICs of KVM, MSHV, and WHP itself, and never run this
    emulator, so their behavior does not change.
  • Nothing in nvx, the guest, or the scripts changes.
  • The emulator serves WHP's user-mode APIC and OpenHCL's SNP and TDX backends.
    The user-mode APIC is selected by --hypervisor whp:user_mode_apic or by
    --hv with whp:no_enlightenments. This pull request tests the emulator's
    behavior with unit tests, and does not boot a guest in those configurations.

Why is this change needed?

The root cause is in cluster_mode. It decoded only the two architectural
models and called unreachable! for the 14 reserved models. Every xAPIC write
of the DFR, whether of the whole register or of the high byte that
is_valid_apic_access allows, reaches it unfiltered. Every restore reaches it
too, even in x2APIC mode. x2APIC mode has no DFR, and a write of MSR 0x80e
stays unimplemented and faults. OpenVMM's rules say that it must never panic on
guest input. The unreachable! comes from upstream, and no chain commit
touched it.

Design: for a reserved model, bit 31 selects the model, as the issue asks.
Hyper-V's APIC, which WHP uses unless the user-mode APIC is selected, does the
same. The issue measured it, and a scratch guest of a few bytes confirmed it on
WHP's in-hypervisor xAPIC. That guest wrote the DFR and read it back in 32-bit
flat mode, on a local Windows 11 build 26300 host with an Intel Core i9-12900H.

After the writes of the new test, each of which switches the model, that APIC
read back exactly what the test expects:

Writes Value read back
0xefffffff, 0x8fffffff, 0xffffffff, high byte 0x80 0xffffffff
0x0fffffff, 0x7fffffff, 0x12345678, 0x00000000, high byte 0x70 0x0fffffff

Every switch of the model followed bit 31. On this host, a write that keeps the
model reads back as written, presumably from the virtual-APIC page of
APIC-register virtualization. Examples are 0x8fffffff in the flat model and
0x00000000 in the cluster model. The issue's host read back the model for
such writes too.

The emulator stores only the model. Its DFR therefore reads back
0xffffffff or 0x0fffffff, as it already does for the architectural values,
and a save stores that model. As a result, no saved state holds a reserved
model, which an earlier OpenVMM would fail to restore.

OpenVMM documents user_mode_apic as using the user-mode APIC emulator instead
of WHP's in-hypervisor APIC. With this change, a guest selects the same model
with either APIC. The same rule covers guest writes and restores.

Alternatives considered and not taken:

  • Ignore the write. virt_support_apic: ignore DFR writes with a reserved model openvmm#5247 has been open upstream since
    2026-11-23. It ignores a write of a reserved model, so the APIC keeps its
    current model, and it restores a reserved DFR as the flat model. A guest
    would then keep the previous model, unlike with WHP's APIC. For example,
    after a write of 0x7fffffff in the flat model, WHP's APIC switches to the
    cluster model and reads back 0x0fffffff, while #5247 stays flat and reads
    back 0xffffffff. The restore would also need a fallback of its own. The two
    changes conflict in lib.rs: git merge-tree of #5247's head a61c5f421
    with 8c1204c68 conflicts there, and with 9805f8984 it does not. The
    roadmap records that the next chain rebase must keep one of them once #5247
    lands.
  • Store the raw model and match no logical destination for a reserved
    model
    , as the APICs of KVM and QEMU do. Logical interrupts would then reach
    no APIC, unlike with WHP's APIC, the routing code would need to change, and
    saved states could carry reserved models, which earlier OpenVMMs fail to
    restore.
  • Fail the restore. save never produces a reserved model, and failing the
    whole restore over one register helps no one.

How was this change validated?

Checks and results:

  • Reproduction at the base: OpenVMM 9805f8984, NVX dev's pin, on a
    local Windows 11 x64 host, with no hypervisor needed. With the new test and
    without the fix, cargo nextest run --profile agent -p virt_support_apic
    failed dfr_reserved_model_follows_bit_31 with
    panicked at vmm_core\virt_support_apic\src\lib.rs:171:14: internal error: entered unreachable code: Unknown DFR value 4026531839 (0xefffffff). Two
    scratch tests, which are not committed, showed that the other paths panic in
    the same way:
    • a one-byte write of 0x70 at 0xfee000e3:
      Unknown DFR value 1879048192;
    • a restore of DFR 0x7fffffff alone: Unknown DFR value 2147483647.
  • With the fix, OpenVMM 8c1204c68:
    cargo nextest run --profile agent -p virt_support_apic ran 9 tests, and 9
    passed. The new test logs one reserved dfr model warning for each reserved
    value.
  • OpenVMM's package checks for virt_support_apic all passed:
    • cargo check;
    • cargo clippy --all-targets on x86_64-pc-windows-msvc;
    • cargo clippy --all-targets with -D warnings on
      x86_64-unknown-linux-gnu;
    • cargo doc --no-deps with RUSTDOCFLAGS=-D warnings;
    • cargo xtask fmt --fix, which changed nothing.
  • Upstream main: efe0b08df with the commit applied (merged tree
    666bfe1af). cargo check -p virt_support_apic passed, and all 9 tests
    passed.
  • WHP's in-hypervisor xAPIC: a scratch program, which is not committed,
    used OpenVMM's whp crate to run guest code of a few bytes in 32-bit flat
    mode. It ran on the local host: Windows 11 build 26300 on an Intel Core
    i9-12900H. The program wrote the DFR, read it back, and exited
    through an I/O port. From reset, the unit test's sequence of writes read back
    exactly the test's expected values, as tabulated above. The issue's sequence
    read back 0x00000000, 0x8fffffff, and 0x12345678 for the writes that
    keep the model. Every switch of the model followed bit 31.
  • NVX pin checks:
    • python scripts\openvmm_pin.py check-branch --topic --target origin/dev:
      passed on 986ca2c7c.
    • python scripts\openvmm_pin.py check-roadmap: passed.
    • python scripts\nvx.py verify: passed.
    • cargo test --locked --manifest-path nvx/Cargo.toml --no-default-features --test openvmm_vectors --test openvmm_cpu_profiles -- --ignored: all 5
      tests passed, so the vectors, contract versions, excerpts, and CPU profiles
      are unchanged.
  • python scripts\local_gates.py --base origin/dev --run:
    • On the head of this pull request, test-changes, markdown-links,
      test-layout, openvmm-vectors, and openvmm-cpu-profiles passed.

    • openvmm-ci, which runs nvx.py check-openvmm-ci, reports the pin's six
      required OpenVMM jobs as pending in microsoft/openvmm's run
      45386438885.
      The openvmm-ci job of this pull request waits for them.

    • Before the rebase onto 986ca2c7c, nvx-cli ran 2,314 tests in 2.9 hours
      on a heavily shared host. 1 test failed and 8 errored, all on timing in
      tests that this change does not touch, since it leaves scripts/ as dev
      has it:

      • seven Git Bash script runs exceeded their 10 s, 40 s, or 60 s limits;
      • one deadline assertion measured 0.85 s against 0.5 s.

      The private-network-ingress timeout recurs at dev on the same host.
      The guest-init test passes alone. CI's nvx-cli jobs run them again.

Backend, host OS, host type, and guest: the crate is platform-independent, and
its tests need no hypervisor. They ran on a local Windows 11 x64 host. The WHP
probe ran on WHP's in-hypervisor xAPIC on the same Intel host, with
its own guest code and no NVX guest. No NVX microVM was booted, because NVX's
microVMs never run this emulator.

Left to CI:

  • The microVM scenarios on KVM, MSHV, and WHP that the gitlink selects. NVX's
    microVMs do not run the emulator.
  • OpenVMM's CI of the pin, which the openvmm-ci job checks.
  • The nvx-cli jobs.

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.

OpenVMM pin

OpenVMM's local APIC emulator, which WHP's user-mode APIC and
OpenHCL's SNP and TDX backends use, decoded only the flat and cluster
models of the xAPIC DFR. A guest's write of one of the 14 reserved
models, or a restore of a saved state that held one, reached
unreachable! and aborted the VMM (#1473).

Pin microsoft/openvmm 8c1204c68381d11d90e58c4ee710a879f71fb601, the
head of microsoft/openvmm#5260, one commit on 9805f8984, the head of
feature/microvm/dev, which NVX pins below this commit:

- virt_support_apic: select a reserved DFR model by bit 31.
  A reserved model selects the flat model when bit 31 is set and the
  cluster model when it is clear, as in Hyper-V's APIC, with a
  rate-limited warning, for a guest's write and a restore alike, and
  the DFR reads back, and a save stores, the selected model. Its test
  panics without the fix and passes with it, on Windows, and a guest
  of a few bytes on WHP's in-hypervisor xAPIC read back the values
  that the test expects after the same writes.

NVX's microVMs use the APICs of KVM, MSHV, and WHP itself, which never
run this emulator, so they behave 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>
… 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>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 11:54

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 pin and roadmap update.

No open issues 🎉

What changed in this PR

This PR pins an OpenVMM fix for #1473 that handles reserved xAPIC DFR models without panicking. It affects the user-mode APIC emulator, not NVX’s normal microVM backends.

Changes:

  • Advances the OpenVMM pin to 8c1204c68, which selects reserved DFR models using bit 31.
  • Maps the commit at roadmap position 369 and updates chain counts and references.
  • Documents register readback, saved-state behavior, and the conflict with the alternative upstream fix in microsoft/openvmm#5247.
File Description
doc/​openvmm-upstream-roadmap.md Records the new pin, position 369, APIC behavior, and rebase considerations.

Review effort: Balanced

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.

openvmm: in virt_support_apic, a guest DFR write with a reserved model hits unreachable! and aborts the VMM

2 participants