All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com>
To: <yi.l.liu@intel.com>
Cc: <kevin.tian@intel.com>, <iommu@lists.linux.dev>,
	<linux-kernel@vger.kernel.org>, Jason Gunthorpe <jgg@nvidia.com>
Subject: Re: [PATCH v2 1/3] iommufd: Add devices_users to track the hw_pagetable usage by device
Date: Thu, 2 Feb 2023 01:12:06 -0800	[thread overview]
Message-ID: <Y9t+ZtnphowLFwr1@Asurada-Nvidia> (raw)
In-Reply-To: <Y9oZMTMRG4mL5FT1@Asurada-Nvidia>

On Tue, Jan 31, 2023 at 11:48:04PM -0800, Nicolin Chen wrote:
> On Mon, Jan 30, 2023 at 12:54:01PM -0800, Nicolin Chen wrote:
> > On Mon, Jan 30, 2023 at 04:35:35PM -0400, Jason Gunthorpe wrote:
> > > On Mon, Jan 30, 2023 at 12:04:33PM -0800, Nicolin Chen wrote:
> > > 
> > > > I recall we've discussed this that SMMU sets up domain when it
> > > > attaches the device to, so we made a compromise here...
> > > 
> > > The ARM driver has a problem that it doesn't know what SMMU instance
> > > will host the domain when it is allocated so it doesn't know if it
> > > should select a S1 or S2 page table format - which is determined by
> > > the capabilities of the specific SMMU HW block.
> > > 
> > > However, we don't have this problem when creating the S2. The S2
> > > should be created by a special alloc_domain_iommufd() asking for the
> > > S2 format. Not only does the new alloc_domain_iommufd API directly
> > > request a S2 format table, but it also specifies the struct device so
> > > any residual details can be determined directly.
> > > 
> > > Thus there is no need to do the two stage process when working with
> > > the S2.
> > 
> > Ah, right! Taking a quick look, we should be able to call that
> > arm_smmu_domain_finalise when handling alloc_domain_iommufd().
> > 
> > > So fixup the driver to create fully configured iommu_domain's
> > > immediately and get rid of this problem.
> > 
> > OK. I will draft a patch today.
> 
> @Yi
> Do you recall doing iopt_table_add_domain() in hwpt_alloc()?
> 
> Jason has a great point above. So even SMMU should be able to
> call the iopt_table_add_domain() after a kernel-manged hwpt
> allocation rather than after an iommu_attach_group(), except
> an auto_domain or a selftest mock_domain that still needs to
> attach the device first, otherwise the SMMU driver (currently)
> cannot finalize the domain aperture.

Some update today: I found ops->domain_alloc_user() is used
for all domain allocations inside IOMMUFD. So, without any
special case, we could entirely do iopt_table_add_domain()
in the __iommufd_hw_pagetable_alloc() and accordingly do
iopt_table_remove_domain() in the hw_pagetable_destroy():
https://github.com/nicolinc/iommufd/commit/85248e1c5f645e1eb701562eb078cf586af617fe
(We can also skip that "symmetric" patch for the list_add,
 moving the list_add/del calls directly to alloc/destroy.)

Without the complication of the add/remove_domain() calls
in the do_attach/detach() functions, there is no need for
the device_users counter any more.

I am not 100% sure if we still need the shared device lock,
though so far the sanity that I run doesn't show a problem.
We may discuss about it later when we converge our branches.
As before, I am also okay to do in the way with incremental
changes on top of your tree and to ask you to integrate,
once you have your branch ready.

My full wip branch:
https://github.com/nicolinc/iommufd/commits/wip/iommufd-v6.2-rc5-nesting

Thanks
Nic

  reply	other threads:[~2023-02-02  9:13 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 [this message]
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
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=Y9t+ZtnphowLFwr1@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.