2023-09-28 13:20:36

by Yi Liu

[permalink] [raw]
Subject: [PATCH v2 6/6] iommu/vt-d: Add domain_alloc_user op

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 <[email protected]>
---
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);
+
+ 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,
--
2.34.1


2023-09-29 04:50:57

by Lu Baolu

[permalink] [raw]
Subject: Re: [PATCH v2 6/6] iommu/vt-d: Add domain_alloc_user op

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<[email protected]>
> ---
> drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)

Reviewed-by: Lu Baolu <[email protected]>

Best regards,
baolu

2023-10-09 01:13:50

by Tian, Kevin

[permalink] [raw]
Subject: RE: [PATCH v2 6/6] iommu/vt-d: Add domain_alloc_user op

> From: Liu, Yi L <[email protected]>
> 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 <[email protected]>

Reviewed-by: Kevin Tian <[email protected]>

2023-10-10 16:44:19

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH v2 6/6] iommu/vt-d: Add domain_alloc_user op

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 <[email protected]>
> ---
> 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

2023-10-11 03:22:40

by Lu Baolu

[permalink] [raw]
Subject: Re: [PATCH v2 6/6] iommu/vt-d: Add domain_alloc_user op

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<[email protected]>
>> ---
>> 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