Skip to content

Commit 5d5c85f

Browse files
nicolincjgunthorpe
authored andcommitted
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.com Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 89e07fd commit 5d5c85f

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ void iommufd_access_destroy_object(struct iommufd_object *obj)
690690
container_of(obj, struct iommufd_access, obj);
691691

692692
if (access->ioas) {
693-
iopt_remove_access(&access->ioas->iopt, access);
693+
iopt_remove_access(&access->ioas->iopt, access,
694+
access->iopt_access_list_id);
694695
refcount_dec(&access->ioas->obj.users);
695696
access->ioas = NULL;
696697
}
@@ -776,7 +777,8 @@ void iommufd_access_detach(struct iommufd_access *access)
776777
access->ops->unmap(access->data, 0, ULONG_MAX);
777778
mutex_lock(&access->ioas_lock);
778779
}
779-
iopt_remove_access(&cur_ioas->iopt, access);
780+
iopt_remove_access(&cur_ioas->iopt, access,
781+
access->iopt_access_list_id);
780782
refcount_dec(&cur_ioas->obj.users);
781783
out:
782784
access->ioas_unpin = NULL;

drivers/iommu/iommufd/io_pagetable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,12 +1158,12 @@ int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access)
11581158
}
11591159

11601160
void iopt_remove_access(struct io_pagetable *iopt,
1161-
struct iommufd_access *access)
1161+
struct iommufd_access *access,
1162+
u32 iopt_access_list_id)
11621163
{
11631164
down_write(&iopt->domains_rwsem);
11641165
down_write(&iopt->iova_rwsem);
1165-
WARN_ON(xa_erase(&iopt->access_list, access->iopt_access_list_id) !=
1166-
access);
1166+
WARN_ON(xa_erase(&iopt->access_list, iopt_access_list_id) != access);
11671167
WARN_ON(iopt_calculate_iova_alignment(iopt));
11681168
up_write(&iopt->iova_rwsem);
11691169
up_write(&iopt->domains_rwsem);

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ struct iommufd_access {
323323

324324
int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access);
325325
void iopt_remove_access(struct io_pagetable *iopt,
326-
struct iommufd_access *access);
326+
struct iommufd_access *access,
327+
u32 iopt_access_list_id);
327328
void iommufd_access_destroy_object(struct iommufd_object *obj);
328329

329330
#ifdef CONFIG_IOMMUFD_TEST

0 commit comments

Comments
 (0)