[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7862ed6f-b834-5dc7-8677-31ff52fec76d@linux.intel.com>
Date: Mon, 25 Jul 2022 17:33:05 +0800
From: Baolu Lu <baolu.lu@...ux.intel.com>
To: Jean-Philippe Brucker <jean-philippe@...aro.org>
Cc: baolu.lu@...ux.intel.com, Jason Gunthorpe <jgg@...dia.com>,
Joerg Roedel <joro@...tes.org>,
Christoph Hellwig <hch@...radead.org>,
Kevin Tian <kevin.tian@...el.com>,
Ashok Raj <ashok.raj@...el.com>, Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Jean-Philippe Brucker <jean-philippe@...aro.com>,
Dave Jiang <dave.jiang@...el.com>,
Vinod Koul <vkoul@...nel.org>,
Eric Auger <eric.auger@...hat.com>,
Liu Yi L <yi.l.liu@...el.com>,
Jacob jun Pan <jacob.jun.pan@...el.com>,
Zhangfei Gao <zhangfei.gao@...aro.org>,
Zhu Tony <tony.zhu@...el.com>, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v10 08/12] iommu/sva: Refactoring
iommu_sva_bind/unbind_device()
Hi Jean,
On 2022/7/25 15:39, Jean-Philippe Brucker wrote:
> On Sun, Jul 24, 2022 at 09:48:15PM +0800, Baolu Lu wrote:
>> /*
>> * iommu_detach_device_pasid() - Detach the domain from pasid of device
>> * @domain: the iommu domain.
>> * @dev: the attached device.
>> * @pasid: the pasid of the device.
>> *
>> * The @domain must have been attached to @pasid of the @dev with
>> * iommu_detach_device_pasid().
>> */
>> void iommu_detach_device_pasid(struct iommu_domain *domain, struct device
>> *dev,
>> ioasid_t pasid)
>> {
>> struct iommu_group *group = iommu_group_get(dev);
>> struct group_pasid *param;
>>
>> mutex_lock(&group->mutex);
>> domain->ops->set_dev_pasid(group->blocking_domain, dev, pasid);
> Please also pass the old domain to this detach() function, so that the
> IOMMU driver doesn't have to keep track of them internally.
The iommu core provides the interface to retrieve attached domain with a
{device, pasid} pair. Therefore in the smmuv3 driver, the set_dev_pasid
could do like this:
+static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain,
+ struct device *dev, ioasid_t id)
+{
+ int ret = 0;
+ struct mm_struct *mm;
+ struct iommu_sva *handle;
+
+ /*
+ * Detach the domain if a blocking domain is set. Check the
+ * right domain type once the IOMMU driver supports a real
+ * blocking domain.
+ */
+ if (!domain || domain->type == IOMMU_DOMAIN_UNMANAGED) {
+ struct pasid_iommu *param;
+
+ param = iommu_device_pasid_param(dev, id);
+ if (!param || !param->domain)
+ return -EINVAL;
+ arm_smmu_sva_block_dev_pasid(param->domain, dev, id);
+
+ return 0;
+ }
+
+ mm = domain->mm;
+ mutex_lock(&sva_lock);
+ handle = __arm_smmu_sva_bind(dev, mm);
+ if (IS_ERR(handle))
+ ret = PTR_ERR(handle);
+ mutex_unlock(&sva_lock);
+
+ return ret;
+}
The check of "(!domain || domain->type == IOMMU_DOMAIN_UNMANAGED)" looks
odd, but could get cleaned up after a real blocking domain is added.
Then, we can simply check "domain->type == IOMMU_DOMAIN_BLOCKING".
> In addition to clearing contexts, detach() also needs to invalidate TLBs,
> and for that the SMMU driver needs to know the old ASID (!= PASID) that
> was used by the context descriptor.
Best regards,
baolu
Powered by blists - more mailing lists