Skip to contentSkip to conversation

iommu/vt-d: Fix missed device TLB cache tag

PATCH Superseded Lu Baolu 4 participants 15 messages Jun 19, 2024 – Jun 24, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

PATCH 1/1 iommu/vt-d: Fix missed device TLB cache tag

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

Create device TLB cache tags for a domain as long as the ats_supported field of the attached device is true. In the cache invalidation paths, the ats_enable field is checked and the device TLB invalidation requests are issued only when the ATS is really enabled on the device.

Fixes 3b1d9e2b2d68 ("iommu/vt-d: Add cache tag assignment interface")
---
 drivers/iommu/intel/cache.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/iommu/intel/cache.c +10 -4
index e8418cdd8331..ec6770f556b9 100644
@@ -112,7 +112,7 @@ static int __cache_tag_assign_domain(struct dmar_domain *domain, u16 did,
 	int ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_IOTLB);
-	if (ret || !info->ats_enabled)
+	if (ret || !info->ats_supported)
 		return ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_DEVTLB);
@@ -129,7 +129,7 @@ static void __cache_tag_unassign_domain(struct dmar_domain *domain, u16 did,
 
 	cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_IOTLB);
 
-	if (info->ats_enabled)
+	if (info->ats_supported)
 		cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_DEVTLB);
 }
 
@@ -140,7 +140,7 @@ static int __cache_tag_assign_parent_domain(struct dmar_domain *domain, u16 did,
 	int ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_NESTING_IOTLB);
-	if (ret || !info->ats_enabled)
+	if (ret || !info->ats_supported)
 		return ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_NESTING_DEVTLB);
@@ -157,7 +157,7 @@ static void __cache_tag_unassign_parent_domain(struct dmar_domain *domain, u16 d
 
 	cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_NESTING_IOTLB);
 
-	if (info->ats_enabled)
+	if (info->ats_supported)
 		cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_NESTING_DEVTLB);
 }
 
