Skip to content

virt: add unit tests for synic dispatch, VP state, and interrupts - #5242

Closed
Sunil Muthuswamy (sunilmut) wants to merge 0 commit into
microsoft:mainfrom
sunilmut:user/sunilmut/virt-unit-tests
Closed

Sunil Muthuswamy (sunilmut) wants to merge 0 commit into
microsoft:mainfrom
sunilmut:user/sunilmut/virt-unit-tests

Conversation

@sunilmut

@sunilmut Sunil Muthuswamy (sunilmut) commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Add behavior-focused tests for widely used, previously untested logic in the virt crate. Two tests expose existing bugs and are marked #[ignore] with notes explaining them; they will be re-enabled with the fixes.

Test changes:

  • Synic hypercall dispatch: connection-ID and port-type checks, minimum VTL, busy ports, handle ownership, teardown, and fast-path cleanup.
  • VP register state: get/set round trips and register-name alignment.
  • XSAVE: standard/compact conversion, disabled features, and normalization across hypervisors.
  • CPUID override merging, DR7 breakpoint encoding, and MSI/IRQ routing.
  • Ignored (known bugs): DR7 write breakpoints use the I/O encoding; SYSENTER EIP/ESP register names are swapped.

Code coverage summary:
virt crate:
Total: 7.3% → 40.7% (+33.4 points, +861 lines)

File Before After Change
x86/vp.rs 0 / 1,078 (0%) 585 / 1,078 (54.3%) +54.3 pts
synic.rs 0 / 198 (0%) 116 / 198 (58.6%) +58.6 pts
irqcon.rs 0 / 62 (0%) 59 / 62 (95.2%) +95.2 pts
x86/mod.rs 32 / 262 (12.2%) 85 / 262 (32.4%) +20.2 pts
cpuid.rs 0 / 73 (0%) 48 / 73 (65.8%) +65.8 pts
Rest of virt (unchanged) 155 / 902 (17.2%) 155 / 902 (17.2%) —
Total 187 / 2,575 (7.3%) 1,048 / 2,575 (40.7%) +33.4 pts

#5274 already brings in these changes

@sunilmut
Sunil Muthuswamy (sunilmut) requested a review from a team as a code owner November 23, 2026 06:21
Copilot AI balanced review requested due to automatic review settings November 23, 2026 06:21

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.

🟡 Changes recommended

The partial ECX override test masks a bit already set in the default, so it cannot detect a skipped override and needs a bit whose value differs.

1 open issue
What changed in this PR

Adds behavior-focused unit tests to OpenVMM’s shared virt crate without changing production behavior.

Changes:

  • Tests SynIC dispatch, access checks, port ownership, teardown, and fast-path cleanup.
  • Covers VP register conversions, XSAVE normalization, CPUID overrides, and interrupt routing.
  • Adds ignored regression tests documenting existing DR7 write-breakpoint and SYSENTER register-name bugs.
File Description
vmm_core/​virt/​src/​x86/​vp.rs Tests register round trips, name alignment, and XSAVE conversion and normalization.
vmm_core/​virt/​src/​x86/​mod.rs Tests breakpoint encoding, decoding, and supported sizes.
vmm_core/​virt/​src/​synic.rs Tests hypercall dispatch, validation, and port lifecycle cleanup.
vmm_core/​virt/​src/​irqcon.rs Tests MSI encoding, interrupt-control mapping, and IRQ route updates.
vmm_core/​virt/​src/​cpuid.rs Tests defaults, masked overrides, merge precedence, and subleaf matching.

Review effort: Balanced

Comment thread vmm_core/virt/src/cpuid.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 24, 2026 00:18

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.

🔵 Needs a closer look

The test’s zero-filled destination masks unintended writes to disabled feature regions; nonzero sentinels are needed to verify those regions remain untouched.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Test that disabled feature regions remain untouched

vmm_core/​virt/​src/​x86/​vp.rs:2564

The zero-filled destination does not verify that disabled feature regions are left untouched: if write_standard loses its xstate_bv guard and copies every compact component, it overwrites these regions with zeros and all assertions still pass. Initialize the destination with a nonzero sentinel and assert that the disabled YMM and A regions retain it, so this test detects unintended writes as well as stale-state copies.

1 resolved since last review

Review effort: Balanced

// 10b 8 bytes.
#[test]
#[ignore = "known bug: DR7 write breakpoints use the I/O encoding (see comment)"]
fn hardware_breakpoint_dr7_bits_match_architectural_encoding() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i’m confused, is there a bug here we’re not fixing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, please see the description for the details.

