Skip to content

Commit f875c3d

Browse files
rmurphy-armgregkh
authored andcommitted
iommu/virtio: Make instance lookup robust
[ Upstream commit 72b6f7c ] Much like arm-smmu in commit 7d83513 ("iommu/arm-smmu: Make instance lookup robust"), virtio-iommu appears to have the same issue where iommu_device_register() makes the IOMMU instance visible to other API callers (including itself) straight away, but internally the instance isn't ready to recognise itself for viommu_probe_device() to work correctly until after viommu_probe() has returned. This matters a lot more now that bus_iommu_probe() has the DT/VIOT knowledge to probe client devices the way that was always intended. Tweak the lookup and initialisation in much the same way as for arm-smmu, to ensure that what we register is functional and ready to go. Cc: stable@vger.kernel.org Fixes: bcb81ac ("iommu: Get DT/ACPI parsing into the proper probe path") Signed-off-by: Robin Murphy <robin.murphy@arm.com> Tested-by: Eric Auger <eric.auger@redhat.com> Link: https://lore.kernel.org/r/308911aaa1f5be32a3a709996c7bd6cf71d30f33.1755190036.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7a4c7d8 commit f875c3d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/iommu/virtio-iommu.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,7 @@ static void viommu_get_resv_regions(struct device *dev, struct list_head *head)
998998
iommu_dma_get_resv_regions(dev, head);
999999
}
10001000

1001-
static const struct iommu_ops viommu_ops;
1002-
static struct virtio_driver virtio_iommu_drv;
1001+
static const struct bus_type *virtio_bus_type;
10031002

10041003
static int viommu_match_node(struct device *dev, const void *data)
10051004
{
@@ -1008,8 +1007,9 @@ static int viommu_match_node(struct device *dev, const void *data)
10081007

10091008
static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
10101009
{
1011-
struct device *dev = driver_find_device(&virtio_iommu_drv.driver, NULL,
1012-
fwnode, viommu_match_node);
1010+
struct device *dev = bus_find_device(virtio_bus_type, NULL, fwnode,
1011+
viommu_match_node);
1012+
10131013
put_device(dev);
10141014

10151015
return dev ? dev_to_virtio(dev)->priv : NULL;
@@ -1160,6 +1160,9 @@ static int viommu_probe(struct virtio_device *vdev)
11601160
if (!viommu)
11611161
return -ENOMEM;
11621162

1163+
/* Borrow this for easy lookups later */
1164+
virtio_bus_type = dev->bus;
1165+
11631166
spin_lock_init(&viommu->request_lock);
11641167
ida_init(&viommu->domain_ids);
11651168
viommu->dev = dev;
@@ -1229,10 +1232,10 @@ static int viommu_probe(struct virtio_device *vdev)
12291232
if (ret)
12301233
goto err_free_vqs;
12311234

1232-
iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
1233-
12341235
vdev->priv = viommu;
12351236

1237+
iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
1238+
12361239
dev_info(dev, "input address: %u bits\n",
12371240
order_base_2(viommu->geometry.aperture_end));
12381241
dev_info(dev, "page mask: %#llx\n", viommu->pgsize_bitmap);

0 commit comments

Comments
 (0)