iommu: Fix iommu selftest running test mock domain fail
PATCH v2 1/1 iommu: Fix iommu selftest running test mock domain fail
When intel_iommu=on is enabled and the iommu selftests are executed, we observed multiple test case failures. Our investigation revealed that both the Intel iommu driver and the mock iommu driver registered iommu_device instances with fwnode=NULL, and both were added to the iommu_device_list. Later, when the mock iommu driver attempted to create a device, iommu_init_device attempted to retrieve the iommu_ops by searching the iommu_device_list using the provided fwnode (which was NULL).
Since the iommu_device registered by the Intel iommu driver appeared earlier in the list, it was matched first instead of the mock iommu driver's iommu_device. This ultimately caused probe_device to fail.
Fix this by alloc a software fwnode for mock iommu driver's iommu_device, and set it to the device which mock iommu driver created.
Test by "make -C toosl/testing/selftests TARGETS=iommu run_tests":
PASSED: 229 / 229 tests passed.
In addition, this issue is also can be found on amd platform, and also tested on a amd machine.
---
Changes from v1 to v2:
- Remove print when iommu_fwspec_init() fail.
drivers/iommu/iommu.c | 12 ++++++++++++ drivers/iommu/iommufd/selftest.c | 9 +++++++++ 2 files changed, 21 insertions(+)
drivers/iommu/iommu.c +12 -0
@@ -304,6 +304,7 @@ void iommu_device_unregister_bus(struct iommu_device *iommu, struct notifier_block *nb) {bus_unregister_notifier (bus, nb); +fwnode_remove_software_node (iommu->fwnode);iommu_device_unregister (iommu); }EXPORT_SYMBOL_GPL (iommu_device_unregister_bus);
@@ -326,6 +327,14 @@ int iommu_device_register_bus(struct iommu_device *iommu,if (err)return err; + iommu->fwnode =fwnode_create_software_node (NULL ,NULL ); +if (IS_ERR (iommu->fwnode)) { + iommu->fwnode =NULL ; +dev_err (iommu->dev,"add property failed:%d\n" , err); +bus_unregister_notifier (bus, nb); +return err; + } +spin_lock (&iommu_device_lock);list_add_tail (&iommu->list, &iommu_device_list);spin_unlock (&iommu_device_lock);
@@ -335,6 +344,7 @@ int iommu_device_register_bus(struct iommu_device *iommu,iommu_device_unregister_bus (iommu, bus, nb);return err; } +WRITE_ONCE (iommu->ready, true);return 0 ; }EXPORT_SYMBOL_GPL (iommu_device_register_bus);
@@ -555,6 +565,7 @@ static struct iommu_domain *pasid_array_entry_to_domain(void *entry) }DEFINE_MUTEX (iommu_probe_device_lock); +EXPORT_SYMBOL_GPL (iommu_probe_device_lock);static int __iommu_probe_device (struct device *dev,struct list_head *group_list) {
@@ -2914,6 +2925,7 @@ void iommu_fwspec_free(struct device *dev)dev_iommu_fwspec_set (dev,NULL ); } } +EXPORT_SYMBOL_GPL (iommu_fwspec_free);int iommu_fwspec_add_ids (struct device *dev,const u32 *ids,int num_ids) {
drivers/iommu/iommufd/selftest.c +9 -0
@@ -1126,12 +1126,21 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) goto err_put; } +mutex_lock (&iommu_probe_device_lock); + rc =iommu_fwspec_init (&mdev->dev, mock_iommu.iommu_dev.fwnode); +if (rc) { +mutex_unlock (&iommu_probe_device_lock); + goto err_put; + } +mutex_unlock (&iommu_probe_device_lock); + 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); }
Signature · 1 line
2.43.0
Gently ping...
Best Regards,
Guixin Liu
Quoted 108 lines · Guixin Liu
When intel_iommu=on is enabled and the iommu selftests are executed, we observed multiple test case failures. Our investigation revealed that both the Intel iommu driver and the mock iommu driver registered
iommu_deviceinstances with fwnode=NULL, and both were added to theiommu_device_list. Later, when the mock iommu driver attempted to create a device,iommu_init_deviceattempted to retrieve theiommu_opsby searching theiommu_device_listusing the provided fwnode (which was NULL).
Since theiommu_deviceregistered by the Intel iommu driver appeared earlier in the list, it was matched first instead of the mock iommu driver'siommu_device. This ultimately causedprobe_deviceto fail.Fix this by alloc a software fwnode for mock iommu driver's
iommu_device, and set it to the device which mock iommu driver created.Test by "make -C toosl/testing/selftests TARGETS=iommu
run_tests":
PASSED: 229 / 229 tests passed.In addition, this issue is also can be found on amd platform, and also tested on a amd machine.
Signed-off-by Guixin Liu <[email protected]>Tested-by Qinyun Tan <[email protected]>---
Changes from v1 to v2:
- Remove print wheniommu_fwspec_init()fail.drivers/iommu/iommu.c | 12 ++++++++++++ drivers/iommu/iommufd/selftest.c | 9 +++++++++ 2 files changed, 21 insertions(+)drivers/iommu/iommu.c +12
-0@@ -304,6 +304,7 @@ void iommu_device_unregister_bus(struct iommu_device *iommu, struct notifier_block *nb) {bus_unregister_notifier (bus, nb); +fwnode_remove_software_node (iommu->fwnode);iommu_device_unregister (iommu); }EXPORT_SYMBOL_GPL (iommu_device_unregister_bus);@@ -326,6 +327,14 @@ int iommu_device_register_bus(struct iommu_device *iommu,if (err)return err; + iommu->fwnode =fwnode_create_software_node (NULL ,NULL ); +if (IS_ERR (iommu->fwnode)) { + iommu->fwnode =NULL ; +dev_err (iommu->dev,"add property failed:%d\n" , err); +bus_unregister_notifier (bus, nb); +return err; + } +spin_lock (&iommu_device_lock);list_add_tail (&iommu->list, &iommu_device_list);spin_unlock (&iommu_device_lock);@@ -335,6 +344,7 @@ int iommu_device_register_bus(struct iommu_device *iommu,iommu_device_unregister_bus (iommu, bus, nb);return err; } +WRITE_ONCE (iommu->ready, true);return 0 ; }EXPORT_SYMBOL_GPL (iommu_device_register_bus);@@ -555,6 +565,7 @@ static struct iommu_domain *pasid_array_entry_to_domain(void *entry) }DEFINE_MUTEX (iommu_probe_device_lock); +EXPORT_SYMBOL_GPL (iommu_probe_device_lock);static int __iommu_probe_device (struct device *dev,struct list_head *group_list) {@@ -2914,6 +2925,7 @@ void iommu_fwspec_free(struct device *dev)dev_iommu_fwspec_set (dev,NULL ); } } +EXPORT_SYMBOL_GPL (iommu_fwspec_free);int iommu_fwspec_add_ids (struct device *dev,const u32 *ids,int num_ids) {drivers/iommu/iommufd/selftest.c +9
-0@@ -1126,12 +1126,21 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) goto err_put; } +mutex_lock (&iommu_probe_device_lock); + rc =iommu_fwspec_init (&mdev->dev, mock_iommu.iommu_dev.fwnode); +if (rc) { +mutex_unlock (&iommu_probe_device_lock); + goto err_put; + } +mutex_unlock (&iommu_probe_device_lock); + 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); }
Quoted 67 lines · Guixin Liu
When intel_iommu=on is enabled and the iommu selftests are executed, we observed multiple test case failures. Our investigation revealed that both the Intel iommu driver and the mock iommu driver registered
iommu_deviceinstances with fwnode=NULL, and both were added to theiommu_device_list. Later, when the mock iommu driver attempted to create a device,iommu_init_deviceattempted to retrieve theiommu_opsby searching theiommu_device_listusing the provided fwnode (which was NULL).
Since theiommu_deviceregistered by the Intel iommu driver appeared earlier in the list, it was matched first instead of the mock iommu driver'siommu_device. This ultimately causedprobe_deviceto fail.Fix this by alloc a software fwnode for mock iommu driver's
iommu_device, and set it to the device which mock iommu driver created.Test by "make -C toosl/testing/selftests TARGETS=iommu
run_tests":
PASSED: 229 / 229 tests passed.In addition, this issue is also can be found on amd platform, and also tested on a amd machine.
Signed-off-by Guixin Liu <[email protected]>Tested-by Qinyun Tan <[email protected]>---
Changes from v1 to v2:
- Remove print wheniommu_fwspec_init()fail.drivers/iommu/iommu.c | 12 ++++++++++++ drivers/iommu/iommufd/selftest.c | 9 +++++++++ 2 files changed, 21 insertions(+)drivers/iommu/iommu.c +10
-0@@ -304,6 +304,7 @@ void iommu_device_unregister_bus(struct iommu_device *iommu, struct notifier_block *nb) {bus_unregister_notifier (bus, nb); +fwnode_remove_software_node (iommu->fwnode);iommu_device_unregister (iommu); }EXPORT_SYMBOL_GPL (iommu_device_unregister_bus);@@ -326,6 +327,14 @@ int iommu_device_register_bus(struct iommu_device *iommu,if (err)return err; + iommu->fwnode =fwnode_create_software_node (NULL ,NULL ); +if (IS_ERR (iommu->fwnode)) { + iommu->fwnode =NULL ; +dev_err (iommu->dev,"add property failed:%d\n" , err); +bus_unregister_notifier (bus, nb); +return err; + } +spin_lock (&iommu_device_lock);list_add_tail (&iommu->list, &iommu_device_list);spin_unlock (&iommu_device_lock);@@ -335,6 +344,7 @@ int iommu_device_register_bus(struct iommu_device *iommu,iommu_device_unregister_bus (iommu, bus, nb);return err; } +WRITE_ONCE (iommu->ready, true);return 0 ; }EXPORT_SYMBOL_GPL (iommu_device_register_bus);
drivers/iommu/iommu.c static struct iommu_domain *pasid_array_entry_to_domain(void *entry) · line 568
Quoted 4 lines
drivers/iommu/iommu.c +1
-0@@ -555,6 +565,7 @@ static struct iommu_domain *pasid_array_entry_to_domain(void *entry) }DEFINE_MUTEX (iommu_probe_device_lock); +EXPORT_SYMBOL_GPL (iommu_probe_device_lock);
I'm still unhappy to see this exported.
I'd rather you export some new selftest only functions for this special fwspec usage.
We already have the block
#if IS_ENABLED(CONFIG_IOMMUFD_TEST)
in iommu.c
So lest add a
iommu_mock_device_init(struct device *dev, struct iommu_device *iommu); iommu_mock_device_abort(struct device *dev);
Quoted 13 lines
drivers/iommu/iommufd/selftest.c +7
-0@@ -1126,12 +1126,21 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) goto err_put; } +mutex_lock (&iommu_probe_device_lock); + rc =iommu_fwspec_init (&mdev->dev, mock_iommu.iommu_dev.fwnode); +if (rc) { +mutex_unlock (&iommu_probe_device_lock); + goto err_put; + } +mutex_unlock (&iommu_probe_device_lock);
drivers/iommu/iommufd/selftest.c static struct mock_dev *mock_dev_create(unsigned long dev_flags) · line 1145
Quoted 10 lines
drivers/iommu/iommufd/selftest.c +2
-0+ 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);
That handles these two cases.
Jason
Quoted 79 lines · Jason Gunthorpe
Quoted 67 lines · Guixin Liu
When intel_iommu=on is enabled and the iommu selftests are executed, we observed multiple test case failures. Our investigation revealed that both the Intel iommu driver and the mock iommu driver registered
iommu_deviceinstances with fwnode=NULL, and both were added to theiommu_device_list. Later, when the mock iommu driver attempted to create a device,iommu_init_deviceattempted to retrieve theiommu_opsby searching theiommu_device_listusing the provided fwnode (which was NULL).
Since theiommu_deviceregistered by the Intel iommu driver appeared earlier in the list, it was matched first instead of the mock iommu driver'siommu_device. This ultimately causedprobe_deviceto fail.Fix this by alloc a software fwnode for mock iommu driver's
iommu_device, and set it to the device which mock iommu driver created.Test by "make -C toosl/testing/selftests TARGETS=iommu
run_tests":
PASSED: 229 / 229 tests passed.In addition, this issue is also can be found on amd platform, and also tested on a amd machine.
Signed-off-by Guixin Liu <[email protected]>Tested-by Qinyun Tan <[email protected]>---
Changes from v1 to v2:
- Remove print wheniommu_fwspec_init()fail.drivers/iommu/iommu.c | 12 ++++++++++++ drivers/iommu/iommufd/selftest.c | 9 +++++++++ 2 files changed, 21 insertions(+)drivers/iommu/iommu.c +10
-0@@ -304,6 +304,7 @@ void iommu_device_unregister_bus(struct iommu_device *iommu, struct notifier_block *nb) {bus_unregister_notifier (bus, nb); +fwnode_remove_software_node (iommu->fwnode);iommu_device_unregister (iommu); }EXPORT_SYMBOL_GPL (iommu_device_unregister_bus);@@ -326,6 +327,14 @@ int iommu_device_register_bus(struct iommu_device *iommu,if (err)return err; + iommu->fwnode =fwnode_create_software_node (NULL ,NULL ); +if (IS_ERR (iommu->fwnode)) { + iommu->fwnode =NULL ; +dev_err (iommu->dev,"add property failed:%d\n" , err); +bus_unregister_notifier (bus, nb); +return err; + } +spin_lock (&iommu_device_lock);list_add_tail (&iommu->list, &iommu_device_list);spin_unlock (&iommu_device_lock);@@ -335,6 +344,7 @@ int iommu_device_register_bus(struct iommu_device *iommu,iommu_device_unregister_bus (iommu, bus, nb);return err; } +WRITE_ONCE (iommu->ready, true);return 0 ; }EXPORT_SYMBOL_GPL (iommu_device_register_bus);drivers/iommu/iommu.c static struct iommu_domain *pasid_array_entry_to_domain(void *entry) · line 568
Quoted 4 lines
drivers/iommu/iommu.c +1
-0@@ -555,6 +565,7 @@ static struct iommu_domain *pasid_array_entry_to_domain(void *entry) }DEFINE_MUTEX (iommu_probe_device_lock); +EXPORT_SYMBOL_GPL (iommu_probe_device_lock);I'm still unhappy to see this exported.
I'd rather you export some new selftest only functions for this special fwspec usage.
We already have the block
Quoted 8 lines
#if
IS_ENABLED(CONFIG_IOMMUFD_TEST)in
iommu.cSo lest add a
iommu_mock_device_init(struct device *dev, struct iommu_device *iommu);iommu_mock_device_abort(struct device *dev);
OK, Changed in v3, thanks.
Best Regards,
Guixin Liu
Quoted 26 lines
Quoted 13 lines
drivers/iommu/iommufd/selftest.c +7
-0@@ -1126,12 +1126,21 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags) goto err_put; } +mutex_lock (&iommu_probe_device_lock); + rc =iommu_fwspec_init (&mdev->dev, mock_iommu.iommu_dev.fwnode); +if (rc) { +mutex_unlock (&iommu_probe_device_lock); + goto err_put; + } +mutex_unlock (&iommu_probe_device_lock);drivers/iommu/iommufd/selftest.c static struct mock_dev *mock_dev_create(unsigned long dev_flags) · line 1145
Quoted 10 lines
drivers/iommu/iommufd/selftest.c +2
-0+ 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);That handles these two cases.
Jason