All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: baolu.lu@linux.intel.com, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Jacob Pan <jacob.jun.pan@linux.intel.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/7] iommu/vt-d: Add helper to flush caches for context change
Date: Thu, 15 Aug 2024 12:47:58 +0800	[thread overview]
Message-ID: <4ff133f3-e541-4a0f-a72c-ce682720e6df@linux.intel.com> (raw)
In-Reply-To: <20240814162726.5efe1a6e.alex.williamson@redhat.com>

On 2024/8/15 6:27, Alex Williamson wrote:
> Hi Baolu,

Hi Alex,

> This appears to be non-functional and breaks device assignment...

Yes. This is broken. Thanks for pointing it out.

Perhaps I can fix it by passing domain id to the helper? Something like
below:

diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index 01002ae2a091..b3b295e60626 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -1152,7 +1152,7 @@ void cache_tag_flush_range_np(struct dmar_domain 
*domain, unsigned long start,

  void intel_context_flush_present(struct device_domain_info *info,
  				 struct context_entry *context,
-				 bool affect_domains);
+				 u16 did, bool affect_domains);

  #ifdef CONFIG_INTEL_IOMMU_SVM
  void intel_svm_check(struct intel_iommu *iommu);
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 159da629349c..34006b6e89eb 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1903,6 +1903,7 @@ static void domain_context_clear_one(struct 
device_domain_info *info, u8 bus, u8
  {
  	struct intel_iommu *iommu = info->iommu;
  	struct context_entry *context;
+	u16 did;

  	spin_lock(&iommu->lock);
  	context = iommu_context_addr(iommu, bus, devfn, 0);
@@ -1911,10 +1912,11 @@ static void domain_context_clear_one(struct 
device_domain_info *info, u8 bus, u8
  		return;
  	}

+	did = context_domain_id(context);
  	context_clear_entry(context);
  	__iommu_flush_cache(iommu, context, sizeof(*context));
  	spin_unlock(&iommu->lock);
-	intel_context_flush_present(info, context, true);
+	intel_context_flush_present(info, context, did, true);
  }

  static int domain_setup_first_level(struct intel_iommu *iommu,
@@ -4077,6 +4079,7 @@ static int context_flip_pri(struct 
device_domain_info *info, bool enable)
  	struct intel_iommu *iommu = info->iommu;
  	u8 bus = info->bus, devfn = info->devfn;
  	struct context_entry *context;
+	u16 did;

  	spin_lock(&iommu->lock);
  	if (context_copied(iommu, bus, devfn)) {
@@ -4089,6 +4092,7 @@ static int context_flip_pri(struct 
device_domain_info *info, bool enable)
  		spin_unlock(&iommu->lock);
  		return -ENODEV;
  	}
+	did = context_domain_id(context);

  	if (enable)
  		context_set_sm_pre(context);
@@ -4097,7 +4101,7 @@ static int context_flip_pri(struct 
device_domain_info *info, bool enable)

  	if (!ecap_coherent(iommu->ecap))
  		clflush_cache_range(context, sizeof(*context));
-	intel_context_flush_present(info, context, true);
+	intel_context_flush_present(info, context, did, true);
  	spin_unlock(&iommu->lock);

  	return 0;
diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index 5792c817cefa..b51fc268dc84 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -683,6 +683,7 @@ static void device_pasid_table_teardown(struct 
device *dev, u8 bus, u8 devfn)
  	struct device_domain_info *info = dev_iommu_priv_get(dev);
  	struct intel_iommu *iommu = info->iommu;
  	struct context_entry *context;
+	u16 did;

  	spin_lock(&iommu->lock);
  	context = iommu_context_addr(iommu, bus, devfn, false);
@@ -691,10 +692,11 @@ static void device_pasid_table_teardown(struct 
device *dev, u8 bus, u8 devfn)
  		return;
  	}

+	did = context_domain_id(context);
  	context_clear_entry(context);
  	__iommu_flush_cache(iommu, context, sizeof(*context));
  	spin_unlock(&iommu->lock);
-	intel_context_flush_present(info, context, false);
+	intel_context_flush_present(info, context, did, false);
  }

  static int pci_pasid_table_teardown(struct pci_dev *pdev, u16 alias, 
void *data)
@@ -885,10 +887,9 @@ static void __context_flush_dev_iotlb(struct 
device_domain_info *info)
   */
  void intel_context_flush_present(struct device_domain_info *info,
  				 struct context_entry *context,
-				 bool flush_domains)
+				 u16 did, bool flush_domains)
  {
  	struct intel_iommu *iommu = info->iommu;
-	u16 did = context_domain_id(context);
  	struct pasid_entry *pte;
  	int i;

Thanks,
baolu

  reply	other threads:[~2024-08-15  4:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-02 13:08 [PATCH 0/7] [PULL REQUEST] Intel IOMMU updates for v6.11 Lu Baolu
2024-07-02 13:08 ` [PATCH 1/7] iommu/vt-d: Handle volatile descriptor status read Lu Baolu
2024-07-02 13:08 ` [PATCH 2/7] iommu/vt-d: Remove comment for def_domain_type Lu Baolu
2024-07-02 13:08 ` [PATCH 3/7] iommu/vt-d: Remove control over Execute-Requested requests Lu Baolu
2024-07-02 13:08 ` [PATCH 4/7] iommu/vt-d: Downgrade warning for pre-enabled IR Lu Baolu
2024-07-02 13:08 ` [PATCH 5/7] iommu/vt-d: Add helper to allocate paging domain Lu Baolu
2024-07-02 13:25   ` Yi Liu
2024-07-02 13:08 ` [PATCH 6/7] iommu/vt-d: Add helper to flush caches for context change Lu Baolu
2024-08-14 22:27   ` Alex Williamson
2024-08-15  4:47     ` Baolu Lu [this message]
2024-08-15 12:34       ` Alex Williamson
2024-08-15 12:41         ` Baolu Lu
2024-07-02 13:08 ` [PATCH 7/7] iommu/vt-d: Refactor PCI PRI enabling/disabling callbacks Lu Baolu
2024-07-03 16:13 ` [PATCH 0/7] [PULL REQUEST] Intel IOMMU updates for v6.11 Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ff133f3-e541-4a0f-a72c-ce682720e6df@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.