diff mbox series

[2/6] virtio: pci: Tear down VQs in virtio_pci_reset()

Message ID 20230329142500.682922-3-paul.liu@linaro.org
State New
Headers show
Series virtio: Use bounce buffers when VIRTIO_F_IOMMU_PLATFORM set | expand

Commit Message

Paul Liu March 29, 2023, 2:24 p.m. UTC
From: Will Deacon <willdeacon@google.com>

The pages backing the virtqueues for virtio PCI devices are not freed
on reset, despite the virtqueue structure being freed as part of the
driver '->priv_auto' destruction at ->remove() time.

Call virtio_pci_del_vqs() from virtio_pci_reset() to free the virtqueue
pages before freeing the virtqueue structure itself.

Signed-off-by: Will Deacon <willdeacon@google.com>
[ Paul: pick from the Android tree. Rebase to the upstream ]
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Link: https://android.googlesource.com/platform/external/u-boot/+/5ed54ccd83cbffd0d8719ce650604b4e44b5b0d8
---
 drivers/virtio/virtio_pci_modern.c | 38 +++++++++++++++---------------
 1 file changed, 19 insertions(+), 19 deletions(-)

Comments

Simon Glass April 1, 2023, 6:31 a.m. UTC | #1
On Thu, 30 Mar 2023 at 03:26, Ying-Chun Liu (PaulLiu)
<paul.liu@linaro.org> wrote:
>
> From: Will Deacon <willdeacon@google.com>
>
> The pages backing the virtqueues for virtio PCI devices are not freed
> on reset, despite the virtqueue structure being freed as part of the
> driver '->priv_auto' destruction at ->remove() time.
>
> Call virtio_pci_del_vqs() from virtio_pci_reset() to free the virtqueue
> pages before freeing the virtqueue structure itself.
>
> Signed-off-by: Will Deacon <willdeacon@google.com>
> [ Paul: pick from the Android tree. Rebase to the upstream ]
> Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
> Cc: Bin Meng <bmeng.cn@gmail.com>
> Link: https://android.googlesource.com/platform/external/u-boot/+/5ed54ccd83cbffd0d8719ce650604b4e44b5b0d8
> ---
>  drivers/virtio/virtio_pci_modern.c | 38 +++++++++++++++---------------
>  1 file changed, 19 insertions(+), 19 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index cfde4007f5..3cdc2d2d6f 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -218,25 +218,6 @@  static int virtio_pci_set_status(struct udevice *udev, u8 status)
 	return 0;
 }
 
-static int virtio_pci_reset(struct udevice *udev)
-{
-	struct virtio_pci_priv *priv = dev_get_priv(udev);
-
-	/* 0 status means a reset */
-	iowrite8(0, &priv->common->device_status);
-
-	/*
-	 * After writing 0 to device_status, the driver MUST wait for a read
-	 * of device_status to return 0 before reinitializing the device.
-	 * This will flush out the status write, and flush in device writes,
-	 * including MSI-X interrupts, if any.
-	 */
-	while (ioread8(&priv->common->device_status))
-		udelay(1000);
-
-	return 0;
-}
-
 static int virtio_pci_get_features(struct udevice *udev, u64 *features)
 {
 	struct virtio_pci_priv *priv = dev_get_priv(udev);
@@ -363,6 +344,25 @@  static int virtio_pci_find_vqs(struct udevice *udev, unsigned int nvqs,
 	return 0;
 }
 
+static int virtio_pci_reset(struct udevice *udev)
+{
+	struct virtio_pci_priv *priv = dev_get_priv(udev);
+
+	/* 0 status means a reset */
+	iowrite8(0, &priv->common->device_status);
+
+	/*
+	 * After writing 0 to device_status, the driver MUST wait for a read
+	 * of device_status to return 0 before reinitializing the device.
+	 * This will flush out the status write, and flush in device writes,
+	 * including MSI-X interrupts, if any.
+	 */
+	while (ioread8(&priv->common->device_status))
+		udelay(1000);
+
+	return virtio_pci_del_vqs(udev);
+}
+
 static int virtio_pci_notify(struct udevice *udev, struct virtqueue *vq)
 {
 	struct virtio_pci_priv *priv = dev_get_priv(udev);