FAILED: patch "[PATCH] iommu/virtio: Reset device before deleting virtqueues on probe failure" failed to apply to 5.10-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 1f8efac19a0870cdfdf8477e447e5a07ddce9623
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 1f8efac19a0870cdfdf8477e447e5a07ddce9623 Mon Sep 17 00:00:00 2001
From: Yuho Choi <[email protected]>
Date: Sun, 4 Oct 2026 14:21:10 -0400
Subject: [PATCH] iommu/virtio: Reset device before deleting virtqueues on
probe failure
viommu_probe() marks the device DRIVER_OK before populating the event virtqueue and registering the IOMMU device in sysfs. viommu_fill_evtq() hands the device a set of device-writable buffers through virtqueue_add_inbuf(), so from that point on the device may write into them and into the rings.
If either step fails, the error path deletes the virtqueues without resetting the device first. The event buffers are allocated with devm_kmalloc_array() and are released as probe unwinds, so the device can go on writing to memory that has been freed.
Reset the device before deleting the virtqueues, the way viommu_remove() already does.
Message-ID: <[email protected]>
--- drivers/iommu/virtio-iommu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/virtio-iommu.c +4 -2
@@ -1227,12 +1227,12 @@ static int viommu_probe(struct virtio_device *vdev)/* Populate the event queue with buffers */ ret =viommu_fill_evtq (viommu);if (ret) - goto err_free_vqs; + goto err_reset_vdev; ret =iommu_device_sysfs_add (&viommu->iommu, dev,NULL ,"%s" ,virtio_bus_name (vdev));if (ret) - goto err_free_vqs; + goto err_reset_vdev; vdev->priv = viommu;
@@ -1244,6 +1244,8 @@ static int viommu_probe(struct virtio_device *vdev)return 0 ; +err_reset_vdev: +virtio_reset_device (vdev); err_free_vqs: vdev->config->del_vqs (vdev);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 iommu/virtio: Clean up bus_set_iommu()
From: Robin Murphy <[email protected]>
[ Upstream commit 19d3607c74bc0332f0ee3a2d54ead6e792c0dce9 ]
Stop calling bus_set_iommu() since it's now unnecessary, and simplify the probe failure path accordingly.
Stable-dep-of: 1f8efac19a08 ("iommu/virtio: Reset device before deleting virtqueues on probe failure")
--- drivers/iommu/virtio-iommu.c | 25 ------------------------- 1 file changed, 25 deletions(-)
drivers/iommu/virtio-iommu.c +0 -25
@@ -7,7 +7,6 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/amba/bus.h> #include <linux/delay.h> #include <linux/dma-iommu.h> #include <linux/freezer.h>
@@ -17,7 +16,6 @@#include <linux/of_iommu.h> #include <linux/of_platform.h> #include <linux/pci.h> -#include <linux/platform_device.h> #include <linux/virtio.h> #include <linux/virtio_config.h> #include <linux/virtio_ids.h>
@@ -1070,26 +1068,6 @@ static int viommu_probe(struct virtio_device *vdev)iommu_device_register (&viommu->iommu); -#ifdef CONFIG_PCI -if (pci_bus_type.iommu_ops != &viommu_ops) { - ret =bus_set_iommu (&pci_bus_type, &viommu_ops); -if (ret) - goto err_unregister; - } -#endif -#ifdef CONFIG_ARM_AMBA -if (amba_bustype.iommu_ops != &viommu_ops) { - ret =bus_set_iommu (&amba_bustype, &viommu_ops); -if (ret) - goto err_unregister; - } -#endif -if (platform_bus_type.iommu_ops != &viommu_ops) { - ret =bus_set_iommu (&platform_bus_type, &viommu_ops); -if (ret) - goto err_unregister; - } - vdev->priv = viommu; dev_info(dev, "input address: %u bits\n",
@@ -1098,9 +1076,6 @@ static int viommu_probe(struct virtio_device *vdev)return 0 ; -err_unregister: -iommu_device_sysfs_remove (&viommu->iommu); -iommu_device_unregister (&viommu->iommu); err_free_vqs: vdev->config->del_vqs (vdev);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 iommu/virtio: Reset device before deleting virtqueues on probe failure
From: Yuho Choi <[email protected]>
[ Upstream commit 1f8efac19a0870cdfdf8477e447e5a07ddce9623 ]
viommu_probe() marks the device DRIVER_OK before populating the event virtqueue and registering the IOMMU device in sysfs. viommu_fill_evtq() hands the device a set of device-writable buffers through virtqueue_add_inbuf(), so from that point on the device may write into them and into the rings.
If either step fails, the error path deletes the virtqueues without resetting the device first. The event buffers are allocated with devm_kmalloc_array() and are released as probe unwinds, so the device can go on writing to memory that has been freed.
Reset the device before deleting the virtqueues, the way viommu_remove() already does.
Message-ID: <[email protected]>
--- drivers/iommu/virtio-iommu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/virtio-iommu.c +4 -2
@@ -1056,12 +1056,12 @@ static int viommu_probe(struct virtio_device *vdev)/* Populate the event queue with buffers */ ret =viommu_fill_evtq (viommu);if (ret) - goto err_free_vqs; + goto err_reset_vdev; ret =iommu_device_sysfs_add (&viommu->iommu, dev,NULL ,"%s" ,virtio_bus_name (vdev));if (ret) - goto err_free_vqs; + goto err_reset_vdev;iommu_device_set_ops (&viommu->iommu, &viommu_ops);iommu_device_set_fwnode (&viommu->iommu, parent_dev->fwnode);
@@ -1076,6 +1076,8 @@ static int viommu_probe(struct virtio_device *vdev)return 0 ; +err_reset_vdev: + vdev->config->reset (vdev); err_free_vqs: vdev->config->del_vqs (vdev);
Signature · 1 line
2.53.0
Robin Murphy
reviewerRe: [PATCH 5.10.y 1/2] iommu/virtio: Clean up bus_set_iommu()
In reply to Sasha LevinQuoted 6 lines · Sasha Levin
From: Robin Murphy <[email protected]>
[ Upstream commit
19d3607c74bc0332f0ee3a2d54ead6e792c0dce9]Stop calling
bus_set_iommu()since it's now unnecessary, and simplify the probe failure path accordingly.
Wait, no - that "now unnecessary" is only in the context of that entire patch series (in the link), which was a fairly significant subsystem-level redesign not suitable for backporting. Applying this patch on its own will just completely break this driver.
Thanks,
Robin.
Quoted 67 lines
Reviewed-by Jean-Philippe Brucker <[email protected]>Signed-off-by Robin Murphy <[email protected]>Link https://lore.kernel.org/r/0ff6f9166081724510e6772e43d45b317cab8c58.1660572783.git.robin.murphy@arm.com open hereSigned-off-by Joerg Roedel <[email protected]>Stable-dep-of:
1f8efac19a08("iommu/virtio: Reset device before deleting virtqueues on probe failure")Signed-off-by Sasha Levin <[email protected]>--- drivers/iommu/virtio-iommu.c | 25 ------------------------- 1 file changed, 25 deletions(-)drivers/iommu/virtio-iommu.c +0
-25@@ -7,7 +7,6 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/amba/bus.h> #include <linux/delay.h> #include <linux/dma-iommu.h> #include <linux/freezer.h> @@ -17,7 +16,6 @@#include <linux/of_iommu.h> #include <linux/of_platform.h> #include <linux/pci.h> -#include <linux/platform_device.h> #include <linux/virtio.h> #include <linux/virtio_config.h> #include <linux/virtio_ids.h> @@ -1070,26 +1068,6 @@ static int viommu_probe(struct virtio_device *vdev)iommu_device_register (&viommu->iommu); -#ifdef CONFIG_PCI -if (pci_bus_type.iommu_ops != &viommu_ops) { - ret =bus_set_iommu (&pci_bus_type, &viommu_ops); -if (ret) - goto err_unregister; - } -#endif -#ifdef CONFIG_ARM_AMBA -if (amba_bustype.iommu_ops != &viommu_ops) { - ret =bus_set_iommu (&amba_bustype, &viommu_ops); -if (ret) - goto err_unregister; - } -#endif -if (platform_bus_type.iommu_ops != &viommu_ops) { - ret =bus_set_iommu (&platform_bus_type, &viommu_ops); -if (ret) - goto err_unregister; - } - vdev->priv = viommu; dev_info(dev, "input address: %u bits\n",@@ -1098,9 +1076,6 @@ static int viommu_probe(struct virtio_device *vdev)return 0 ; -err_unregister: -iommu_device_sysfs_remove (&viommu->iommu); -iommu_device_unregister (&viommu->iommu); err_free_vqs: vdev->config->del_vqs (vdev);
Sasha Levin
maintainerRe: [PATCH 5.10.y 1/2] iommu/virtio: Clean up bus_set_iommu()
Quoted 4 lines · Robin Murphy
Wait, no - that "now unnecessary" is only in the context of that entire patch series (in the link), which was a fairly significant subsystem-level redesign not suitable for backporting. Applying this patch on its own will just completely break this driver.
You are right, sorry about that. I dropped this patch. Only the fix, 1f8efac19a08 ("iommu/virtio: Reset device before deleting virtqueues on probe failure"), is queued for 5.10 (and 5.15), without the bus_set_iommu() cleanup.
Signature · 2 lines
Thanks, Sasha