Repository navigation
[DO NOT REVIEW] chipset: zero-extend wide reads of the RTC's ports - #5072
Merged
Pedro Henrique Penna (ppenna) merged 1 commit intoNov 13, 2026
Conversation
Rtc::io_read wrote only the first byte of the read buffer, although its comment says that a read wider than a byte returns the register's byte zero-extended to the size of the access. The other bytes kept what the buffer held. On MSHV and WHP, emulate_io gives the device the guest's EAX as the buffer, so a 16- or 32-bit IN from port 0x70 or 0x71 kept the guest's upper bytes of AX or EAX, as an 8-bit IN does (microsoft/nvx#1151). KVM zeroes its PIO data before it exits to the VMM for an IN, which hid the defect there. io_read now reads the register first, so that a read of another port still leaves the buffer as it was, then zeroes the whole buffer and stores the register's byte in its first byte, as the DMA controller's io_read does. A one-byte read returns the same byte as before. Tests: wide_reads_are_zero_extended reads both ports with 2- and 4-byte buffers that hold 0xa5 bytes, and requires the register's byte followed by zeros. At 6f57a6d, a 2-byte read of port 0x70 returns [0x40, 0xa5]. Evidence: in NVX's Alpine microVM, with OpenVMM built from 6f57a6d, a guest program selected status D, 0x80, and read port 0x70 and 0x71 with 16- and 32-bit INs, each starting with EAX = 0xdeadbeef. On MSHV and WHP, every read returned 0xdeadbe0d from port 0x70 and 0xdeadbe80 from port 0x71. On KVM they returned the zero-extended values, 0xdead000d and 0x0000000d, and 0xdead0080 and 0x00000080, since a 16-bit IN keeps EAX[31:16]. With cargo test -p chipset on Windows x64, the new test fails at 6f57a6d and passes with this commit, with the crate's other 112 tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
requested a review
from a team
as a code owner
November 13, 2026 02:25
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 13, 2026
OpenVMM's emulated CMOS RTC stored only the first byte of a read of its ports, 0x70 and 0x71, although its comment says that a wider read returns the register's byte zero-extended to the size of the access. The other bytes kept what the backend's buffer held. On MSHV and WHP, OpenVMM passes the guest's EAX as that buffer, so a 16- or 32-bit IN from either port kept the guest's upper bytes of AX or EAX, as an 8-bit IN does (#1151). KVM zeroes its PIO data before it exits to the VMM for an IN, which hid the defect there. Pin 60e160369b1f1f10543e0699d4ae1e95810a1e62, the head of microsoft/openvmm#5072, one commit on 6f57a6d61, the head of feature/microvm/dev: - 60e160369 chipset: zero-extend wide reads of the RTC's ports Rtc::io_read now reads the register, then zeroes the whole buffer and stores the register's byte in its first byte. A one-byte read returns the same byte as before, and a read of another port still fails without touching the buffer. Evidence: in NVX's Alpine microVM, a guest program selected status D, 0x80, and read each port with 16- and 32-bit INs that start with EAX = 0xdeadbeef, three times per boot. With OpenVMM 6f57a6d61, from the release v0.1.0-dev.8e9e9eb74cf2, every read returned 0xdeadbe0d from port 0x70 and 0xdeadbe80 from port 0x71 on nvx-mshv-test and nvx-whp-test. On nvx-kvm-test, the reads returned the zero-extended values, 0xdead000d and 0x0000000d, and 0xdead0080 and 0x00000080, since a 16-bit IN keeps EAX[31:16]. With OpenVMM built from the pin, all three hosts returned the zero-extended values. The revision's new chipset test fails at 6f57a6d61, where a 2-byte read of port 0x70 returns [0x40, 0xa5], and passes at the pin with the crate's other 112 tests, on Windows and on Linux. Tests: with OpenVMM built from the pin, the microVM scenarios guest-boot, lifecycle, which reads the RTC's status B one byte at a time, interrupt-map, snapshot-core, restore-processors, smp-snapshot, restore-downtime, time-abi-conformance, and time-host-correction pass with 1 and 2 processors on nvx-kvm-test, nvx-mshv-test, and nvx-whp-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>
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 13, 2026
The NVX pin moves to 60e160369, position 267, 136 commits past the mapped tip. Position 267, which microsoft/openvmm#5072 proposes for feature/microvm/dev on its head, 6f57a6d61, is unassigned. The Scope also says that microsoft/openvmm#5067 merged positions 265 and 266. Position 267 makes the RTC's io_read zero-extend a read of port 0x70 or 0x71 that is wider than a byte, in code that upstream main has, and adds a test, in a file that PR10's position 020, PR15's position 057, and position 200 also change, none of them in the code that it changes. It changes nothing that a mapped PR adds. Replaying it on upstream main applies without conflicts, and chipset type-checks there and its 64 tests pass, so it can go upstream on its own. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
merged commit Nov 13, 2026
60e1603
into
feature/microvm/dev
73 of 74 checks passed
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 13, 2026
The NVX pin moves to 5ca20ee08, position 268, 137 commits past the mapped tip. Position 268, which microsoft/openvmm#5073 proposes for feature/microvm/dev on its head, 60e160369, is unassigned. The Scope also says that microsoft/openvmm#5072 merged position 267. Position 268 makes VmTimerPeriodic skip at once the deadlines that VM time passed, and register its next deadline under the timer state's lock, in code that upstream main has, and adds tests, in a file that PR10's position 019 and positions 156, 157, and 255 also change, none of them in the code that it changes. It changes nothing that a mapped PR adds. Replaying it on upstream main, 7d90c4104, applies without conflicts, and vmcore type-checks there with all its targets and its 35 tests pass, so it can go upstream on its own. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 13, 2026
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.
Makes the emulated CMOS RTC zero-extend a read of its ports
0x70and0x71that is wider than a byte, as the comment in itsio_readsays it does, for microsoft/nvx#1151.Rtc::io_readwrote only the first byte of the read buffer, so the other bytes kept what the buffer held.One commit on
6f57a6d61, the head offeature/microvm/dev.Zero-extend wide reads of the RTC's ports (
60e160369)Rtc::io_readstored the register's byte indata[0]and leftdata[1..]as the caller passed them, and what they held depends on the backend. On MSHV and WHP,virt_support_x86emu::emulate::emulate_iopasses the guest's EAX as the buffer, so a 16- or 32-bitinfrom port0x70or0x71kept the guest's upper bytes of AX or EAX, as an 8-bitindoes. KVM zeroes its PIO data before it exits to the VMM for anin(emulator_pio_in_outinarch/x86/kvm/x86.c, in Linux 5.15, 6.1, 6.8, and master), which hid the defect there, and the stringinspath throughx86emupasses a zeroed buffer on every backend.io_readreads the register first, so that a read of another port still fails withInvalidRegisterand leaves the buffer as it was, then zeroes the whole buffer and stores the register's byte in its first byte, as the DMA controller'sio_readdoes. A one-byte read returns the same byte as before, and a read of port0x71still reads the selected register once.vmotherboard's dispatch would cover every device, but the chipset devices own the whole buffer: the PIC, the PIT, and the i8042 reject a wide access withInvalidAccessSize, and the DMA controller and the microVM devices fill the buffer. The patch attached to openvmm: wide RTC port reads leave stale bytes in the upper portion of the result nvx#1151 also adds a test of one-byte reads, whichtest_default,test_readonly, andtest_writeablealready cover throughget_cmos_data.wide_reads_are_zero_extendedreads both ports with 2- and 4-byte buffers that hold0xa5bytes, and requires the register's byte followed by zeros. At6f57a6d61, a 2-byte read of port0x70returns[0x40, 0xa5].Not in this change, found while auditing the read path:
Piix4CmosRtc::io_readinchipset_legacy, which the microVM does not use, also writes onlydata[0]for its extended ports,0x72and0x73, and their shadows,0x76and0x77. Its other ports,0x70,0x71,0x74, and0x75, go toRtc::io_read, which this change fixes.emulate_ioreturns RAX with bits 63:32 cleared after an 8- or 16-bitin, where the processor keeps bits 63:8 or 63:16, as KVM'skvm_fast_pio_indoes. This is read from the code, not reproduced.Validation
With Rust 1.97.1, on Windows, for
chipset, at60e160369:cargo check,cargo clippy --all-targets(clean apart from the environment's LNK4199 linker notices),cargo doc --no-deps, andcargo nextest run --profile agent(113 passed), thencargo xtask fmt --fix(complete, no changes). At6f57a6d61, with the new test alone, it fails: "port 0x70, 2 bytes",[64, 165]where[64, 0]is expected.In NVX's Alpine microVM, with OpenVMM built from
6f57a6d61(the releasev0.1.0-dev.8e9e9eb74cf2), a static guest program selected status D,0x80, and read each port with an 8-, a 16-, and a 32-bitin, each starting with EAX =0xdeadbeef, three times per boot:inw 0x70inl 0x70inw 0x71inl 0x71dead000d0000000ddead008000000080dead000d0000000ddead008000000080deadbe0ddeadbe0ddeadbe80deadbe80deadbe0ddeadbe0ddeadbe80deadbe80The 8-bit reads returned
deadbe0danddeadbe80on every backend. With OpenVMM built from60e160369, every 16- and 32-bit read returned the zero-extended value on all three backends:dead000dand0000000dfrom port0x70, anddead0080and00000080from port0x71.On Linux, on the Azure Linux 3 KVM test VM, at
60e160369:cargo nextest run --profile agent -p chipsetandcargo test -p chipset --lib, 113 passed each. Replayed on upstream main, where it applies without conflicts,chipsettype-checks and its 64 tests pass on Windows.The RTC is OpenVMM's own on every backend. NVX's microVM scenarios, among them one that reads the RTC's status B one byte at a time, pass with this head on KVM, MSHV, and WHP; microsoft/nvx#1563 pins it and records those runs.
OpenVMM CI of this head, run 43352068114, passed every job that NVX requires. Its
run vmm-tests [x64-windows-amd-snp]failed in one of its 114 tests,multiarch::vmgs::hyperv_openhcl_uefi_x64_windows_datacenter_core_2025_x64_prepped_snp_vmgstool_copy_igvmfile, whose Hyper-V VM never started because the runner's Hyper-V failed to load the CVM firmwarevmfirmwarecvm.dll(0x80070002). The same test failed the same way at6f57a6d61, in #5067's run 43331611028, so it predates this change.