-
Notifications
You must be signed in to change notification settings - Fork 8
smb: client: introduce close_cached_dir_locked() #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ksmbd-for-next
Are you sure you want to change the base?
Conversation
Replace close_cached_dir() calls under cfid_list_lock with a new close_cached_dir_locked() variant that uses kref_put() instead of kref_put_lock() to avoid recursive locking when dropping references. While the existing code works if the refcount >= 2 invariant holds, this area has proven error-prone. Make deadlocks impossible and WARN on invariant violations. Cc: [email protected] Signed-off-by: Henrique Carvalho <[email protected]> Signed-off-by: Steve French <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new close_cached_dir_locked() function to safely drop cached directory references while holding the cfid_list_lock spinlock. The change prevents potential recursive locking deadlocks by using kref_put() instead of kref_put_lock() when the lock is already held.
- Adds
close_cached_dir_locked()variant that expectscfid_list_lockto be held and validates refcount >= 2 before decrementing - Updates two call sites to use the new locked variant where the spinlock is already held
- Adds comprehensive documentation and lockdep assertions to prevent misuse
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * The release function will be called with cfid_list_lock held to remove the | ||
| * cached dirs from the list before any other thread can take another @cfid | ||
| * ref. Must not be called with cfid_list_lock held; use | ||
| * close_cached_dir_locked() called instead. |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states "Must not be called with cfid_list_lock held; use close_cached_dir_locked() called instead." The word "called" appears to be redundant or incorrectly placed. It should be either "use close_cached_dir_locked() instead" or "call close_cached_dir_locked() instead".
| * close_cached_dir_locked() called instead. | |
| * close_cached_dir_locked() instead. |
| * two references. If that invariant is violated, WARNs and returns without | ||
| * dropping a reference; the final put must still go through | ||
| * close_cached_dir(). | ||
| * |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The documentation could be clearer about the safety mechanism. While it mentions that calling with refcount < 2 would cause a deadlock, it should explicitly state that when refcount >= 2, calling kref_put() is safe because the refcount will remain >= 1 after decrement, ensuring smb2_close_cached_fid() (the release function) is not invoked while holding the lock.
| * | |
| * | |
| * When refcount >= 2, calling kref_put() is safe because the refcount will remain | |
| * >= 1 after decrement, ensuring smb2_close_cached_fid() (the release function) | |
| * is not invoked while holding the lock. | |
| * |
664a0f9 to
851934d
Compare
6461f77 to
3d99347
Compare
Replace close_cached_dir() calls under cfid_list_lock with a new close_cached_dir_locked() variant that uses kref_put() instead of kref_put_lock() to avoid recursive locking when dropping references.
While the existing code works if the refcount >= 2 invariant holds, this area has proven error-prone. Make deadlocks impossible and WARN on invariant violations.
Cc: [email protected]