@@ -309,6 +309,9 @@ void cache_tag_flush_range(struct dmar_domain *domain, unsigned long start,
 			info = dev_iommu_priv_get(tag->dev);
 			sid = PCI_DEVID(info->bus, info->devfn);
 
+			if (!info->ats_enabled)
+				break;
+
 			if (tag->pasid == IOMMU_NO_PASID)
 				qi_flush_dev_iotlb(iommu, sid, info->pfsid,
 						   info->ats_qdep, addr, mask);
@@ -356,6 +359,9 @@ void cache_tag_flush_all(struct dmar_domain *domain)
 			info = dev_iommu_priv_get(tag->dev);
 			sid = PCI_DEVID(info->bus, info->devfn);
 
+			if (!info->ats_enabled)
+				break;
+
 			qi_flush_dev_iotlb(iommu, sid, info->pfsid, info->ats_qdep,
 					   0, MAX_AGAW_PFN_WIDTH);
 			quirk_extra_dev_tlb_flush(info, 0, MAX_AGAW_PFN_WIDTH,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 9 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Jason

author maintainer
#2 lore raw
Quoted 7 lines · Jason Gunthorpe
Quoted 6 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

Quoted 7 lines
Quoted 3 lines

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Yes. ATS is currently controlled exclusively by the iommu driver. The intel iommu driver enables PCI/ATS on the probe path after the default domain is attached. That means when the default domain is attached to the device, the ats_supported is set, but ats_enabled is cleared. So the cache tag for the device TLB won't be created.

A possible solution is to move ATS enabling to a place before the default domain attachment. However, this is not future-proof, considering that we will eventually hand over the ATS control to the device drivers. Therefore, this fix creates the device TLB cache tags as long as ats_supported is true and relies on ats_enabled to decide whether device TLB needs to be invalidated.

Best regards,
baolu

#3 lore raw
Quoted 16 lines

From: Baolu Lu <[email protected]>
Sent: Thursday, June 20, 2024 8:50 AM

Quoted 12 lines · Jason Gunthorpe
Quoted 9 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

Quoted 8 lines
Quoted 2 lines

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Yes. ATS is currently controlled exclusively by the iommu driver. The intel iommu driver enables PCI/ATS on the probe path after the default domain is attached. That means when the default domain is attached to the device, the ats_supported is set, but ats_enabled is cleared. So the cache tag for the device TLB won't be created.

I don't quite get why this is specific to the probe path and the default domain.

dmar_domain_attach_device()

{
	cache_tag_assign_domain();
	//setup pasid entry for pt/1st/2nd
	iommu_enable_pci_caps();
}

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned. why is it considered to affect only some devices e.g. intel_vpu?

Quoted 8 lines

A possible solution is to move ATS enabling to a place before the default domain attachment. However, this is not future-proof, considering that we will eventually hand over the ATS control to the device drivers. Therefore, this fix creates the device TLB cache tags as long as ats_supported is true and relies on ats_enabled to decide whether device TLB needs to be invalidated.

author maintainer
#4 lore raw
Quoted 18 lines · Kevin
Quoted 18 lines

From: Baolu Lu<[email protected]>
Sent: Thursday, June 20, 2024 8:50 AM

Quoted 14 lines · Jason Gunthorpe
Quoted 9 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Quoted 7 lines
Quoted 5 lines

Yes. ATS is currently controlled exclusively by the iommu driver. The intel iommu driver enables PCI/ATS on the probe path after the default domain is attached. That means when the default domain is attached to the device, the ats_supported is set, but ats_enabled is cleared. So the cache tag for the device TLB won't be created.

I don't quite get why this is specific to the probe path and the default domain.

The issue is with the domain attaching device path, not specific to the probe or default domain.

Quoted 10 lines

dmar_domain_attach_device()

{
	cache_tag_assign_domain();
	//setup pasid entry for pt/1st/2nd
	iommu_enable_pci_caps();
}

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

Quoted 2 lines

why is it considered
to affect only some devices e.g. intel_vpu?

This bug was discovered during testing of the intel_vpu device and affects devices other than the intel_vpu. The commit message is a bit confusing. :-)

Best regards,
baolu

#5 lore raw
Quoted 41 lines

From: Baolu Lu <[email protected]>
Sent: Thursday, June 20, 2024 11:14 AM

Quoted 18 lines · Kevin
Quoted 18 lines

From: Baolu Lu<[email protected]>
Sent: Thursday, June 20, 2024 8:50 AM

Quoted 14 lines · Jason Gunthorpe
Quoted 9 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Quoted 7 lines
Quoted 5 lines

Yes. ATS is currently controlled exclusively by the iommu driver. The intel iommu driver enables PCI/ATS on the probe path after the default domain is attached. That means when the default domain is attached to the device, the ats_supported is set, but ats_enabled is cleared. So the cache tag for the device TLB won't be created.

I don't quite get why this is specific to the probe path and the default domain.

The issue is with the domain attaching device path, not specific to the probe or default domain.

Quoted 8 lines

dmar_domain_attach_device()

{
	cache_tag_assign_domain();
	//setup pasid entry for pt/1st/2nd
	iommu_enable_pci_caps();
}
Quoted 5 lines
Quoted 2 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

I'm not sure the way this patch goes is future-proof either. Ideally the devtlb cache tag should always be assigned together with enabling the ats capability then in that case we won't have a case assigning a tag upon info->ats_supported at attach and then check info->ats_enabled run-time for flush.

and order-wise it makes slightly more sense to assign cache tag at end of the attach function after all other configurations have been completed.

with that I prefer to a simple fix by reverting the order instead of adding unnecessary run-time overhead for unclear future. 😊

Quoted 10 lines
Quoted 3 lines

why is it considered
to affect only some devices e.g. intel_vpu?

This bug was discovered during testing of the intel_vpu device and affects devices other than the intel_vpu. The commit message is a bit confusing. :-)

Best regards,
baolu

author maintainer
#6 lore raw
Quoted 39 lines · Kevin
Quoted 39 lines

From: Baolu Lu<[email protected]>
Sent: Thursday, June 20, 2024 11:14 AM

Quoted 18 lines · Kevin
Quoted 18 lines

From: Baolu Lu<[email protected]>
Sent: Thursday, June 20, 2024 8:50 AM

Quoted 14 lines · Jason Gunthorpe
Quoted 9 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Quoted 7 lines
Quoted 5 lines

