Skip to contentSkip to conversation

iommu: fix device remove

PATCH In review Rob Clark 4 participants 5 messages May 5, 2017 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 iommu: fix device remove

It looks like it *used* to make sense to free the device. But now it is embedded in 'struct iommu' (which is allocated or embedded in something that the device allocated).

Spotted when testing qcom_iommu with CONFIG_DEBUG_TEST_DRIVER_REMOVE.

Fixes 39ab955 ("iommu: Add sysfs bindings for struct iommu_device")
---
 drivers/iommu/iommu-sysfs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iommu/iommu-sysfs.c +0 -1
index c58351e..ad19cbb 100644
@@ -34,7 +34,6 @@ static const struct attribute_group *iommu_dev_groups[] = {
 
 static void iommu_release_device(struct device *dev)
 {
-	kfree(dev);
 }
 
 static struct class iommu_class = {
Signature · 1 line
2.9.3
#1 lore raw
Quoted 17 lines · Rob Clark

It looks like it *used* to make sense to free the device. But now it is embedded in 'struct iommu' (which is allocated or embedded in something that the device allocated).

Spotted when testing qcom_iommu with CONFIG_DEBUG_TEST_DRIVER_REMOVE.

Fixes 39ab955 ("iommu: Add sysfs bindings for struct iommu_device")
---
 drivers/iommu/iommu-sysfs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iommu/iommu-sysfs.c +0 -0
index c58351e..ad19cbb 100644

drivers/iommu/iommu-sysfs.c static const struct attribute_group *iommu_dev_groups[] = { · line 37

Quoted 5 lines
drivers/iommu/iommu-sysfs.c +0 -1
@@ -34,7 +34,6 @@ static const struct attribute_group *iommu_dev_groups[] = {
 
 static void iommu_release_device(struct device *dev)
 {
-	kfree(dev);
 }

As per the documentation in the kernel tree, I now get to make fun of you for doing such a crazh and foolish thing!

Come on, don't do that, a release function _HAS_ to free the memory involved. If not, then it is really broken...

greg k-h

#3 lore raw
In reply to a message not in the archive
Quoted 27 lines · Greg KH
Quoted 17 lines · Rob Clark

It looks like it *used* to make sense to free the device. But now it is embedded in 'struct iommu' (which is allocated or embedded in something that the device allocated).

Spotted when testing qcom_iommu with CONFIG_DEBUG_TEST_DRIVER_REMOVE.

Fixes 39ab955 ("iommu: Add sysfs bindings for struct iommu_device")
---
 drivers/iommu/iommu-sysfs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iommu/iommu-sysfs.c +0 -0
index c58351e..ad19cbb 100644

drivers/iommu/iommu-sysfs.c static const struct attribute_group *iommu_dev_groups[] = { · line 37

Quoted 5 lines
drivers/iommu/iommu-sysfs.c +0 -1
@@ -34,7 +34,6 @@ static const struct attribute_group *iommu_dev_groups[] = {
 
 static void iommu_release_device(struct device *dev)
 {
-     kfree(dev);
 }

As per the documentation in the kernel tree, I now get to make fun of you for doing such a crazh and foolish thing!

Quoted 2 lines

Come on, don't do that, a release function _HAS_ to free the memory involved. If not, then it is really broken...

There are shenanigans going on.. so release isn't counterpoint to a _probe() which allocates some memory. See iommu_device_sysfs_add(). So I'm not the one you get to make fun of ;-)

This the correct thing to do. Whether the way the extra fake device embedded in something allocated in the iommu driver's probe (and free'd it *it's* _release()) stuff for iommu sysfs stuff works is bonkers or not, I'll let someone else decide.. it was like that when I got here.

BR,
-R

Quoted 1 line

greg k-h

#5 lore raw
In reply to a message not in the archive
Quoted 35 lines · Rob Clark
Quoted 27 lines · Greg KH
Quoted 17 lines · Rob Clark

It looks like it *used* to make sense to free the device. But now it is embedded in 'struct iommu' (which is allocated or embedded in something that the device allocated).

Spotted when testing qcom_iommu with CONFIG_DEBUG_TEST_DRIVER_REMOVE.

Fixes 39ab955 ("iommu: Add sysfs bindings for struct iommu_device")
---
 drivers/iommu/iommu-sysfs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iommu/iommu-sysfs.c +0 -0
index c58351e..ad19cbb 100644

drivers/iommu/iommu-sysfs.c static const struct attribute_group *iommu_dev_groups[] = { · line 37

Quoted 5 lines
drivers/iommu/iommu-sysfs.c +0 -1
@@ -34,7 +34,6 @@ static const struct attribute_group *iommu_dev_groups[] = {
 
 static void iommu_release_device(struct device *dev)
 {
-     kfree(dev);
 }

As per the documentation in the kernel tree, I now get to make fun of you for doing such a crazh and foolish thing!

Quoted 2 lines

Come on, don't do that, a release function _HAS_ to free the memory involved. If not, then it is really broken...

There are shenanigans going on.. so release isn't counterpoint to a _probe() which allocates some memory. See iommu_device_sysfs_add(). So I'm not the one you get to make fun of ;-)

Quoted 5 lines

This the correct thing to do. Whether the way the extra fake device embedded in something allocated in the iommu driver's probe (and free'd it *it's* _release()) stuff for iommu sysfs stuff works is bonkers or not, I'll let someone else decide.. it was like that when I got here.

If you have multiple reference counts in the same structure, your code is wrong. That is the root issue here that needs to be resolved. Yes, your patch papers over that, but again, it isn't right either.

greg k-h

author
#6 lore raw
Quoted 42 lines · Greg KH
Quoted 35 lines · Rob Clark
Quoted 27 lines · Greg KH
Quoted 17 lines · Rob Clark

It looks like it *used* to make sense to free the device. But now it is embedded in 'struct iommu' (which is allocated or embedded in something that the device allocated).

Spotted when testing qcom_iommu with CONFIG_DEBUG_TEST_DRIVER_REMOVE.

Fixes 39ab955 ("iommu: Add sysfs bindings for struct iommu_device")
---
 drivers/iommu/iommu-sysfs.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iommu/iommu-sysfs.c +0 -0
index c58351e..ad19cbb 100644

drivers/iommu/iommu-sysfs.c static const struct attribute_group *iommu_dev_groups[] = { · line 37

Quoted 5 lines
drivers/iommu/iommu-sysfs.c +0 -1
@@ -34,7 +34,6 @@ static const struct attribute_group *iommu_dev_groups[] = {
 
 static void iommu_release_device(struct device *dev)
 {
-     kfree(dev);
 }

As per the documentation in the kernel tree, I now get to make fun of you for doing such a crazh and foolish thing!

Quoted 2 lines

Come on, don't do that, a release function _HAS_ to free the memory involved. If not, then it is really broken...

There are shenanigans going on.. so release isn't counterpoint to a _probe() which allocates some memory. See iommu_device_sysfs_add(). So I'm not the one you get to make fun of ;-)

Quoted 5 lines

This the correct thing to do. Whether the way the extra fake device embedded in something allocated in the iommu driver's probe (and free'd it *it's* _release()) stuff for iommu sysfs stuff works is bonkers or not, I'll let someone else decide.. it was like that when I got here.

Quoted 4 lines

If you have multiple reference counts in the same structure, your code is wrong. That is the root issue here that needs to be resolved. Yes, your patch papers over that, but again, it isn't right either.

fair enough, I should have been more precise and said that this patch is "the correct thing to do for how the code works now".. as far as bigger refactoring, I'll leave that to someone who understands why the code works the way it currently does. My patch at least makes things less wrong. (But removing an iommu is kind of a crazy thing to do so it's perhaps a rather theoretical problem.)

BR,
-R