Linux IOMMU Development
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Tina Zhang <tina.zhang@intel.com>, iommu@lists.linux.dev
Cc: baolu.lu@linux.intel.com, Kevin Tian <kevin.tian@intel.com>
Subject: Re: [PATCH 07/11] iommu/vt-d: Use RCU for dev_pasids list updates in set/remove_dev_pasid()
Date: Wed, 17 Jan 2024 15:30:11 +0800	[thread overview]
Message-ID: <dd7b65e4-0a76-4a85-91ed-47992f91eeda@linux.intel.com> (raw)
In-Reply-To: <20240116011146.18645-8-tina.zhang@intel.com>

On 2024/1/16 9:11, Tina Zhang wrote:
> 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. However, for sva
> domain, the dev_pasids list accesses could be performed concurrently.
> For example, the callbacks invoked by memory management notifier may run
> in a process which runs concurrently with another process wherein the
> intel_iommu_set/remove_dev_pasid operations are performed.
> 
> 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 847e21117e7a..0eec5d971315 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -4553,7 +4553,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;
>   		}
> @@ -4563,7 +4563,7 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
>   
>   	domain_detach_iommu(dmar_domain, iommu);
>   	intel_iommu_debugfs_remove_dev_pasid(dev_pasid);
> -	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);
> @@ -4613,8 +4613,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);
>   
>   	if (domain->type & __IOMMU_DOMAIN_PAGING)

It appears you're using an RCU lock within another spinlock critical
region. Wouldn't that be redundant?

Best regards,
baolu

  reply	other threads:[~2024-01-17  7:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16  1:11 [PATCH 00/11] iommu/vt-d: Remove superfluous IOMMU IOTLB invalidations Tina Zhang
2024-01-16  1:11 ` [PATCH 01/11] iommu/vt-d: Retire the treatment for revoking PASIDs with pending pgfaults Tina Zhang
2024-01-16  1:11 ` [PATCH 02/11] iommu/vt-d: Remove initialization for dynamically heap-allocated rcu_head Tina Zhang
2024-01-16  1:11 ` [PATCH 03/11] iommu/vt-d: Refactor intel_svm_set_dev_pasid function Tina Zhang
2024-01-16  1:11 ` [PATCH 04/11] iommu/vt-d: Retire struct intel_svm_dev Tina Zhang
2024-01-17  7:20   ` Baolu Lu
2024-01-30  3:04     ` Zhang, Tina
2024-02-16  3:28       ` Zhang, Tina
2024-01-16  1:11 ` [PATCH 05/11] iommu: Add ops->domain_alloc_sva() Tina Zhang
2024-01-16  1:11 ` [PATCH 06/11] iommu/vt-d: Retire struct intel_svm Tina Zhang
2024-01-16  1:11 ` [PATCH 07/11] iommu/vt-d: Use RCU for dev_pasids list updates in set/remove_dev_pasid() Tina Zhang
2024-01-17  7:30   ` Baolu Lu [this message]
2024-01-16  1:11 ` [PATCH 08/11] iommu/vt-d: Add domain_type_is_sva helper function Tina Zhang
2024-01-17  7:32   ` Baolu Lu
2024-02-19  0:13     ` Zhang, Tina
2024-02-19  1:05       ` Baolu Lu
2024-01-16  1:11 ` [PATCH 09/11] iommu/vt-d: Reuse intel_iommu_set_dev_pasid function Tina Zhang
2024-01-17  7:40   ` Baolu Lu
2024-02-19  1:01     ` Zhang, Tina
2024-02-19  1:17       ` Baolu Lu
2024-01-16  1:11 ` [PATCH 10/11] iommu/vt-d: Retire intel_svm_remove_dev_pasid function Tina Zhang
2024-01-16  1:11 ` [PATCH 11/11] iommu/vt-d: Remove superfluous IOMMU IOTLB invalidations Tina Zhang
2024-01-17  7:59   ` Baolu Lu
2024-02-16  5:38     ` Zhang, Tina
2024-02-18  9:19       ` Baolu Lu
2024-02-18 13:09         ` Zhang, Tina

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=dd7b65e4-0a76-4a85-91ed-47992f91eeda@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=kevin.tian@intel.com \
    --cc=tina.zhang@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