Bug 288127 - Deadlock in vfs
Summary: Deadlock in vfs
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: crash, regression
Depends on:
Blocks:
 
Reported: 2025-07-10 05:56 UTC by Gleb Popov
Modified: 2026-08-05 15:17 UTC (History)
3 users (show)

See Also:


Attachments
procstat output (219.92 KB, text/plain)
2025-07-10 05:56 UTC, Gleb Popov
no flags Details
Another example of hang (270.47 KB, text/plain)
2025-07-10 06:30 UTC, Gleb Popov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gleb Popov freebsd_committer freebsd_triage 2025-07-10 05:56:07 UTC
Created attachment 262016 [details]
procstat output

On the fresh ( https://github.com/freebsd/freebsd-src/commit/f6e5bcd4716c2974c7ceb1fbbfc0ef8db8e13d8b ) CURRENT I started getting random processes to hang at random times. When the process hangs, `top` reports its state as [zfs].

Here is the procstat output for the hanged system state: https://termbin.com/o8sf (also attached). In that case the hanged processes were
- yakuake
- nextcloud
- kalendarac
- plasmashell
- pulseaudio

All of these processes are waiting on

mi_switch+0x172 sleepq_switch+0x109 sleeplk+0x110 lockmgr_slock_hard+0x3c3 VOP_LOCK1_APV+0x2a _vn_lock+0x53 vfs_lookup+0x14c namei+0x35d kern_accessat+0x1c0 amd64_syscall+0x169 fast_syscall_common+0xf8 

Interestingly, there is one more process waiting on this lock, but in the "select" state - xdg-desktop-portal:

mi_switch+0x172 sleepq_switch+0x109 sleeplk+0x110 lockmgr_slock_hard+0x3c3 VOP_LOCK1_APV+0x2a _vn_lock+0x53 vfs_lookup+0x14c namei+0x35d vn_inotify_add_watch+0x1f5 VOP_INOTIFY_ADD_WATCH_APV+0x2a kern_inotify_add_watch+0x34a amd64_syscall+0x169 fast_syscall_common+0xf8 

This made me think that recent inotify changes might be related to this hang.

After the deadlock resolver kicked in I was able to print the location: https://github.com/freebsd/freebsd-src/blob/78935fa40eee14aab1c6de676a1017bcabdf5fa1/sys/kern/vfs_subr.c#L3384
Comment 1 Gleb Popov freebsd_committer freebsd_triage 2025-07-10 06:30:43 UTC
Created attachment 262018 [details]
Another example of hang

Attached another example of the hang. This time xdg-desktop-portal has no mentions of inotify, so maybe it is indeed unrelated.
Comment 2 Konstantin Belousov freebsd_committer freebsd_triage 2025-07-10 07:05:04 UTC
All "zfs" thjreads wait for some zfs vnode lock.  It is crucial to understand
which lock is it, and what does it owner do.

I do not see an obvious owner candidate from the backtraces, but there are a lot,
so it is not hard to miss it.

Follow https://docs.freebsd.org/en/books/developers-handbook/kerneldebug/#kerneldebug-deadlocks
to gather the required debugging info.
Comment 3 Konstantin Belousov freebsd_committer freebsd_triage 2025-07-10 07:18:17 UTC
In fact it might be as simple as https://reviews.freebsd.org/D51233
Comment 4 oleg.nauman 2025-07-10 08:10:23 UTC
I can confirm that https://reviews.freebsd.org/D51233 fixed issue with processes that stuck in _vn_lock vfs_lookup namei vn_inotify_add_watch sequence

Thank you
Comment 5 commit-hook freebsd_committer freebsd_triage 2025-07-10 14:35:46 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=63389aea24f15fe823c775960d77017f1a35f54b

commit 63389aea24f15fe823c775960d77017f1a35f54b
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-07-10 07:15:13 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-07-10 14:34:45 +0000

    inotify: do not call into namei() with a locked vnode

    PR:     288127
    Reviewed by:    markj
    Fixes:  f1f230439fa48581f40a57f095627f667a9713c3
    Sponsored by:   The FreeBSD Foundation
    Differential revision:  https://reviews.freebsd.org/D51233

 sys/kern/vfs_inotify.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 6 Gleb Popov freebsd_committer freebsd_triage 2025-07-10 18:35:53 UTC
I haven't seen a hang yet after applying this patch too.

But it feels weird to me that the bug happens during the mount attempt, because for me most of hangs were happening during the KDE Plasma startup - and nothing is mounted during the process.

I will monitor for hangs for a few days more.
Comment 7 Konstantin Belousov freebsd_committer freebsd_triage 2025-07-10 21:59:28 UTC
(In reply to Gleb Popov from comment #6)
It is not about mount action, but about passing the mount point during lookup.
Comment 8 Gleb Popov freebsd_committer freebsd_triage 2025-07-12 09:56:57 UTC
I think we can close this, I see no hangs after applying Konstantin's fix. Thanks kib for quickly fixing this!
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-08-05 15:17:01 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e8c54222acdbb977c4164667627b6ee569d2eb90

commit e8c54222acdbb977c4164667627b6ee569d2eb90
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-07-10 07:15:13 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-08-05 15:15:16 +0000

    inotify: do not call into namei() with a locked vnode

    PR:     288127
    Reviewed by:    markj
    Fixes:  f1f230439fa48581f40a57f095627f667a9713c3
    Sponsored by:   The FreeBSD Foundation
    Differential revision:  https://reviews.freebsd.org/D51233

    (cherry picked from commit 63389aea24f15fe823c775960d77017f1a35f54b)

 sys/kern/vfs_inotify.c | 2 ++
 1 file changed, 2 insertions(+)