diff mbox series

[v2,6/6] iommu/vt-d: Add domain_alloc_user op

Message ID 20230928071528.26258-7-yi.l.liu@intel.com (mailing list archive)
State Accepted
Commit c97d1b20d3835178bcd0e3a86c20ce4e36b6d80c
Headers show
Series iommufd support allocating nested parent domain | expand

Commit Message

Yi Liu Sept. 28, 2023, 7:15 a.m. UTC
This adds the domain_alloc_user op implementation. It supports allocating
domains to be used as parent under nested translation.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Baolu Lu Sept. 29, 2023, 3:38 a.m. UTC | #1
On 9/28/23 3:15 PM, Yi Liu wrote:
> This adds the domain_alloc_user op implementation. It supports allocating
> domains to be used as parent under nested translation.
> 
> Signed-off-by: Yi Liu<yi.l.liu@intel.com>
> ---
>   drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

Best regards,
baolu
Tian, Kevin Oct. 9, 2023, 1:13 a.m. UTC | #2
> From: Liu, Yi L <yi.l.liu@intel.com>
> Sent: Thursday, September 28, 2023 3:15 PM
> 
> This adds the domain_alloc_user op implementation. It supports allocating
> domains to be used as parent under nested translation.
> 
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Jason Gunthorpe Oct. 10, 2023, 4:43 p.m. UTC | #3
On Thu, Sep 28, 2023 at 12:15:28AM -0700, Yi Liu wrote:
> This adds the domain_alloc_user op implementation. It supports allocating
> domains to be used as parent under nested translation.
> 
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> ---
>  drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index 5db283c17e0d..017aed5813d8 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -4074,6 +4074,33 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
>  	return NULL;
>  }
>  
> +static struct iommu_domain *
> +intel_iommu_domain_alloc_user(struct device *dev, u32 flags)
> +{
> +	struct iommu_domain *domain;
> +	struct intel_iommu *iommu;
> +
> +	if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT))
> +		return ERR_PTR(-EOPNOTSUPP);
> +
> +	iommu = device_to_iommu(dev, NULL, NULL);
> +	if (!iommu)
> +		return ERR_PTR(-ENODEV);

Why isn't this just

	struct device_domain_info *info = dev_iommu_priv_get(dev)
	struct intel_iommu *iommu = info->iommu

???

Same question for almost all other calls to this function! The one in
probe is reasonable, but I don't think it should be ever called again.

I'm going to leave this, but please make a series cleaning all the
device_to_iommu() stuff next cycle..

Jason
Baolu Lu Oct. 11, 2023, 3:18 a.m. UTC | #4
On 10/11/23 12:43 AM, Jason Gunthorpe wrote:
> On Thu, Sep 28, 2023 at 12:15:28AM -0700, Yi Liu wrote:
>> This adds the domain_alloc_user op implementation. It supports allocating
>> domains to be used as parent under nested translation.
>>
>> Signed-off-by: Yi Liu<yi.l.liu@intel.com>
>> ---
>>   drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++
>>   1 file changed, 28 insertions(+)
>>
>> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
>> index 5db283c17e0d..017aed5813d8 100644
>> --- a/drivers/iommu/intel/iommu.c
>> +++ b/drivers/iommu/intel/iommu.c
>> @@ -4074,6 +4074,33 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
>>   	return NULL;
>>   }
>>   
>> +static struct iommu_domain *
>> +intel_iommu_domain_alloc_user(struct device *dev, u32 flags)
>> +{
>> +	struct iommu_domain *domain;
>> +	struct intel_iommu *iommu;
>> +
>> +	if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT))
>> +		return ERR_PTR(-EOPNOTSUPP);
>> +
>> +	iommu = device_to_iommu(dev, NULL, NULL);
>> +	if (!iommu)
>> +		return ERR_PTR(-ENODEV);
> Why isn't this just
> 
> 	struct device_domain_info *info = dev_iommu_priv_get(dev)
> 	struct intel_iommu *iommu = info->iommu
> 
> ???
> 
> Same question for almost all other calls to this function! The one in
> probe is reasonable, but I don't think it should be ever called again.
> 
> I'm going to leave this, but please make a series cleaning all the
> device_to_iommu() stuff next cycle..

Sure. I also have a plan to do this. device_to_iommu() is only needed in
the probe path. For runtime callbacks, we can just retrieve it from the
device's iommu private data.

Best regards,
baolu
diff mbox series

Patch

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 5db283c17e0d..017aed5813d8 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4074,6 +4074,33 @@  static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
 	return NULL;
 }
 
+static struct iommu_domain *
+intel_iommu_domain_alloc_user(struct device *dev, u32 flags)
+{
+	struct iommu_domain *domain;
+	struct intel_iommu *iommu;
+
+	if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT))
+		return ERR_PTR(-EOPNOTSUPP);
+
+	iommu = device_to_iommu(dev, NULL, NULL);
+	if (!iommu)
+		return ERR_PTR(-ENODEV);
+
+	if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap))
+		return ERR_PTR(-EOPNOTSUPP);
+
+	/*
+	 * domain_alloc_user op needs to fully initialize a domain
+	 * before return, so uses iommu_domain_alloc() here for
+	 * simple.
+	 */
+	domain = iommu_domain_alloc(dev->bus);
+	if (!domain)
+		domain = ERR_PTR(-ENOMEM);
+	return domain;
+}
+
 static void intel_iommu_domain_free(struct iommu_domain *domain)
 {
 	if (domain != &si_domain->domain && domain != &blocking_domain)
@@ -4807,6 +4834,7 @@  const struct iommu_ops intel_iommu_ops = {
 	.capable		= intel_iommu_capable,
 	.hw_info		= intel_iommu_hw_info,
 	.domain_alloc		= intel_iommu_domain_alloc,
+	.domain_alloc_user	= intel_iommu_domain_alloc_user,
 	.probe_device		= intel_iommu_probe_device,
 	.probe_finalize		= intel_iommu_probe_finalize,
 	.release_device		= intel_iommu_release_device,