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

Jason Gunthorpe
2023-10-24T17:13:22Z

On Tue, Oct 24, 2023 at 08:06:06AM -0700, Yi Liu wrote:
> +static struct iommufd_hwpt_nested *
> +iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
> + struct iommufd_hwpt_paging *parent,
> + struct iommufd_device *idev, u32 flags,
> + const struct iommu_user_data *user_data)
> +{
> + const struct iommu_ops *ops = dev_iommu_ops(idev->dev);
> + struct iommufd_hwpt_nested *hwpt_nested;
> + struct iommufd_hw_pagetable *hwpt;
> + int rc;
> +
> + if (flags != 0)
> + return ERR_PTR(-EOPNOTSUPP);
> + if (!user_data)
> + return ERR_PTR(-EINVAL);

user_data is never NULL now, I removed this

> + if (user_data->type == IOMMU_HWPT_DATA_NONE)
> + return ERR_PTR(-EINVAL);
> + if (parent->auto_domain)
> + return ERR_PTR(-EINVAL);
> + if (!parent->nest_parent)
> + return ERR_PTR(-EINVAL);

And put these all together

if (flags || user_data->type == IOMMU_HWPT_DATA_NONE ||
!ops->domain_alloc_user)
return ERR_PTR(-EOPNOTSUPP);
if (parent->auto_domain || !parent->nest_parent)
return ERR_PTR(-EINVAL);

> +
> + if (!ops->domain_alloc_user)
> + return ERR_PTR(-EOPNOTSUPP);
> +
> + hwpt_nested = __iommufd_object_alloc(ictx, hwpt_nested,
> + IOMMUFD_OBJ_HWPT_NESTED,
> + common.obj);
> + if (IS_ERR(hwpt_nested))
> + return ERR_CAST(hwpt_nested);
> + hwpt = &hwpt_nested->common;
> +
> + refcount_inc(&parent->common.obj.users);
> + hwpt_nested->parent = parent;
> +
> + hwpt->domain = ops->domain_alloc_user(idev->dev, 0,

And we may as well pass flags here even though we know it is 0 today.

Jason