* [RFC] iommu: arm-smmu: correct reference count @ 2015-11-03 12:59 Peng Fan 2015-11-03 13:17 ` Will Deacon 0 siblings, 1 reply; 5+ messages in thread From: Peng Fan @ 2015-11-03 12:59 UTC (permalink / raw) To: linux-arm-kernel iommu_group_alloc will initialize the reference count for group to 1. iommu_group_add_device also increase the group reference count, if nothing bad happends. And we need to add iommu_group_put to decrease the reference count for group. Signed-off-by: Peng Fan <van.freenix@gmail.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Joerg Roedel <joro@8bytes.org> --- Not sure whether my understanding is correct or not. I checked rockchip-iommu.c exynos-iommu.c and fsl_pamu_domain.c, and they all have iommu_group_put after iommu_group_add_device. drivers/iommu/arm-smmu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 48a39df..1cab720 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1344,6 +1344,7 @@ static int arm_smmu_add_platform_device(struct device *dev) struct iommu_group *group; struct arm_smmu_master *master; struct arm_smmu_device *smmu = find_smmu_for_device(dev); + int ret; if (!smmu) return -ENODEV; @@ -1358,7 +1359,11 @@ static int arm_smmu_add_platform_device(struct device *dev) return PTR_ERR(group); iommu_group_set_iommudata(group, &master->cfg, NULL); - return iommu_group_add_device(group, dev); + + ret = iommu_group_add_device(group, dev); + iommu_group_put(group); + + return ret; } static int arm_smmu_add_device(struct device *dev) -- 1.8.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [RFC] iommu: arm-smmu: correct reference count 2015-11-03 12:59 [RFC] iommu: arm-smmu: correct reference count Peng Fan @ 2015-11-03 13:17 ` Will Deacon 2015-11-04 2:48 ` Peng Fan 0 siblings, 1 reply; 5+ messages in thread From: Will Deacon @ 2015-11-03 13:17 UTC (permalink / raw) To: linux-arm-kernel On Tue, Nov 03, 2015 at 08:59:17PM +0800, Peng Fan wrote: > iommu_group_alloc will initialize the reference count for group to 1. > iommu_group_add_device also increase the group reference count, > if nothing bad happends. And we need to add iommu_group_put to > decrease the reference count for group. > > Signed-off-by: Peng Fan <van.freenix@gmail.com> > Cc: Will Deacon <will.deacon@arm.com> > Cc: Joerg Roedel <joro@8bytes.org> > --- > > Not sure whether my understanding is correct or not. I checked rockchip-iommu.c > exynos-iommu.c and fsl_pamu_domain.c, and they all have iommu_group_put after > iommu_group_add_device. Doesn't this pair up with the iommu_group_remove_device in arm_smmu_remove_device? Are you actually seeing an issue in practice? Will ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC] iommu: arm-smmu: correct reference count 2015-11-03 13:17 ` Will Deacon @ 2015-11-04 2:48 ` Peng Fan 2015-11-06 12:23 ` Will Deacon 0 siblings, 1 reply; 5+ messages in thread From: Peng Fan @ 2015-11-04 2:48 UTC (permalink / raw) To: linux-arm-kernel Hi Will, On Tue, Nov 03, 2015 at 01:17:34PM +0000, Will Deacon wrote: >On Tue, Nov 03, 2015 at 08:59:17PM +0800, Peng Fan wrote: >> iommu_group_alloc will initialize the reference count for group to 1. >> iommu_group_add_device also increase the group reference count, >> if nothing bad happends. And we need to add iommu_group_put to >> decrease the reference count for group. >> >> Signed-off-by: Peng Fan <van.freenix@gmail.com> >> Cc: Will Deacon <will.deacon@arm.com> >> Cc: Joerg Roedel <joro@8bytes.org> >> --- >> >> Not sure whether my understanding is correct or not. I checked rockchip-iommu.c >> exynos-iommu.c and fsl_pamu_domain.c, and they all have iommu_group_put after >> iommu_group_add_device. > >Doesn't this pair up with the iommu_group_remove_device in >arm_smmu_remove_device? Are you actually seeing an issue in practice? In arm_smmu_add_platform_device, iommu_group_alloc --> group->device_kobj ref count will be init to 1. iommu_group_add_device --> group->device_kobj ref count will be added 1 to 2. In arm_smmu_remove_device: iommu_group_remove_device --> Decrease group->device_kobj ref count by 1. After arm_smmu_remove_device, the ref count of group->device_kobj is not 0. So I think need to add iommu_group_put after iommu_group_add_device. If I am wrong, please correct me. Just code inspection, not have a platform to test this. Regards, Peng. > >Will >_______________________________________________ >iommu mailing list >iommu at lists.linux-foundation.org >https://lists.linuxfoundation.org/mailman/listinfo/iommu -- ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC] iommu: arm-smmu: correct reference count 2015-11-04 2:48 ` Peng Fan @ 2015-11-06 12:23 ` Will Deacon 2015-11-09 5:41 ` Peng Fan 0 siblings, 1 reply; 5+ messages in thread From: Will Deacon @ 2015-11-06 12:23 UTC (permalink / raw) To: linux-arm-kernel On Wed, Nov 04, 2015 at 10:48:28AM +0800, Peng Fan wrote: > On Tue, Nov 03, 2015 at 01:17:34PM +0000, Will Deacon wrote: > >On Tue, Nov 03, 2015 at 08:59:17PM +0800, Peng Fan wrote: > >> iommu_group_alloc will initialize the reference count for group to 1. > >> iommu_group_add_device also increase the group reference count, > >> if nothing bad happends. And we need to add iommu_group_put to > >> decrease the reference count for group. > >> > >> Signed-off-by: Peng Fan <van.freenix@gmail.com> > >> Cc: Will Deacon <will.deacon@arm.com> > >> Cc: Joerg Roedel <joro@8bytes.org> > >> --- > >> > >> Not sure whether my understanding is correct or not. I checked rockchip-iommu.c > >> exynos-iommu.c and fsl_pamu_domain.c, and they all have iommu_group_put after > >> iommu_group_add_device. > > > >Doesn't this pair up with the iommu_group_remove_device in > >arm_smmu_remove_device? Are you actually seeing an issue in practice? > > In arm_smmu_add_platform_device, > iommu_group_alloc --> group->device_kobj ref count will be init to 1. > iommu_group_add_device --> group->device_kobj ref count will be added 1 to 2. > > In arm_smmu_remove_device: > iommu_group_remove_device --> Decrease group->device_kobj ref count by 1. > After arm_smmu_remove_device, the ref count of group->device_kobj is not 0. > > So I think need to add iommu_group_put after iommu_group_add_device. > If I am wrong, please correct me. Ok, I see what you're saying. iommu_group_get_for_dev has exactly the same issue, so could you update arm-smmu-v3.c as well, please? Thanks, Will ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC] iommu: arm-smmu: correct reference count 2015-11-06 12:23 ` Will Deacon @ 2015-11-09 5:41 ` Peng Fan 0 siblings, 0 replies; 5+ messages in thread From: Peng Fan @ 2015-11-09 5:41 UTC (permalink / raw) To: linux-arm-kernel Hi Will, On Fri, Nov 06, 2015 at 12:23:39PM +0000, Will Deacon wrote: >On Wed, Nov 04, 2015 at 10:48:28AM +0800, Peng Fan wrote: >> On Tue, Nov 03, 2015 at 01:17:34PM +0000, Will Deacon wrote: >> >On Tue, Nov 03, 2015 at 08:59:17PM +0800, Peng Fan wrote: >> >> iommu_group_alloc will initialize the reference count for group to 1. >> >> iommu_group_add_device also increase the group reference count, >> >> if nothing bad happends. And we need to add iommu_group_put to >> >> decrease the reference count for group. >> >> >> >> Signed-off-by: Peng Fan <van.freenix@gmail.com> >> >> Cc: Will Deacon <will.deacon@arm.com> >> >> Cc: Joerg Roedel <joro@8bytes.org> >> >> --- >> >> >> >> Not sure whether my understanding is correct or not. I checked rockchip-iommu.c >> >> exynos-iommu.c and fsl_pamu_domain.c, and they all have iommu_group_put after >> >> iommu_group_add_device. >> > >> >Doesn't this pair up with the iommu_group_remove_device in >> >arm_smmu_remove_device? Are you actually seeing an issue in practice? >> >> In arm_smmu_add_platform_device, >> iommu_group_alloc --> group->device_kobj ref count will be init to 1. >> iommu_group_add_device --> group->device_kobj ref count will be added 1 to 2. >> >> In arm_smmu_remove_device: >> iommu_group_remove_device --> Decrease group->device_kobj ref count by 1. >> After arm_smmu_remove_device, the ref count of group->device_kobj is not 0. >> >> So I think need to add iommu_group_put after iommu_group_add_device. >> If I am wrong, please correct me. > >Ok, I see what you're saying. iommu_group_get_for_dev has exactly the >same issue, so could you update arm-smmu-v3.c as well, please? I did not see the update about device_group for iommu, when I worked out this patch. Rebased to latest linux/master, whether to arm-smmu.c or arm-smmu-v3.c, only add 'iommu_group_put' at the end of iommu_group_get_for_dev is ok as the following. I'll send out V2. Thanks, Peng. > >Thanks, > >Will ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-11-09 5:41 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-11-03 12:59 [RFC] iommu: arm-smmu: correct reference count Peng Fan 2015-11-03 13:17 ` Will Deacon 2015-11-04 2:48 ` Peng Fan 2015-11-06 12:23 ` Will Deacon 2015-11-09 5:41 ` Peng Fan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).