From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <kevin.tian@intel.com>, <yi.l.liu@intel.com>,
<iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] iommufd: Add devices_users to track the hw_pagetable usage by device
Date: Wed, 1 Feb 2023 09:46:23 -0800 [thread overview]
Message-ID: <Y9qlb0SZWEpJs0v1@Asurada-Nvidia> (raw)
In-Reply-To: <Y9qK3nJHjU4Bvxaf@nvidia.com>
On Wed, Feb 01, 2023 at 11:53:02AM -0400, Jason Gunthorpe wrote:
> On Tue, Jan 31, 2023 at 10:57:13PM -0800, Nicolin Chen wrote:
> > On Mon, Jan 30, 2023 at 04:35:35PM -0400, Jason Gunthorpe wrote:
> >
> > > IMHO I would structure the smmu driver so that all the different
> > > iommu_domain formats have their own ops pointer. The special
> > > "undecided" format would have a special ops with only attach_dev and
> > > at first attach it would switch the ops to whatever format it
> > > selected.
> > >
> > > I think this could get rid of a lot of the 'if undecided/S1/S2/CD'
> > > complexity all over the place. You know what type it is because you
> > > were called on a op that is only called on its type.
> >
> > An auto/unmanaged domain allocation via iommu_domain_alloc() would
> > be S1, while an allocation via ops->domain_alloc_user can be S1 or
> > S2 with a given parameter/flag. So, actually the format is always
> > decided.
>
> No, it can't decide the S1/S2 format until it knows the smmu because
> of this:
>
> /* Restrict the stage to what we can actually support */
> if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1))
> smmu_domain->stage = ARM_SMMU_DOMAIN_S2;
> if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S2))
> smmu_domain->stage = ARM_SMMU_DOMAIN_S1;
>
> So the format is never decided.
OK. That's right. And the solution to that is also passing a dev
pointer in regular ->domain_alloc() op.
> > that we don't pass the dev pointer down to ops->domain_alloc. So,
> > the SMMU driver can't know which SMMU device the device is behind,
> > resulting in being unable to finalizing the domain. Robin mentioned
> > that he has a patch "iommu: Pass device through ops->domain_alloc".
> > Perhaps that is required for us to entirely fix the add_domain()
> > problem?
>
> Robin is making progress, hopefully soon
>
> So the issue is with replace you need to have the domain populated
> before we can call replace but you can't populate the domain until it
> is bound because of the above issue? That seems unsovlable without
> fixing up the driver.
Not really. A REPLACE ioctl is just an ATTACH, if the device just
gets BIND-ed. So the SMMU driver will initialize ("finalise") the
domain during the replace() call, then iopt_table_add_domain() can
be done.
So, not a blocker here.
> I'd say replace can go ahead ingoring that issue and that for now
> replace will only work on ARM with domains created by
> domain_alloc_user that are fully configured.
>
> It will start working correctly for auto domains once Robin's changes
> get finished.
>
> Is there another issue?
Oh. I think we mixed the topics here. These three patches were
not to unblock but to clean up a way for the replace series and
the nesting series, for the device locking issue:
if (cur_hwpt != hwpt)
mutex_lock(&cur_hwpt->device_lock);
mutex_lock(&hwpt->device_lock);
...
if (iommufd_hw_pagetabe_has_group()) { // touching device list
...
iommu_group_replace_domain();
...
}
if (cur_hwpt && hwpt)
list_del(&idev->devices_item);
list_add(&idev->devices_item, &cur_hwpt->devices);
...
mutex_unlock(&hwpt->device_lock);
if (cur_hwpt != hwpt)
mutex_unlock(&cur_hwpt->device_lock);
I just gave another thought about it. Since we have the patch-2
from this series moving the ioas->mutex, it already serializes
attach/detach routines. And I see that all the places touching
idev->device_item and hwpt->devices are protected by ioas->mutex.
So, perhaps we can simply remove the device_lock?
do_attach():
mutex_lock(&ioas->mutex); // protect both devices_item and hwpt_item
...
if (iommufd_hw_pagetabe_has_group()) { // touching device list
...
iommu_group_replace_domain();
...
}
if (cur_hwpt && hwpt)
list_del(&idev->devices_item);
list_add(&idev->devices_item, &cur_hwpt->devices);
...
mutex_unlock(&ioas->mutex);
do_detach():
mutex_lock(&ioas->mutex); // protect both devices_item and hwpt_item
...
if (iommufd_hw_pagetabe_has_group()) { // touching device list
...
iommu_detach_group();
...
}
list_del(&idev->devices_item);
...
mutex_unlock(&ioas->mutex);
If this is correct, I think I can prepare the replace series and
send it by the end of the day.
Thanks
Nic
next prev parent reply other threads:[~2023-02-01 17:46 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-28 21:18 [PATCH v2 0/3] iommufd: Remove iommufd_hw_pagetable_has_group Nicolin Chen
2023-01-28 21:18 ` [PATCH v2 1/3] iommufd: Add devices_users to track the hw_pagetable usage by device Nicolin Chen
2023-01-29 9:23 ` Tian, Kevin
2023-01-29 9:30 ` Nicolin Chen
2023-01-29 9:39 ` Tian, Kevin
2023-01-30 2:22 ` Liu, Yi L
2023-01-30 15:02 ` Jason Gunthorpe
2023-01-30 19:27 ` Nicolin Chen
2023-01-30 19:50 ` Jason Gunthorpe
2023-01-30 20:04 ` Nicolin Chen
2023-01-30 20:35 ` Jason Gunthorpe
2023-01-30 20:53 ` Nicolin Chen
2023-02-01 7:48 ` Nicolin Chen
2023-02-02 9:12 ` Nicolin Chen
2023-02-07 4:19 ` Liu, Yi L
2023-02-01 6:57 ` Nicolin Chen
2023-02-01 7:56 ` Nicolin Chen
2023-02-01 15:53 ` Jason Gunthorpe
2023-02-01 17:46 ` Nicolin Chen [this message]
2023-02-01 18:37 ` Jason Gunthorpe
2023-02-01 19:25 ` Nicolin Chen
2023-02-01 20:00 ` Jason Gunthorpe
2023-02-01 21:18 ` Nicolin Chen
2023-02-02 7:28 ` Nicolin Chen
2023-02-02 15:03 ` Jason Gunthorpe
2023-02-07 4:27 ` Liu, Yi L
2023-01-28 21:18 ` [PATCH v2 2/3] iommufd/device: Make hwpt_list list_add/del symmetric Nicolin Chen
2023-01-29 9:24 ` Tian, Kevin
2023-01-29 9:31 ` Nicolin Chen
2023-01-30 14:59 ` Jason Gunthorpe
2023-01-30 19:03 ` Nicolin Chen
2023-01-30 19:07 ` Jason Gunthorpe
2023-01-30 19:38 ` Nicolin Chen
2023-01-28 21:18 ` [PATCH v2 3/3] iommufd/device: Change iommufd_hw_pagetable_has_group to device centric Nicolin Chen
2023-01-29 9:37 ` Tian, Kevin
2023-01-29 10:38 ` Nicolin Chen
2023-01-30 0:44 ` Tian, Kevin
2023-01-30 10:22 ` Nicolin Chen
2023-02-01 3:07 ` Tian, Kevin
2023-02-01 6:49 ` Baolu Lu
2023-02-01 6:59 ` Tian, Kevin
2023-02-01 7:20 ` Nicolin Chen
2023-02-02 6:32 ` Tian, Kevin
2023-02-02 6:36 ` Nicolin Chen
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=Y9qlb0SZWEpJs0v1@Asurada-Nvidia \
--to=nicolinc@nvidia.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=yi.l.liu@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 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.