Skip to content

Commit 4e14176

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/sva: Stop using ioasid_set for SVA
Instead SVA drivers can use a simple global IDA to allocate PASIDs for each mm_struct. Future work would be to allow drivers using the SVA APIs to reserve global PASIDs from this IDA for their internal use, eg with the DMA API PASID support. Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20230322200803.869130-5-jacob.jun.pan@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 2bef9ba commit 4e14176

2 files changed

Lines changed: 14 additions & 29 deletions

File tree

drivers/iommu/iommu-sva.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,34 @@
99
#include "iommu-sva.h"
1010

1111
static DEFINE_MUTEX(iommu_sva_lock);
12-
static DECLARE_IOASID_SET(iommu_sva_pasid);
12+
static DEFINE_IDA(iommu_global_pasid_ida);
1313

14-
/**
15-
* iommu_sva_alloc_pasid - Allocate a PASID for the mm
16-
* @mm: the mm
17-
* @min: minimum PASID value (inclusive)
18-
* @max: maximum PASID value (inclusive)
19-
*
20-
* Try to allocate a PASID for this mm, or take a reference to the existing one
21-
* provided it fits within the [@min, @max] range. On success the PASID is
22-
* available in mm->pasid and will be available for the lifetime of the mm.
23-
*
24-
* Returns 0 on success and < 0 on error.
25-
*/
26-
int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
14+
/* Allocate a PASID for the mm within range (inclusive) */
15+
static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
2716
{
2817
int ret = 0;
29-
ioasid_t pasid;
3018

31-
if (min == INVALID_IOASID || max == INVALID_IOASID ||
19+
if (!pasid_valid(min) || !pasid_valid(max) ||
3220
min == 0 || max < min)
3321
return -EINVAL;
3422

3523
mutex_lock(&iommu_sva_lock);
3624
/* Is a PASID already associated with this mm? */
3725
if (pasid_valid(mm->pasid)) {
38-
if (mm->pasid < min || mm->pasid >= max)
26+
if (mm->pasid < min || mm->pasid > max)
3927
ret = -EOVERFLOW;
4028
goto out;
4129
}
4230

43-
pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm);
44-
if (!pasid_valid(pasid))
45-
ret = -ENOMEM;
46-
else
47-
mm->pasid = pasid;
31+
ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_ATOMIC);
32+
if (ret < 0)
33+
goto out;
34+
mm->pasid = ret;
35+
ret = 0;
4836
out:
4937
mutex_unlock(&iommu_sva_lock);
5038
return ret;
5139
}
52-
EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid);
5340

5441
/**
5542
* iommu_sva_bind_device() - Bind a process address space to a device
@@ -221,8 +208,8 @@ iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
221208

222209
void mm_pasid_drop(struct mm_struct *mm)
223210
{
224-
if (pasid_valid(mm->pasid)) {
225-
ioasid_free(mm->pasid);
226-
mm->pasid = INVALID_IOASID;
227-
}
211+
if (likely(!pasid_valid(mm->pasid)))
212+
return;
213+
214+
ida_free(&iommu_global_pasid_ida, mm->pasid);
228215
}

drivers/iommu/iommu-sva.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <linux/ioasid.h>
99
#include <linux/mm_types.h>
1010

11-
int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max);
12-
1311
/* I/O Page fault */
1412
struct device;
1513
struct iommu_fault;

0 commit comments

Comments
 (0)