diff mbox series

[RFC,8/8] iommu/vt-d: Add set_dev_pasid callback for nested domain

Message ID 20230926092651.17041-9-yi.l.liu@intel.com (mailing list archive)
State New, archived
Headers show
Series iommufd support pasid attach/replace | expand

Commit Message

Yi Liu Sept. 26, 2023, 9:26 a.m. UTC
From: Lu Baolu <baolu.lu@linux.intel.com>

This allows the upper layers to set a nested type domain to a PASID of a
device if the PASID feature is supported by the IOMMU hardware.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/intel/nested.c | 47 ++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

Comments

Tian, Kevin Sept. 27, 2023, 7:52 a.m. UTC | #1
> From: Liu, Yi L <yi.l.liu@intel.com>
> Sent: Tuesday, September 26, 2023 5:27 PM
> 
> From: Lu Baolu <baolu.lu@linux.intel.com>
> 
> This allows the upper layers to set a nested type domain to a PASID of a
> device if the PASID feature is supported by the IOMMU hardware.
> 
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> ---
>  drivers/iommu/intel/nested.c | 47
> ++++++++++++++++++++++++++++++++++++
>  1 file changed, 47 insertions(+)

pasid can be attached to either user hwpt or kernel hwpt.

We should also introduce a set_dev_pasid callback for non-nest domain ops.
Baolu Lu Sept. 27, 2023, 7:57 a.m. UTC | #2
On 2023/9/27 15:52, Tian, Kevin wrote:
>> From: Liu, Yi L<yi.l.liu@intel.com>
>> Sent: Tuesday, September 26, 2023 5:27 PM
>>
>> From: Lu Baolu<baolu.lu@linux.intel.com>
>>
>> This allows the upper layers to set a nested type domain to a PASID of a
>> device if the PASID feature is supported by the IOMMU hardware.
>>
>> Signed-off-by: Lu Baolu<baolu.lu@linux.intel.com>
>> Signed-off-by: Yi Liu<yi.l.liu@intel.com>
>> ---
>>   drivers/iommu/intel/nested.c | 47
>> ++++++++++++++++++++++++++++++++++++
>>   1 file changed, 47 insertions(+)
> pasid can be attached to either user hwpt or kernel hwpt.
> 
> We should also introduce a set_dev_pasid callback for non-nest domain ops.

We already have the code in Linus' tree. The idxd driver uses it for
kernel DMA with pasid.

Best regards,
baolu
Tian, Kevin Sept. 27, 2023, 8:09 a.m. UTC | #3
> From: Baolu Lu <baolu.lu@linux.intel.com>
> Sent: Wednesday, September 27, 2023 3:58 PM
> 
> On 2023/9/27 15:52, Tian, Kevin wrote:
> >> From: Liu, Yi L<yi.l.liu@intel.com>
> >> Sent: Tuesday, September 26, 2023 5:27 PM
> >>
> >> From: Lu Baolu<baolu.lu@linux.intel.com>
> >>
> >> This allows the upper layers to set a nested type domain to a PASID of a
> >> device if the PASID feature is supported by the IOMMU hardware.
> >>
> >> Signed-off-by: Lu Baolu<baolu.lu@linux.intel.com>
> >> Signed-off-by: Yi Liu<yi.l.liu@intel.com>
> >> ---
> >>   drivers/iommu/intel/nested.c | 47
> >> ++++++++++++++++++++++++++++++++++++
> >>   1 file changed, 47 insertions(+)
> > pasid can be attached to either user hwpt or kernel hwpt.
> >
> > We should also introduce a set_dev_pasid callback for non-nest domain
> ops.
> 
> We already have the code in Linus' tree. The idxd driver uses it for
> kernel DMA with pasid.
> 

ah, I forgot. 
Yi Liu Oct. 10, 2023, 3:33 a.m. UTC | #4
On 2023/9/27 16:09, Tian, Kevin wrote:
>> From: Baolu Lu <baolu.lu@linux.intel.com>
>> Sent: Wednesday, September 27, 2023 3:58 PM
>>
>> On 2023/9/27 15:52, Tian, Kevin wrote:
>>>> From: Liu, Yi L<yi.l.liu@intel.com>
>>>> Sent: Tuesday, September 26, 2023 5:27 PM
>>>>
>>>> From: Lu Baolu<baolu.lu@linux.intel.com>
>>>>
>>>> This allows the upper layers to set a nested type domain to a PASID of a
>>>> device if the PASID feature is supported by the IOMMU hardware.
>>>>
>>>> Signed-off-by: Lu Baolu<baolu.lu@linux.intel.com>
>>>> Signed-off-by: Yi Liu<yi.l.liu@intel.com>
>>>> ---
>>>>    drivers/iommu/intel/nested.c | 47
>>>> ++++++++++++++++++++++++++++++++++++
>>>>    1 file changed, 47 insertions(+)
>>> pasid can be attached to either user hwpt or kernel hwpt.
>>>
>>> We should also introduce a set_dev_pasid callback for non-nest domain
>> ops.
>>
>> We already have the code in Linus' tree. The idxd driver uses it for
>> kernel DMA with pasid.
>>
> 
> ah, I forgot. 
diff mbox series

Patch

diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c
index 4853fee216d9..dc99ea1abf68 100644
--- a/drivers/iommu/intel/nested.c
+++ b/drivers/iommu/intel/nested.c
@@ -63,6 +63,52 @@  static int intel_nested_attach_dev(struct iommu_domain *domain,
 	return 0;
 }
 
+static int intel_nested_set_dev_pasid(struct iommu_domain *domain,
+				      struct device *dev, ioasid_t pasid)
+{
+	struct device_domain_info *info = dev_iommu_priv_get(dev);
+	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+	struct intel_iommu *iommu = info->iommu;
+	struct dev_pasid_info *dev_pasid;
+	unsigned long flags;
+	int ret = 0;
+
+	if (!pasid_supported(iommu))
+		return -EOPNOTSUPP;
+
+	if (iommu->agaw < dmar_domain->s2_domain->agaw)
+		return -EINVAL;
+
+	ret = prepare_domain_attach_device(&dmar_domain->s2_domain->domain, dev);
+	if (ret)
+		return ret;
+
+	dev_pasid = kzalloc(sizeof(*dev_pasid), GFP_KERNEL);
+	if (!dev_pasid)
+		return -ENOMEM;
+
+	ret = domain_attach_iommu(dmar_domain, iommu);
+	if (ret)
+		goto err_free;
+
+	ret = intel_pasid_setup_nested(iommu, dev, pasid, dmar_domain);
+	if (ret)
+		goto err_detach_iommu;
+
+	dev_pasid->dev = dev;
+	dev_pasid->pasid = pasid;
+	spin_lock_irqsave(&dmar_domain->lock, flags);
+	list_add(&dev_pasid->link_domain, &dmar_domain->dev_pasids);
+	spin_unlock_irqrestore(&dmar_domain->lock, flags);
+
+	return 0;
+err_detach_iommu:
+	domain_detach_iommu(dmar_domain, iommu);
+err_free:
+	kfree(dev_pasid);
+	return ret;
+}
+
 static void intel_nested_domain_free(struct iommu_domain *domain)
 {
 	kfree(to_dmar_domain(domain));
@@ -127,6 +173,7 @@  static int intel_nested_cache_invalidate_user(struct iommu_domain *domain,
 
 static const struct iommu_domain_ops intel_nested_domain_ops = {
 	.attach_dev		= intel_nested_attach_dev,
+	.set_dev_pasid		= intel_nested_set_dev_pasid,
 	.free			= intel_nested_domain_free,
 	.cache_invalidate_user	= intel_nested_cache_invalidate_user,
 };