Commit 15060aba authored by CQ Tang's avatar CQ Tang Committed by Joerg Roedel

iommu/vt-d: Helper function to query if a pasid has any active users

A driver would need to know if there are any active references to a
a PASID before cleaning up its resources. This function helps check
if there are any active users of a PASID before it can perform any
recovery on that device.

To: Joerg Roedel <>
To: David Woodhouse <>
Cc: Jean-Phillipe Brucker <>
Signed-off-by: default avatarCQ Tang <>
Signed-off-by: default avatarAshok Raj <>
Signed-off-by: default avatarJoerg Roedel <>
parent 2ea659a9
......@@ -489,6 +489,36 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)
int intel_svm_is_pasid_valid(struct device *dev, int pasid)
struct intel_iommu *iommu;
struct intel_svm *svm;
int ret = -EINVAL;
iommu = intel_svm_device_to_iommu(dev);
if (!iommu || !iommu->pasid_table)
goto out;
svm = idr_find(&iommu->pasid_idr, pasid);
if (!svm)
goto out;
/* init_mm is used in this case */
if (!svm->mm)
ret = 1;
else if (atomic_read(&svm->mm->mm_users) > 0)
ret = 1;
ret = 0;
return ret;
/* Page request queue descriptor */
struct page_req_dsc {
u64 srr:1;
......@@ -102,6 +102,21 @@ extern int intel_svm_bind_mm(struct device *dev, int *pasid, int flags,
extern int intel_svm_unbind_mm(struct device *dev, int pasid);
* intel_svm_is_pasid_valid() - check if pasid is valid
* @dev: Device for which PASID was allocated
* @pasid: PASID value to be checked
* This function checks if the specified pasid is still valid. A
* valid pasid means the backing mm is still having a valid user.
* For kernel callers init_mm is always valid. for other mm, if mm->mm_users
* is non-zero, it is valid.
* returns -EINVAL if invalid pasid, 0 if pasid ref count is invalid
* 1 if pasid is valid.
extern int intel_svm_is_pasid_valid(struct device *dev, int pasid);
static inline int intel_svm_bind_mm(struct device *dev, int *pasid,
......@@ -114,6 +129,11 @@ static inline int intel_svm_unbind_mm(struct device *dev, int pasid)
static int intel_svm_is_pasid_valid(struct device *dev, int pasid)
return -EINVAL;
#define intel_svm_available(dev) (!intel_svm_bind_mm((dev), NULL, 0, NULL))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment