From: Peng Fan <van.freenix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Alex Williamson
<alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: will.deacon-5wv7dgnIgG8@public.gmane.org,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [RFC V2] iommu: correct group reference count
Date: Tue, 10 Nov 2015 09:24:09 +0800 [thread overview]
Message-ID: <20151110012407.GA17404@linux-jyl1.ap.freescale.net> (raw)
In-Reply-To: <1447082889.4925.5.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Hi Alex,
On Mon, Nov 09, 2015 at 08:28:09AM -0700, Alex Williamson wrote:
>On Mon, 2015-11-09 at 14:13 +0800, Peng Fan wrote:
>> The basic flow for iommu_group_for_dev is:
>> iommu_group_get_for_dev
>> |-> iommu_group_get : increase reference count by 1.
>> return group;
>> |-> ops->device_group : Init/increase reference count to/by 1.
>> iommu_group_add_device : Increase reference count by 1.
>> return group;
>>
>> We can see that ops->device_group and iommu_group_add_device will together
>> increase the iommu group reference count by 2. Actually we only need 1,
>> but not 2. So we need add iommu_group_put after iommu_group_add_device
>> to make sure iommu_group_get_for_dev only increase reference count by 1.
>
Thanks for comments.
>The premise seems incorrect to me. In the first case where
>iommu_group_get() provides a group, the reference is increased by 1, but
>the device is already a member of the group and therefore already
>increases the reference count of the group by 1. The minimum group
>reference at that point is therefore 2.
Yeah. The minimum group reference at that point is 2.
>In the second case, the group
>is created, which gives us our first reference, and the device is added,
>giving us our second reference. Therefore the minimum reference count
>is also 2.
Yeah.
>If we decrement it, allowing the caller to get the group
>with a single reference and they release that reference, the group will
>be destroyed even though it has a device member.
Thanks. Then Caller of iommu_group_get_for_dev should decrease the count by 1.
Thanks,
Peng.
>One reference to the
>group is for the caller, the other reference is for the device contained
>in the group. Thanks,
>
>Alex
>
>> Signed-off-by: Peng Fan <van.freenix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> Cc: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
>> Cc: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
>> ---
>>
>> V1 thread: https://lkml.org/lkml/2015/11/3/304
>> Changes V2:
>> I did not see the update about device_group when I worked out V1. So
>> redo the patch and refine commit msg and rebased to latest linus'
>> linux master tree.
>>
>> drivers/iommu/iommu.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index abae363..9c1971b 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -852,10 +852,10 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
>> }
>>
>> ret = iommu_group_add_device(group, dev);
>> - if (ret) {
>> - iommu_group_put(group);
>> + iommu_group_put(group);
>> +
>> + if (ret)
>> return ERR_PTR(ret);
>> - }
>>
>> return group;
>> }
>
>
>
WARNING: multiple messages have this Message-ID (diff)
From: Peng Fan <van.freenix@gmail.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: joro@8bytes.org, will.deacon@arm.com,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC V2] iommu: correct group reference count
Date: Tue, 10 Nov 2015 09:24:09 +0800 [thread overview]
Message-ID: <20151110012407.GA17404@linux-jyl1.ap.freescale.net> (raw)
In-Reply-To: <1447082889.4925.5.camel@redhat.com>
Hi Alex,
On Mon, Nov 09, 2015 at 08:28:09AM -0700, Alex Williamson wrote:
>On Mon, 2015-11-09 at 14:13 +0800, Peng Fan wrote:
>> The basic flow for iommu_group_for_dev is:
>> iommu_group_get_for_dev
>> |-> iommu_group_get : increase reference count by 1.
>> return group;
>> |-> ops->device_group : Init/increase reference count to/by 1.
>> iommu_group_add_device : Increase reference count by 1.
>> return group;
>>
>> We can see that ops->device_group and iommu_group_add_device will together
>> increase the iommu group reference count by 2. Actually we only need 1,
>> but not 2. So we need add iommu_group_put after iommu_group_add_device
>> to make sure iommu_group_get_for_dev only increase reference count by 1.
>
Thanks for comments.
>The premise seems incorrect to me. In the first case where
>iommu_group_get() provides a group, the reference is increased by 1, but
>the device is already a member of the group and therefore already
>increases the reference count of the group by 1. The minimum group
>reference at that point is therefore 2.
Yeah. The minimum group reference at that point is 2.
>In the second case, the group
>is created, which gives us our first reference, and the device is added,
>giving us our second reference. Therefore the minimum reference count
>is also 2.
Yeah.
>If we decrement it, allowing the caller to get the group
>with a single reference and they release that reference, the group will
>be destroyed even though it has a device member.
Thanks. Then Caller of iommu_group_get_for_dev should decrease the count by 1.
Thanks,
Peng.
>One reference to the
>group is for the caller, the other reference is for the device contained
>in the group. Thanks,
>
>Alex
>
>> Signed-off-by: Peng Fan <van.freenix@gmail.com>
>> Cc: Joerg Roedel <joro@8bytes.org>
>> Cc: Will Deacon <will.deacon@arm.com>
>> ---
>>
>> V1 thread: https://lkml.org/lkml/2015/11/3/304
>> Changes V2:
>> I did not see the update about device_group when I worked out V1. So
>> redo the patch and refine commit msg and rebased to latest linus'
>> linux master tree.
>>
>> drivers/iommu/iommu.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index abae363..9c1971b 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -852,10 +852,10 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
>> }
>>
>> ret = iommu_group_add_device(group, dev);
>> - if (ret) {
>> - iommu_group_put(group);
>> + iommu_group_put(group);
>> +
>> + if (ret)
>> return ERR_PTR(ret);
>> - }
>>
>> return group;
>> }
>
>
>
next prev parent reply other threads:[~2015-11-10 1:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-09 6:13 [RFC V2] iommu: correct group reference count Peng Fan
2015-11-09 6:13 ` Peng Fan
[not found] ` <1447049608-6123-1-git-send-email-van.freenix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-09 10:10 ` Will Deacon
2015-11-09 10:10 ` Will Deacon
2015-11-09 13:30 ` Peng Fan
2015-11-09 15:28 ` Alex Williamson
2015-11-09 15:28 ` Alex Williamson
[not found] ` <1447082889.4925.5.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-11-10 1:24 ` Peng Fan [this message]
2015-11-10 1:24 ` Peng Fan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151110012407.GA17404@linux-jyl1.ap.freescale.net \
--to=van.freenix-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.