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: Thu, 11 Jan 2024 09:59:52 -0400 [thread overview]
Message-ID: <20240111135952.GV50608@ziepe.ca> (raw)
In-Reply-To: <d71a2bc0-ed07-53eb-faf1-bd36b6ff6ffb@amd.com>
On Thu, Jan 11, 2024 at 04:48:01PM +0530, Vasant Hegde wrote:
> > The code seems to be fine, domain_flush_pages_v1() looks optimal?
>
> I'd say its optimal for given state. I have a patch to move dev_iommu[] to
> xarray. I am planning to fine tune and post those patches after SVA. With that
> changes it will be better.
I'm not keen on an xarray, that isn't fully addressing the problem and
when Intel did it they messed up the locking..
I would like to make a shared helper to solve this problem. A rcu
backed linked list, with a helper API to iterate once per-iommu.
The RCU is a bit tricky.
> >> --- a/drivers/iommu/amd/amd_iommu_types.h
> >> +++ b/drivers/iommu/amd/amd_iommu_types.h
> >> @@ -842,6 +842,8 @@ struct iommu_dev_data {
> >> u8 ppr :1; /* Enable device PPR support */
> >> bool use_vapic; /* Enable device to use vapic mode */
> >> bool defer_attach;
> >> + /* Per device domain ID. Used with V2 page table */
> >> + u16 domid;
> >
> > This should really be put into the 'struct gcr3_tbl_info' - logically
> > that is the struct the HW cache tag is linked to. ie if the gcr3 table
> > is the same pointer then the cache tag can be re-used by the HW.
> >
>
> The reason we put it in dev_data is because its per device ID, not specific to
> GCR3 table.
But from a HW perspective it is actually linked to the GCR3 table as
that is the data pointer that is being cached. Two devices that share
a GCR3 pointer can share a domain ID.
If you want to optimize the domain ID tagging the logical way to do it
is to add code to share the GCR3 tables across devices. If the GCR3
table is the same then the domain ID can be the same.
> > Then when you want to optimize for the no-pasid case then the right
> > way to do it is putting a 'struct gcr3_tbl_info' inside the v2
> > protection_domain.
> >
> > The DTE will point at the v2 protection_domain's version of the gcr3
> > if the PASID table is empty, otherwise the DTE will point at the
> > struct iommu_dev_data version of the gcr3 table.
>
> This makese sense if we are sure we will do per-device-domain-ID only with V2
> page table. I still need to see how SVA support with vIOMMU works. For now I
> will keep this in my list. Once I have better picture I will fine tune.
SVA support is ugly on AMD - you need to flow through the virtual
domain ID to a consistent physical domain ID even though the guest may
have a DTEs tagged with the same domain ID but different GCR3
pointers.
Most likely the implementation will have the physical domain ID be
part of the nesting domain to achieve this.
> UNAMANGED Domain and PASID support:
> - I was considering this scenario as well. I don't think I understood the use
> case of and how invalidation is suppose to work here.
>
> Can you explain (again?) the use case and how invalidation is suppose to work?
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.
> - For PASID capable device we will have per-device-domain-ID
> - We will have default page table setup (PASID zero in our case) during domain
> initialization.
Domain initialization???
> - We attach PASIDs to same domain. We can add this to list (protection domain
> device List info - which will have dev_data/PASID). So set/remove PASIDs is fine.
Right
> - 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.
> - For other PASIDs do we have mmu notifier to invalidate as its attached to
> some process?
mmu notifier has nothing to do with PASID.
The driver should have a general scheme to keep track of a
iommu_domain's cache tags. This is the per-domain linked list of
pasid/device/iommu.
When the page table changes (however that page table is stored) it
walks that linked list and pushes invalidation commands.
For an unmanaged domain this common code is called by the
iommu_domain ops unmap/flush/etc.
For a SVA domain this common code is called by the MMU notifier
arch_invalidate_range
> > And this algorithm matches what Intel and SMMU need and I'm strongly
> > thinking about making a driver utility library to handle it, so
> > we can revisit this later on.
>
> If things are common across drivers then it makes sense. We can consider common
> set of functions.
I have been meaning to try to make something, lets see next week
Jason
next prev parent reply other threads:[~2024-01-11 13: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 [this message]
2024-01-12 12:45 ` Vasant Hegde
2024-01-12 14:59 ` Jason Gunthorpe
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=20240111135952.GV50608@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