Skip to content

Commit 6c5df3c

Browse files
mstsirkinSasha Levin
authored and
Sasha Levin
committed
virtio_console: fix misc probe bugs
[ Upstream commit b9efbe2 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent f134d11 commit 6c5df3c

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
@@ -2075,25 +2075,27 @@ static int virtcons_probe(struct virtio_device *vdev)
20752075
multiport = true;
20762076
}
20772077

2078-
err = init_vqs(portdev);
2079-
if (err < 0) {
2080-
dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
2081-
goto free_chrdev;
2082-
}
2083-
20842078
spin_lock_init(&portdev->ports_lock);
20852079
INIT_LIST_HEAD(&portdev->ports);
20862080
INIT_LIST_HEAD(&portdev->list);
20872081

2088-
virtio_device_ready(portdev->vdev);
2089-
20902082
INIT_WORK(&portdev->config_work, &config_work_handler);
20912083
INIT_WORK(&portdev->control_work, &control_work_handler);
20922084

20932085
if (multiport) {
20942086
spin_lock_init(&portdev->c_ivq_lock);
20952087
spin_lock_init(&portdev->c_ovq_lock);
2088+
}
20962089

2090+
err = init_vqs(portdev);
2091+
if (err < 0) {
2092+
dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
2093+
goto free_chrdev;
2094+
}
2095+
2096+
virtio_device_ready(portdev->vdev);
2097+
2098+
if (multiport) {
20972099
err = fill_queue(portdev->c_ivq, &portdev->c_ivq_lock);
20982100
if (err < 0) {
20992101
dev_err(&vdev->dev,

0 commit comments

Comments
 (0)