Commit d7cfdc17 authored by Jean-Philippe Brucker's avatar Jean-Philippe Brucker Committed by Will Deacon
Browse files

virtio-console: Fix pthread_cond initialization race



When characters are input on the console before virtio_console is
initialized, the term.c poll thread will get stuck in
virtio_console__inject_interrupt, because it ends up doing
pthread_cond_wait on the uninitialized poll_cond, which will hang
indefinitely. As a result it becomes impossible to input characters into
the guest, even when using serial instead of virtio console.

Initialize poll_cond statically to prevent this race.
Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent f77d646b
......@@ -44,6 +44,7 @@ struct con_dev {
static struct con_dev cdev = {
.mutex = MUTEX_INITIALIZER,
.poll_cond = PTHREAD_COND_INITIALIZER,
.vq_ready = 0,
......@@ -213,8 +214,6 @@ int virtio_console__init(struct kvm *kvm)
if (kvm->cfg.active_console != CONSOLE_VIRTIO)
return 0;
pthread_cond_init(&cdev.poll_cond, NULL);
virtio_init(kvm, &cdev, &cdev.vdev, &con_dev_virtio_ops,
VIRTIO_DEFAULT_TRANS(kvm), PCI_DEVICE_ID_VIRTIO_CONSOLE,
VIRTIO_ID_CONSOLE, PCI_CLASS_CONSOLE);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment