diff options
| author | Christian Brauner <brauner@kernel.org> | 2026-11-01 11:57:20 +0100 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2026-11-05 15:52:38 +0100 |
| commit | e7d73cef9726bea49de97ae1fd76405df4050a75 (patch) | |
| tree | a28a8745b64e721523f6714017b81466fe7e3339 /include/linux/timerqueue.h | |
| parent | 05441d697f7f9a927264f4058cbbc6a03dfcac9d (diff) | |
libfs: make i_rwsem the lock of the offset tree
The offset tree of a directory is only changed with the directory's
i_rwsem held exclusive and offset_readdir() walks it with i_rwsem held
shared. But the maple tree doesn't know that. It is set up with its
internal spinlock, which every mtree_*() helper takes, and readdir takes
rcu_read_lock() around each lookup.
The next patch makes readdir keep one ma_state across dir_emit(), which
can sleep. That is safe because no writer can run while readdir holds
i_rwsem. But the maple tree only allows keeping a ma_state across a
sleep if it is protected by the tree's lock. A reader that relies on
rcu_read_lock() has to mas_pause() before it drops it, and that means a
walk from the root for every entry again.
So tell the tree what protects it. Initialize it with
MT_FLAGS_LOCK_EXTERN and the directory's i_rwsem as its lock and switch
the writers from the mtree_*() helpers to the mas_*() api. They all run
with i_rwsem held exclusive already. With lockdep enabled the maple tree
now also checks that every writer holds i_rwsem exclusive.
Nothing can reach the offset tree anymore when the directory inode is
destroyed. So clear the external lock with mt_on_stack() and destroy the
tree with __mt_destroy() instead of taking i_rwsem in ->destroy_inode().
Cc: stable@vger.kernel.org # v6.14+
Link: https://patch.msgid.link/20261101-work-libfs-offset_readdir-v2-1-c621125b56d1@kernel.org
Reviewed-by: Chuck Lever <cel@kernel.org>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'include/linux/timerqueue.h')
0 files changed, 0 insertions, 0 deletions
