Skip to content

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

Merged
slp merged 1 commit intocontainers:mainfrom
d-e-s-o:topic/virtio-port-stop
Mar 16, 2026
Merged

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

Conversation

@d-e-s-o
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

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

Copy link
Copy Markdown
Collaborator

@mtjhrc mtjhrc left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@slp slp merged commit 788cf91 into containers:main Mar 16, 2026
12 of 13 checks passed
@d-e-s-o d-e-s-o deleted the topic/virtio-port-stop branch March 16, 2026 16:39
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.

3 participants