From: Baolu Lu <baolu.lu@linux.intel.com>
To: Robin Murphy <robin.murphy@arm.com>, Jason Gunthorpe <jgg@nvidia.com>
Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev,
Joerg Roedel <joro@8bytes.org>,
Christoph Hellwig <hch@infradead.org>,
Kevin Tian <kevin.tian@intel.com>, Will Deacon <will@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] iommu: Add dev_iommu->ops_rwsem
Date: Thu, 16 Feb 2023 08:40:42 +0800 [thread overview]
Message-ID: <ba0fab4b-61dc-a5de-cc0e-70a6e6f66f51@linux.intel.com> (raw)
In-Reply-To: <d4f1b33d-dec7-6582-34a1-495bacfcd396@arm.com>
On 2/15/23 7:24 PM, Robin Murphy wrote:
> On 2023-02-15 05:34, Baolu Lu wrote:
>> On 2/13/23 10:16 PM, Jason Gunthorpe wrote:
>>> On Mon, Feb 13, 2023 at 03:49:38PM +0800, Lu Baolu wrote:
>>>
>>>> +static int iommu_group_freeze_dev_ops(struct iommu_group *group)
>>>> +{
>>>> + struct group_device *device;
>>>> + struct device *dev;
>>>> +
>>>> + mutex_lock(&group->mutex);
>>>> + list_for_each_entry(device, &group->devices, list) {
>>>> + dev = device->dev;
>>>> + down_read(&dev->iommu->ops_rwsem);
>>>
>>> This isn't allowed, you can't obtain locks in a loop like this, it
>>> will deadlock.
>>>
>>> You don't need more locks, we already have the group mutex, the
>>> release path should be fixed to use it properly as I was trying to do
>>> here:
>>>
>>> https://lore.kernel.org/kvm/4-v1-ef00ffecea52+2cb-iommu_group_lifetime_jgg@nvidia.com/
>>> https://lore.kernel.org/kvm/YyyTxx0HnA3maxEk@nvidia.com/
>>>
>>> Then what you'd do in a path like this is:
>>>
>>> mutex_lock(&group->mutex);
>>> dev = iommu_group_first_device(group)
>>> if (!dev)
>>> /* Racing with group cleanup */
>>> return -EINVAL;
>>> /* Now dev->ops is valid and must remain valid so long as
>>> group->mutex is held */
>>>
>>> The only reason this doesn't work already is because of the above
>>> stuff about release not holding the group mutex when manipulating the
>>> devices in the group. This is simply mis-locked.
>>>
>>> Robin explained it was done like this because
>>> arm_iommu_detach_device() re-enters the iommu core during release_dev,
>>> so I suggest fixing that by simply not doing that (see above)
>>>
>>> Below is the lastest attempt I had tried, I didn't have time to get back
>>> to it and we fixed the bug another way. It needs a bit of adjusting to
>>> also remove the device from the group after release is called within
>>> the same mutex critical region.
>>
>> Yes. If we can make remove device from list and device release in the
>> same mutex critical region, we don't need any other lock mechanism
>> anymore.
>>
>> The ipmmu driver supports default domain.
>
> It supports default domains *on arm64*. Nothing on 32-bit ARM uses
> default domains, they won't even exist since iommu-dma is not enabled,
> and either way the ARM DMA ops don't understand groups. I don't see an
> obvious satisfactory solution while the arm_iommu_* APIs still exist,
> but if we need bodges in the interim could we please try to concentrate
> them in ARM-specific code?
Yes, sure. Thanks for the guide.
Best regards,
baolu
next prev parent reply other threads:[~2023-02-16 0:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 7:49 [PATCH 0/4] iommu: Extend changing default domain to normal group Lu Baolu
2023-02-13 7:49 ` [PATCH 1/4] iommu: Add dev_iommu->ops_rwsem Lu Baolu
2023-02-13 14:16 ` Jason Gunthorpe
2023-02-15 5:34 ` Baolu Lu
2023-02-15 11:24 ` Robin Murphy
2023-02-16 0:40 ` Baolu Lu [this message]
2023-02-13 7:49 ` [PATCH 2/4] iommu: Use group ownership to avoid driver attachment Lu Baolu
2023-02-13 14:19 ` Jason Gunthorpe
2023-02-15 5:51 ` Baolu Lu
2023-02-15 6:56 ` Tian, Kevin
2023-02-15 7:28 ` Baolu Lu
2023-02-15 11:09 ` Robin Murphy
2023-02-16 0:42 ` Baolu Lu
2023-02-15 12:56 ` Jason Gunthorpe
2023-02-16 0:36 ` Baolu Lu
2023-02-13 7:49 ` [PATCH 3/4] iommu: Remove unnecessary device_lock() Lu Baolu
2023-02-13 7:49 ` [PATCH 4/4] iommu: Cleanup iommu_change_dev_def_domain() Lu Baolu
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=ba0fab4b-61dc-a5de-cc0e-70a6e6f66f51@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=hch@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®