Repository navigation
virtio: defer descriptor reuse until completion is published - #5193
John Starks (jstarks) wants to merge 11 commits into
Conversation
Route kick waiting through the in-order completion helper so virtio-net does not need to understand descriptor reuse deferral. Use the queue's native capacity accounting for both fetching and waiting, including packed chains that fill the ring with fewer outstanding heads. Preserve pipelined backend submissions and test readiness, packed-ring exhaustion, and reuse within a synchronous TX batch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec4be585-791a-424b-8063-cb04e696f8a9
The shared readiness gate already returns before revisiting a blocked head. Record each newly discovered reuse directly instead of checking that same condition again around the diagnostic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec4be585-791a-424b-8063-cb04e696f8a9
Describe ordered completion directly without referring to another implementation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9babc888-46c1-4a2b-bcb0-92f11dbf4d97
Add crate-private peek and kick-wait variants that defer exhausted capacity without changing strict callers or masking malformed-chain errors. Keep the in-order helper focused on descriptor reuse, clearing its blocked index when the earlier use is published on either completion path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 16e5f3a5-d366-4f74-b35b-b7c24f6ee864
Use the existing peek capacity error to apply backpressure before latching a fatal fetch failure. Record capacity blocking only when a chain fails to fit, and clear it when a completion releases capacity, so kick waiting no longer predicts fullness. Keep strict queue APIs and malformed-chain failures unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 93b90882-b87b-44d8-a40b-a3d9d47a37e5
Avoid checking reuse blocking before every fetch, since the existing ownership check already defers reused heads. Check reuse and capacity blocking only after the underlying kick poll is ready, and count repeated reuse retries once. Keep descriptor validation active on blocked retries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 895d872c-2aa7-4452-ac3a-f1929bd804ba
Remember the used cursor when an ordered fetch encounters descriptor reuse or insufficient capacity, and retry once publication advances. This removes capacity-blocked state and completion-path bookkeeping without restructuring the virtio-net worker. Keep malformed input fatal and preserve strict queue capacity errors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3dfacc79-e3cb-43ed-8722-6a1c158c54f4
Descriptor reuse is tolerated for guest compatibility, so keep its diagnostic rate limited without warning on expected guest behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9ed761ba-52fc-44b2-8955-bb70e51401b5
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
There was a problem hiding this comment.
🟡 Changes recommended
A critical packed-ring overlap can lose deferred requests, and a split used-element write failure can leave deferred TX work blocked after ownership is released.
2 open issues
What changed in this PR
This PR reworks #5161 to tolerate premature descriptor reuse without stopping virtio queues, addressing guest shutdown hangs while preserving virtio-net batching and backend concurrency.
Changes:
- Defers reused heads and treats capacity limits as temporary backpressure in the in-order helper.
- Uses publication-aware kick readiness in virtio-net to avoid spinning on deferred work.
- Adds split- and packed-ring regressions, including wraparound and RX/TX recovery.
| File | Description |
|---|---|
vm/devices/virtio/virtio/src/tests.rs |
Adds deferral, publication, capacity, and wraparound regressions. |
vm/devices/virtio/virtio/src/queue.rs |
Adds an opt-in nonfatal capacity-error policy. |
vm/devices/virtio/virtio/src/in_order.rs |
Defers outstanding heads and gates readiness on publication progress. |
vm/devices/virtio/virtio/src/common.rs |
Distinguishes capacity blocking from empty queues and fatal errors. |
vm/devices/virtio/virtio_net/src/tests.rs |
Tests deferred descriptor reuse and resumed RX/TX processing. |
vm/devices/virtio/virtio_net/src/lib.rs |
Routes kick readiness through the in-order helper. |
Review effort: Balanced
Packed completions overwrite reposted descriptor metadata, so keep packed capacity errors fatal instead of retrying a damaged chain. Detect split-ring retry progress using the existing outstanding count rather than the used cursor, which may not advance when publication fails. This leaves completion bookkeeping and the virtio-net worker unchanged. Update regressions to reject full and partial packed overlap without reposting after completion, resume deferred split work after publication errors, and clear stale count snapshots on successful fetches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 273b2eae-4093-4071-ba5b-390bc3cbdae3
Anatol Belski (weltling)
left a comment
There was a problem hiding this comment.
Deferring the repeated submission makes sense as a resilience workaround.
Which guest driver/version reposts descriptors like this before the first completion is published? Fixing it in the driver would be better long term. It would also be interesting to research there, too.
I left one concern inline about making sure the retry doesn't unnecessarily wait for another guest dorbell.
Thanks
| /// retry fetching after processing completions: this method does not | ||
| /// register a waker for retirement. | ||
| pub fn poll_kick(&self, queue: &mut VirtioQueue, cx: &mut Context<'_>) -> Poll<()> { | ||
| ready!(queue.poll_kick(cx)); |
There was a problem hiding this comment.
ready! can return Pending before the outstanding count is checked. So this might lead to a packet stuck in the queue. If order.len() has already dropped, the worker can retry the queued work without another guest kick. It might make sense to check order.len() first.
Thanks


Some guests reuse a split-ring descriptor head before its previous completion has been published. Although this violates the virtio protocol, permanently stopping the queue is unnecessarily disruptive.
Leave reused split-ring heads unconsumed until the earlier use retires. Treat exhausted split-ring capacity as temporary backpressure in the in-order helper, and snapshot the outstanding count to wait without spinning, including when a completion write fails. Packed-ring capacity overlap remains a fatal error because publishing a completion overwrites descriptor metadata.
Virtio-net uses the helper for kick readiness; its worker loop, batching, and asynchronous backend concurrency remain unchanged. Other queue callers retain strict capacity errors, malformed descriptors still fail the queue, and deferred reuse is logged at rate-limited debug level.
Adds regressions for split-ring deferral, completion write failures, cursor wraparound, packed-overlap rejection, and virtio-net RX/TX behavior. Reworks #5161.