Yes. ATS is currently controlled exclusively by the iommu driver. The intel iommu driver enables PCI/ATS on the probe path after the default domain is attached. That means when the default domain is attached to the device, the ats_supported is set, but ats_enabled is cleared. So the cache tag for the device TLB won't be created.

I don't quite get why this is specific to the probe path and the default domain.

The issue is with the domain attaching device path, not specific to the probe or default domain.

Quoted 7 lines

dmar_domain_attach_device()

{
	cache_tag_assign_domain();
	//setup pasid entry for pt/1st/2nd
	iommu_enable_pci_caps();
}
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

I'm not sure the way this patch goes is future-proof either. Ideally the devtlb cache tag should always be assigned together with enabling the ats capability then in that case we won't have a case assigning a tag upon info->ats_supported at attach and then check info->ats_enabled run-time for flush.

Yes, creating the required cache tag when enabling the ATS feature makes more sense.

Quoted 6 lines

and order-wise it makes slightly more sense to assign cache tag at end of the attach function after all other configurations have been completed.

with that I prefer to a simple fix by reverting the order instead of adding unnecessary run-time overhead for unclear future. 😊

Okay, I will follow this way to fix it.

Best regards,
baolu

#7 lore raw
In reply to Baolu Lu

Hi Baolu,

Quoted 38 lines · Baolu Lu
Quoted 18 lines · Kevin
Quoted 18 lines

From: Baolu Lu<[email protected]>
Sent: Thursday, June 20, 2024 8:50 AM

Quoted 14 lines · Jason Gunthorpe
Quoted 9 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Quoted 7 lines
Quoted 5 lines

Yes. ATS is currently controlled exclusively by the iommu driver. The intel iommu driver enables PCI/ATS on the probe path after the default domain is attached. That means when the default domain is attached to the device, the ats_supported is set, but ats_enabled is cleared. So the cache tag for the device TLB won't be created.

I don't quite get why this is specific to the probe path and the default domain.

The issue is with the domain attaching device path, not specific to the probe or default domain.

Quoted 8 lines

dmar_domain_attach_device()
{
    cache_tag_assign_domain();
    //setup pasid entry for pt/1st/2nd
    iommu_enable_pci_caps();
}

Quoted 5 lines
Quoted 2 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

[Unrelated to this patch]

You mean ATS setup will be moved to individual device driver? Is there any reason for that?

-Vasant

author maintainer
#8 lore raw
Quoted 37 lines · Vasant Hegde
Quoted 36 lines · Baolu Lu
Quoted 18 lines · Kevin
Quoted 18 lines

From: Baolu Lu<[email protected]>
Sent: Thursday, June 20, 2024 8:50 AM

Quoted 14 lines · Jason Gunthorpe
Quoted 9 lines · Lu Baolu

When a domain is attached to a device, the required cache tags are assigned to the domain so that the related caches could be flushed whenever it is needed. The device TLB cache tag is created selectively by checking the ats_enabled field of the device's iommu data. This creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled after the domain attachment. This causes some devices, for example intel_vpu, to malfunction.

What? How is this even possible?

ATS is controlled exclusively by the iommu driver, how can it be changed without the driver knowing??

Quoted 7 lines
Quoted 5 lines

Yes. ATS is currently controlled exclusively by the iommu driver. The intel iommu driver enables PCI/ATS on the probe path after the default domain is attached. That means when the default domain is attached to the device, the ats_supported is set, but ats_enabled is cleared. So the cache tag for the device TLB won't be created.

I don't quite get why this is specific to the probe path and the default domain.

The issue is with the domain attaching device path, not specific to the probe or default domain.

Quoted 7 lines

dmar_domain_attach_device()
{
    cache_tag_assign_domain();
    //setup pasid entry for pt/1st/2nd
    iommu_enable_pci_caps();
}

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

[Unrelated to this patch]

You mean ATS setup will be moved to individual device driver? Is there any reason for that?

Not exactly to individual device drivers, but it should be out of the iommu drivers.

https://lore.kernel.org/linux-iommu/BL1PR12MB51441FC4303BD0442EDB7A9CF7FFA@BL1PR12MB5144.namprd12.prod.outlook.com/

Best regards,
baolu

#9 lore raw

