From: Vasant Hegde <vasant.hegde@amd.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Joerg Roedel <joro@8bytes.org>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Baolu Lu <baolu.lu@linux.intel.com>
Subject: Re: [RFC] iommu_ops->domain_alloc_paging() enhancement to support AMD IOMMU driver
Date: Mon, 1 Jul 2024 16:18:01 +0530 [thread overview]
Message-ID: <1f8f04e5-3b70-45de-bd93-e3c96fb0a555@amd.com> (raw)
In-Reply-To: <Zn77FbsQWmByf16t@ziepe.ca>
Joson,
On 6/28/2024 11:34 PM, Jason Gunthorpe wrote:
> On Fri, Jun 28, 2024 at 11:19:23PM +0530, Vasant Hegde wrote:
>> Hi Jason,
>>
>> On 6/28/2024 6:33 PM, Jason Gunthorpe wrote:
>>> On Fri, Jun 28, 2024 at 12:13:43PM +0530, Vasant Hegde wrote:
>>>> Hi All,
>>>>
>>>> We are working on adding domain_alloc_paging() support in AMD driver and came
>>>> across below issue.
>>>>
>>>> BACKGROUND:
>>>> ============
>>>> - AMD IOMMU HW has two different page tables : V1 (host page table) and V2
>>>> (guest page table). Only V2 page table supports PASID and PRI features.
>>>>
>>>> - With V2 page table we have an aliasing issue. Hence we added
>>>> per-device-domain-id when domain is configured with v2 page table. See upstream
>>>> commit 87a6f1f22c97 ("iommu/amd: Introduce per-device domain ID to fix potential
>>>> TLB aliasing issue")
>>>
>>> Yes, but IIRC this is a shortcut to developing a proper packing
>>> algorithm to optimize the IOTLB. HW like this that has aliasing issues
>>> needs some more complex SW support to get optimal usage.
>>>
>>> ie you can share DIDs if devices have a logically equivilant GCR3
>>> table. Optimizing this is a SW problem inside the driver and should
>>> not leak out to API.
>>
>> Its not just SW issue. With V1 page table HW supports variable page size. (not
>> just fixed 4k, 2M and 1G). So in terms of HW cache management, V1 page table is
>> better.
>
> Okay, that does make alot of sense.
>
>> Another issue is with VFIO device passthrough and mixed device passthrough (few
>> w/ PASID and few w/o PASID), type of domain we endup allocating is depends on
>> the order in which VFIO requested for domain allocation. So its not deterministic.
>
> Yes, VFIO is not good about optimizing disjoint domain types to
> minimize domain requirements. This probably does need some more
> work. You have the other problem too where if you attach the non-pasid
> device first then pasid will be blocked and this is not expected
> either.
Right. If we solve the domain allocation issue, then we can fix our attach
device path to solve this (Yes. It needs code change. But its doable).
>
>> By the way, can you point me to your series please?
>
> https://lore.kernel.org/linux-iommu/0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com/
Thanks.
>
>>>
>>>> Please let us know which one is preferred -OR- is there any other better way to
>>>> handle this.
>>>
>>> Neither is really going to work. VFIO will have to assume the user
>>> will want to use the PASID API and will always request a PASID capable
>>> domain anyhow.
>>
>> Even to make PASID support with VFIO, some way it should communicate the driver
>> saying like "I need PASID capable domain". So that driver can allocate with
>> right page table type.
>
> Well, that is already implicit in the fact it asked for the domain from a
> PASID capable device.
All we need a explicit indication in domain_alloc_paging() saying allocate
*PASID* capable domain.
>
> What we perhaps need is for VFIO to have some way to evaluate a lot of
> devices together and decide on the best domain configuration for the
> full set. It prpbably makes little sense to have a v1 page table and
> then a copy with a v2 page table, for the PASID device.
>
>>> We already have a path where the VFIO userspace can request a v1
>>> domain by using the NESTING_PARENT flags during user domain
>>> allocation.
>>
>> That's with domain_alloc_user() API right? As I understand that should work fine
>> for AMD driver.
>
> Yes I expect so.
Thanks.
>
>>> But I don't see any option here that doesn't involve userspace itself
>>> making a request and indicating it wants a degrated VFIO
>>> functionality.
>>
>> That's along an option. We can explore it later.
>
> But there is no later.
>
> Your said your desire is to get a v1 domain even if the device
> supports PASID, and VFIO will get PASID support likely before you post
> your patches for this. Yi's work looks almost done to me.
>
> Then VFIO will just request the V2 domain anyhow and you are right
> back to the starting problem again.
Let me see if I can put together here.
- Basically we want domain_alloc_paging() to explicitly tell domain requirement
(ex: allocate PASID capable UNMANAGED domain)
If we do that then we will fix ordering issue I described earlier.
- Fix attach device path so that for 'PASID capable UNMANAGED domain' :
non-PASID capable device will use AMD V2 page table with GCR3[0]
PASID capable device will setup its GCR3 table as well and it should work fine.
Net we need a enhancement to domain_alloc_paging(). Otherwise I don't see a way
to reliable implement things.
Regarding performance impact: Thanks for pointing out. I will start discussion
in that thread. Lets see if we can come up with something.
But these two can go independently?
-Vasant
>
> Given your remarks it may make sense that VIFO disable PASID support
> by default so that by default AMD does not have a performance
> regression. You should start discussing this with Alex in Yi's series
> to come to a decision. It makes sense to me at least.
>
> If that is the choice then the idea of adding some flags/etc would
> work well.
>
> Jason
next prev parent reply other threads:[~2024-07-01 10:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 6:43 [RFC] iommu_ops->domain_alloc_paging() enhancement to support AMD IOMMU driver Vasant Hegde
2024-06-28 12:23 ` Baolu Lu
2024-06-28 13:06 ` Robin Murphy
2024-06-28 17:08 ` Vasant Hegde
2024-06-28 17:58 ` Robin Murphy
2024-07-01 10:28 ` Vasant Hegde
2024-06-28 14:50 ` Vasant Hegde
2024-06-28 15:34 ` Jason Gunthorpe
2024-06-28 13:03 ` Jason Gunthorpe
2024-06-28 17:49 ` Vasant Hegde
2024-06-28 18:04 ` Jason Gunthorpe
2024-07-01 10:48 ` Vasant Hegde [this message]
2024-07-01 17:26 ` Jason Gunthorpe
2024-07-03 5:42 ` Vasant Hegde
2024-07-03 6:57 ` Yi Liu
2024-07-09 18:23 ` Jason Gunthorpe
2024-07-10 4:17 ` Yi Liu
2024-07-11 23:49 ` Jason Gunthorpe
2024-07-12 13:40 ` Robin Murphy
2024-07-12 13:53 ` Jason Gunthorpe
2024-07-12 15:12 ` Robin Murphy
2024-07-12 15:19 ` Jason Gunthorpe
2024-07-15 8:46 ` Yi Liu
2024-07-11 10:15 ` Vasant Hegde
2024-07-11 13:56 ` Yi Liu
2024-07-12 1:39 ` Baolu Lu
2024-07-12 2:43 ` Yi Liu
2024-07-15 10:39 ` Vasant Hegde
2024-07-16 7:43 ` Yi Liu
2024-07-16 13:41 ` Jason Gunthorpe
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=1f8f04e5-3b70-45de-bd93-e3c96fb0a555@amd.com \
--to=vasant.hegde@amd.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=will@kernel.org \
/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