Re: [PATCH RFC v2 0/3] Add set_dev_data and unset_dev_data support

From: Nicolin Chen
Date: Fri Apr 21 2023 - 14:19:43 EST


On Fri, Apr 21, 2023 at 02:59:37PM -0300, Jason Gunthorpe wrote:
> On Fri, Apr 21, 2023 at 10:37:22AM -0700, Nicolin Chen wrote:
>
> > How about the following piece? Needs a test with QEMU though..
> >
> > static const size_t iommufd_device_data_size[] = {
> > [IOMMU_HW_INFO_TYPE_NONE] = 0,
> > [IOMMU_HW_INFO_TYPE_INTEL_VTD] = 0,
> > [IOMMU_HW_INFO_TYPE_ARM_SMMUV3] =
> > sizeof(struct iommu_device_data_arm_smmuv3),
> > };
>
> If we need more than one of these things we'll need a better
> solution..

How about adding ops->device_data_size to store the value?

And, since we have a few size arrays in hw_pagetable.c too,
perhaps a new structure in ops packing all these sizes can
clean up a bit things too? For example,

static struct iommu_user_data_size arm_smmu_user_data_size = {
.device_data_size = sizeof(iommu_device_data_arm_smmuv3),
.hwpt_alloc_data_size = sizeof(iommu_hwpt_alloc_arm_smmuv3),
.hwpt_invalidate_data_size = sizeof(iommu_hwpt_invalidate_arm_smmuv3),
}

The hwpt_xxx_data_size might be in form of arrays for multi-
HWPT_TYPE support.

> > rc = ops->set_dev_data_user(idev->dev, data);
>
> Where will the iommu driver store the vsid to sid xarray from these
> arguments?

The ARM structure packs a vsid. For example:

static int arm_smmu_set_data(struct device *dev, const void *user_data)
{
const struct iommufd_device_data_arm_smmuv3 *data = user_data;
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
struct arm_smmu_stream *stream = &master->streams[0];
struct arm_smmu_device *smmu = master->smmu;
u32 sid_user = data->sid;
int ret = 0;

if (!sid_user)
return -EINVAL;

ret = xa_alloc(&smmu->streams_user, &sid_user, stream,
XA_LIMIT(sid_user, sid_user), GFP_KERNEL_ACCOUNT);
if (ret)
return ret;
stream->id_user = sid_user;
return 0;
}

Thanks
Nic