Skip to content

virtio-pmem: migrate from VirtioQueueWorkerContext to direct VirtioQueue#2945

Open
jstarks wants to merge 2 commits intomicrosoft:mainfrom
jstarks:virtio-pmem
Open

virtio-pmem: migrate from VirtioQueueWorkerContext to direct VirtioQueue#2945
jstarks wants to merge 2 commits intomicrosoft:mainfrom
jstarks:virtio-pmem

Conversation

@jstarks
Copy link
Member

@jstarks jstarks commented Mar 11, 2026

Replace the VirtioQueueWorker + VirtioQueueWorkerContext indirection with direct VirtioQueue ownership and a custom AsyncRun implementation.

Replace the VirtioQueueWorker + VirtioQueueWorkerContext indirection with
direct VirtioQueue ownership and a custom AsyncRun implementation.

Before: PmemWorker implemented VirtioQueueWorkerContext::process_work(),
and VirtioQueueWorker managed queue creation, the run loop, and spawned
a dedicated OS thread via DefaultPool::spawn_on_thread.

After: PmemWorker is the long-lived task (T) created at Device::new(),
and PmemQueue (containing the VirtioQueue) is the late-bound state (S)
inserted during enable() and removed during poll_disable(). This follows
the TaskControl convention used by virtio-net: T holds device logic, S
holds per-enable queue state.

- No Option<TaskControl> needed -- TaskControl lives in Device directly
- Remove exit_event (StopTask handles cancellation)
- Remove async-trait and event-listener deps
- Add pal_async (PolledWait) and futures (StreamExt) deps
- Extract process_pmem_request() as a free function
- Remove dead Device::file field (now owned by PmemWorker from init)
@jstarks jstarks requested review from a team as code owners March 11, 2026 17:56
Copilot AI review requested due to automatic review settings March 11, 2026 17:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the virtio_pmem device to use the newer TaskControl + VirtioQueue streaming model (replacing the prior VirtioQueueWorker/async-trait/event-listener approach), and updates crate dependencies accordingly.

Changes:

  • Reworks the pmem queue worker to run via task_control::AsyncRun and consume requests from VirtioQueue as a stream.
  • Updates virtio_pmem crate dependencies (adds futures/pal_async, removes async-trait/event-listener).
  • Updates the workspace Cargo.lock (includes several unrelated dependency bumps).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
vm/devices/virtio/virtio_pmem/src/lib.rs Switches pmem queue processing to TaskControl + VirtioQueue stream-based handling.
vm/devices/virtio/virtio_pmem/Cargo.toml Adjusts dependencies to match the new queue/worker implementation.
Cargo.lock Records updated dependency resolutions, including several version/rev bumps.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +115 to +119
self.worker.task().mem.clone(),
qr.notify,
queue_event,
)
.expect("failed to create virtio queue");
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

VirtioQueue::new(...) returns a Result and can fail based on guest-provided queue parameters. Using .expect(...) will panic on malformed/untrusted guest input and can crash the VMM. Please propagate/handle the error (log + return, and avoid calling self.worker.task() here since TaskControl::task() panics if the task is running).

Copilot uses AI. Check for mistakes.
Comment on lines +110 to +112
let qr = resources.queues.remove(0);
let queue_event = PolledWait::new(&self.driver, qr.event).unwrap();
let queue = VirtioQueue::new(
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Both resources.shared_memory_region.unwrap() and PolledWait::new(...).unwrap() can panic. shared_memory_region is None for the MMIO transport, and PolledWait::new can fail. Panics here will crash the VMM. Please handle these error/None cases (log + return) and avoid discarding the result of map() so failures are visible.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

@jstarks
Copy link
Member Author

jstarks commented Mar 12, 2026

Blocked on #2947

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.

2 participants