Skip to content

Commit 83f7bc6

Browse files
committed
iommufd: Make destroy_rwsem use a lock class per object type
The selftest invokes things like replace under the object lock of its idev which protects the idev in a similar way to a real user. Unfortunately this triggers lockdep. A lock class per type will solve the problem. Link: https://lore.kernel.org/r/15-v8-6659224517ea+532-iommufd_alloc_jgg@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent e88d4ec commit 83f7bc6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ enum iommufd_object_type {
119119
#ifdef CONFIG_IOMMUFD_TEST
120120
IOMMUFD_OBJ_SELFTEST,
121121
#endif
122+
IOMMUFD_OBJ_MAX,
122123
};
123124

124125
/* Base struct for all objects with a userspace ID handle. */

drivers/iommu/iommufd/main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@ struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx,
3333
size_t size,
3434
enum iommufd_object_type type)
3535
{
36+
static struct lock_class_key obj_keys[IOMMUFD_OBJ_MAX];
3637
struct iommufd_object *obj;
3738
int rc;
3839

3940
obj = kzalloc(size, GFP_KERNEL_ACCOUNT);
4041
if (!obj)
4142
return ERR_PTR(-ENOMEM);
4243
obj->type = type;
43-
init_rwsem(&obj->destroy_rwsem);
44+
/*
45+
* In most cases the destroy_rwsem is obtained with try so it doesn't
46+
* interact with lockdep, however on destroy we have to sleep. This
47+
* means if we have to destroy an object while holding a get on another
48+
* object it triggers lockdep. Using one locking class per object type
49+
* is a simple and reasonable way to avoid this.
50+
*/
51+
__init_rwsem(&obj->destroy_rwsem, "iommufd_object::destroy_rwsem",
52+
&obj_keys[type]);
4453
refcount_set(&obj->users, 1);
4554

4655
/*

0 commit comments

Comments
 (0)