Skip to content

vpci: hot-add/removal for PCI devices over VPCI - #4377

Open
Daman Mulye (damanm24) wants to merge 9 commits into
microsoft:mainfrom
damanm24:virtiofs-pcie-hotplug
Open

vpci: hot-add/removal for PCI devices over VPCI#4377
Daman Mulye (damanm24) wants to merge 9 commits into
microsoft:mainfrom
damanm24:virtiofs-pcie-hotplug

Conversation

@damanm24

Copy link
Copy Markdown
Contributor

To use OpenVMM for WSL, we need the ability to add/remove devices after a VM has been created. This PR adds the following:

  • Adds AddVpciDevice and RemoveVpciDevice to the RPC control plane
  • Builds a dynamic vpci device backed by a PCI-device state unit and a VPCI bus state unit

There were a couple of special considerations that made this implementation more complicated than I had initially intended.

  1. We need to prevent a guest from opening a channel before the device has been started. The current vpci code makes an offer before starting the device (which is okay when a VM is still being created and has not booted yet), but for hot-add a guest opening a channel to the device before it's been created would cause a panic
  2. When removing a vpci device, an uncooperative or crashed guest can block the removal and therefore halt the worker's RPC processing. Therefore, there's a timer that when fired will revoke the channel and finish the device removal.

Copilot AI lite review requested due to automatic review settings September 3, 2026 16:04
@github-actions github-actions Bot added the Guide label Sep 3, 2026

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 change set touches core hotplug/eject behavior across the control plane, worker dispatch, and VPCI device protocol handling, so it warrants final human validation of edge cases and operational safety.

Pull request overview

This PR adds runtime hot-add/hot-remove support for PCI devices over Hyper-V VPCI, exposing it through the ttrpc control plane and implementing the necessary dynamic device + bus state-unit plumbing to safely offer/revoke VPCI channels while a guest is running (including a bounded grace-period for guest-acknowledged ejection).

Changes:

  • Add new ttrpc RPCs AddVpciDevice / RemoveVpciDevice, plus worker-side dispatch to dynamically build and tear down VPCI-backed PCI devices.
  • Introduce deferred VPCI channel offering and an ejection control path so hot-added devices can be started before the guest can open the channel, and removed even with an uncooperative guest.
  • Extend tests and docs to cover the new RPCs and validate VPCI virtio-fs hotplug behavior on supported hosts.
File summaries
File Description
vmm_tests/vmm_tests/tests/tests/ttrpc.rs Expands ttrpc integration tests to exercise VPCI add/remove (including virtio-fs over VPCI).
vmm_core/src/vmbus_unit.rs Updates offer_simple_device_unit call site for the new offer API parameter.
vmm_core/src/device_builder.rs Adds DynamicVpciDevice and builder flow to create a dynamic PCI device + VPCI bus with deferred channel offer.
vm/devices/vmbus/vmbus_channel/src/simple.rs Extends offer_simple_device to optionally start a device before offering the channel.
vm/devices/pci/vpci/src/device.rs Adds an eject control mechanism and protocol handling for EJECT_COMPLETE, integrating with the VPCI worker loop.
vm/devices/pci/vpci/src/bus.rs Refactors VPCI bus to support “unoffered/offered/revoked” channel state, deferred offer, and channel revocation + eject handle.
openvmm/openvmm_ttrpc_vmservice/src/vmservice.proto Defines the new AddVpciDevice/RemoveVpciDevice RPCs and related request/response messages; adds built-in virtio-fs config.
openvmm/openvmm_entry/src/ttrpc/mod.rs Wires new RPCs into the entry service and implements request translation into worker RPCs/resources.
openvmm/openvmm_defs/src/rpc.rs Adds VmRpc::AddVpciDevice / VmRpc::RemoveVpciDevice worker RPC variants.
openvmm/openvmm_core/src/worker/dispatch.rs Implements add/remove handling, enforces the 64-device limit, and adds a timed ejection grace period before forced removal.
Guide/src/reference/openvmm/management/grpc.md Documents the new management RPCs and VPCI semantics/constraints.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Install Rust toolchain

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

Copilot AI review requested due to automatic review settings September 3, 2026 16:38

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

It introduces a new hotplug control-plane surface and significant runtime device-lifecycle/concurrency behavior changes that warrant final human review despite only minor nits found.

Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread vm/devices/pci/vpci/src/device.rs

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.

the vmbus side looks fine but someone should look from the vpci pov

Comment thread openvmm/openvmm_ttrpc_vmservice/src/vmservice.proto Outdated
Comment thread vm/devices/vmbus/vmbus_channel/src/simple.rs Outdated
Copilot AI review requested due to automatic review settings September 3, 2026 22:47
@damanm24
Daman Mulye (damanm24) marked this pull request as ready for review September 3, 2026 22:48

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

offer_simple_device_unit should select InitialDeviceState::Running when state units are already running to avoid a guest-open panic for dynamically offered simple VMBus devices.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread vmm_core/src/vmbus_unit.rs
Copilot AI review requested due to automatic review settings September 3, 2026 23:07

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 VPCI eject path in vpci/src/device.rs can be blocked by completion-ring backpressure, preventing timely processing of eject requests and undermining the intended graceful-removal behavior.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

vm/devices/pci/vpci/src/device.rs:781

  • wait_for_completion_space() is awaited before the loop can observe eject_recv, but VPCI eject requests are sent as InBandNoCompletion packets. If the completion ring is full (e.g., a stuck guest), the worker can block here and never process the eject request, causing the remove path to unnecessarily hit the grace-period timeout and force-remove the device.
  • Files reviewed: 11/11 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Copilot AI review requested due to automatic review settings September 4, 2026 00:43

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 added VPCI test helper/probe has brittleness and shell-quoting issues that should be fixed to avoid flaky or unsafe test behavior across environments.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

vmm_tests/vmm_tests/tests/tests/ttrpc.rs:1117

  • mount_virtio_fs builds a shell script that interpolates {tag}/{target} into the command text without quoting/parameterization. While current callers pass simple constants, this helper will break on spaces/shell metacharacters and is unnecessarily risky; pass values as positional parameters to sh -c instead.
  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +542 to +543
Err(err) => assert!(err.message.contains("does not support VPCI devices")),
}
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants