Skip to content

virt_whp: reset the assigned PCI device - #5076

Open
Robert Nowotny (bitranox) wants to merge 2 commits into
microsoft:mainfrom
bitranox:whp-assigned-device-reset
Open

Robert Nowotny (bitranox) wants to merge 2 commits into
microsoft:mainfrom
bitranox:whp-assigned-device-reset

Conversation

@bitranox

Copy link
Copy Markdown
Contributor

AssignedPciDevice::reset was a TODO, so after a VM reset the device kept its MMIO mapped and its command register, power state and BARs as the guest had left them. The reset now clears the command register through pci_cfg_write, which unmaps MMIO and, on a device without a power management capability, moves it to D3. It then puts the power state and BARs back to what new() sets.

disable_mmio() never set mmio_enabled back to false, so once MMIO had been turned off, enable_mmio() returned early and never mapped the BARs again. The reset above depends on that, and so does any guest that turns MMIO off and on again.

In #5075 the VPCI channel's close skips a device whose state unit is resetting it, and leaves turning the device off to that reset. This is the third device that PR names.

Testing

  • cargo fmt, and cargo check plus cargo clippy -p virt_whp --target x86_64-pc-windows-msvc --all-targets -- -D warnings, cross-compiled from Linux.
  • Not run: it needs a Windows host with an assigned device, which I don't have, and there are no unit tests for this device.

AssignedPciDevice::reset was a TODO, so a VM reset left the device's
MMIO mapped and its command register, power state and BARs as the guest
had set them. Clear the command register through the normal config write
path, which unmaps MMIO, then put the power state and BARs back to their
initial values.

disable_mmio() never cleared mmio_enabled, so once MMIO had been turned
off, enable_mmio() returned early and never mapped it again. Clear the
flag.
@bitranox
Robert Nowotny (bitranox) requested a review from a team as a code owner November 13, 2026 15:43
Copilot AI balanced review requested due to automatic review settings November 13, 2026 15:43
@github-actions github-actions Bot added the unsafe Related to unsafe code label Nov 13, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

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 reset changes physical-device power state and WHP MMIO mappings, but Windows assigned-device hardware validation is still needed to verify BAR reprogramming, D0 transition, and MMIO re-enablement.

No open issues 🎉

What changed in this PR

Implements assigned PCI device reset in WHP, supporting #5075’s change to let device reset handle cleanup when VPCI channel close skips a device.

Changes:

  • Clears the command register through the PCI configuration write path to disable MMIO, then restores power state and BARs to their initial values.
  • Clears mmio_enabled after unmapping so MMIO can be enabled again.
File Description
vmm_core/​virt_whp/​src/​device.rs Implements reset cleanup and fixes MMIO enable-state tracking.

Review effort: Balanced

Replace the raw power state numbers, the 0b11 mask and the power
management capability id in the assigned device with named constants.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 17: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.

🔵 Needs a closer look

WHP power transitions and MMIO teardown/remapping require reset/re-enable validation on a Windows host with an assigned PCI device, as cross-compilation alone does not verify hardware recovery.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants