Linux IOMMU Development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Vasant Hegde <vasant.hegde@amd.com>
Cc: iommu@lists.linux.dev, joro@8bytes.org,
	suravee.suthikulpanit@amd.com, wei.huang2@amd.com,
	jsnitsel@redhat.com, Baolu Lu <baolu.lu@linux.intel.com>
Subject: Re: [PATCH v4 07/16] iommu/amd: Introduce per-device domain ID to workaround potential TLB aliasing issue
Date: Fri, 12 Jan 2024 10:59:34 -0400	[thread overview]
Message-ID: <20240112145934.GY50608@ziepe.ca> (raw)
In-Reply-To: <0215990a-dff1-c6c3-bfa1-c90fa63b0c7b@amd.com>

On Fri, Jan 12, 2024 at 06:15:07PM +0530, Vasant Hegde wrote:

> Right. It makes sense when using V2 page table. But when we are in V1 page table
> we don't have GCR3. We will revisit once we finalize some of the vIOMMU stuff.

But in v1 mode the domain_id comes from the iommu_domain struct, there
is no case where it logically is part of the device.

> > Invalidation is no different than any other V2 domain use case. The
> > domain ops trigger invalidation. In AMD HW you need to record that an
> > unmanaged domain is connected to a domain ID & PASID and push the
> > right invalidate. The driver can't just assume the PASID is 0 for V2
> > unmanaged domains.
> > 
> > So the implementation is to track the attacked devices, iommus and
> > PASIDs in a linked list and use that linked list to generate
> > invalidations. Intel and SMMU (after my patches) both have
> > implementations of this. I would like to unify them to a helper
> > because they are both kind of bad.
> > 
> > There are many use cases for PASID mappings without SVA, including
> > SIOV-like devices and virtualization modes with non-SVA PRI.
> 
> What kind of page table will be attached with non zero PASID? like KVM page table?

Probably at copy of the KVM page table in some for, certainly today
starting with an UNAMANGED domain as is normal. I think people will
want to do different things here..

> >>   - iommu_ops->iotlb_sync_map/flush_iotlb_all will flush PASID zero.
> >>     Looking into intel driver they seems to be invalidating all PASIDs in this
> >> path. I didn't get why it has to flush all PASIDs here.
> > 
> > You iterate ove the list above and flush every PASID in the list. I
> > don't know what Intel is doing, fush all PASID on domain invalidation
> > sounds like overkill.
> 
> IIUC with UNMANAGED domain with PASID, we will have device/pasid list with
> different PASIDs pointing to different page tables.
>   ex: PASID 0 with DMA-API mode , PASID1 pointing to some other page table.

The *device* has a list of PASID's that point to iommu_domains. This
is stored in an xarray inside the iommu_group.

The *iommu_domain* has a list of *devices & PASIDs* that can use this
domain for translation (ie that it was attached to)

The RID attach is just PASID 0.

> This is where the confusion is. Current iommu ops doesn't take pasid as
> parameter. So if we go over entire dev/pasid list and flush it becomes overkill
> right?

If I have a v2 paging iommu domain (unmanaged) and I change the IOPTE
to effect a certain IOVA range then I have to invalidate it at every
place that is caching it.

For ATC that means I need to issue an invalidation to every
(iommu, RID, PASID) combination that has it in cache.

For V2 AMD IOTLB I need to issue an invalidation for every
(iommu, device->gcr3->domain_id, PASID) that has it in the cache.

For V1 AMD IOTLB I need to invalidate every
(iommu, domain->domain_id) combination.

It is a data structure problem to store a minimal list of those
things off of the iommu_domain.

No new op parameters are needed.

ATC is a list of every attached struct device and PASID, populated by
ops->attach_dev (PASID=0) or ops->set_dev_pasid.

V2 IOTLB is that same list with duplicate device->gcr3->domain_id's
removed

IOMMU is that same list with duplicate device->amd_iommu's removed,
which is the list V1 IOTLB needs.