Hi,

Quoted 6 lines · Baolu Lu
Quoted 5 lines · Vasant Hegde
Quoted 4 lines · Baolu Lu
Quoted 3 lines · Kevin
Quoted 3 lines

From: Baolu Lu<[email protected]>
Sent: Thursday, June 20, 2024 8:50 AM

.../...

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

[Unrelated to this patch]

Quoted 7 lines
Quoted 2 lines

You mean ATS setup will be moved to individual device driver? Is there any reason for that?

Not exactly to individual device drivers, but it should be out of the iommu drivers.

https://lore.kernel.org/linux-iommu/BL1PR12MB51441FC4303BD0442EDB7A9CF7FFA@BL1PR12MB5144.namprd12.prod.outlook.com/

Got it. Thanks.

I remember of this discussion. May be we can provide API from IOMMU driver so that individual driver can enable/disable ATS (like iommu_dev_enable_feature()).

-Vasant

#10 lore raw
Quoted 12 lines · Vasant Hegde
Quoted 12 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

[Unrelated to this patch]

You mean ATS setup will be moved to individual device driver? Is there any reason for that?

Not exactly to individual device drivers, but it should be out of the iommu drivers.

Quoted 6 lines
Quoted 1 line

https://lore.kernel.org/linux-iommu/BL1PR12MB51441FC4303BD0442EDB7A9CF7FFA@BL1PR12MB5144.namprd12.prod.outlook.com/

Got it. Thanks.

I remember of this discussion. May be we can provide API from IOMMU driver so that individual driver can enable/disable ATS (like iommu_dev_enable_feature()).

But I have a feeling if we do that it should be done by re-attaching the domain.

For instance if you look at how I structued SMMUv3, the ATSness is an effective property of the domain type and ATS switches on and off dynamically already.

Having an additional input to domain attach "inhibit ats", as a flag would be all the support the driver would need to provide for the core code to manage this with some kind of global policy.

I would suggest to steer VTD in that direction too and make the ATS enable be done on domain attach, and put the first ATS enable in attach, not in probe. The logic in smmuv3 would apply just as well to VTD, though you'd need the hitless update logic too :)

Jason

author maintainer
#11 lore raw
Quoted 24 lines · Jason Gunthorpe
Quoted 8 lines · Vasant Hegde
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

[Unrelated to this patch]

You mean ATS setup will be moved to individual device driver? Is there any reason for that?

Quoted 8 lines
Quoted 4 lines

Not exactly to individual device drivers, but it should be out of the iommu drivers.

https://lore.kernel.org/linux-iommu/BL1PR12MB51441FC4303BD0442EDB7A9CF7FFA@BL1PR12MB5144.namprd12.prod.outlook.com/

Got it. Thanks.

I remember of this discussion. May be we can provide API from IOMMU driver so that individual driver can enable/disable ATS (like iommu_dev_enable_feature()).

But I have a feeling if we do that it should be done by re-attaching the domain.

For instance if you look at how I structued SMMUv3, the ATSness is an effective property of the domain type and ATS switches on and off dynamically already.

Quoted 8 lines

Having an additional input to domain attach "inhibit ats", as a flag would be all the support the driver would need to provide for the core code to manage this with some kind of global policy.

I would suggest to steer VTD in that direction too and make the ATS enable be done on domain attach, and put the first ATS enable in attach, not in probe. The logic in smmuv3 would apply just as well to VTD, though you'd need the hitless update logic too 🙂

Enabling/Disabling ATS on domain attach seems like a feasible approach. The ATS requirement information (required/disallowed/neutral) could be included as an opt-in option in the domain attach path. This likely applies to PASID attachments and VF/PF devices. The iommu driver maintains the per-device ATS refcount and enables it for the first request and disables it after the last one. The attachment fails accordingly if the hardware capability doesn't match the domain attach requirement.

Perhaps we could further include PRI as a domain attach option, indicating that the domain requires IOPF functionality. This would allow us to simplify the SVA and IOMMUFD by hiding device and IOMMU details within the IOMMU driver.

Best regards,
baolu

#12 lore raw
Quoted 8 lines · Baolu Lu

