mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iommu/intel: Enable pci capabilities before assigning cache tags
@ 2024-06-25 13:49 Joel Granados via B4 Relay
  2024-06-26  1:09 ` Baolu Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Granados via B4 Relay @ 2024-06-25 13:49 UTC (permalink / raw)
  To: David Woodhouse, Lu Baolu, Joerg Roedel, Will Deacon, Robin Murphy
  Cc: iommu, linux-kernel, Joel Granados

From: Joel Granados <j.granados@samsung.com>

Enable the pci capabilities by calling iommu_enable_pci_caps before we
assign a cache tag. The cache_tag_assign_domain call in
dmar_domain_attach_device uses the device_domain_info->ats_enabled
element to decide on the cache_tag_type value. Therefore ats_enabled
needs to be evaluated before the call to the tag cache assignment.

Signed-off-by: Joel Granados <j.granados@samsung.com>
---
The "what" and "why" are included in the commit message.

Tried to place cache_tag_assign_domain before the early return in
"if(dev_is_real_dma_subdevice(dev))". This means that the call to
iommu_enable_pci_caps landed before the setup functions [1] which is not
an issue as they seem to be orthogonal (I would like to be proven wrong
here).

An alternative to this patch would be to use a different way of checking
if the device is ATS enabled in __cache_tag_assign_domain.

Comments greatly appreciated

Best

joel

[1] setup functions: domain_context_mapping,
    intel_pasid_setup_pass_through, domain_setup_first_level and
    intel_pasid_setup_second_level.
---
 drivers/iommu/intel/iommu.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 2e9811bf2a4e..ecd79741e67c 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2114,17 +2114,20 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
 	if (ret)
 		return ret;
 
-	ret = cache_tag_assign_domain(domain, dev, IOMMU_NO_PASID);
-	if (ret) {
-		domain_detach_iommu(domain, iommu);
-		return ret;
-	}
-
 	info->domain = domain;
 	spin_lock_irqsave(&domain->lock, flags);
 	list_add(&info->link, &domain->devices);
 	spin_unlock_irqrestore(&domain->lock, flags);
 
+	if (sm_supported(info->iommu) || !domain_type_is_si(info->domain))
+		iommu_enable_pci_caps(info);
+
+	ret = cache_tag_assign_domain(domain, dev, IOMMU_NO_PASID);
+	if (ret) {
+		domain_detach_iommu(domain, iommu);
+		return ret;
+	}
+
 	if (dev_is_real_dma_subdevice(dev))
 		return 0;
 
@@ -2142,9 +2145,6 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
 		return ret;
 	}
 
-	if (sm_supported(info->iommu) || !domain_type_is_si(info->domain))
-		iommu_enable_pci_caps(info);
-
 	return 0;
 }
 

---
base-commit: f2661062f16b2de5d7b6a5c42a9a5c96326b8454
change-id: 20240625-jag-ats_cache_tag_fix-d747bb0f5d48

Best regards,
-- 
Joel Granados <j.granados@samsung.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/intel: Enable pci capabilities before assigning cache tags
  2024-06-25 13:49 [PATCH] iommu/intel: Enable pci capabilities before assigning cache tags Joel Granados via B4 Relay
@ 2024-06-26  1:09 ` Baolu Lu
  2024-06-26 13:43   ` Joel Granados
  0 siblings, 1 reply; 3+ messages in thread
From: Baolu Lu @ 2024-06-26  1:09 UTC (permalink / raw)
  To: j.granados, David Woodhouse, Joerg Roedel, Will Deacon, Robin Murphy
  Cc: baolu.lu, iommu, linux-kernel

On 6/25/24 9:49 PM, Joel Granados via B4 Relay wrote:
> From: Joel Granados<j.granados@samsung.com>
> 
> Enable the pci capabilities by calling iommu_enable_pci_caps before we
> assign a cache tag. The cache_tag_assign_domain call in
> dmar_domain_attach_device uses the device_domain_info->ats_enabled
> element to decide on the cache_tag_type value. Therefore ats_enabled
> needs to be evaluated before the call to the tag cache assignment.
> 
> Signed-off-by: Joel Granados<j.granados@samsung.com>
> ---
> The "what" and "why" are included in the commit message.
> 
> Tried to place cache_tag_assign_domain before the early return in
> "if(dev_is_real_dma_subdevice(dev))". This means that the call to
> iommu_enable_pci_caps landed before the setup functions [1] which is not
> an issue as they seem to be orthogonal (I would like to be proven wrong
> here).
> 
> An alternative to this patch would be to use a different way of checking
> if the device is ATS enabled in __cache_tag_assign_domain.
> 
> Comments greatly appreciated

Thank you very much for the patch. But we already have a similar patch
which has been picked by Joerg for 6.10-rc.

https://lore.kernel.org/linux-iommu/20240620062940.201786-1-baolu.lu@linux.intel.com/

Can you please check whether above patch works for you?

Best regards,
baolu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/intel: Enable pci capabilities before assigning cache tags
  2024-06-26  1:09 ` Baolu Lu
@ 2024-06-26 13:43   ` Joel Granados
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Granados @ 2024-06-26 13:43 UTC (permalink / raw)
  To: Baolu Lu
  Cc: David Woodhouse, Joerg Roedel, Will Deacon, Robin Murphy, iommu,
	linux-kernel

On Wed, Jun 26, 2024 at 09:09:04AM +0800, Baolu Lu wrote:
> On 6/25/24 9:49 PM, Joel Granados via B4 Relay wrote:
> > From: Joel Granados<j.granados@samsung.com>
> > 
> > Enable the pci capabilities by calling iommu_enable_pci_caps before we
> > assign a cache tag. The cache_tag_assign_domain call in
> > dmar_domain_attach_device uses the device_domain_info->ats_enabled
> > element to decide on the cache_tag_type value. Therefore ats_enabled
> > needs to be evaluated before the call to the tag cache assignment.
> > 
> > Signed-off-by: Joel Granados<j.granados@samsung.com>
> > ---
> > The "what" and "why" are included in the commit message.
> > 
> > Tried to place cache_tag_assign_domain before the early return in
> > "if(dev_is_real_dma_subdevice(dev))". This means that the call to
> > iommu_enable_pci_caps landed before the setup functions [1] which is not
> > an issue as they seem to be orthogonal (I would like to be proven wrong
> > here).
> > 
> > An alternative to this patch would be to use a different way of checking
> > if the device is ATS enabled in __cache_tag_assign_domain.
> > 
> > Comments greatly appreciated
> 
> Thank you very much for the patch. But we already have a similar patch
> which has been picked by Joerg for 6.10-rc.
> 
> https://lore.kernel.org/linux-iommu/20240620062940.201786-1-baolu.lu@linux.intel.com/
Completely missed this. I'll give it a try tomorrow and report back.

Best

-- 

Joel Granados

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-26 13:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-25 13:49 [PATCH] iommu/intel: Enable pci capabilities before assigning cache tags Joel Granados via B4 Relay
2024-06-26  1:09 ` Baolu Lu
2024-06-26 13:43   ` Joel Granados

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®