From: Lu Baolu <baolu.lu@linux.intel.com>
To: Liu Yi L <yi.l.liu@intel.com>,
joro@8bytes.org, will@kernel.org, jacob.jun.pan@linux.intel.com
Cc: baolu.lu@linux.intel.com, kevin.tian@intel.com,
ashok.raj@intel.com, jun.j.tian@intel.com, yi.y.sun@intel.com,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] iommu/vt-d: Fix ineffective devTLB invalidation for subdevices
Date: Wed, 23 Dec 2020 18:09:53 +0800 [thread overview]
Message-ID: <176f7835-a5cf-e049-22b7-724636f74af0@linux.intel.com> (raw)
In-Reply-To: <20201223062720.29364-4-yi.l.liu@intel.com>
Hi Yi,
On 2020/12/23 14:27, Liu Yi L wrote:
> iommu_flush_dev_iotlb() is called to invalidate caches on device. It only
> loops the devices which are full-attached to the domain. For sub-devices,
> this is ineffective. This results in invalid caching entries left on the
> device. Fix it by adding loop for subdevices as well. Also, the domain->
> has_iotlb_device needs to be updated when attaching to subdevices.
>
> Fixes: 67b8e02b5e761 ("iommu/vt-d: Aux-domain specific domain attach/detach")
> Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
> ---
> drivers/iommu/intel/iommu.c | 63 +++++++++++++++++++++++++++----------
> 1 file changed, 47 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index acfe0a5b955e..e97c5ac1d7fc 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -726,6 +726,8 @@ static int domain_update_device_node(struct dmar_domain *domain)
> return nid;
> }
>
> +static void domain_update_iotlb(struct dmar_domain *domain);
> +
> /* Some capabilities may be different across iommus */
> static void domain_update_iommu_cap(struct dmar_domain *domain)
> {
> @@ -739,6 +741,8 @@ static void domain_update_iommu_cap(struct dmar_domain *domain)
> */
> if (domain->nid == NUMA_NO_NODE)
> domain->nid = domain_update_device_node(domain);
> +
> + domain_update_iotlb(domain);
> }
>
> struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus,
> @@ -1459,6 +1463,18 @@ iommu_support_dev_iotlb (struct dmar_domain *domain, struct intel_iommu *iommu,
> return NULL;
> }
>
> +static bool dev_iotlb_enabled(struct device_domain_info *info)
> +{
> + struct pci_dev *pdev;
> +
> + if (!info->dev || !dev_is_pci(info->dev))
> + return false;
> +
> + pdev = to_pci_dev(info->dev);
> +
> + return !!pdev->ats_enabled;
> +}
I know this is just separated from below function. But isn't "(info &&
info->ats_enabled)" is enough?
> +
> static void domain_update_iotlb(struct dmar_domain *domain)
> {
> struct device_domain_info *info;
> @@ -1466,17 +1482,20 @@ static void domain_update_iotlb(struct dmar_domain *domain)
>
> assert_spin_locked(&device_domain_lock);
>
> - list_for_each_entry(info, &domain->devices, link) {
> - struct pci_dev *pdev;
> -
> - if (!info->dev || !dev_is_pci(info->dev))
> - continue;
> -
> - pdev = to_pci_dev(info->dev);
> - if (pdev->ats_enabled) {
> + list_for_each_entry(info, &domain->devices, link)
> + if (dev_iotlb_enabled(info)) {
> has_iotlb_device = true;
> break;
> }
> +
> + if (!has_iotlb_device) {
> + struct subdev_domain_info *sinfo;
> +
> + list_for_each_entry(sinfo, &domain->subdevices, link_domain)
> + if (dev_iotlb_enabled(get_domain_info(sinfo->pdev))) {
Please make the code easier for reading by:
info = get_domain_info(sinfo->pdev);
if (dev_iotlb_enabled(info))
....
Best regards,
baolu
> + has_iotlb_device = true;
> + break;
> + }
> }
>
> domain->has_iotlb_device = has_iotlb_device;
> @@ -1557,25 +1576,37 @@ static void iommu_disable_dev_iotlb(struct device_domain_info *info)
> #endif
> }
>
> +static void __iommu_flush_dev_iotlb(struct device_domain_info *info,
> + u64 addr, unsigned int mask)
> +{
> + u16 sid, qdep;
> +
> + if (!info || !info->ats_enabled)
> + return;
> +
> + sid = info->bus << 8 | info->devfn;
> + qdep = info->ats_qdep;
> + qi_flush_dev_iotlb(info->iommu, sid, info->pfsid,
> + qdep, addr, mask);
> +}
> +
> static void iommu_flush_dev_iotlb(struct dmar_domain *domain,
> u64 addr, unsigned mask)
> {
> - u16 sid, qdep;
> unsigned long flags;
> struct device_domain_info *info;
> + struct subdev_domain_info *sinfo;
>
> if (!domain->has_iotlb_device)
> return;
>
> spin_lock_irqsave(&device_domain_lock, flags);
> - list_for_each_entry(info, &domain->devices, link) {
> - if (!info->ats_enabled)
> - continue;
> + list_for_each_entry(info, &domain->devices, link)
> + __iommu_flush_dev_iotlb(info, addr, mask);
>
> - sid = info->bus << 8 | info->devfn;
> - qdep = info->ats_qdep;
> - qi_flush_dev_iotlb(info->iommu, sid, info->pfsid,
> - qdep, addr, mask);
> + list_for_each_entry(sinfo, &domain->subdevices, link_domain) {
> + __iommu_flush_dev_iotlb(get_domain_info(sinfo->pdev),
> + addr, mask);
> }
> spin_unlock_irqrestore(&device_domain_lock, flags);
> }
>
next prev parent reply other threads:[~2020-12-23 10:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-23 6:27 [PATCH v2 0/3] iommu/vt-d: Misc fixes on scalable mode Liu Yi L
2020-12-23 6:27 ` [PATCH v2 1/3] iommu/vt-d: Move intel_iommu info from struct intel_svm to struct intel_svm_dev Liu Yi L
2020-12-23 6:27 ` [PATCH v2 2/3] iommu/vt-d: Track device aux-attach with subdevice_domain_info Liu Yi L
2020-12-23 6:27 ` [PATCH v2 3/3] iommu/vt-d: Fix ineffective devTLB invalidation for subdevices Liu Yi L
2020-12-23 10:09 ` Lu Baolu [this message]
2020-12-25 8:23 ` Liu, Yi L
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=176f7835-a5cf-e049-22b7-724636f74af0@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=ashok.raj@intel.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@linux.intel.com \
--cc=joro@8bytes.org \
--cc=jun.j.tian@intel.com \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.com \
--cc=yi.y.sun@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
Powered by JetHome