Enabling/Disabling ATS on domain attach seems like a feasible approach. The ATS requirement information (required/disallowed/neutral) could be included as an opt-in option in the domain attach path. This likely applies to PASID attachments and VF/PF devices. The iommu driver maintains the per-device ATS refcount and enables it for the first request and disables it after the last one. The attachment fails accordingly if the hardware capability doesn't match the domain attach requirement.

Yes. if we do this the core code would have to take some responsibility to manage ATS and PASID needs together. It is a bit tricky potentially, but probably better than having drivers repeat the same logic.

But it probably does require the drivers actually implement hitless replace. I'd imagin a core driven flow is something like:

- Install an identity domain without ATS
- Decide we want a SVA pasid
- Replace the identiy domain with the same identity domain and ATS
- Install the SVA pasid

(assuming we want some policy like only enable ATS when needed)

Quoted 4 lines

Perhaps we could further include PRI as a domain attach option, indicating that the domain requires IOPF functionality. This would allow us to simplify the SVA and IOMMUFD by hiding device and IOMMU details within the IOMMU driver.

This is my desire, if the domain has a fault handler then the driver should just make PRI work on attach or fail attach.

None of the weird feature stuff is needed. We are getting closer, I think the SVA enable stuff is almost all NO-OP'd.

Jason

#13 lore raw
In reply to Jason Gunthorpe

Jason,

Quoted 15 lines · Jason Gunthorpe
Quoted 14 lines · Vasant Hegde
Quoted 13 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

seems that for all domain attaches above is coded in a wrong order as ats is enabled after the cache tag is assigned.

Yes, exactly. But simply changing the order isn't future-proof, considering ATS control will eventually be moved out of iommu drivers.

[Unrelated to this patch]

You mean ATS setup will be moved to individual device driver? Is there any reason for that?

Not exactly to individual device drivers, but it should be out of the iommu drivers.

https://lore.kernel.org/linux-iommu/BL1PR12MB51441FC4303BD0442EDB7A9CF7FFA@BL1PR12MB5144.namprd12.prod.outlook.com/

Quoted 7 lines
Quoted 4 lines

Got it. Thanks.

I remember of this discussion. May be we can provide API from IOMMU driver so that individual driver can enable/disable ATS (like iommu_dev_enable_feature()).

But I have a feeling if we do that it should be done by re-attaching the domain.

Right. By default IOMMU will enable the ATS.. But if device driver decides to disable it (say due to HW bug), then we have to re-attach domain (in AMD case we have to update the DTE and flush the TLB).

Quoted 4 lines

For instance if you look at how I structued SMMUv3, the ATSness is an effective property of the domain type and ATS switches on and off dynamically already.

In AMD case its per device property. We check both IOMMU capability and device property before enabling ATS.

Quoted 4 lines

Having an additional input to domain attach "inhibit ats", as a flag would be all the support the driver would need to provide for the core code to manage this with some kind of global policy.

You mean for attach_dev() ?

.. and what about PRI and PASID? Don't device driver needs similar interface ?

-Vasant

#14 lore raw
Quoted 9 lines · Vasant Hegde
Quoted 5 lines
Quoted 2 lines

I remember of this discussion. May be we can provide API from IOMMU driver so that individual driver can enable/disable ATS (like iommu_dev_enable_feature()).

But I have a feeling if we do that it should be done by re-attaching the domain.

Right. By default IOMMU will enable the ATS.. But if device driver decides to disable it (say due to HW bug), then we have to re-attach domain (in AMD case we have to update the DTE and flush the TLB).

SMMUv3 is the same, this is why I like doing it via the existing re-attach domain interface since it already composes nicely with the mechanisms the driver should have to update the DTE/etc.

Quoted 5 lines
Quoted 3 lines

Having an additional input to domain attach "inhibit ats", as a flag would be all the support the driver would need to provide for the core code to manage this with some kind of global policy.

You mean for attach_dev() ?

Yes

Quoted 1 line

.. and what about PRI and PASID? Don't device driver needs similar interface ?

PRI is enabled by attaching a PRI capable domain

PASID should be assumed to be required if the device supports PASID.

Inhibiting PASID support would have to be done during domain allocation. Soon the dev will always be available there and we could do a policy like that via the dev structs? Not sure how much value there is..

Jason