lkml.org 
[lkml]   [2022]   [Jul]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v10 08/12] iommu/sva: Refactoring iommu_sva_bind/unbind_device()
On Tue, Jul 05, 2022 at 01:07:06PM +0800, Lu Baolu wrote:
> The existing iommu SVA interfaces are implemented by calling the SVA
> specific iommu ops provided by the IOMMU drivers. There's no need for
> any SVA specific ops in iommu_ops vector anymore as we can achieve
> this through the generic attach/detach_dev_pasid domain ops.
>
> This refactors the IOMMU SVA interfaces implementation by using the
> set/block_pasid_dev ops and align them with the concept of the SVA
> iommu domain. Put the new SVA code in the sva related file in order
> to make it self-contained.
>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> Tested-by: Zhangfei Gao <zhangfei.gao@linaro.org>
> Tested-by: Tony Zhu <tony.zhu@intel.com>
> ---
> include/linux/iommu.h | 67 +++++++++++--------
> drivers/iommu/iommu-sva-lib.c | 98 ++++++++++++++++++++++++++++
> drivers/iommu/iommu.c | 119 ++++++++--------------------------
> 3 files changed, 165 insertions(+), 119 deletions(-)
>
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index 42f0418dc22c..f59b0ecd3995 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -39,7 +39,6 @@ struct device;
> struct iommu_domain;
> struct iommu_domain_ops;
> struct notifier_block;
> -struct iommu_sva;
> struct iommu_fault_event;
> struct iommu_dma_cookie;
>
> @@ -57,6 +56,14 @@ struct iommu_domain_geometry {
> bool force_aperture; /* DMA only allowed in mappable range? */
> };
>
> +/**
> + * struct iommu_sva - handle to a device-mm bond
> + */
> +struct iommu_sva {
> + struct device *dev;
> + refcount_t users;
> +};
> +
> /* Domain feature flags */
> #define __IOMMU_DOMAIN_PAGING (1U << 0) /* Support for iommu_map/unmap */
> #define __IOMMU_DOMAIN_DMA_API (1U << 1) /* Domain for use in DMA-API
> @@ -105,6 +112,7 @@ struct iommu_domain {
> };
> struct { /* IOMMU_DOMAIN_SVA */
> struct mm_struct *mm;
> + struct iommu_sva bond;

We can't store a single struct device inside a domain, this is not
layed out right.

The API is really refcounting the PASID:

> +struct iommu_sva *iommu_sva_bind_device(struct device *dev,
> + struct mm_struct *mm);
> +void iommu_sva_unbind_device(struct iommu_sva *handle);

So what you need to do is store that 'iommu_sva' in the group's PASID
xarray.

The bind logic would be

sva = xa_load(group->pasid, mm->pasid)
if (sva)
refcount_inc(sva->users)
return sva
sva = kalloc
sva->domain = domain
xa_store(group->pasid, sva);

Jason

\
 
 \ /
  Last update: 2022-07-23 16:28    [W:0.355 / U:0.748 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site