um: virtio_uml: free command if adding to virtqueue failed
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.
--- arch/um/drivers/virt-pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/um/drivers/virt-pci.c +4 -1
@@ -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
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.
--- arch/um/drivers/virtio_uml.c | 2 ++ 1 file changed, 2 insertions(+)
arch/um/drivers/virtio_uml.c +2 -0
@@ -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
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.
--- arch/um/drivers/virtio_uml.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
arch/um/drivers/virtio_uml.c +15 -1
@@ -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
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.
--- arch/um/drivers/virt-pci.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
arch/um/drivers/virt-pci.c +16 -5
@@ -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