Re: [PATCH v6 02/10] iommu: Pass in parent domain with user_data to domain_alloc_user op

From: Yi Liu
Date: Tue Oct 24 2023 - 12:13:17 EST


On 2023/10/24 23:56, Joao Martins wrote:
On 24/10/2023 16:06, Yi Liu wrote:
domain_alloc_user op already accepts user flags for domain allocation, add
a parent domain pointer and a driver specific user data support as well.

Add a struct iommu_user_data as a bundle of data_ptr/data_len/type from an
iommufd core uAPI structure. Make the user data opaque to the core, since
a userspace driver must match the kernel driver. In the future, if drivers
share some common parameter, there would be a generic parameter as well.

Define an enum iommu_hwpt_data_type (with IOMMU_HWPT_DATA_NONE type) for
iommu drivers to add their own driver specific user data per hw_pagetable.

Signed-off-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Co-developed-by: Nicolin Chen <nicolinc@xxxxxxxxxx>
Signed-off-by: Nicolin Chen <nicolinc@xxxxxxxxxx>
Signed-off-by: Yi Liu <yi.l.liu@xxxxxxxxx>
---
drivers/iommu/intel/iommu.c | 7 ++++++-

You are sadly missing AMD IOMMU

good catch.


This would fix the build and nack the op should parent or user_data be passed:

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index caad10f9cee3..bc747513afcb 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2220,13 +2220,17 @@ static struct iommu_domain
*amd_iommu_domain_alloc(unsigned int type)
}

static struct iommu_domain *amd_iommu_domain_alloc_user(struct device *dev,
- u32 flags)
+ u32 flags, struct iommu_domain *parent,
+ const struct iommu_user_data *user_data)
{
unsigned int type = IOMMU_DOMAIN_UNMANAGED;

if (flags & ~IOMMU_HWPT_ALLOC_DIRTY_TRACKING)
return ERR_PTR(-EOPNOTSUPP);

+ if (parent || user_data)
+ return ERR_PTR(-EOPNOTSUPP);
+
return do_iommu_domain_alloc(type, dev, flags);
}

yes, this should work. @Jason, one more version or just this one with the
above diff from Joao?

--
Regards,
Yi Liu