mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tina Zhang <tina.zhang@intel.com>
To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: David Woodhouse <dwmw2@infradead.org>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Joerg Roedel <joro@8bytes.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	Kevin Tian <kevin.tian@intel.com>,
	Tina Zhang <tina.zhang@intel.com>
Subject: [RFC PATCH 08/12] iommu/vt-d: Use RCU for dev_pasids list updates in set/remove_dev_pasid()
Date: Tue, 17 Oct 2023 11:20:41 +0800	[thread overview]
Message-ID: <20231017032045.114868-10-tina.zhang@intel.com> (raw)
In-Reply-To: <20231017032045.114868-1-tina.zhang@intel.com>

Extend intel_iommu_remove_dev_pasid() and intel_iommu_set_dev_pasid() to
support updating dev_pasids list concurrently with readers.

For default domain operations, the dev_pasids list accesses are protected
by domain->lock and therefore all read/write accesses of default domain
operations to dev_pasids list are performed sequentially. To extend
intel_iommu_set/remove_dev_pasid() to have the ability to update the
dev_pasids list concurrently with multiple readers (which is required by
sva domain), RCU mechanism is being used here.

Signed-off-by: Tina Zhang <tina.zhang@intel.com>
---
 drivers/iommu/intel/iommu.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index eeb658d3bc6e..fe063e1250fa 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4694,7 +4694,7 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
 	spin_lock_irqsave(&dmar_domain->lock, flags);
 	list_for_each_entry(curr, &dmar_domain->dev_pasids, link_domain) {
 		if (curr->dev == dev && curr->pasid == pasid) {
-			list_del(&curr->link_domain);
+			list_del_rcu(&curr->link_domain);
 			dev_pasid = curr;
 			break;
 		}
@@ -4703,7 +4703,7 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
 	spin_unlock_irqrestore(&dmar_domain->lock, flags);
 
 	domain_detach_iommu(dmar_domain, iommu);
-	kfree(dev_pasid);
+	kfree_rcu(dev_pasid, rcu);
 out_tear_down:
 	intel_pasid_tear_down_entry(iommu, dev, pasid, false);
 	intel_drain_pasid_prq(dev, pasid);
@@ -4751,8 +4751,14 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
 
 	dev_pasid->dev = dev;
 	dev_pasid->pasid = pasid;
+
+	/*
+	 * Spin lock protects dev_pasids list from being updated concurrently with
+	 * multiple updaters, while rcu ensures concurrency between one updater
+	 * and multiple readers
+	 */
 	spin_lock_irqsave(&dmar_domain->lock, flags);
-	list_add(&dev_pasid->link_domain, &dmar_domain->dev_pasids);
+	list_add_rcu(&dev_pasid->link_domain, &dmar_domain->dev_pasids);
 	spin_unlock_irqrestore(&dmar_domain->lock, flags);
 
 	return 0;
-- 
2.39.3


  parent reply	other threads:[~2023-10-17  3:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17  3:20 [RFC PATCH 00/12] iommu/vt-d: Remove superfluous IOMMU IOTLB invalidations Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 01/12] iommu/vt-d: Retire the treatment for revoking PASIDs with pending pgfaults Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 02/12] iommu/vt-d: Remove initialization for dynamically heap-allocated rcu_head Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 03/12] iommu/vt-d: Retire intel_svm_bind_mm() Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 04/12] iommu/vt-d: Make dev_to_intel_iommu() helper global Tina Zhang
2023-10-17  3:20 ` Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 05/12] iommu/vt-d: Retire struct intel_svm_dev Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 06/12] iommu: Add mmu_notifier to sva domain Tina Zhang
2023-10-23 18:35   ` Jason Gunthorpe
2023-11-01 11:58     ` Zhang, Tina
2023-10-17  3:20 ` [RFC PATCH 07/12] iommu/vt-d: Retire struct intel_svm Tina Zhang
2023-10-17  3:20 ` Tina Zhang [this message]
2023-10-17  3:20 ` [RFC PATCH 09/12] iommu/vt-d: Refactor intel_iommu_set_dev_pasid() Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 10/12] iommu/vt-d: Refactor intel_iommu_remove_dev_pasid() Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 11/12] iommu/vt-d: Use intel_iommu_set_dev_pasid() for sva domain Tina Zhang
2023-10-17  3:20 ` [RFC PATCH 12/12] iommu/vt-d: Remove superfluous IOMMU IOTLB invalidations Tina Zhang

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=20231017032045.114868-10-tina.zhang@intel.com \
    --to=tina.zhang@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.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 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®