diff options
author | Jean-Philippe Brucker <jean-philippe.brucker@arm.com> | 2017-11-29 19:46:35 +0000 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2017-12-14 11:44:15 +0000 |
commit | d7cfdc1739d54e8a52e2ec69a7df746178b3d490 (patch) | |
tree | 1841c6803e13e07236c9dd0600ff17b027ffaf92 | |
parent | f77d646ba01d04be5aad9449ac00719c043fe36e (diff) | |
download | kvmtool-d7cfdc1739d54e8a52e2ec69a7df746178b3d490.tar.gz |
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: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | virtio/console.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/virtio/console.c b/virtio/console.c index f1c0a190..dc0a9c4e 100644 --- a/virtio/console.c +++ b/virtio/console.c @@ -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); |