Re: [PATCH v5 2/9] iommu: Replace sva_iommu with iommu_attach_handle

From: Jason Gunthorpe
Date: Tue May 07 2024 - 20:10:00 EST


On Tue, Apr 30, 2024 at 10:57:03PM +0800, Lu Baolu wrote:
> diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h
> index da1addaa1a31..ae65e0b85d69 100644
> --- a/drivers/iommu/iommu-priv.h
> +++ b/drivers/iommu/iommu-priv.h
> @@ -30,6 +30,13 @@ void iommu_device_unregister_bus(struct iommu_device *iommu,
>
> struct iommu_attach_handle {
> struct iommu_domain *domain;
> + union {
> + /* attach data for SVA domain */
> + struct {
> + struct device *dev;
> + refcount_t users;
> + };
> + };
> };

FWIW I was thinking of having the caller allocate the handle and pass it
down, but this seems workable too and is a bit simpler.

> diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
> index bdc2e6fda782..b325097421c1 100644
> --- a/drivers/misc/uacce/uacce.c
> +++ b/drivers/misc/uacce/uacce.c
> @@ -106,7 +106,7 @@ static long uacce_fops_compat_ioctl(struct file *filep,
> static int uacce_bind_queue(struct uacce_device *uacce, struct uacce_queue *q)
> {
> u32 pasid;
> - struct iommu_sva *handle;
> + struct iommu_attach_handle *handle;

Though I'm much less keen on this..

Maybe

struct iommu_attach_handle {
struct iommu_domain *domain;
union {
struct iommu_sva sva;
};
};

?

Then container_of(sva) to get back to handle and keep the meaningful
type?

Jason