Re: [PATCH v6 07/10] iommufd: Add a nested HW pagetable object

Jason Gunthorpe
2023-10-24T18:00:59Z

On Tue, Oct 24, 2023 at 10:50:58AM -0700, Nicolin Chen wrote:

> > The point is for the user_data to always be available, the driver
> > needs to check it if it is passed.
> >
> > This should all be plumbed to allow drivers to also customize their
> > paging domains too.
>
> We don't have a use case of customizing the paging domains.
> And our selftest isn't covering this path. Nor the case is
> supported by the uAPI:

But this is the design, it is why everything is setup like this - we
didn't create a new op to allocate nesting domains, we made a flexible
user allocator.

> 458- * A kernel-managed HWPT will be created with the mappings from the given
> 459- * IOAS via the @pt_id. The @data_type for this allocation must be set to
> 460: * IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a
> 461- * nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via @flags.
> 462- *

Yes, that is the reality today. If someone comes to use the more
complete interface they need to fix that comment..

> Also, if we do passing in the data, we'd need to...

> 280-static struct iommu_domain *
> 281-mock_domain_alloc_user(struct device *dev, u32 flags,
> 282- struct iommu_domain *parent,
> 283: const struct iommu_user_data *user_data)
> 284-{
> 285- struct mock_iommu_domain *mock_parent;
> 286- struct iommu_hwpt_selftest user_cfg;
> 287- int rc;
> 288-
> 289: if (!user_data) { /* must be mock_domain */
>
> ...change this to if (!parent)...

Yes, this logic is not ideal. The parent is the request for nesting,
not user_data. user_data is the generic creation parameters, which are
not supported outside nesting

Like this:

--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -286,14 +286,12 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
int rc;

/* must be mock_domain */
- if (!user_data) {
+ if (!parent) {
struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
bool has_dirty_flag = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
bool no_dirty_ops = mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY;

- if (parent)
- return ERR_PTR(-EINVAL);
- if (has_dirty_flag && no_dirty_ops)
+ if (user_data || (has_dirty_flag && no_dirty_ops))
return ERR_PTR(-EOPNOTSUPP);
return __mock_domain_alloc_paging(IOMMU_DOMAIN_UNMANAGED,
has_dirty_flag);

Thanks,
Jason