Skip to content

[DO NOT REVIEW] chipset: zero-extend wide IOAPIC MMIO reads - #5084

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1140-ioapic-wide-read
Nov 13, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1140-ioapic-wide-read

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Makes the emulated IOAPIC return a read of its index or data register that is wider than 4 bytes zero-extended, instead of panicking, for microsoft/nvx#1140. IoApicDevice::mmio_read copied the register's min(len, 4) low bytes into the whole read buffer, so a 64-bit read panicked the VP thread and ended OpenVMM and the VM.

One commit on 09cd771c0, the head of feature/microvm/dev. microsoft/nvx#1570 pins it; this pull request lands first, by fast-forwarding feature/microvm/dev to e2458a6ce.

Zero-extend wide IOAPIC MMIO reads (e2458a6ce)

  • Cause. mmio_read computed n = data.len().min(size_of_val(&v)), 4 at most, and then called data.copy_from_slice(&v.to_ne_bytes()[..n]), which requires both slices to have the same length. Reads of 1 to 4 bytes worked; a 5- to 8-byte read, such as a 64-bit mov from 0xfec00000 or 0xfec00010, panicked with "copy_from_slice: source slice length (4) does not match destination slice length (8)" at vm/devices/chipset/src/ioapic/mod.rs:724. The IOAPIC is OpenVMM's own on every backend, since KVM runs with a split irqchip, so the guest's MMIO reaches IoApicDevice on KVM, MSHV, and WHP alike.
  • Change. mmio_read copies the n low bytes into data[..n] and zeroes data[n..], so a wider read returns the 32-bit register zero-extended, as Rtc::io_read does for a wide read of its ports since [DO NOT REVIEW] chipset: zero-extend wide reads of the RTC's ports #5072, and a narrower one still returns the register's low bytes. A read of another offset still fails with InvalidRegister and leaves the buffer as it was. The patch attached to openvmm: 64-bit IOAPIC MMIO reads panic in IoApicDevice::mmio_read nvx#1140 makes the same change.
  • Tests. mmio_reads_of_any_size_are_zero_extended sets the IOAPIC's ID and redirection entry 5, then reads the index and data registers with the ID, the version, and both halves of entry 5 selected, with every length from 1 to 8 bytes into a buffer of 0xa5 bytes, and requires the register's low bytes followed by zeros. At 09cd771c0, it fails at its first 5-byte read with the panic above, at mod.rs:724:14.

Validation

With Rust 1.97.1 and cargo-nextest 0.9.133, for chipset, with this change: on Windows x64, cargo check, cargo clippy --all-targets, cargo doc --no-deps, and cargo nextest run --profile agent (132 passed), then cargo xtask fmt --fix (no changes); on Linux x64, on the Azure Linux 3 KVM test VM, cargo check, cargo clippy --all-targets, cargo doc --no-deps, and cargo nextest run --profile agent (132 passed).

In NVX's Alpine microVM, at NVX f02bdcd53, which pins 09cd771c0, a static guest program mapped /dev/mem at 0xfec00000 and read the index (+0x00) and data (+0x10) registers with 32-bit and then 64-bit loads:

Backend Host Processors OpenVMM 09cd771c0 With this change
KVM Azure Linux 3 VM, Linux 6.18.57 1 32-bit reads 0x34, 0x21; the first 64-bit read panics at mod.rs:724:14 64-bit reads 0x34, 0x21
KVM Azure Linux 3 VM, Linux 6.18.57 2 64-bit reads 0x34, 0x20
MSHV Azure Linux 3 VM, Linux 6.18.34 1 32-bit reads 0x34, 0x21; the first 64-bit read panics at mod.rs:724:14 64-bit reads 0x34, 0x21
MSHV Azure Linux 3 VM, Linux 6.18.34 2 64-bit reads 0x34, 0x20
WHP Windows Server 2025 VM 1 32-bit reads 0x34, 0x21; the first 64-bit read panics at mod.rs:724:14 64-bit reads 0x34, 0x21
WHP Windows Server 2025 VM 2 64-bit reads 0x34, 0x20

With this change, each 64-bit read returned the 32-bit read's value with zero upper bits, and the guest exited cleanly.

In this pull request's CI, run 43511358061:

  • run vmm-tests [x64-windows-intel-tdx] timed out in one test of 119, a Windows OpenHCL guest's memstat memory test (770 s). It passed on its one rerun, and so did openvmm checkin gates.
  • run vmm-tests [x64-windows-amd-snp] fails at 09cd771c0 too (run 43489085265), mostly with "VM did not start after reset in the required time": 19 of 86 tests failed there and 16 here, 11 of them in both runs.