// Expected: Each named register reports its own field (for example,
// SysenterEip reports sysenter_eip).
#[test]
#[ignore = "known bug: SysenterEip/SysenterEsp names are swapped (see comment)"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why have this test if it’s ignored? i don’t understand

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

there are two bugs that this test catches, that will be fixed in following PRs. I wanted to keep this PR as test only so that its easy to review. Please see the description for details.

@chris-oo Chris Oo (chris-oo) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how much more code coverage do we get from this PR?

@sunilmut

Copy link
Copy Markdown
Member Author

how much more code coverage do we get from this PR?

Total: 7.3% → 40.7% (+33.4 points, +861 lines)
Its also in the description of the PR

Sunil Muthuswamy (sunilmut) added a commit to sunilmut/openvmm that referenced this pull request Nov 25, 2026
Build on microsoft#5242 with tests for CPUID capabilities, reset state,
Intel/AMD topology, partition state, APICs, MSI routing, ARM64 state,
isolation, and VP stop/yield behavior. Tests use fake CPUID tables,
fake VPs, and recording interrupt controllers without requiring a VM.

Across the combined tests, four existing product bugs are exposed.
Their tests are currently marked #[ignore] because they assert correct
behavior that the existing implementation does not satisfy. The DR7
and SYSENTER bugs were exposed in microsoft#5242; this extension also exposes
the MSI retarget and Intel cache-sharing bugs.

| Ignored test | Bug |
|---|---|
| failed_retarget_leaves_interrupt_unchanged | 1 |
| hardware_breakpoint_dr7_bits_match_architectural_encoding | 2 |
| intel_cache_sharing_is_reported_per_cache_level | 3 |
| virtual_msrs_report_fields_under_their_names | 4 |

1. A failed MSI retarget changes the existing interrupt vector.
2. DR7 write breakpoints use the I/O encoding instead of data-write encoding.
3. Cache sharing uses the wrong source for the cache level and omits subleaf
   indices.
4. SYSENTER EIP/ESP names are swapped relative to their fields; the fix
   requires saved-state compatibility handling.

Fixes are incoming in separate PRs and will re-enable these tests.
Keep this PR unit-test-only so the tests and product fixes can be
reviewed independently. No production behavior is changed here.

Code coverage (virt production lines, Linux x64):

| Scope                    | Before | After |
|--------------------------|--------|-------|
| This extension           | 40.7%  | 95.3% |
| Combined with microsoft#5242      |  7.3%  | 95.3% |
Sunil Muthuswamy (sunilmut) added a commit that referenced this pull request Nov 26, 2026
Build on #5242 with tests for CPUID capabilities, reset state, Intel/AMD
topology, partition state, APICs, MSI routing, ARM64 state, isolation,
and
VP stop/yield behavior. Tests use fake CPUID tables, fake VPs, and
recording
interrupt controllers without requiring a VM.

### Four Existing Product Bugs

Across the combined tests, **four existing product bugs are exposed**.
Their tests are currently marked `#[ignore]` because they assert correct
behavior that the existing implementation does not satisfy.

The DR7 and SYSENTER bugs were exposed in #5242; this extension also
exposes the MSI retarget and Intel cache-sharing bugs.

| Ignored Test | Bug |
|---|---|
| `failed_retarget_leaves_interrupt_unchanged` | 1 |
| `hardware_breakpoint_dr7_bits_match_architectural_encoding` | 2 |
| `intel_cache_sharing_is_reported_per_cache_level` | 3 |
| `virtual_msrs_report_fields_under_their_names` | 4 |

1. A failed MSI retarget changes the existing interrupt vector.
2. DR7 write breakpoints use the I/O encoding instead of the data-write
   encoding.
3. Cache sharing uses the wrong source for the cache level and omits
   subleaf indices.
4. SYSENTER EIP/ESP names are swapped relative to their fields. The fix
   requires saved-state compatibility handling.

**Fixes are incoming in separate PRs and will re-enable these tests.**
This PR intentionally remains unit-test-only so the tests and product
fixes can be reviewed independently. No production behavior is changed
here.

### Code Coverage

Previously measured `virt` production-line coverage on Linux x64:

| Scope | Before | After | Increase |
|---|---:|---:|---:|
| This extension | 40.7% | 95.3% | +54.6 percentage points |
| Combined with #5242 | 7.3% | 95.3% | +88.0 percentage points |

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 21:53

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.

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

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.

4 participants