From: Julien Grall <julien.grall@linaro.org>
To: Robert VanVossen <robert.vanvossen@dornerworks.com>,
xen-devel@lists.xenproject.org
Cc: julien.grall@citrix.com, edgar.iglesias@xilinx.com,
Josh.Whitehead@dornerworks.com, Ian.Campbell@citrix.com,
Stefano.Stabellini@eu.citrix.com
Subject: Re: [PATCH] xen/passthrough: Support a single iommu_domain(context bank) per xen domain per SMMU
Date: Fri, 20 Mar 2015 15:29:40 +0000 [thread overview]
Message-ID: <550C3CE4.2040003@linaro.org> (raw)
In-Reply-To: <550C2710.5080107@dornerworks.com>
On 20/03/2015 13:56, Robert VanVossen wrote:
>>> xen/drivers/passthrough/arm/smmu.c | 113 ++++++++++++++++++++++++++++--------
>>> 1 file changed, 88 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
>>> index a7a7da9..9b46054 100644
>>
>> [..]
>>
>>> @@ -1596,7 +1617,7 @@ static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
>>> if (!cfg)
>>> return;
>>>
>>> - dev_iommu_domain(dev) = NULL;
>>> + iommu_domain_remove_device(domain, dev);
>>> arm_smmu_domain_remove_master(smmu_domain, cfg);
>>> }
>>
>> I'd like to avoid modifying arm_smmu_attach_dev and arm_smmu_detach_dev
>> as it's part of the Linux code.
>>
>> I think you can increment the reference counter in arm_smmu_assign_dev
>> and arm_smmu_deassign_dev. That would avoid some possible race condition
>> (see below).
>>
>
> I can definitely increment the reference counter in arm_smmu_assign_dev, but
> arm_smmu_detach_dev doesn't return any results, so there isn't a guarantee that
> the iommu_domain has actually been dereferenced for the device.
AFAICT arm_smmu_detach_dev will only fail it's not able to find an
iommu_group (i.e the list of Stream IDs) for a device.
On Xen case, the check in arm_smmu_deassign_dev guaranty us that the
device is used by the SMMU and therefore an iommu_group exits for it.
So I think we can safely move the call in arm_smmu_detach_dev.
[..]
>>> + dev_err(dev, "cannot attach device to already existing iommu_domain\n");
>>> + return -ENXIO;
>>> + }
>
> Is this an appropriate return error?
I would return the result of arm_smmu_attach_dev (i.e ret).
[..]
>>> @@ -2633,12 +2692,16 @@ static int arm_smmu_deassign_dev(struct domain *d, struct device *dev)
>>>
>>> arm_smmu_detach_dev(domain, dev);
>>>
>>> - spin_lock(&xen_domain->lock);
>>> - list_del(&domain->list);
>>> - spin_unlock(&xen_domain->lock);
>>> + if (domain->ref.counter == 0)
>>> + {
>>
>> There is a possible race with the previous function. arm_smmu_assign_dev
>> still have time to increment domain->ref and we will free a domain with
>> 1 device assigned.
>>
>> Overall, I think the 2 functions should be completely protected by the
>> xen_domain->lock.
>
> Agreed. I will move the locks around.
Thanks.
Regards,
--
Julien Grall
prev parent reply other threads:[~2015-03-20 15:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-19 18:25 [PATCH] xen/passthrough: Support a single iommu_domain(context bank) per xen domain per SMMU Robbie VanVossen
2015-03-20 12:39 ` Julien Grall
2015-03-20 13:56 ` Robert VanVossen
2015-03-20 15:29 ` Julien Grall [this message]
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=550C3CE4.2040003@linaro.org \
--to=julien.grall@linaro.org \
--cc=Ian.Campbell@citrix.com \
--cc=Josh.Whitehead@dornerworks.com \
--cc=Stefano.Stabellini@eu.citrix.com \
--cc=edgar.iglesias@xilinx.com \
--cc=julien.grall@citrix.com \
--cc=robert.vanvossen@dornerworks.com \
--cc=xen-devel@lists.xenproject.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.