[PATCH 1/2] iommufd/selftest: Use a fwnode to distinguish devices

From: Robin Murphy
Date: Tue Nov 28 2023 - 05:42:23 EST


With bus ops gone, the trick of registering against a specific bus no
longer really works, and we start getting given devices from other buses
to probe, which leads to spurious groups for devices with no IOMMU on
arm64, but may inadvertently steal devices from the real IOMMU on Intel,
AMD or S390. Driver coexistence is based on the fwspec mechanism, so
register with a non-NULL fwnode and give mock devices a corresponding
fwspec, to let the IOMMU core distinguish things correctly for us.

Signed-off-by: Robin Murphy <robin.murphy@xxxxxxx>
---
drivers/iommu/iommufd/selftest.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 5d93434003d8..f46ce0f8808d 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -432,7 +432,11 @@ static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)
return false;
}

+static struct fwnode_handle mock_fwnode = {
+};
+
static struct iommu_device mock_iommu_device = {
+ .fwnode = &mock_fwnode,
};

static struct iommu_device *mock_probe_device(struct device *dev)
@@ -569,12 +573,17 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags)
if (rc)
goto err_put;

+ rc = iommu_fwspec_init(&mdev->dev, &mock_fwnode, &mock_ops);
+ if (rc)
+ goto err_put;
+
rc = device_add(&mdev->dev);
if (rc)
goto err_put;
return mdev;

err_put:
+ iommu_fwspec_free(&mdev->dev);
put_device(&mdev->dev);
return ERR_PTR(rc);
}
--
2.39.2.101.g768bb238c484.dirty