Commit 5d5c85ff authored by Nicolin Chen's avatar Nicolin Chen Committed by Jason Gunthorpe

iommufd: Allow passing in iopt_access_list_id to iopt_remove_access()

This is a preparatory change for ioas replacement support for accesses.
The replacement routine does an iopt_add_access() for a new IOAS first and
then iopt_remove_access() for the old IOAS upon the success of the first
call. However, the first call overrides the iopt_access_list_id in the
access struct, resulting in iopt_remove_access() being unable to work on
the old IOAS.

Add an iopt_access_list_id as a parameter to iopt_remove_access, so the
replacement routine can save the id before it gets overwritten. Pass the
id in iopt_remove_access() for a proper cleanup.

The existing callers should just pass in access->iopt_access_list_id.

Link: https://lore.kernel.org/r/7bb939b9e0102da0c099572bb3de78ab7622221e.1690523699.git.nicolinc@nvidia.comSuggested-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Signed-off-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 89e07fd4
...@@ -690,7 +690,8 @@ void iommufd_access_destroy_object(struct iommufd_object *obj) ...@@ -690,7 +690,8 @@ void iommufd_access_destroy_object(struct iommufd_object *obj)
container_of(obj, struct iommufd_access, obj); container_of(obj, struct iommufd_access, obj);
if (access->ioas) { if (access->ioas) {
iopt_remove_access(&access->ioas->iopt, access); iopt_remove_access(&access->ioas->iopt, access,
access->iopt_access_list_id);
refcount_dec(&access->ioas->obj.users); refcount_dec(&access->ioas->obj.users);
access->ioas = NULL; access->ioas = NULL;
} }
...@@ -776,7 +777,8 @@ void iommufd_access_detach(struct iommufd_access *access) ...@@ -776,7 +777,8 @@ void iommufd_access_detach(struct iommufd_access *access)
access->ops->unmap(access->data, 0, ULONG_MAX); access->ops->unmap(access->data, 0, ULONG_MAX);
mutex_lock(&access->ioas_lock); mutex_lock(&access->ioas_lock);
} }
iopt_remove_access(&cur_ioas->iopt, access); iopt_remove_access(&cur_ioas->iopt, access,
access->iopt_access_list_id);
refcount_dec(&cur_ioas->obj.users); refcount_dec(&cur_ioas->obj.users);
out: out:
access->ioas_unpin = NULL; access->ioas_unpin = NULL;
......
...@@ -1158,12 +1158,12 @@ int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access) ...@@ -1158,12 +1158,12 @@ int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access)
} }
void iopt_remove_access(struct io_pagetable *iopt, void iopt_remove_access(struct io_pagetable *iopt,
struct iommufd_access *access) struct iommufd_access *access,
u32 iopt_access_list_id)
{ {
down_write(&iopt->domains_rwsem); down_write(&iopt->domains_rwsem);
down_write(&iopt->iova_rwsem); down_write(&iopt->iova_rwsem);
WARN_ON(xa_erase(&iopt->access_list, access->iopt_access_list_id) != WARN_ON(xa_erase(&iopt->access_list, iopt_access_list_id) != access);
access);
WARN_ON(iopt_calculate_iova_alignment(iopt)); WARN_ON(iopt_calculate_iova_alignment(iopt));
up_write(&iopt->iova_rwsem); up_write(&iopt->iova_rwsem);
up_write(&iopt->domains_rwsem); up_write(&iopt->domains_rwsem);
......
...@@ -323,7 +323,8 @@ struct iommufd_access { ...@@ -323,7 +323,8 @@ struct iommufd_access {
int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access); int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access);
void iopt_remove_access(struct io_pagetable *iopt, void iopt_remove_access(struct io_pagetable *iopt,
struct iommufd_access *access); struct iommufd_access *access,
u32 iopt_access_list_id);
void iommufd_access_destroy_object(struct iommufd_object *obj); void iommufd_access_destroy_object(struct iommufd_object *obj);
#ifdef CONFIG_IOMMUFD_TEST #ifdef CONFIG_IOMMUFD_TEST
......
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