iommu_ops->domain_alloc_paging() enhancement to support AMD IOMMU driver
Subsystems (2)
Vasant Hegde
maintainerRFC 1/1 iommu_ops->domain_alloc_paging() enhancement to support AMD IOMMU driver
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")
PROBLEM :
=========
With iommu_ops->domain_alloc_paging(dev) API AMD driver will chose best page table based on device capabilities (V2 for PASID capable device and V1 page table for rest of the devices).
But we would like to continue enforcing V1 page table for UNMANAGED domain. As in terms of IOMMU caching, it performs better than V2 page table.
Also while adding SVA in AMD driver Jason mentioned that we should support PASID with UNMANAGED domain. As I understand currently we don't have this feature in upstream but we would like to support it in future. Keeping this use case also in mind, we came up with below two options :
1 - Pass domain type : domain_alloc_paging(dev, type)
When we add PASID with UNMANAGED domain we need a way to differentiate the
domain 'type' (See below attach sample code)
2 - Introduce new flag for domain_alloc_paging()
Something like :
#define DOMAIN_FLAG_UNMANAGED 0x01
#define DOMAIN_FLAG_UNMANAGED_SVA 0x02 domain_alloc_paging(dev, flag)
For now we will have 'DOMAIN_PAGING_UNMANAGED'.
Please let us know which one is preferred -OR- is there any other better way to handle this.
-Vasant
---------------
commit bdf17f429dfb76b5a9a5714045ce3f38a4ee98b3
Author: Vasant Hegde <[email protected]> Date: Fri Jun 28 11:56:18 2024 +0530
[RFC] iommu: domain_alloc_paging enhancement
Prototype to show how domain_alloc_paging() looks like. This doesn't even compile as I have not modified other driver which has domain_alloc_paging() implementation.
drivers/iommu/amd/iommu.c +0 -0
@@ -2429,6 +2429,22 @@ static struct iommu_domain
*amd_iommu_domain_alloc(unsigned int type)
return domain;
}
+static struct iommu_domain *amd_iommu_domain_alloc_paging(struct device *dev, u32 type)
+{
+ struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
+ int pgtable = amd_iommu_pgtable;
+
+ /* TODO: Add SNP and other checks */
+
+ /* Force V1 page table for UNMANAGED domain */
+ if (type == IOMMU_DOMAIN_UNMANAGED)
+ pgtable = AMD_IOMMU_V1;
+ else if (dev_is_pci(dev) && pdev_pasid_supported(dev_data))
+ pgtable = AMD_IOMMU_V2;
+
+ return do_iommu_domain_alloc(IOMMU_DOMAIN_DMA, dev, 0, pgtable);
+}
+
static struct iommu_domain *
amd_iommu_domain_alloc_user(struct device *dev, u32 flags,
struct iommu_domain *parent,
@@ -2860,6 +2876,7 @@ static int amd_iommu_dev_disable_feature(struct device *dev,
const struct iommu_ops amd_iommu_ops = {
.capable = amd_iommu_capable,
.domain_alloc = amd_iommu_domain_alloc,
+ .domain_alloc_paging = amd_iommu_domain_alloc_paging,
.domain_alloc_user = amd_iommu_domain_alloc_user, .domain_alloc_sva = amd_iommu_domain_alloc_sva,
.probe_device = amd_iommu_probe_device,
drivers/iommu/iommu.c +0 -0
@@ -1952,7 +1952,7 @@ static struct iommu_domain *__iommu_domain_alloc(const
struct iommu_ops *ops,
else if (alloc_type == IOMMU_DOMAIN_BLOCKED && ops->blocked_domain)
return ops->blocked_domain;
else if (type & __IOMMU_DOMAIN_PAGING && ops->domain_alloc_paging)
- domain = ops->domain_alloc_paging(dev);
+ domain = ops->domain_alloc_paging(dev, type);
else if (ops->domain_alloc)
domain = ops->domain_alloc(alloc_type);
else
include/linux/iommu.h +4 -1
@@ -192,6 +192,9 @@ struct iommu_domain_geometry {#define IOMMU_DOMAIN_BLOCKED (0U)#define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT)#define IOMMU_DOMAIN_UNMANAGED (__IOMMU_DOMAIN_PAGING) +/* XXX: Introduce this type when we add PASID support for UNMANAGED domain */ +#define IOMMU_DOMAIN_UNMANAGED_SVA (__IOMMU_DOMAIN_PAGING | \ + __IOMMU_DOMAIN_SVA)#define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | \ __IOMMU_DOMAIN_DMA_API)#define IOMMU_DOMAIN_DMA_FQ (__IOMMU_DOMAIN_PAGING | \
@@ -557,7 +560,7 @@ struct iommu_ops {struct iommu_domain *(*domain_alloc_user)(struct device *dev,u32 flags,struct iommu_domain *parent,const struct iommu_user_data *user_data); -struct iommu_domain *(*domain_alloc_paging)(struct device *dev); + struct iommu_domain *(*domain_alloc_paging)(struct device *dev, u32
iommu_domain_type);
struct iommu_domain *(*domain_alloc_sva)(struct device *dev,
struct mm_struct *mm);
Quoted 24 lines · Vasant Hegde
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")PROBLEM :
=========
Withiommu_ops->domain_alloc_paging(dev)API AMD driver will chose best page table based on device capabilities (V2 for PASID capable device and V1 page table for rest of the devices).But we would like to continue enforcing V1 page table for UNMANAGED domain. As in terms of IOMMU caching, it performs better than V2 page table.
Quoted 8 lines
Also while adding SVA in AMD driver Jason mentioned that we should support PASID with UNMANAGED domain. As I understand currently we don't have this feature in upstream but we would like to support it in future. Keeping this use case also in mind, we came up with below two options :
1 - Pass domain type :
domain_alloc_paging(dev, type)
When we add PASID with UNMANAGED domain we need a way to differentiate the
domain 'type' (See below attach sample code)
The domain type is not enough for the iommu driver to differentiate between device or PASID. For example, a domain of type UNMANAGED could be attached to either a device or a PASID. Furthermore, SVA domain is not a paging domain.
Quoted 7 lines
2 - Introduce new flag for domain_alloc_paging() Something like : #define DOMAIN_FLAG_UNMANAGED 0x01 #define DOMAIN_FLAG_UNMANAGED_SVA 0x02
domain_alloc_paging(dev, flag)
For now we will have 'DOMAIN_PAGING_UNMANAGED'.
Add an allocation flag seems to work. It doesn't indicate any type of domain. Instead, it indicates the required iommu feature.
Something like
#define DOMAIN_ALLOC_FLAG_PASID 0x1
means the allocated domain requires PASID to support on both device and IOMMU. If the hardware lacks this support, it should return failure.
Best regards,
baolu
Robin Murphy
reviewerQuoted 51 lines · Baolu Lu
Quoted 25 lines · Vasant Hegde
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")PROBLEM :
=========
Withiommu_ops->domain_alloc_paging(dev)API AMD driver will chose best page table based on device capabilities (V2 for PASID capable device and V1 page table for rest of the devices).But we would like to continue enforcing V1 page table for UNMANAGED domain. As in terms of IOMMU caching, it performs better than V2 page table.
Quoted 8 lines
Also while adding SVA in AMD driver Jason mentioned that we should support PASID with UNMANAGED domain. As I understand currently we don't have this feature in upstream but we would like to support it in future. Keeping this use case also in mind, we came up with below two options :
1 - Pass domain type :
domain_alloc_paging(dev, type)
When we add PASID with UNMANAGED domain we need a way to differentiate the domain 'type' (See below attach sample code)The domain type is not enough for the iommu driver to differentiate between device or PASID. For example, a domain of type UNMANAGED could be attached to either a device or a PASID. Furthermore, SVA domain is not a paging domain.
Quoted 7 lines
2 - Introduce new flag for
domain_alloc_paging()Something like :
#define DOMAIN_FLAG_UNMANAGED0x01#define DOMAIN_FLAG_UNMANAGED_SVA0x02
domain_alloc_paging(dev, flag)
For now we will have 'DOMAIN_PAGING_UNMANAGED'.Add an allocation flag seems to work. It doesn't indicate any type of domain. Instead, it indicates the required iommu feature.
Quoted 6 lines
Something like
#define DOMAIN_ALLOC_FLAG_PASID
0x1means the allocated domain requires PASID to support on both device and IOMMU. If the hardware lacks this support, it should return failure.
Yeah, we could do with something sufficiently general, as we'll also have a need for passing pagetable-format options through to drivers to be able to replace iommu_set_pgtable_quirks().
Thanks,
Robin.
Vasant Hegde
maintainerHi Robin,
Quoted 5 lines · Robin Murphy
Quoted 4 lines · Baolu Lu
Quoted 3 lines · Vasant Hegde
We are working on adding
domain_alloc_paging()support in AMD driver and came across below issue.
.../...
Quoted 5 lines
Quoted 5 lines
Add an allocation flag seems to work. It doesn't indicate any type of domain. Instead, it indicates the required iommu feature.
Something like
Quoted 8 lines
Quoted 4 lines
#define DOMAIN_ALLOC_FLAG_PASID
0x1means the allocated domain requires PASID to support on both device and IOMMU. If the hardware lacks this support, it should return failure.
Yeah, we could do with something sufficiently general, as we'll also have a need for passing pagetable-format options through to drivers to be able to replace
iommu_set_pgtable_quirks().
Sorry. I doubt I understood it completely. You mean to say:
Enhance iommu_domain_alloc() such that caller can pass any special quirks they need and then pass those quirk flag along with the other flags we need (like PASID support or not) to indivisual driver? So that at the end we are remove ops->set_pgtable_quirks().
Is that what you are thinking or something else?
-Vasant
Robin Murphy
reviewerQuoted 25 lines · Vasant Hegde
Hi Robin,
Quoted 5 lines · Robin Murphy
Quoted 4 lines · Baolu Lu
Quoted 3 lines · Vasant Hegde
We are working on adding
domain_alloc_paging()support in AMD driver and came across below issue..../...
Quoted 5 lines
Quoted 5 lines
Add an allocation flag seems to work. It doesn't indicate any type of domain. Instead, it indicates the required iommu feature.
Something like
Quoted 8 lines
Quoted 4 lines
#define DOMAIN_ALLOC_FLAG_PASID
0x1means the allocated domain requires PASID to support on both device and IOMMU. If the hardware lacks this support, it should return failure.
Yeah, we could do with something sufficiently general, as we'll also have a need for passing pagetable-format options through to drivers to be able to replace
iommu_set_pgtable_quirks().
Quoted 7 lines
Sorry. I doubt I understood it completely. You mean to say:
Enhanceiommu_domain_alloc()such that caller can pass any special quirks they need and then pass those quirk flag along with the other flags we need (like PASID support or not) to indivisual driver? So that at the end we are removeops->set_pgtable_quirks().Is that what you are thinking or something else?
Basically, what set_pgtable_quirks does currently will need to be known at domain_alloc_paging time in order to convert arm-smmu to the latter properly. You don't need to worry about the public interface for it just yet, but if we're going to start extending the driver-level interface already then it would be good to plan ahead for what other domain properties we may want to accommodate callers requesting. The things we have as io-pgtable quirks today are definite ones (and those would happen to be OK as simple flags), but it's always seemed like a good idea for callers to be able to indicate their preference for other things like VA size (or even full domain geometry), even perhaps specific io-pgtable formats, such that the IOMMU driver can make the most effective choice about what it actually allocates.
Thanks,
Robin.
Vasant Hegde
maintainerHi Robin,
Quoted 34 lines · Robin Murphy
Quoted 25 lines · Vasant Hegde
Hi Robin,
Quoted 5 lines · Robin Murphy
Quoted 4 lines · Baolu Lu
Quoted 3 lines · Vasant Hegde
We are working on adding
domain_alloc_paging()support in AMD driver and came across below issue..../...
Quoted 5 lines
Quoted 5 lines
Add an allocation flag seems to work. It doesn't indicate any type of domain. Instead, it indicates the required iommu feature.
Something like
Quoted 8 lines
Quoted 4 lines
#define DOMAIN_ALLOC_FLAG_PASID
0x1means the allocated domain requires PASID to support on both device and IOMMU. If the hardware lacks this support, it should return failure.
Yeah, we could do with something sufficiently general, as we'll also have a need for passing pagetable-format options through to drivers to be able to replace
iommu_set_pgtable_quirks().Quoted 7 lines
Sorry. I doubt I understood it completely. You mean to say:
Enhanceiommu_domain_alloc()such that caller can pass any special quirks they need and then pass those quirk flag along with the other flags we need (like PASID support or not) to indivisual driver? So that at the end we are removeops->set_pgtable_quirks().Is that what you are thinking or something else?
Quoted 11 lines
Basically, what
set_pgtable_quirksdoes currently will need to be known atdomain_alloc_pagingtime in order to convert arm-smmu to the latter properly. You don't need to worry about the public interface for it just yet, but if we're going to start extending the driver-level interface already then it would be good to plan ahead for what other domain properties we may want to accommodate callers requesting. The things we have as io-pgtable quirks today are definite ones (and those would happen to be OK as simple flags), but it's always seemed like a good idea for callers to be able to indicate their preference for other things like VA size (or even full domain geometry), even perhaps specific io-pgtable formats, such that the IOMMU driver can make the most effective choice about what it actually allocates.
Thanks for explaining. It does make sense to pass enough details to individual drivers.
-Vasant
Vasant Hegde
maintainerHi Lu,
Quoted 50 lines · Baolu Lu
Quoted 24 lines · Vasant Hegde
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")PROBLEM :
=========
Withiommu_ops->domain_alloc_paging(dev)API AMD driver will chose best page table based on device capabilities (V2 for PASID capable device and V1 page table for rest of the devices).But we would like to continue enforcing V1 page table for UNMANAGED domain. As in terms of IOMMU caching, it performs better than V2 page table.
Quoted 8 lines
Also while adding SVA in AMD driver Jason mentioned that we should support PASID with UNMANAGED domain. As I understand currently we don't have this feature in upstream but we would like to support it in future. Keeping this use case also in mind, we came up with below two options :
1 - Pass domain type :
domain_alloc_paging(dev, type)
When we add PASID with UNMANAGED domain we need a way to differentiate the domain 'type' (See below attach sample code)The domain type is not enough for the iommu driver to differentiate between device or PASID. For example, a domain of type UNMANAGED could be attached to either a device or a PASID. Furthermore, SVA domain is not a paging domain.
Quoted 7 lines
2 - Introduce new flag for
domain_alloc_paging()Something like :
#define DOMAIN_FLAG_UNMANAGED0x01#define DOMAIN_FLAG_UNMANAGED_SVA0x02
domain_alloc_paging(dev, flag)
For now we will have 'DOMAIN_PAGING_UNMANAGED'.Add an allocation flag seems to work. It doesn't indicate any type of domain. Instead, it indicates the required iommu feature.
Quoted 6 lines
Something like
#define DOMAIN_ALLOC_FLAG_PASID
0x1means the allocated domain requires PASID to support on both device and IOMMU. If the hardware lacks this support, it should return failure.
Sure. Flag is fine for us. We can do
domain_alloc_paging(dev, flag)
But that means:
- For IOMMU_DOMAIN_DMA[_FQ] : pass DOMAIN_ALLOC_FLAG_PASID
- DOMAIN_PAGING_UNMANAGED : *No* flags
.. and when PASID with UNMANAGED domain support is added, we should pass ALLOC_FLAG_PASID.
Is this fine for other drivers? Do you see any issue?
-Vasant
Quoted 9 lines · Vasant Hegde
Quoted 2 lines
means the allocated domain requires PASID to support on both device and IOMMU. If the hardware lacks this support, it should return failure.
Sure. Flag is fine for us. We can do
domain_alloc_paging(dev, flag)But that means:
- For IOMMU_DOMAIN_DMA[_FQ] : passDOMAIN_ALLOC_FLAG_PASID
-DOMAIN_PAGING_UNMANAGED: *No* flags
As I said, VFIO would have to set the flag once it gets PASID support, which is likely to happen in a few months.
So this won't solve the problem you stated of poor DID caching.
IMHO if you want to optimize the DID assignment then that is a algorithm contained in the driver and we don't need to disturb any of the core code or uAPI for you to make that optimization.
JAson
Quoted 10 lines · Vasant Hegde
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.
Quoted 4 lines
- 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.
Quoted 3 lines
With
iommu_ops->domain_alloc_paging(dev)API AMD driver will chose best page table based on device capabilities (V2 for PASID capable device and V1 page table for rest of the devices).
Yes, this is correct.
Quoted 2 lines
But we would like to continue enforcing V1 page table for UNMANAGED domain. As in terms of IOMMU caching, it performs better than V2 page table.
We are getting rid of UNMANAGED domains. And we are adding PASID support to VFIO.
There is no reason VFIO should have a V1 domain by default and end up with a non-working VFIO PASID API. That doesn't make any sense.
You need to actually explain when and why you need V1 page table support in the VFIO context.
Quoted 3 lines
Also while adding SVA in AMD driver Jason mentioned that we should support PASID with UNMANAGED domain. As I understand currently we don't have this feature in upstream but we would like to support it in future.
My patch series enables it on SMMUv3 and Intel VT-d already supports it. Only AMD is missing the funtionality, which is why I keep asking you to structure things properly so it gets it too :)
Quoted 2 lines
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.
We already have a path where the VFIO userspace can request a v1 domain by using the NESTING_PARENT flags during user domain allocation.
If it is really important and logical we could also add a NO_PASID flag to hint to the driver that userspace doesn't want to use PASID in combination with this domain. That could also trigger v1.
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.
Jason
Vasant Hegde
maintainerHi Jason,
Quoted 16 lines · Jason Gunthorpe
Quoted 10 lines · Vasant Hegde
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.Quoted 4 lines
- 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")
Quoted 7 lines
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.
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.
Quoted 10 lines
Quoted 4 lines
With
iommu_ops->domain_alloc_paging(dev)API AMD driver will chose best page table based on device capabilities (V2 for PASID capable device and V1 page table for rest of the devices).Yes, this is correct.
Quoted 2 lines
But we would like to continue enforcing V1 page table for UNMANAGED domain. As in terms of IOMMU caching, it performs better than V2 page table.
Quoted 8 lines
We are getting rid of UNMANAGED domains. And we are adding PASID support to VFIO.
There is no reason VFIO should have a V1 domain by default and end up with a non-working VFIO PASID API. That doesn't make any sense.
You need to actually explain when and why you need V1 page table support in the VFIO context.
Adding further to above explanation, driver should have enough information to decide page table type.
Quoted 8 lines
Quoted 4 lines
Also while adding SVA in AMD driver Jason mentioned that we should support PASID with UNMANAGED domain. As I understand currently we don't have this feature in upstream but we would like to support it in future.
My patch series enables it on SMMUv3 and Intel VT-d already supports it. Only AMD is missing the funtionality, which is why I keep asking you to structure things properly so it gets it too :)
I have not looked into this series yet. We will look into it after fixing domain allocation path and few other things.
By the way, can you point me to your series please?
Quoted 7 lines
Quoted 3 lines
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.
Quoted 4 lines
We already have a path where the VFIO userspace can request a v1 domain by using the
NESTING_PARENTflags during user domain allocation.
That's with domain_alloc_user() API right? As I understand that should work fine for AMD driver.
Quoted 8 lines
If it is really important and logical we could also add a
NO_PASIDflag to hint to the driver that userspace doesn't want to use PASID in combination with this domain. That could also trigger v1.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.
-Vasant
Quoted 23 lines · Vasant Hegde
Hi Jason,
Quoted 20 lines · Jason Gunthorpe
Quoted 10 lines · Vasant Hegde
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.Quoted 4 lines
- 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.
Quoted 7 lines
Quoted 3 lines
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.
Quoted 3 lines
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.
Quoted 1 line
By the way, can you point me to your series please?
https://lore.kernel.org/linux-iommu/[email protected]/
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
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.
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.
Quoted 6 lines
Quoted 3 lines
We already have a path where the VFIO userspace can request a v1 domain by using the
NESTING_PARENTflags 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.
Quoted 5 lines
Quoted 3 lines
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.
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
Vasant Hegde
maintainerJoson,
Quoted 38 lines · Jason Gunthorpe
Quoted 23 lines · Vasant Hegde
Hi Jason,
Quoted 20 lines · Jason Gunthorpe
Quoted 10 lines · Vasant Hegde
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.Quoted 4 lines
- 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.
Quoted 7 lines
Quoted 3 lines
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.
Quoted 3 lines
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.
Quoted 5 lines
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).
Quoted 4 lines
Quoted 2 lines
By the way, can you point me to your series please?
Thanks.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
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.
Quoted 6 lines
Quoted 3 lines
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.
Quoted 6 lines
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.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
We already have a path where the VFIO userspace can request a v1 domain by using the
NESTING_PARENTflags 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.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
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.
Quoted 8 lines
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
Quoted 10 lines
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
Quoted 13 lines · Vasant Hegde
Quoted 2 lines
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.
Quoted 2 lines
Net we need a enhancement to
domain_alloc_paging(). Otherwise I don't see a way to reliable implement things.
Yes, some flag at domain allocation time is clearly needed
But you need the whole story, including when will VFIO set the flag, which requires a uAPI someplace.
Quoted 1 line
But these two can go independently?
If PASID goes with a default-on uAPI then you loose what you are asking for as VFIO will always request PASID.
So the overall plan has to be sorted out now..
Jason
Vasant Hegde
maintainerJason,
Quoted 15 lines · Jason Gunthorpe
Quoted 13 lines · Vasant Hegde
Quoted 2 lines
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.
Quoted 4 lines
Quoted 2 lines
Net we need a enhancement to
domain_alloc_paging(). Otherwise I don't see a way to reliable implement things.Yes, some flag at domain allocation time is clearly needed
Right. I will try to get this going and then we can fine tune with Robin's suggestion.
Quoted 10 lines
But you need the whole story, including when will VFIO set the flag, which requires a uAPI someplace.
Quoted 1 line
But these two can go independently?
If PASID goes with a default-on uAPI then you loose what you are asking for as VFIO will always request PASID.
So the overall plan has to be sorted out now..
Is this the Yi's thread you were referring ?
https://lore.kernel.org/linux-iommu/[email protected]/
-Vasant
Quoted 33 lines · Vasant Hegde
Jason,
Quoted 15 lines · Jason Gunthorpe
Quoted 13 lines · Vasant Hegde
Quoted 2 lines
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.Quoted 4 lines
Quoted 2 lines
Net we need a enhancement to
domain_alloc_paging(). Otherwise I don't see a way to reliable implement things.Yes, some flag at domain allocation time is clearly needed
Right. I will try to get this going and then we can fine tune with Robin's suggestion.
Quoted 6 lines
But you need the whole story, including when will VFIO set the flag, which requires a uAPI someplace.
Quoted 1 line
But these two can go independently?
Quoted 8 lines
Quoted 4 lines
If PASID goes with a default-on uAPI then you loose what you are asking for as VFIO will always request PASID.
So the overall plan has to be sorted out now..
Is this the Yi's thread you were referring ?
This is part of the whole work. What Jason refers may be the below one. It includes how VFIO report the PASID capability to userspace. There is an open to be closed though. I'll loop you in the next version. :)
https://lore.kernel.org/kvm/[email protected]/
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Signature · 2 lines
Regards, Yi Liu
Quoted 3 lines · Yi Liu
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Yes, ARM and AMD both have kinds of iommu_domains that cannot be attached to a PASID.
We are going to have to deal with that as well at some point. Currently ARM is always creating PASID compatible iommu domains.
While AMD would like to use a RID-only type by default.
Jason
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Yi Liu
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Yes, ARM and AMD both have kinds of
iommu_domainsthat cannot be attached to a PASID.
I see. VT-d does not have such a limitation AFAIK. BTW. SVA domain shall not be attached to RID I suppose. This should be a common restriction across vendors. Do you think it is valuable to let iommu core block such an attempt?
Quoted 5 lines
We are going to have to deal with that as well at some point. Currently ARM is always creating PASID compatible iommu domains.
While AMD would like to use a RID-only type by default.
thanks for the explanation.
Signature · 2 lines
Regards, Yi Liu
Quoted 11 lines · Yi Liu
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Yi Liu
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Yes, ARM and AMD both have kinds of
iommu_domainsthat cannot be attached to a PASID.I see. VT-d does not have such a limitation AFAIK.
Yeah, it is nice for software that VT-d put the right bits in to let all paths select either format.
Quoted 3 lines
BTW. SVA domain shall not be attached to RID I suppose. This should be a common restriction across vendors. Do you think it is valuable to let iommu core block such an attempt?
Yeah, maybe.
Jason
Robin Murphy
reviewerQuoted 13 lines · Jason Gunthorpe
Quoted 11 lines · Yi Liu
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Yi Liu
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Yes, ARM and AMD both have kinds of
iommu_domainsthat cannot be attached to a PASID.I see. VT-d does not have such a limitation AFAIK.
Quoted 8 lines
Yeah, it is nice for software that VT-d put the right bits in to let all paths select either format.
Quoted 3 lines
BTW. SVA domain shall not be attached to RID I suppose. This should be a common restriction across vendors. Do you think it is valuable to let iommu core block such an attempt?
Yeah, maybe.
There's no functional reason to disallow it for Arm SMMUs, at least, so it's something that could potentially want relaxing back to per-driver in future. I've heard murmurings over the years about potential use-cases for SVA with platform and/or non-PASID PCI devices, but never anything concrete for existing hardware. I imagine we can expect to see more SVA-interested on-chip accelerators in future, but whether they'll all be nice and support Substreams (i.e. "platform PASIDs") is the question...
Thanks,
Robin.
Quoted 9 lines · Robin Murphy
Quoted 5 lines
Quoted 3 lines
BTW. SVA domain shall not be attached to RID I suppose. This should be a common restriction across vendors. Do you think it is valuable to let iommu core block such an attempt?
Yeah, maybe.
There's no functional reason to disallow it for Arm SMMUs, at least, so it's something that could potentially want relaxing back to per-driver in future.
I think everyone can technically do SVA as everyone should be able to do PRI on the RID. We want PRI on RID anyhow for unpinned guest KVM support someday.
My specific "maybe" was because SVA is troublesome for MSI, on ARM we won't have an ITS page mapped for instance.
Quoted 5 lines
I've heard murmurings over the years about potential use-cases for SVA with platform and/or non-PASID PCI devices, but never anything concrete for existing hardware. I imagine we can expect to see more SVA-interested on-chip accelerators in future, but whether they'll all be nice and support Substreams (i.e. "platform PASIDs") is the question...
So I guess they don't send MSI down those special stream ids? It makes sense as a use case to me.
Thanks,
Jason
Robin Murphy
reviewerQuoted 11 lines · Jason Gunthorpe
Quoted 9 lines · Robin Murphy
Quoted 5 lines
Quoted 3 lines
BTW. SVA domain shall not be attached to RID I suppose. This should be a common restriction across vendors. Do you think it is valuable to let iommu core block such an attempt?
Yeah, maybe.
There's no functional reason to disallow it for Arm SMMUs, at least, so it's something that could potentially want relaxing back to per-driver in future.
Quoted 6 lines
I think everyone can technically do SVA as everyone should be able to do PRI on the RID. We want PRI on RID anyhow for unpinned guest KVM support someday.
My specific "maybe" was because SVA is troublesome for MSI, on ARM we won't have an ITS page mapped for instance.
Yeah, I think the trick for that is going to be to require the device to be happy with shoving any kernel-owned mappings (MSIs, firmware, etc.) into the TTB1 range.
Quoted 8 lines
Quoted 5 lines
I've heard murmurings over the years about potential use-cases for SVA with platform and/or non-PASID PCI devices, but never anything concrete for existing hardware. I imagine we can expect to see more SVA-interested on-chip accelerators in future, but whether they'll all be nice and support Substreams (i.e. "platform PASIDs") is the question...
So I guess they don't send MSI down those special stream ids? It makes sense as a use case to me.
Indeed I'd hope that people follow the intuitive usage model and MSIs are sent without a SubstreamID, but I guess we're just going to have to wait and see what gets built. Of course, the one real SSID-capable device I *have* seen so far still only has wired interrupts anyway...
Thanks,
Robin.
Quoted 16 lines · Robin Murphy
Quoted 15 lines · Jason Gunthorpe
Quoted 9 lines · Robin Murphy
Quoted 5 lines
Quoted 3 lines
BTW. SVA domain shall not be attached to RID I suppose. This should be a common restriction across vendors. Do you think it is valuable to let iommu core block such an attempt?
Yeah, maybe.
There's no functional reason to disallow it for Arm SMMUs, at least, so it's something that could potentially want relaxing back to per-driver in future.
I think everyone can technically do SVA as everyone should be able to do PRI on the RID. We want PRI on RID anyhow for unpinned guest KVM support someday.
Quoted 6 lines
Quoted 2 lines
My specific "maybe" was because SVA is troublesome for MSI, on ARM we won't have an ITS page mapped for instance.
Yeah, I think the trick for that is going to be to require the device to be happy with shoving any kernel-owned mappings (MSIs, firmware, etc.) into the TTB1 range.
Oh that's a really clever trick!
Jason
Quoted 17 lines · Robin Murphy
Quoted 16 lines · Jason Gunthorpe
Quoted 11 lines · Yi Liu
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Yi Liu
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Yes, ARM and AMD both have kinds of
iommu_domainsthat cannot be attached to a PASID.I see. VT-d does not have such a limitation AFAIK.
Yeah, it is nice for software that VT-d put the right bits in to let all paths select either format.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
BTW. SVA domain shall not be attached to RID I suppose. This should be a common restriction across vendors. Do you think it is valuable to let iommu core block such an attempt?
Yeah, maybe.
There's no functional reason to disallow it for Arm SMMUs, at least, so it's something that could potentially want relaxing back to per-driver in future. I've heard murmurings over the years about potential use-cases for SVA with platform and/or non-PASID PCI devices, but never anything concrete for existing hardware. I imagine we can expect to see more SVA-interested on-chip accelerators in future, but whether they'll all be nice and support Substreams (i.e. "platform PASIDs") is the question...
I see. Then let's keep the core as it is now.
Signature · 2 lines
Regards, Yi Liu
Vasant Hegde
maintainerHi Yi,
Quoted 40 lines · Yi Liu
Quoted 39 lines · Vasant Hegde
Jason,
Quoted 16 lines · Jason Gunthorpe
Quoted 14 lines · Vasant Hegde
Quoted 2 lines
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.Quoted 4 lines
Quoted 2 lines
Net we need a enhancement to
domain_alloc_paging(). Otherwise I don't see a way to reliable implement things.Yes, some flag at domain allocation time is clearly needed
Right. I will try to get this going and then we can fine tune with Robin's suggestion.
Quoted 10 lines
But you need the whole story, including when will VFIO set the flag, which requires a uAPI someplace.
Quoted 1 line
But these two can go independently?
If PASID goes with a default-on uAPI then you loose what you are asking for as VFIO will always request PASID.
So the overall plan has to be sorted out now..
Quoted 7 lines
Quoted 3 lines
Is this the Yi's thread you were referring ?
This is part of the whole work. What Jason refers may be the below one. It includes how VFIO report the PASID capability to userspace. There is an open to be closed though. I'll loop you in the next version. :)
Thank you Yi. I will start looking into this series.
Quoted 6 lines
https://lore.kernel.org/kvm/[email protected]/
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Jason covered this part in his response. Basically AMD has two page table :
V1 which doesn't support PASID.
V2 which support PASID
By default when host is booted it will be in V1 page table. What we are planning is we will implement domain_alloc_paging() interface in AMD driver. As part of that:
- PASID capable device will be placed in V2 page table, rest will be in V1
page table
For UNMANAGED domain (like vfio-pci), we would need a indication from core layer saying whether we want to allocate PASID capable domain or not. So that internally we can allocate appropriate page table type.
That means from VFIO layer we need to pass this detail to IOMMU layer. For this part, I will start watching your patch. May be we can start discussion in that thread itself.
-Vasant
Quoted 62 lines · Vasant Hegde
Hi Yi,
Quoted 40 lines · Yi Liu
Quoted 39 lines · Vasant Hegde
Jason,
Quoted 16 lines · Jason Gunthorpe
Quoted 14 lines · Vasant Hegde
Quoted 2 lines
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.Quoted 4 lines
Quoted 2 lines
Net we need a enhancement to
domain_alloc_paging(). Otherwise I don't see a way to reliable implement things.Yes, some flag at domain allocation time is clearly needed
Right. I will try to get this going and then we can fine tune with Robin's suggestion.
Quoted 10 lines
But you need the whole story, including when will VFIO set the flag, which requires a uAPI someplace.
Quoted 1 line
But these two can go independently?
If PASID goes with a default-on uAPI then you loose what you are asking for as VFIO will always request PASID.
So the overall plan has to be sorted out now..
Quoted 7 lines
Quoted 3 lines
Is this the Yi's thread you were referring ?
This is part of the whole work. What Jason refers may be the below one. It includes how VFIO report the PASID capability to userspace. There is an open to be closed though. I'll loop you in the next version. :)
Thank you Yi. I will start looking into this series.
Quoted 6 lines
https://lore.kernel.org/kvm/[email protected]/
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Quoted 8 lines
Jason covered this part in his response. Basically AMD has two page table :
V1 which doesn't support PASID.
V2 which support PASIDBy default when host is booted it will be in V1 page table. What we are planning is we will implement
domain_alloc_paging()interface in AMD driver. As part of that:
- PASID capable device will be placed in V2 page table, rest will be in V1
page table
looks like the format of V1 and V2 page tables are different. Can the V2 page table be attached to a device (RID) and used to do address translation for the DMAs w/o PASID? I have an impression that a RID can only use V1 page table. I may be wrong here. :)
Quoted 8 lines
For UNMANAGED domain (like vfio-pci), we would need a indication from core layer saying whether we want to allocate PASID capable domain or not. So that internally we can allocate appropriate page table type.
That means from VFIO layer we need to pass this detail to IOMMU layer. For this part, I will start watching your patch. May be we can start discussion in that thread itself.
yeah. Looks like you need to pass a hint to iommu driver for domain allocation. For the usage vfio+iommufd, it is fine as the domain_alloc_user accepts a flag. For legacy vfio (using vfio iommu type1) usage, it's a bit tough as the domain allocation is within kernel, userspace does not have any input on it so far. And vfio type1 does not expose the domain concept to userspace, it only exposes container which is kind of an address space object. This means no good way for userspace to control the domain allocation.
If it's only a matter when PASID is enabled, perhaps we can skip vfio iommu type1 as it is not supposed to support PASID.
Signature · 2 lines
Regards, Yi Liu
Quoted 19 lines · Yi Liu
Quoted 9 lines
For UNMANAGED domain (like vfio-pci), we would need a indication from core layer saying whether we want to allocate PASID capable domain or not. So that internally we can allocate appropriate page table type.
That means from VFIO layer we need to pass this detail to IOMMU layer. For this part, I will start watching your patch. May be we can start discussion in that thread itself.
yeah. Looks like you need to pass a hint to iommu driver for domain allocation. For the usage vfio+iommufd, it is fine as the
domain_alloc_useraccepts a flag. For legacy vfio (using vfio iommu type1) usage, it's a bit tough as the domain allocation is within kernel, userspace does not have any input on it so far. And vfio type1 does not expose the domain concept to userspace, it only exposes container which is kind of an address space object. This means no good way for userspace to control the domain allocation.
Quoted 2 lines
If it's only a matter when PASID is enabled, perhaps we can skip vfio iommu type1 as it is not supposed to support PASID.
As we have already agreed that new features should go through IOMMUFD and vfio/type1 is only kept for legacy compatible purpose, I don't think we need to carry any PASID bits in the vifo path. Did I miss anything?
Thanks,
baolu
Quoted 20 lines · Baolu Lu
Quoted 19 lines · Yi Liu
Quoted 9 lines
For UNMANAGED domain (like vfio-pci), we would need a indication from core layer saying whether we want to allocate PASID capable domain or not. So that internally we can allocate appropriate page table type.
That means from VFIO layer we need to pass this detail to IOMMU layer. For this part, I will start watching your patch. May be we can start discussion in that thread itself.
yeah. Looks like you need to pass a hint to iommu driver for domain allocation. For the usage vfio+iommufd, it is fine as the
domain_alloc_useraccepts a flag. For legacy vfio (using vfio iommu type1) usage, it's a bit tough as the domain allocation is within kernel, userspace does not have any input on it so far. And vfio type1 does not expose the domain concept to userspace, it only exposes container which is kind of an address space object. This means no good way for userspace to control the domain allocation.
Quoted 6 lines
Quoted 2 lines
If it's only a matter when PASID is enabled, perhaps we can skip vfio iommu type1 as it is not supposed to support PASID.
As we have already agreed that new features should go through IOMMUFD and vfio/type1 is only kept for legacy compatible purpose, I don't think we need to carry any PASID bits in the vifo path. Did I miss anything?
yes, we do. I have below kdoc for it in my pasid series [1]. Let's wait for Vasant's confirmation if it's only a matter of pasid. It's not quite clear to me based on my limited AMD iommu knowledge yet. :)
+ * Associate a pasid (of a cdev device) with an address space within the
+ * bound iommufd. Undo by VFIO_DEVICE_PASID_DETACH_IOMMUFD_PT or device fd
+ * close. This is only allowed on cdev fds.
[1] https://lore.kernel.org/kvm/[email protected]/
Signature · 2 lines
Regards, Yi Liu
Vasant Hegde
maintainerHi,
Quoted 11 lines · Yi Liu
Quoted 10 lines · Vasant Hegde
Hi Yi,
Quoted 6 lines · Yi Liu
Quoted 5 lines · Vasant Hegde
Jason,
Quoted 1 line · Jason Gunthorpe
On Mon, Jul 01, 2024 at 04:18:01PM +0530, Vasant Hegde wrote:
.../...
Quoted 17 lines
Quoted 11 lines
Quoted 6 lines
https://lore.kernel.org/kvm/[email protected]/
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Jason covered this part in his response. Basically AMD has two page table :
V1 which doesn't support PASID.
V2 which support PASIDQuoted 5 lines
By default when host is booted it will be in V1 page table. What we are planning is we will implement
domain_alloc_paging()interface in AMD driver. As part of that:
- PASID capable device will be placed in V2 page table, rest will be in V1 page table
Quoted 4 lines
looks like the format of V1 and V2 page tables are different. Can the V2 page table be attached to a device (RID) and used to do address translation for the DMAs w/o PASID? I have an impression that a RID can only use V1 page table. I may be wrong here. :)
We can attach V2 page table to a device. DMAs without PASID will use GCR3[0] (PASID zero).
V1 is AMD IOMMU specific, V2 is compatible with CPU page table hence it can support PASID.
Quoted 19 lines
Quoted 9 lines
For UNMANAGED domain (like vfio-pci), we would need a indication from core layer saying whether we want to allocate PASID capable domain or not. So that internally we can allocate appropriate page table type.
That means from VFIO layer we need to pass this detail to IOMMU layer. For this part, I will start watching your patch. May be we can start discussion in that thread itself.
yeah. Looks like you need to pass a hint to iommu driver for domain allocation. For the usage vfio+iommufd, it is fine as the
domain_alloc_useraccepts a flag. For legacy vfio (using vfio iommu type1) usage, it's a bit tough as the domain allocation is within kernel, userspace does not have any input on it so far. And vfio type1 does not expose the domain concept to userspace, it only exposes container which is kind of an address space object. This means no good way for userspace to control the domain allocation.
Quoted 2 lines
If it's only a matter when PASID is enabled, perhaps we can skip vfio iommu type1 as it is not supposed to support PASID.
Right. My understanding is with vfio IOMMU we will not support PASID. SO it should be fine.
-Vasant
Quoted 36 lines · Vasant Hegde
Hi,
Quoted 11 lines · Yi Liu
Quoted 10 lines · Vasant Hegde
Hi Yi,
Quoted 6 lines · Yi Liu
Quoted 5 lines · Vasant Hegde
Jason,
Quoted 1 line · Jason Gunthorpe
On Mon, Jul 01, 2024 at 04:18:01PM +0530, Vasant Hegde wrote:
.../...
Quoted 17 lines
Quoted 16 lines
Quoted 6 lines
https://lore.kernel.org/kvm/[email protected]/
BTW. For AMD, can a single device be attached to multiple V1 page table? IIRC. looks like AMD has only one V1 page table pointer per BDF. But there is a PASID table which has multiple cr3 page table pointers.
Jason covered this part in his response. Basically AMD has two page table :
V1 which doesn't support PASID.
V2 which support PASIDBy default when host is booted it will be in V1 page table. What we are planning is we will implement
domain_alloc_paging()interface in AMD driver. As part of that:
- PASID capable device will be placed in V2 page table, rest will be in V1
page table
Quoted 7 lines
Quoted 4 lines
looks like the format of V1 and V2 page tables are different. Can the V2 page table be attached to a device (RID) and used to do address translation for the DMAs w/o PASID? I have an impression that a RID can only use V1 page table. I may be wrong here. :)
We can attach V2 page table to a device. DMAs without PASID will use GCR3[0] (PASID zero).
got it. :)
Quoted 3 lines
V1 is AMD IOMMU specific, V2 is compatible with CPU page table hence it can support PASID.
yeah, this suits my understanding.
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
For UNMANAGED domain (like vfio-pci), we would need a indication from core layer saying whether we want to allocate PASID capable domain or not. So that internally we can allocate appropriate page table type.
That means from VFIO layer we need to pass this detail to IOMMU layer. For this part, I will start watching your patch. May be we can start discussion in that thread itself.
yeah. Looks like you need to pass a hint to iommu driver for domain allocation. For the usage vfio+iommufd, it is fine as the
domain_alloc_useraccepts a flag. For legacy vfio (using vfio iommu type1) usage, it's a bit tough as the domain allocation is within kernel, userspace does not have any input on it so far. And vfio type1 does not expose the domain concept to userspace, it only exposes container which is kind of an address space object. This means no good way for userspace to control the domain allocation.
Quoted 5 lines
Quoted 2 lines
If it's only a matter when PASID is enabled, perhaps we can skip vfio iommu type1 as it is not supposed to support PASID.
Right. My understanding is with vfio IOMMU we will not support PASID. SO it should be fine.
then you only need to take good care of the iommufd hwpt allocation uapi, and the domain_alloc_user() callback to achieve your goal of this thread. Anyhow, I'll still loop you in my pasid series in case anything missed here. :)
Signature · 2 lines
Regards, Yi Liu
Quoted 7 lines · Yi Liu
Quoted 2 lines
Right. My understanding is with vfio IOMMU we will not support PASID. SO it should be fine.
then you only need to take good care of the iommufd hwpt allocation uapi, and the
domain_alloc_user()callback to achieve your goal of this thread. Anyhow, I'll still loop you in my pasid series in case anything missed here. :)
Right, Yi's series to add PASID support to VFIO is the primary issue here, that has to be done in some way to accommodate this AMD situation.
Jason