Skip to content

Commit 9c5d291

Browse files
mstsirkinmehmetb0
authored andcommitted
virtio_console: fix misc probe bugs
BugLink: https://bugs.launchpad.net/bugs/2097301 [ 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 <mst@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
1 parent e511df6 commit 9c5d291

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
@@ -2016,25 +2016,27 @@ static int virtcons_probe(struct virtio_device *vdev)
20162016
multiport = true;
20172017
}
20182018

2019-
err = init_vqs(portdev);
2020-
if (err < 0) {
2021-
dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
2022-
goto free_chrdev;
2023-
}
2024-
20252019
spin_lock_init(&portdev->ports_lock);
20262020
INIT_LIST_HEAD(&portdev->ports);
20272021
INIT_LIST_HEAD(&portdev->list);
20282022

2029-
virtio_device_ready(portdev->vdev);
2030-
20312023
INIT_WORK(&portdev->config_work, &config_work_handler);
20322024
INIT_WORK(&portdev->control_work, &control_work_handler);
20332025

20342026
if (multiport) {
20352027
spin_lock_init(&portdev->c_ivq_lock);
20362028
spin_lock_init(&portdev->c_ovq_lock);
2029+
}
20372030

2031+
err = init_vqs(portdev);
2032+
if (err < 0) {
2033+
dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
2034+
goto free_chrdev;
2035+
}
2036+
2037+
virtio_device_ready(portdev->vdev);
2038+
2039+
if (multiport) {
20382040
err = fill_queue(portdev->c_ivq, &portdev->c_ivq_lock);
20392041
if (err < 0) {
20402042
dev_err(&vdev->dev,

0 commit comments

Comments
 (0)