From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>,
"Prakhya, Sai Praneeth" <sai.praneeth.prakhya@intel.com>
Cc: "iommu@lists.linux-foundation.org" <iommu@lists.linux-foundation.org>
Subject: Re: [PATCH] iommu: Remove functions that support private domain
Date: Fri, 15 May 2020 20:55:42 +0800 [thread overview]
Message-ID: <9d65b30a-d22e-d566-d740-601f8d638bfd@linux.intel.com> (raw)
In-Reply-To: <20200515095919.GQ18353@8bytes.org>
Hi,
On 2020/5/15 17:59, Joerg Roedel wrote:
> On Thu, May 14, 2020 at 11:12:52PM +0000, Prakhya, Sai Praneeth wrote:
>> +static int is_driver_bound(struct device *dev, void *not_used)
>> +{
>> + int ret = 0;
>> +
>> + device_lock(dev);
>> + if (device_is_bound(dev))
>> + ret = 1;
>> + device_unlock(dev);
>> + return ret;
>> +}
>
> This locks only one device, so without lock-conversion there could be a
> driver probe after the device_unlock(), while we are probing the other
> devices of the group.
>
>> [SNIP]
>>
>> + /*
>> + * Check if any device in the group still has a driver binded to it.
>> + * This might race with device driver probing code and unfortunately
>> + * there is no clean way out of that either, locking all devices in the
>> + * group and then do the re-attach will introduce a lock-inversion with
>> + * group->mutex - Joerg.
>> + */
>> + if (iommu_group_for_each_dev(group, NULL, is_driver_bound)) {
>> + pr_err("Active drivers exist for devices in the group\n");
>> + return -EBUSY;
>> + }
>
> The lock inversion comes into the picture when this code is called from
> device(-driver) core through the bus-notifiers. The notifiers are called
> with the device already locked.
>
>> Another question I have is.. if it's racy then it should be racy even
>> for one device iommu groups.. right? Why would it be racy only with
>> multiple devices iommu group?
>
> Valid point. So the device needs to be locked _while_ the default domain
> change happens. If triggered by sysfs there should be no locking
> problems, I guess. But you better try it out.
It seems that we can do like this:
[1] mutex_lock(&group->lock)
[2] for_each_group_device(device_lock())
[3] if (for_each_group_device(!device_is_bound()))
change_default_domain()
[4] for_each_group_device_reverse(device_unlock())
[5] mutex_unlock(&group->lock)
A possible problem exists at step 2 when another thread is trying to
lock devices in the reverse order at the same time.
Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-05-15 12:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 22:47 [PATCH] iommu: Remove functions that support private domain Sai Praneeth Prakhya
2020-05-14 13:13 ` Joerg Roedel
2020-05-14 17:51 ` Prakhya, Sai Praneeth
2020-05-14 18:32 ` Joerg Roedel
2020-05-14 18:44 ` Prakhya, Sai Praneeth
2020-05-14 19:56 ` Joerg Roedel
2020-05-14 23:12 ` Prakhya, Sai Praneeth
2020-05-15 9:59 ` Joerg Roedel
2020-05-15 12:55 ` Lu Baolu [this message]
2020-05-15 15:46 ` Joerg Roedel
2020-05-17 8:29 ` Prakhya, Sai Praneeth
2020-05-25 13:56 ` Joerg Roedel
2020-05-28 19:31 ` Prakhya, Sai Praneeth
2020-05-15 18:35 ` Prakhya, Sai Praneeth
2020-05-15 10:01 ` Joerg Roedel
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=9d65b30a-d22e-d566-d740-601f8d638bfd@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=sai.praneeth.prakhya@intel.com \
/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 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).