Skip to contentSkip to conversation

um: virtio_uml: free command if adding to virtqueue failed

PATCH New [email protected] 1 participant 4 messages Feb 9, 2023 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 um: virtio_uml: free command if adding to virtqueue failed

From: Benjamin Berg <[email protected]>

If adding the command fails (i.e. the virtqueue is broken) then free it again if the function allocated a new buffer for it.

Change-Id I03d2c687aeccb8bc8da280925ffdaeb8fb70eee7
Fixes 68f5d3f3b654 ("um: add PCI over virtio emulation driver")
---
 arch/um/drivers/virt-pci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/um/drivers/virt-pci.c +4 -1
index 3ac220dafec4..3b637ad75ec8 100644
@@ -132,8 +132,11 @@ static int um_pci_send_cmd(struct um_pci_device *dev,
 				out ? 1 : 0,
 				posted ? cmd : HANDLE_NO_FREE(cmd),
 				GFP_ATOMIC);
-	if (ret)
+	if (ret) {
+		if (posted)
+			kfree(cmd);
 		goto out;
+	}
 
 	if (posted) {
 		virtqueue_kick(dev->cmd_vq);
Signature · 7 lines
2.39.1


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#1 lore raw

PATCH 2/4 um: virtio_uml: mark device as unregistered when breaking it

From: Benjamin Berg <[email protected]>

Mark the device as not registered anymore when scheduling the work to remove it. Otherwise we could end up scheduling the work multiple times in a row, including scheduling it while it is already running.

Change-Id I5debd5084986f37b793cfac98d95b3a577d7a345
Fixes af9fb41ed315 ("um: virtio_uml: Fix broken device handling in time-travel")
---
 arch/um/drivers/virtio_uml.c | 2 ++
 1 file changed, 2 insertions(+)
arch/um/drivers/virtio_uml.c +2 -0
index 588930a0ced1..dcfd0ca534ee 100644
@@ -168,6 +168,8 @@ static void vhost_user_check_reset(struct virtio_uml_device *vu_dev,
 	if (!vu_dev->registered)
 		return;
 
+	vu_dev->registered = 0;
+
 	virtio_break_device(&vu_dev->vdev);
 	schedule_work(&pdata->conn_broken_wk);
 }
Signature · 7 lines
2.39.1


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#2 lore raw

PATCH 3/4 um: virtio_uml: move device breaking into workqueue

In reply to [email protected]

From: Benjamin Berg <[email protected]>

We should not be calling virtio_break_device from an IRQ context. Move breaking the device into the workqueue so that it is done from a reasonable context.

Change-Id I4f5f075d7f40ed050c08a7435c1cf45e2387022c
Fixes af9fb41ed315 ("um: virtio_uml: Fix broken device handling in time-travel")
---
 arch/um/drivers/virtio_uml.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
arch/um/drivers/virtio_uml.c +15 -1
index dcfd0ca534ee..ddd080f6dd82 100644
@@ -170,7 +170,6 @@ static void vhost_user_check_reset(struct virtio_uml_device *vu_dev,
 
 	vu_dev->registered = 0;
 
-	virtio_break_device(&vu_dev->vdev);
 	schedule_work(&pdata->conn_broken_wk);
 }
 
@@ -1138,6 +1137,15 @@ void virtio_uml_set_no_vq_suspend(struct virtio_device *vdev,
 
 static void vu_of_conn_broken(struct work_struct *wk)
 {
+	struct virtio_uml_platform_data *pdata;
+	struct virtio_uml_device *vu_dev;
+
+	pdata = container_of(wk, struct virtio_uml_platform_data, conn_broken_wk);
+
+	vu_dev = platform_get_drvdata(pdata->pdev);
+
+	virtio_break_device(&vu_dev->vdev);
+
 	/*
 	 * We can't remove the device from the devicetree so the only thing we
 	 * can do is warn.
@@ -1268,8 +1276,14 @@ static int vu_unregister_cmdline_device(struct device *dev, void *data)
 static void vu_conn_broken(struct work_struct *wk)
 {
 	struct virtio_uml_platform_data *pdata;
+	struct virtio_uml_device *vu_dev;
 
 	pdata = container_of(wk, struct virtio_uml_platform_data, conn_broken_wk);
+
+	vu_dev = platform_get_drvdata(pdata->pdev);
+
+	virtio_break_device(&vu_dev->vdev);
+
 	vu_unregister_cmdline_device(&pdata->pdev->dev, NULL);
 }
 
Signature · 7 lines
2.39.1


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#3 lore raw

PATCH 4/4 um: virt-pci: properly remove PCI device from bus

In reply to [email protected]

From: Benjamin Berg <[email protected]>

Triggering a bus rescan will not cause the PCI device to be removed. It is required to explicitly stop and remove the device from the bus.

Change-Id Ie51a08cde45e829fd68fe7d7ebaa0bd9e1c06c6e
Fixes 68f5d3f3b654 ("um: add PCI over virtio emulation driver")
---
 arch/um/drivers/virt-pci.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
arch/um/drivers/virt-pci.c +16 -5
index 3b637ad75ec8..5472b1a0a039 100644
@@ -626,22 +626,33 @@ static void um_pci_virtio_remove(struct virtio_device *vdev)
 	struct um_pci_device *dev = vdev->priv;
 	int i;
 
-        /* Stop all virtqueues */
-        virtio_reset_device(vdev);
-        vdev->config->del_vqs(vdev);
-
 	device_set_wakeup_enable(&vdev->dev, false);
 
 	mutex_lock(&um_pci_mtx);
 	for (i = 0; i < MAX_DEVICES; i++) {
 		if (um_pci_devices[i].dev != dev)
 			continue;
+
 		um_pci_devices[i].dev = NULL;
 		irq_free_desc(dev->irq);
+
+		break;
 	}
 	mutex_unlock(&um_pci_mtx);
 
-	um_pci_rescan();
+	if (i < MAX_DEVICES) {
+		struct pci_dev *pci_dev;
+
+		pci_dev = pci_get_slot(bridge->bus, i);
+		if (pci_dev)
+			pci_stop_and_remove_bus_device_locked(pci_dev);
+	}
+
+	/* Stop all virtqueues */
+	virtio_reset_device(vdev);
+	dev->cmd_vq = NULL;
+	dev->irq_vq = NULL;
+	vdev->config->del_vqs(vdev);
 
 	kfree(dev);
 }
Signature · 7 lines
2.39.1


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um