All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe via iommu <iommu@lists.linux-foundation.org>
To: Lu Baolu <baolu.lu@linux.intel.com>
Cc: Kevin Tian <kevin.tian@intel.com>,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Alex Williamson <alex.williamson@redhat.com>,
	Jacob jun Pan <jacob.jun.pan@intel.com>
Subject: Re: [PATCH 3/5] iommu/vt-d: Check domain force_snooping against attached devices
Date: Mon, 2 May 2022 10:17:47 -0300	[thread overview]
Message-ID: <20220502131747.GJ8364@nvidia.com> (raw)
In-Reply-To: <20220501112434.874236-4-baolu.lu@linux.intel.com>

On Sun, May 01, 2022 at 07:24:32PM +0800, Lu Baolu wrote:
> +static bool domain_support_force_snooping(struct dmar_domain *domain)
> +{
> +	struct device_domain_info *info;
> +	unsigned long flags;
> +	bool support = true;
> +
> +	spin_lock_irqsave(&device_domain_lock, flags);
> +	if (list_empty(&domain->devices))
> +		goto out;

Why? list_for_each_entry will just do nothing..

> +	list_for_each_entry(info, &domain->devices, link) {
> +		if (!ecap_sc_support(info->iommu->ecap)) {
> +			support = false;
> +			break;
> +		}
> +	}
> +out:
> +	spin_unlock_irqrestore(&device_domain_lock, flags);
> +	return support;
> +}
> +
> +static void domain_set_force_snooping(struct dmar_domain *domain)
> +{
> +	struct device_domain_info *info;
> +	unsigned long flags;
> +
> +	/*
> +	 * Second level page table supports per-PTE snoop control. The
> +	 * iommu_map() interface will handle this by setting SNP bit.
> +	 */
> +	if (!domain_use_first_level(domain))
> +		return;
> +
> +	spin_lock_irqsave(&device_domain_lock, flags);
> +	if (list_empty(&domain->devices))
> +		goto out_unlock;
> +
> +	list_for_each_entry(info, &domain->devices, link)
> +		intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
> +						     PASID_RID2PASID);
> +
> +out_unlock:
> +	spin_unlock_irqrestore(&device_domain_lock, flags);
> +}
> +
>  static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
>  {
>  	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
>  
> -	if (!domain_update_iommu_snooping(NULL))
> +	if (!domain_support_force_snooping(dmar_domain))
>  		return false;

Maybe exit early if force_snooping = true?

> +	domain_set_force_snooping(dmar_domain);
>  	dmar_domain->force_snooping = true;
> +
>  	return true;
>  }
>  
> diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
> index f8d215d85695..815c744e6a34 100644
> +++ b/drivers/iommu/intel/pasid.c
> @@ -762,3 +762,21 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
>  
>  	return 0;
>  }
> +
> +/*
> + * Set the page snoop control for a pasid entry which has been set up.
> + */

So the 'first level' is only used with pasid?

> +void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu,
> +					  struct device *dev, u32 pasid)
> +{
> +	struct pasid_entry *pte;
> +	u16 did;
> +
> +	pte = intel_pasid_get_entry(dev, pasid);
> +	if (WARN_ON(!pte || !pasid_pte_is_present(pte)))
> +		return;
> +
> +	pasid_set_pgsnp(pte);

Doesn't this need to be done in other places too, like when a new attach
is made? Patch 5 removed it, but should that be made if
domain->force_snooping?

Jason
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: Lu Baolu <baolu.lu@linux.intel.com>
Cc: Joerg Roedel <joro@8bytes.org>,
	Alex Williamson <alex.williamson@redhat.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Jacob jun Pan <jacob.jun.pan@intel.com>,
	Liu Yi L <yi.l.liu@intel.com>,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] iommu/vt-d: Check domain force_snooping against attached devices
Date: Mon, 2 May 2022 10:17:47 -0300	[thread overview]
Message-ID: <20220502131747.GJ8364@nvidia.com> (raw)
In-Reply-To: <20220501112434.874236-4-baolu.lu@linux.intel.com>

