* Re: [PATCH v5 15/25] iommufd/selftest: Make the mock iommu driver into a real driver
[not found] ` <15-v5-d0a204c678c7+3d16a-iommu_all_defdom_jgg@nvidia.com>
@ 2023-08-02 23:50 ` Jason Gunthorpe
0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2023-08-02 23:50 UTC (permalink / raw)
To: Andy Gross, Alim Akhtar, Bjorn Andersson,
AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
Matthias Brugger, Matthew Rosato, Michael Ellerman,
Nicholas Piggin, Orson Zhai, Rob Clark, Robin Murphy,
Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
Will Deacon, Yong Wu, Chunyan Zhang
Cc: Lu Baolu, Dmitry Osipenko, Marek Szyprowski, Nicolin Chen,
Niklas Schnelle, Steven Price, Thierry Reding
On Mon, Jul 24, 2023 at 02:22:05PM -0300, Jason Gunthorpe wrote:
> -void __init iommufd_test_init(void)
> +int __init iommufd_test_init(void)
> {
> + struct platform_device_info pdevinfo = {
> + .name = "iommufd_selftest_iommu",
> + };
> + int rc;
> +
> dbgfs_root =
> fault_create_debugfs_attr("fail_iommufd", NULL, &fail_iommufd);
> - WARN_ON(bus_register(&iommufd_mock_bus_type));
> +
> + selftest_iommu_dev = platform_device_register_full(&pdevinfo);
> + if (IS_ERR(selftest_iommu_dev)) {
> + rc = PTR_ERR(selftest_iommu_dev);
> + goto err_dbgfs;
> + }
> +
> + rc = bus_register(&iommufd_mock_bus_type.bus);
> + if (rc)
> + goto err_platform;
> +
> + mock_iommu_device.dev = &selftest_iommu_dev->dev;
> + rc = iommu_device_register_bus(&mock_iommu_device, &mock_ops,
> + &iommufd_mock_bus_type.bus,
> + &iommufd_mock_bus_type.nb);
> + if (rc)
> + goto err_bus;
> + return 0;
> +
> +err_bus:
> + bus_unregister(&iommufd_mock_bus_type.bus);
> +err_platform:
> + platform_device_del(selftest_iommu_dev);
> +err_dbgfs:
> + debugfs_remove_recursive(dbgfs_root);
> + return rc;
> }
>
> void iommufd_test_exit(void)
> {
> + iommu_device_unregister_bus(&mock_iommu_device,
> + &iommufd_mock_bus_type.bus,
> + &iommufd_mock_bus_type.nb);
> + bus_unregister(&iommufd_mock_bus_type.bus);
> + platform_device_del(selftest_iommu_dev);
> debugfs_remove_recursive(dbgfs_root);
> - bus_unregister(&iommufd_mock_bus_type);
> }
There is a mistake here that started to become visible after one of
the rebases, it needs to call iommu_device_sysfs_add() prior to
iommu_device_register_bus() otherwise the iommu core stuff does not
fully initialize and weird stuff starts happening.
So, it needs this:
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 5433c9c545526d..d2b59a1157441c 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -987,14 +987,21 @@ int __init iommufd_test_init(void)
if (rc)
goto err_platform;
- mock_iommu_device.dev = &selftest_iommu_dev->dev;
+ rc = iommu_device_sysfs_add(&mock_iommu_device,
+ &selftest_iommu_dev->dev, NULL, "%s",
+ dev_name(&selftest_iommu_dev->dev));
+ if (rc)
+ goto err_bus;
+
rc = iommu_device_register_bus(&mock_iommu_device, &mock_ops,
&iommufd_mock_bus_type.bus,
&iommufd_mock_bus_type.nb);
if (rc)
- goto err_bus;
+ goto err_sysfs;
return 0;
+err_sysfs:
+ iommu_device_sysfs_remove(&mock_iommu_device);
err_bus:
bus_unregister(&iommufd_mock_bus_type.bus);
err_platform:
@@ -1006,6 +1013,7 @@ int __init iommufd_test_init(void)
void iommufd_test_exit(void)
{
+ iommu_device_sysfs_remove(&mock_iommu_device);
iommu_device_unregister_bus(&mock_iommu_device,
&iommufd_mock_bus_type.bus,
&iommufd_mock_bus_type.nb);
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 2+ messages in thread