Skip to content

Commit 3f5f632

Browse files
ohartoovrleon
authored andcommitted
IB/core: Annotate umem_mutex acquisition under fs_reclaim for lockdep
Following the fix in the previous commit ("IB/mlx5: Fix potential deadlock in MR deregistration"), teach lockdep explicitly about the locking order between fs_reclaim and umem_mutex. The previous commit resolved a potential deadlock scenario where kzalloc(GFP_KERNEL) was called while holding umem_mutex, which could lead to reclaim and eventually invoke the MMU notifier (mlx5_ib_invalidate_range()), causing a recursive acquisition of umem_mutex. To prevent such issues from reoccurring unnoticed in future code changes, add a lockdep annotation in ib_init_umem_odp() that simulates taking umem_mutex inside a reclaim context. This makes lockdep aware of this locking dependency and ensures that future violations—such as calling kzalloc() or any memory allocator that may enter reclaim while holding umem_mutex—will immediately raise a lockdep warning. Signed-off-by: Or Har-Toov <[email protected]> Reviewed-by: Michael Guralnik <[email protected]> Link: https://patch.msgid.link/9d31b9d8fe1db648a9f47cec3df6b8463319dee5.1750061698.git.leon@kernel.org Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 2ed25aa commit 3f5f632

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/infiniband/core/umem_odp.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ static int ib_init_umem_odp(struct ib_umem_odp *umem_odp,
7676
end = ALIGN(end, page_size);
7777
if (unlikely(end < page_size))
7878
return -EOVERFLOW;
79+
/*
80+
* The mmu notifier can be called within reclaim contexts and takes the
81+
* umem_mutex. This is rare to trigger in testing, teach lockdep about
82+
* it.
83+
*/
84+
if (IS_ENABLED(CONFIG_LOCKDEP)) {
85+
fs_reclaim_acquire(GFP_KERNEL);
86+
mutex_lock(&umem_odp->umem_mutex);
87+
mutex_unlock(&umem_odp->umem_mutex);
88+
fs_reclaim_release(GFP_KERNEL);
89+
}
7990

8091
nr_entries = (end - start) >> PAGE_SHIFT;
8192
if (!(nr_entries * PAGE_SIZE / page_size))

0 commit comments

Comments
 (0)