From: Jacob Pan <jacob.jun.pan@linux.intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: "Tian, Kevin" <kevin.tian@intel.com>,
Tony Luck <tony.luck@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Raj Ashok <ashok.raj@intel.com>,
"Zanussi, Tom" <tom.zanussi@intel.com>,
"Kumar, Sanjay K" <sanjay.k.kumar@intel.com>,
LKML <linux-kernel@vger.kernel.org>,
Christoph Hellwig <hch@infradead.org>,
iommu@lists.linux-foundation.org,
Jacob Pan <jacob.jun.pan@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
Jean-Philippe Brucker <jean-philippe@linaro.com>
Subject: Re: [PATCH v2 3/8] iommu/vt-d: Implement device_pasid domain attach ops
Date: Thu, 17 Mar 2022 11:23:04 -0700 [thread overview]
Message-ID: <20220317112304.61cf8953@jacob-builder> (raw)
In-Reply-To: <20220317132308.GV11336@nvidia.com>
Hi Jason,
On Thu, 17 Mar 2022 10:23:08 -0300, Jason Gunthorpe <jgg@nvidia.com> wrote:
> On Wed, Mar 16, 2022 at 05:49:59PM -0700, Jacob Pan wrote:
>
> > > I would expect real applications will try to use the same PASID for
> > > the same IOVA map to optimize IOTLB caching.
> > >
> > > Is there a use case for that I'm missing?
> > >
> > Yes. it would be more efficient for PASID selective domain TLB flush.
> > But on VT-d IOTLB is also tagged by domain ID, domain flush can use DID
> > if there are many PASIDs. Not sure about other archs. Agree that
> > optimizing PASIDs for TLB flush should be a common goal.
>
> If you sort the list of (device, pasid) tuples can something like VT-d
> collapse all the same devices and just issue one DID invalidation:
>
> list_for_each()
> if (itm->device == last_invalidated_device)
> continue;
> invalidate(itm->device);
> last_invalidated_device = itm->device;
>
I assume this is for devTLB since IOMMU's IOTLB flush doesn't care about
device. I think it works for device-wide invalidation.
> While something that was per-pasid could issue per-pasid invalidations
> from the same data structure?
>
yes. we can use the same data structure for PASID selective devTLB but
list_for_each()
if (itm->pasid == pasid_to_be_invalidated;
invalidate(itm->device, pasid);
For IOMMU's IOTLB, we also have two granularities
1. domain-wide
2. pasid-wide
For #1, we just use DID to invalidate w/o traverse the list.
For #2, we just need to sanity check the pasid is indeed attached by going
through the list.
Seems to work!
> > > Otherwise your explanation is what I was imagining as well.
> > >
> > > I would also think about expanding your struct so that the device
> > > driver can track per-device per-domain data as well, that seems
> > > useful IIRC?
> > >
> > yes, at least both VT-d and FSL drivers have struct device_domain_info.
> >
> > > ie put a 'sizeof_iommu_dev_pasid_data' in the domain->ops and
> > > allocate that much memory so the driver can use the trailer space for
> > > its own purpose.
> > >
> > That sounds great to have but not sure i understood correctly how to do
> > it.
> >
> > Do you mean for each vendor driver's struct device_domain_info (or
> > equivalent), we carve out sizeof_iommu_dev_pasid_data as common data,
> > then the rest of the space is vendor specific? I don't feel I get your
> > point, could you elaborate?
>
> I've seen it done two ways..
>
> With a flex array:
>
> struct iommu_device_data {
> struct list_head list
> ioasid_t pasid;
> struct device *dev;
> [..]
> u64 device_data[];
> }
>
> struct intel_device_data {
> [..]
> }
> struct iommu_device_data *dev_data;
> struct intel_device_data *intel_data = (void *)&dev_data->device_data;
>
> Or with container of:
>
> struct iommu_device_data {
> struct list_head list
> ioasid_t pasid;
> struct device *dev;
> [..]
> }
>
> struct intel_device_data {
> struct iommu_device_data iommu; // must be first
> [...]
> }
> struct iommu_device_data *dev_data;
> struct intel_device_data *intel_data = container_of(dev_data, struct
> intel_device_data, iommu);
>
> In either case you'd add a size_t to the domain->ops specifying how
> much extra memory for the core code to allocate when it manages the
> datastructure. The first case allocates based on struct_size, the
> second case allocates what is specified.
>
> Look at INIT_RDMA_OBJ_SIZE() for some more complicated example how the
> latter can work. I like it because it has the nice container_of
> pattern in drivers, the downside is it requires a BUILD_BUG_ON to
> check that the driver ordered its struct properly.
>
> The point is to consolidate all the code for allocating and walking
> the data structure without having to force two allocations and extra
> pointer indirections on performance paths.
Make sense, very neat. Vendor driver would not need to do allocations. Let
me give that a try. Seems #2 has better type safety.
Thank you so much for the thorough explanation!
Jacob
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
WARNING: multiple messages have this Message-ID (diff)
From: Jacob Pan <jacob.jun.pan@linux.intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: iommu@lists.linux-foundation.org,
LKML <linux-kernel@vger.kernel.org>,
Joerg Roedel <joro@8bytes.org>,
Christoph Hellwig <hch@infradead.org>,
Lu Baolu <baolu.lu@linux.intel.com>,
Jean-Philippe Brucker <jean-philippe@linaro.com>,
Jacob Pan <jacob.jun.pan@intel.com>,
Raj Ashok <ashok.raj@intel.com>,
"Kumar, Sanjay K" <sanjay.k.kumar@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Tony Luck <tony.luck@intel.com>,
"Zanussi, Tom" <tom.zanussi@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
"Tian, Kevin" <kevin.tian@intel.com>, Yi Liu <yi.l.liu@intel.com>,
jacob.jun.pan@linux.intel.com
Subject: Re: [PATCH v2 3/8] iommu/vt-d: Implement device_pasid domain attach ops
Date: Thu, 17 Mar 2022 11:23:04 -0700 [thread overview]
Message-ID: <20220317112304.61cf8953@jacob-builder> (raw)
In-Reply-To: <20220317132308.GV11336@nvidia.com>
Hi Jason,
On Thu, 17 Mar 2022 10:23:08 -0300, Jason Gunthorpe <jgg@nvidia.com> wrote:
> On Wed, Mar 16, 2022 at 05:49:59PM -0700, Jacob Pan wrote:
>
> > > I would expect real applications will try to use the same PASID for
> > > the same IOVA map to optimize IOTLB caching.
> > >
> > > Is there a use case for that I'm missing?
> > >
> > Yes. it would be more efficient for PASID selective domain TLB flush.
> > But on VT-d IOTLB is also tagged by domain ID, domain flush can use DID
> > if there are many PASIDs. Not sure about other archs. Agree that
> > optimizing PASIDs for TLB flush should be a common goal.
>
> If you sort the list of (device, pasid) tuples can something like VT-d
> collapse all the same devices and just issue one DID invalidation:
>
> list_for_each()
> if (itm->device == last_invalidated_device)
> continue;
> invalidate(itm->device);
> last_invalidated_device = itm->device;
>
I assume this is for devTLB since IOMMU's IOTLB flush doesn't care about
device. I think it works for device-wide invalidation.
> While something that was per-pasid could issue per-pasid invalidations
> from the same data structure?
>
yes. we can use the same data structure for PASID selective devTLB but
list_for_each()
if (itm->pasid == pasid_to_be_invalidated;
invalidate(itm->device, pasid);
For IOMMU's IOTLB, we also have two granularities
1. domain-wide
2. pasid-wide
For #1, we just use DID to invalidate w/o traverse the list.
For #2, we just need to sanity check the pasid is indeed attached by going
through the list.
Seems to work!
> > > Otherwise your explanation is what I was imagining as well.
> > >
> > > I would also think about expanding your struct so that the device
> > > driver can track per-device per-domain data as well, that seems
> > > useful IIRC?
> > >
> > yes, at least both VT-d and FSL drivers have struct device_domain_info.
> >
> > > ie put a 'sizeof_iommu_dev_pasid_data' in the domain->ops and
> > > allocate that much memory so the driver can use the trailer space for
> > > its own purpose.
> > >
> > That sounds great to have but not sure i understood correctly how to do
> > it.
> >
> > Do you mean for each vendor driver's struct device_domain_info (or
> > equivalent), we carve out sizeof_iommu_dev_pasid_data as common data,
> > then the rest of the space is vendor specific? I don't feel I get your
> > point, could you elaborate?
>
> I've seen it done two ways..
>
> With a flex array:
>
> struct iommu_device_data {
> struct list_head list
> ioasid_t pasid;
> struct device *dev;
> [..]
> u64 device_data[];
> }
>
> struct intel_device_data {
> [..]
> }
> struct iommu_device_data *dev_data;
> struct intel_device_data *intel_data = (void *)&dev_data->device_data;
>
> Or with container of:
>
> struct iommu_device_data {
> struct list_head list
> ioasid_t pasid;
> struct device *dev;
> [..]
> }
>
> struct intel_device_data {
> struct iommu_device_data iommu; // must be first
> [...]
> }
> struct iommu_device_data *dev_data;
> struct intel_device_data *intel_data = container_of(dev_data, struct
> intel_device_data, iommu);
>
> In either case you'd add a size_t to the domain->ops specifying how
> much extra memory for the core code to allocate when it manages the
> datastructure. The first case allocates based on struct_size, the
> second case allocates what is specified.
>
> Look at INIT_RDMA_OBJ_SIZE() for some more complicated example how the
> latter can work. I like it because it has the nice container_of
> pattern in drivers, the downside is it requires a BUILD_BUG_ON to
> check that the driver ordered its struct properly.
>
> The point is to consolidate all the code for allocating and walking
> the data structure without having to force two allocations and extra
> pointer indirections on performance paths.
Make sense, very neat. Vendor driver would not need to do allocations. Let
me give that a try. Seems #2 has better type safety.
Thank you so much for the thorough explanation!
Jacob
next prev parent reply other threads:[~2022-03-17 18:19 UTC|newest]
Thread overview: 122+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-15 5:07 [PATCH v2 0/8] Enable PASID for DMA API users Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-15 5:07 ` [PATCH v2 1/8] iommu: Assign per device max PASID Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-15 5:07 ` [PATCH v2 2/8] iommu: Add attach/detach_dev_pasid domain ops Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-15 10:24 ` Tian, Kevin
2022-03-15 10:24 ` Tian, Kevin
2022-03-15 11:26 ` Jean-Philippe Brucker
2022-03-15 11:26 ` Jean-Philippe Brucker
2022-03-15 11:49 ` Tian, Kevin
2022-03-15 11:49 ` Tian, Kevin
2022-03-15 16:11 ` Jacob Pan
2022-03-15 16:11 ` Jacob Pan
2022-03-18 12:01 ` Lu Baolu
2022-03-18 12:01 ` Lu Baolu
2022-03-18 13:50 ` Jason Gunthorpe via iommu
2022-03-18 13:50 ` Jason Gunthorpe
2022-03-18 11:52 ` Lu Baolu
2022-03-18 11:52 ` Lu Baolu
2022-03-18 13:48 ` Jason Gunthorpe via iommu
2022-03-18 13:48 ` Jason Gunthorpe
2022-03-15 5:07 ` [PATCH v2 3/8] iommu/vt-d: Implement device_pasid domain attach ops Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-15 10:33 ` Tian, Kevin
2022-03-15 10:33 ` Tian, Kevin
2022-03-15 22:23 ` Jacob Pan
2022-03-15 22:23 ` Jacob Pan
2022-03-15 14:33 ` Jason Gunthorpe via iommu
2022-03-15 14:33 ` Jason Gunthorpe
2022-03-15 22:36 ` Jacob Pan
2022-03-15 22:36 ` Jacob Pan
2022-03-15 23:04 ` Jason Gunthorpe via iommu
2022-03-15 23:04 ` Jason Gunthorpe
2022-03-16 20:50 ` Jacob Pan
2022-03-16 20:50 ` Jacob Pan
2022-03-16 22:15 ` Jason Gunthorpe via iommu
2022-03-16 22:15 ` Jason Gunthorpe
2022-03-16 22:23 ` Luck, Tony
2022-03-16 22:23 ` Luck, Tony
2022-03-17 0:04 ` Jason Gunthorpe via iommu
2022-03-17 0:04 ` Jason Gunthorpe
2022-03-18 5:47 ` Tian, Kevin
2022-03-18 5:47 ` Tian, Kevin
2022-03-18 13:47 ` Jason Gunthorpe via iommu
2022-03-18 13:47 ` Jason Gunthorpe
2022-03-17 0:49 ` Jacob Pan
2022-03-17 0:49 ` Jacob Pan
2022-03-17 13:23 ` Jason Gunthorpe via iommu
2022-03-17 13:23 ` Jason Gunthorpe
2022-03-17 18:23 ` Jacob Pan [this message]
2022-03-17 18:23 ` Jacob Pan
2022-03-16 7:41 ` Tian, Kevin
2022-03-16 7:41 ` Tian, Kevin
2022-03-16 21:01 ` Jacob Pan
2022-03-16 21:01 ` Jacob Pan
2022-03-18 5:33 ` Tian, Kevin
2022-03-18 5:33 ` Tian, Kevin
2022-03-28 21:41 ` Jacob Pan
2022-03-28 21:41 ` Jacob Pan
2022-03-16 7:39 ` Tian, Kevin
2022-03-16 7:39 ` Tian, Kevin
2022-03-16 20:51 ` Jacob Pan
2022-03-16 20:51 ` Jacob Pan
2022-03-15 5:07 ` [PATCH v2 4/8] iommu/vt-d: Use device_pasid attach op for RID2PASID Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-16 7:54 ` Tian, Kevin
2022-03-16 7:54 ` Tian, Kevin
2022-03-17 20:45 ` Jacob Pan
2022-03-17 20:45 ` Jacob Pan
2022-03-15 5:07 ` [PATCH v2 5/8] iommu: Add PASID support for DMA mapping API users Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-15 11:16 ` Robin Murphy
2022-03-15 11:16 ` Robin Murphy
2022-03-15 14:22 ` Jason Gunthorpe via iommu
2022-03-15 14:22 ` Jason Gunthorpe
2022-03-15 16:31 ` Jacob Pan
2022-03-15 16:31 ` Jacob Pan
2022-03-15 17:05 ` Jason Gunthorpe via iommu
2022-03-15 17:05 ` Jason Gunthorpe
2022-03-15 21:24 ` Jacob Pan
2022-03-15 21:24 ` Jacob Pan
2022-03-16 10:32 ` Tian, Kevin
2022-03-16 10:32 ` Tian, Kevin
2022-03-16 8:41 ` Tian, Kevin
2022-03-16 8:41 ` Tian, Kevin
2022-03-16 14:07 ` Jason Gunthorpe via iommu
2022-03-16 14:07 ` Jason Gunthorpe
2022-03-15 14:35 ` Jason Gunthorpe via iommu
2022-03-15 14:35 ` Jason Gunthorpe
2022-03-15 16:38 ` Jacob Pan
2022-03-15 16:38 ` Jacob Pan
2022-03-15 23:05 ` Jason Gunthorpe via iommu
2022-03-15 23:05 ` Jason Gunthorpe
2022-03-18 12:43 ` Lu Baolu
2022-03-18 12:43 ` Lu Baolu
2022-03-28 21:44 ` Jacob Pan
2022-03-28 21:44 ` Jacob Pan
2022-03-15 5:07 ` [PATCH v2 6/8] dmaengine: idxd: Use DMA API for in-kernel DMA with PASID Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-18 6:10 ` Tian, Kevin
2022-03-18 6:10 ` Tian, Kevin
2022-03-29 17:39 ` Jacob Pan
2022-03-29 17:39 ` Jacob Pan
2022-03-15 5:07 ` [PATCH v2 7/8] iommu/vt-d: Delete supervisor/kernel SVA Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-18 6:16 ` Tian, Kevin
2022-03-18 6:16 ` Tian, Kevin
2022-03-29 17:42 ` Jacob Pan
2022-03-29 17:42 ` Jacob Pan
2022-03-15 5:07 ` [PATCH v2 8/8] iommu: Remove unused driver data in sva_bind_device Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-15 11:37 ` Jean-Philippe Brucker
2022-03-15 11:37 ` Jean-Philippe Brucker
2022-03-15 5:07 ` [PATCH v2 9/9] dmaengine: idxd: separate user and kernel pasid enabling Jacob Pan
2022-03-15 5:07 ` Jacob Pan
2022-03-18 6:28 ` Tian, Kevin
2022-03-18 6:28 ` Tian, Kevin
2022-03-15 8:16 ` [PATCH v2 0/8] Enable PASID for DMA API users Tian, Kevin
2022-03-15 8:16 ` Tian, Kevin
2022-03-15 15:49 ` Jacob Pan
2022-03-15 15:49 ` Jacob Pan
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=20220317112304.61cf8953@jacob-builder \
--to=jacob.jun.pan@linux.intel.com \
--cc=ashok.raj@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=hch@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@intel.com \
--cc=jean-philippe@linaro.com \
--cc=jgg@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sanjay.k.kumar@intel.com \
--cc=tom.zanussi@intel.com \
--cc=tony.luck@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.