On Sun, May 01, 2022 at 07:24:32PM +0800, Lu Baolu wrote:
> +static bool domain_support_force_snooping(struct dmar_domain *domain)
> +{
> +	struct device_domain_info *info;
> +	unsigned long flags;
> +	bool support = true;
> +
> +	spin_lock_irqsave(&device_domain_lock, flags);
> +	if (list_empty(&domain->devices))
> +		goto out;

Why? list_for_each_entry will just do nothing..

> +	list_for_each_entry(info, &domain->devices, link) {
> +		if (!ecap_sc_support(info->iommu->ecap)) {
> +			support = false;
> +			break;
> +		}
> +	}
> +out:
> +	spin_unlock_irqrestore(&device_domain_lock, flags);
> +	return support;
> +}
> +
> +static void domain_set_force_snooping(struct dmar_domain *domain)
> +{
> +	struct device_domain_info *info;
> +	unsigned long flags;
> +
> +	/*
> +	 * Second level page table supports per-PTE snoop control. The
> +	 * iommu_map() interface will handle this by setting SNP bit.
> +	 */
> +	if (!domain_use_first_level(domain))
> +		return;
> +
> +	spin_lock_irqsave(&device_domain_lock, flags);
> +	if (list_empty(&domain->devices))
> +		goto out_unlock;
> +
> +	list_for_each_entry(info, &domain->devices, link)
> +		intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
> +						     PASID_RID2PASID);
> +
> +out_unlock:
> +	spin_unlock_irqrestore(&device_domain_lock, flags);
> +}
> +
>  static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
>  {
>  	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
>  
> -	if (!domain_update_iommu_snooping(NULL))
> +	if (!domain_support_force_snooping(dmar_domain))
>  		return false;

Maybe exit early if force_snooping = true?

> +	domain_set_force_snooping(dmar_domain);
>  	dmar_domain->force_snooping = true;
> +
>  	return true;
>  }
>  
> diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
> index f8d215d85695..815c744e6a34 100644
> +++ b/drivers/iommu/intel/pasid.c
> @@ -762,3 +762,21 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
>  
>  	return 0;
>  }
> +
> +/*
> + * Set the page snoop control for a pasid entry which has been set up.
> + */

So the 'first level' is only used with pasid?

> +void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu,
> +					  struct device *dev, u32 pasid)
> +{
> +	struct pasid_entry *pte;
> +	u16 did;
> +
> +	pte = intel_pasid_get_entry(dev, pasid);
> +	if (WARN_ON(!pte || !pasid_pte_is_present(pte)))
> +		return;
> +
> +	pasid_set_pgsnp(pte);

Doesn't this need to be done in other places too, like when a new attach
is made? Patch 5 removed it, but should that be made if
domain->force_snooping?

Jason

  reply	other threads:[~2022-05-02 13:17 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-01 11:24 [PATCH 0/5] iommu/vt-d: Force snooping improvement Lu Baolu
2022-05-01 11:24 ` Lu Baolu
2022-05-01 11:24 ` [PATCH 1/5] iommu/vt-d: Block force-snoop domain attaching if no SC support Lu Baolu
2022-05-01 11:24   ` Lu Baolu
2022-05-02 13:04   ` Jason Gunthorpe via iommu
2022-05-02 13:04     ` Jason Gunthorpe
2022-05-01 11:24 ` [PATCH 2/5] iommu/vt-d: Set SNP bit only in second-level page table entries Lu Baolu
2022-05-01 11:24   ` Lu Baolu
2022-05-02 13:05   ` Jason Gunthorpe via iommu
2022-05-02 13:05     ` Jason Gunthorpe
2022-05-04  7:25     ` Baolu Lu
2022-05-04  7:25       ` Baolu Lu
2022-05-04 13:31       ` Jason Gunthorpe via iommu
2022-05-04 13:31         ` Jason Gunthorpe
2022-05-04 14:37         ` Baolu Lu
2022-05-04 14:37           ` Baolu Lu
2022-05-01 11:24 ` [PATCH 3/5] iommu/vt-d: Check domain force_snooping against attached devices Lu Baolu
2022-05-01 11:24   ` Lu Baolu
2022-05-02 13:17   ` Jason Gunthorpe via iommu [this message]
2022-05-02 13:17     ` Jason Gunthorpe
2022-05-04  7:58     ` Baolu Lu
2022-05-04  7:58       ` Baolu Lu
2022-05-02 21:31   ` Jacob Pan
2022-05-02 21:31     ` Jacob Pan
2022-05-04  8:06     ` Baolu Lu
2022-05-04  8:06       ` Baolu Lu
2022-05-01 11:24 ` [PATCH 4/5] iommu/vt-d: Remove domain_update_iommu_snooping() Lu Baolu
2022-05-01 11:24   ` Lu Baolu
2022-05-02 13:19   ` Jason Gunthorpe via iommu
2022-05-02 13:19     ` Jason Gunthorpe
2022-05-02 21:36   ` Jacob Pan
2022-05-02 21:36     ` Jacob Pan
2022-05-04  8:47     ` Baolu Lu
2022-05-04  8:47       ` Baolu Lu
2022-05-01 11:24 ` [PATCH 5/5] iommu/vt-d: Remove hard coding PGSNP bit in PASID entries Lu Baolu
2022-05-01 11:24   ` Lu Baolu
2022-05-02 13:19   ` Jason Gunthorpe via iommu
2022-05-02 13:19     ` Jason Gunthorpe
2022-05-04  8:49     ` Baolu Lu
2022-05-04  8:49       ` Baolu Lu

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=20220502131747.GJ8364@nvidia.com \
    --to=iommu@lists.linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=jacob.jun.pan@intel.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --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 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.