Skip to content

devices: Make sure to drain virtio TX port on stop#583

Open
d-e-s-o wants to merge 1 commit intocontainers:mainfrom
d-e-s-o:topic/virtio-port-stop
Open

devices: Make sure to drain virtio TX port on stop#583
d-e-s-o wants to merge 1 commit intocontainers:mainfrom
d-e-s-o:topic/virtio-port-stop

Conversation

@d-e-s-o
Copy link
Contributor

@d-e-s-o d-e-s-o commented Mar 12, 2026

I've encountered a race-condition where guest writes data to stderr shortly before exiting and that data never manifests on the host. The reason seems to be in pop_head_blocking() (in the virtio console TX thread), when the stop flag is set the thread returns None without checking the queue one final time. Data already sitting in the virtio transmit queue is abandoned.
Reorder the thread::park() call to make sure we check the queue one last time before stopping, which will ensure flushing of any remaining data on the port. I've verified the fix with several thousand iterations of a test case that earlier reproduced the problem in typically 10-50.

@d-e-s-o d-e-s-o force-pushed the topic/virtio-port-stop branch from 1eec515 to a389e70 Compare March 12, 2026 00:30
@d-e-s-o d-e-s-o changed the title Make sure to drain virtio TX port on stop devices: Make sure to drain virtio TX port on stop Mar 12, 2026
@slp
Copy link
Collaborator

slp commented Mar 12, 2026

LGTM, thanks!

@mtjhrc PTAAL.

I've encountered a race-condition where guest writes data to stderr
shortly before exiting and that data never manifests on the host. The
reason seems to be in libkrun's pop_head_blocking() (in the virtio
console TX thread), when the stop flag is set the thread returns None
without checking the queue one final time. Data already sitting in the
virtio transmit queue is abandoned.
Reorder the thread::park() call to make sure we check the queue one last
time before stopping, which will ensure flushing of any remaining data
on the port. I've verified the fix with several thousand iterations of a
test case that earlier reproduced the problem in typically 10-50.

Signed-off-by: Daniel Müller <deso@posteo.net>
@d-e-s-o d-e-s-o force-pushed the topic/virtio-port-stop branch from a389e70 to dab0c5d Compare March 12, 2026 14:09
@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented Mar 12, 2026

Sorry, I rebased somehow thinking there was a need to update.

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