A guest read of the IOAPIC's index or data register wider than 4
bytes, such as a 64-bit mov from 0xfec00000, panicked the VP thread
with "copy_from_slice: source slice length (4) does not match
destination slice length (8)", which ended OpenVMM and the VM.
IoApicDevice::mmio_read means to accept a read of any size, but it
copied the register's min(len, 4) low bytes into the whole buffer, so
only reads of at most 4 bytes matched the slice lengths.

mmio_read now copies those low bytes into the start of the buffer and
zeroes the rest, so a wider read returns the 32-bit register
zero-extended, as the RTC already does for a wide read of its ports,
and a narrower one still returns the register's low bytes.

Tests: the new test ioapic::tests::
mmio_reads_of_any_size_are_zero_extended reads the index and data
registers, for the ID, the version, and both halves of a redirection
entry, with every length from 1 to 8 bytes into a buffer of stale
bytes. At feature/microvm/dev 09cd771, it fails with the panic above
at vm/devices/chipset/src/ioapic/mod.rs:724:14. NVX f02bdcd53 pins
09cd771; there, an Alpine guest on 1 processor that maps /dev/mem at
0xfec00000 and reads both registers with 32-bit and then 64-bit loads
panics OpenVMM at the same line on its first 64-bit read, on KVM,
MSHV, and WHP. With this change, the same guest reads the registers'
32-bit values zero-extended on all three, on 1 and 2 processors, and
the 132 chipset tests pass with cargo nextest on Windows x64 and Linux
x64.

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 13, 2026
@ppenna
Pedro Henrique Penna (ppenna) merged commit e2458a6 into feature/microvm/dev Nov 13, 2026
104 of 108 checks passed
@github-actions

Copy link
Copy Markdown

syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 14, 2026
A guest read of the emulated IOAPIC's index or data register wider
than 4 bytes, such as a 64-bit mov from 0xfec00000, panicked OpenVMM's
VP thread with "copy_from_slice: source slice length (4) does not
match destination slice length (8)" in IoApicDevice::mmio_read, which
ended the VM (microsoft#1140).

Pin e2458a6cef958c3ac2d710e13a6ba490a9911b88, the head of
microsoft/openvmm#5084, one commit on 09cd771c0, the head of
feature/microvm/dev:

- e2458a6ce chipset: zero-extend wide IOAPIC MMIO reads

mmio_read copied the 32-bit register's min(len, 4) low bytes into the
whole buffer, so only reads of at most 4 bytes matched the slice
lengths. It now copies those bytes into the start of the buffer and
zeroes the rest, so a wider read returns the register zero-extended,
as the CMOS RTC does for a wide read of its ports, and a narrower one
still returns the register's low bytes.

Evidence: with OpenVMM built from 09cd771c0, the previous pin, an
Alpine guest on 1 processor that maps /dev/mem at 0xfec00000 and reads
the index and data registers with 32-bit and then 64-bit loads
panicked OpenVMM at vm/devices/chipset/src/ioapic/mod.rs:724:14 on its
first 64-bit load, on nvx-kvm-test, nvx-mshv-test, and nvx-whp-test.
At the pin, its 64-bit loads read the values of its 32-bit loads,
zero-extended, on all three hosts, on 1 and 2 processors.

Tests: with OpenVMM built from the pin, the microVM scenarios smp, on
1 and 2 processors, and interrupt-map pass on nvx-kvm-test,
nvx-mshv-test, and nvx-whp-test. The revision's new chipset test,
mmio_reads_of_any_size_are_zero_extended, fails at 09cd771c0 with the
panic above, and its 132 chipset tests pass on Windows and on Linux,
on nvx-kvm-test.

NVX needs no coordinated change: the control-session vectors, the
source excerpts, the contract versions, the activation bound, and the
CPU profiles that nvx-rs copies from OpenVMM match the revision's.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 14, 2026
The NVX pin moves to e2458a6ce, position 274, 150 commits past the
mapped tip. Position 274, the one commit of microsoft/openvmm#5084 on
09cd771c0, the head of feature/microvm/dev, is not yet assigned to a
PR.

Position 274 makes the IOAPIC's mmio_read zero-extend a read of its
index or data register wider than 4 bytes, which panicked the vCPU
thread, and so OpenVMM, because it copied the register's low bytes
into the whole buffer. The code is upstream main's, and the commit
adds a test to the device's tests, in a file whose saved-state tests
position 183 also changes; it changes none of position 183's code and
nothing that a mapped PR adds. Replaying it on upstream main,
7d90c4104, applies without conflicts, and chipset type-checks there
with its tests, which pass, so it can go upstream on its own.

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