From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: Yi Liu <yi.l.liu@intel.com>, Arnd Bergmann <arnd@arndb.de>,
Kevin Tian <kevin.tian@intel.com>,
Joao Martins <joao.m.martins@oracle.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 08/10] iommu/vt-d: Add missing dirty tracking set for parent domain
Date: Mon, 19 Feb 2024 19:15:59 +0800 [thread overview]
Message-ID: <20240219111601.96405-9-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20240219111601.96405-1-baolu.lu@linux.intel.com>
From: Yi Liu <yi.l.liu@intel.com>
Setting dirty tracking for a s2 domain requires to loop all the related
devices and set the dirty tracking enable bit in the PASID table entry.
This includes the devices that are attached to the nested domains of a
s2 domain if this s2 domain is used as parent. However, the existing dirty
tracking set only loops s2 domain's own devices. It will miss dirty page
logs in the parent domain.
Now, the parent domain tracks the nested domains, so it can loop the
nested domains and the devices attached to the nested domains to ensure
dirty tracking on the parent is set completely.
Fixes: b41e38e22539 ("iommu/vt-d: Add nested domain allocation")
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20240208082307.15759-9-yi.l.liu@intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/iommu.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 2ad8fbe6dc21..11652e0bcab3 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4748,6 +4748,35 @@ static int device_set_dirty_tracking(struct list_head *devices, bool enable)
return ret;
}
+static int parent_domain_set_dirty_tracking(struct dmar_domain *domain,
+ bool enable)
+{
+ struct dmar_domain *s1_domain;
+ unsigned long flags;
+ int ret;
+
+ spin_lock(&domain->s1_lock);
+ list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) {
+ spin_lock_irqsave(&s1_domain->lock, flags);
+ ret = device_set_dirty_tracking(&s1_domain->devices, enable);
+ spin_unlock_irqrestore(&s1_domain->lock, flags);
+ if (ret)
+ goto err_unwind;
+ }
+ spin_unlock(&domain->s1_lock);
+ return 0;
+
+err_unwind:
+ list_for_each_entry(s1_domain, &domain->s1_domains, s2_link) {
+ spin_lock_irqsave(&s1_domain->lock, flags);
+ device_set_dirty_tracking(&s1_domain->devices,
+ domain->dirty_tracking);
+ spin_unlock_irqrestore(&s1_domain->lock, flags);
+ }
+ spin_unlock(&domain->s1_lock);
+ return ret;
+}
+
static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain,
bool enable)
{
@@ -4762,6 +4791,12 @@ static int intel_iommu_set_dirty_tracking(struct iommu_domain *domain,
if (ret)
goto err_unwind;
+ if (dmar_domain->nested_parent) {
+ ret = parent_domain_set_dirty_tracking(dmar_domain, enable);
+ if (ret)
+ goto err_unwind;
+ }
+
dmar_domain->dirty_tracking = enable;
out_unlock:
spin_unlock(&dmar_domain->lock);
--
2.34.1
next prev parent reply other threads:[~2024-02-19 11:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 11:15 [PATCH 00/10] [PULL REQUEST] iommu/vt-d: Fixes for v6.8-rc5 Lu Baolu
2024-02-19 11:15 ` [PATCH 01/10] iommu/vt-d: Track nested domains in parent Lu Baolu
2024-02-19 11:15 ` [PATCH 02/10] iommu/vt-d: Add __iommu_flush_iotlb_psi() Lu Baolu
2024-02-19 11:15 ` [PATCH 03/10] iommu/vt-d: Add missing iotlb flush for parent domain Lu Baolu
2024-02-19 11:15 ` [PATCH 04/10] iommu/vt-d: Update iotlb in nested domain attach Lu Baolu
2024-02-19 11:15 ` [PATCH 05/10] iommu/vt-d: Add missing device iotlb flush for parent domain Lu Baolu
2024-02-19 11:15 ` [PATCH 06/10] iommu/vt-d: Remove domain parameter for intel_pasid_setup_dirty_tracking() Lu Baolu
2024-02-19 11:15 ` [PATCH 07/10] iommu/vt-d: Wrap the dirty tracking loop to be a helper Lu Baolu
2024-02-19 11:15 ` Lu Baolu [this message]
2024-02-19 11:16 ` [PATCH 09/10] iommu/vt-d: Set SSADE when attaching to a parent with dirty tracking Lu Baolu
2024-02-19 11:16 ` [PATCH 10/10] iommu/vt-d: Fix constant-out-of-range warning Lu Baolu
2024-02-21 9:29 ` [PATCH 00/10] [PULL REQUEST] iommu/vt-d: Fixes for v6.8-rc5 Joerg Roedel
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=20240219111601.96405-9-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=arnd@arndb.de \
--cc=iommu@lists.linux.dev \
--cc=joao.m.martins@oracle.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=yi.l.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox