From: Baolu Lu <baolu.lu@linux.intel.com>
To: "Zhang, Tina" <tina.zhang@intel.com>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>
Cc: baolu.lu@linux.intel.com, "Tian, Kevin" <kevin.tian@intel.com>
Subject: Re: [PATCH 11/11] iommu/vt-d: Remove superfluous IOMMU IOTLB invalidations
Date: Sun, 18 Feb 2024 17:19:09 +0800 [thread overview]
Message-ID: <7afa0043-5230-42f7-947a-ee0e88358edf@linux.intel.com> (raw)
In-Reply-To: <MW5PR11MB5881721113BCB56830201188894C2@MW5PR11MB5881.namprd11.prod.outlook.com>
On 2024/2/16 13:38, Zhang, Tina wrote:
>>> diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c
>>> index 79d1f3107847..bf4962eb229c 100644
>>> --- a/drivers/iommu/intel/svm.c
>>> +++ b/drivers/iommu/intel/svm.c
>>> @@ -134,31 +134,39 @@ void intel_svm_check(struct intel_iommu *iommu)
>>> iommu->flags |= VTD_FLAG_SVM_CAPABLE;
>>> }
>>>
>>> -static void __flush_svm_range_dev(struct dmar_domain *domain,
>>> - struct dev_pasid_info *dev_pasid,
>>> +static void __flush_svm_range(struct iommu_domain *domain,
>>> unsigned long address,
>>> unsigned long pages, int ih)
>>> {
>>> - struct device_domain_info *info = dev_iommu_priv_get(dev_pasid-
>>> dev);
>>> - u32 pasid = mm_get_enqcmd_pasid(domain->domain.mm);
>>> + u32 pasid = mm_get_enqcmd_pasid(domain->mm);
>>> + struct device_domain_info *dev_info;
>>> + struct iommu_domain_info *iommu_info;
>>> + struct dev_pasid_info *dev_pasid;
>>> + unsigned long idx;
>>>
>>> if (WARN_ON(!pages))
>>> return;
>>>
>>> - qi_flush_piotlb(info->iommu, dev_pasid->did, pasid, address, pages, ih);
>>> - if (info->ats_enabled) {
>>> - qi_flush_dev_iotlb_pasid(info->iommu, dev_pasid->sid, info-
>>> pfsid,
>>> - pasid, dev_pasid->qdep, address,
>>> - order_base_2(pages));
>>> - quirk_extra_dev_tlb_flush(info, address, order_base_2(pages),
>>> - pasid, dev_pasid->qdep);
>>> + rcu_read_lock();
>>> + xa_for_each(&to_dmar_domain(domain)->iommu_array, idx,
>> iommu_info)
>>> + qi_flush_piotlb(iommu_info->iommu, dev_pasid->did,
>>> + pasid, address, pages, ih);
>> The xa_array for iommu is already broken. We should fix it before further use.
>>
>> https://lore.kernel.org/linux-iommu/20240103124403.GM50406@nvidia.com/
> Agree that domain->iommu_array needs to protect the element (struct iommu_domain_info) from UAF as well. This could be another topic.
>
> I realize that we don't need to use domain->iommu_array here. What we want here is a pointer pointing to a struct intel_iommu. We can get the info from device using dev_iommu_priv_get(), instead of getting the info from iommu_array.
>
> Besides, I'm thinking about sorting the domain->dev_pasids in intel_iommu_set_dev_pasid() to make struct dev_pasid_info of the devices behind the same IOMMU stay together. It can be helpful to reduce the redundant IOMMU IOTLB invalidations.
I think what you want here are the {domain_id, pasid} pairs to flush the
IOTLB cache in the IOMMU, right? Perhaps we could refine this code
further by introducing a structure of cache tag. The cache tags can be
stored in the domain's IOMMU array. I'm working on a solution and I can
post it for discussion later.
Best regards,
baolu
next prev parent reply other threads:[~2024-02-18 9:19 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
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 [this message]
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=7afa0043-5230-42f7-947a-ee0e88358edf@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