So, store one linked list for ATC in the iommu_domain.

Sort it by (device->amd_iommu, device->gcr3->domain_id, device->id)

Skip consecutive runs of same domain_id or same iommu when generating
the invalidation sequences.

Use RCU to lock the list so the invalidation fast path is
lockless. (this is tricky)

Jason

  reply	other threads:[~2024-01-12 14:59 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12  8:52 [PATCH v4 00/16] iommu/amd: SVA Support (part 3) - refactor support for GCR3 table Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 01/16] iommu/amd: Pass struct iommu_dev_data to set_dte_entry() Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 02/16] iommu/amd: Enable Guest Translation before registering devices Vasant Hegde
2024-01-05 18:17   ` Jason Gunthorpe
2023-12-12  8:52 ` [PATCH v4 03/16] iommu/amd: Introduce get_amd_iommu_from_dev() Vasant Hegde
2024-01-05 18:27   ` Jason Gunthorpe
2024-01-10 12:07     ` Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 04/16] iommu/amd: Introduce struct protection_domain.pd_mode Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 05/16] iommu/amd: Introduce per-device GCR3 table Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 06/16] iommu/amd: Use protection_domain.flags to check page table mode Vasant Hegde
2024-01-05 18:28   ` Jason Gunthorpe
2023-12-12  8:52 ` [PATCH v4 07/16] iommu/amd: Introduce per-device domain ID to workaround potential TLB aliasing issue Vasant Hegde
2024-01-05 18:55   ` Jason Gunthorpe
2024-01-11 11:18     ` Vasant Hegde
2024-01-11 13:59       ` Jason Gunthorpe
2024-01-12 12:45         ` Vasant Hegde
2024-01-12 14:59           ` Jason Gunthorpe [this message]
2024-01-16 10:52             ` Vasant Hegde
2024-01-16 14:00               ` Jason Gunthorpe
2024-01-16 17:08                 ` Vasant Hegde
2024-01-16 17:22                   ` Jason Gunthorpe
2023-12-12  8:52 ` [PATCH v4 08/16] iommu/amd: Add support for device based TLB invalidation Vasant Hegde
2024-01-05 19:03   ` Jason Gunthorpe
2023-12-12  8:52 ` [PATCH v4 09/16] iommu/amd: Rearrange GCR3 table setup code Vasant Hegde
2024-01-05 19:04   ` Jason Gunthorpe
2023-12-12  8:52 ` [PATCH v4 10/16] iommu/amd: Refactor helper function for setting / clearing GCR3 Vasant Hegde
2024-01-05 19:12   ` Jason Gunthorpe
2024-01-11 11:52     ` Vasant Hegde
2024-01-11 13:26       ` Jason Gunthorpe
2024-01-12  9:00         ` Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 11/16] iommu/amd: Refactor attaching / detaching device functions Vasant Hegde
2024-01-05 19:14   ` Jason Gunthorpe
2024-01-11 10:06     ` Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 12/16] iommu/amd: Refactor protection_domain helper functions Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 13/16] iommu/amd: Refactor GCR3 table " Vasant Hegde
2024-01-05 19:21   ` Jason Gunthorpe
2024-01-11  5:39     ` Vasant Hegde
2023-12-12  8:52 ` [PATCH v4 14/16] iommu/amd: Remove unused flush pasid functions Vasant Hegde
2024-01-05 19:22   ` Jason Gunthorpe
2023-12-12  8:52 ` [PATCH v4 15/16] iommu/amd: Rearrange device flush code Vasant Hegde
2024-01-05 19:22   ` Jason Gunthorpe
2023-12-12  8:52 ` [PATCH v4 16/16] iommu/amd: Remove unused GCR3 table parameters from struct protection_domain Vasant Hegde

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=20240112145934.GY50608@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=jsnitsel@redhat.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=vasant.hegde@amd.com \
    --cc=wei.huang2@amd.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