Skip to content

Commit b9efbe2

Browse files
committed
virtio_console: fix misc probe bugs
This fixes the following issue discovered by code review: after vqs have been created, a buggy device can send an interrupt. A control vq callback will then try to schedule control_work which has not been initialized yet. Similarly for config interrupt. Further, in and out vq callbacks invoke find_port_by_vq which attempts to take ports_lock which also has not been initialized. To fix, init all locks and work before creating vqs. Message-ID: <ad982e975a6160ad110c623c016041311ca15b4f.1726511547.git.mst@redhat.com> Fixes: 17634ba ("virtio: console: Add a new MULTIPORT feature, support for generic ports") Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 83c334e commit b9efbe2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/char/virtio_console.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,25 +2007,27 @@ static int virtcons_probe(struct virtio_device *vdev)
20072007
multiport = true;
20082008
}
20092009

2010-
err = init_vqs(portdev);
2011-
if (err < 0) {
2012-
dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
2013-
goto free_chrdev;
2014-
}
2015-
20162010
spin_lock_init(&portdev->ports_lock);
20172011
INIT_LIST_HEAD(&portdev->ports);
20182012
INIT_LIST_HEAD(&portdev->list);
20192013

2020-
virtio_device_ready(portdev->vdev);
2021-
20222014
INIT_WORK(&portdev->config_work, &config_work_handler);
20232015
INIT_WORK(&portdev->control_work, &control_work_handler);
20242016

20252017
if (multiport) {
20262018
spin_lock_init(&portdev->c_ivq_lock);
20272019
spin_lock_init(&portdev->c_ovq_lock);
2020+
}
20282021

2022+
err = init_vqs(portdev);
2023+
if (err < 0) {
2024+
dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
2025+
goto free_chrdev;
2026+
}
2027+
2028+
virtio_device_ready(portdev->vdev);
2029+
2030+
if (multiport) {
20292031
err = fill_queue(portdev->c_ivq, &portdev->c_ivq_lock);
20302032
if (err < 0) {
20312033
dev_err(&vdev->dev,

0 commit comments

Comments
 (0)