gfs2_statfs_slow() stops queueing glock requests once gfs2_rgrpd_get_next() returns NULL. Since the resource groups were moved into an rbtree, gfs2_rgrpd_get_next() wraps around to the first resource group instead, so with two or more of them the walk can request the first resource group's glock again while still holding it: gfs2: fsid=vda.0: original: statfs_by_dentry+0x8a/0xe0 gfs2: fsid=vda.0: new: statfs_by_dentry+0x8a/0xe0 kernel BUG at fs/gfs2/glock.c:1490! This path is used when mounting with statfs_quantum=0 or after setting tune/statfs_slow in sysfs. Remember the first resource group and stop when the walk returns to it, as set_rgrp_preferences() already does. Tested in QEMU with lock_nolock filesystems: before the change, one statfs() after mounting with statfs_quantum=0 hit the BUG with 2, 9 and 63 resource groups and did not return with 64, 65 and 96; after it, statfs() returns the same values as with the default mount. Claude (Anthropic) was used to help with code analysis, testing and review. The fix was written by the submitter. Fixes: 7c9ca621137c ("GFS2: Use rbtree for resource groups and clean up bitmap buffer ref count scheme") Reported-by: syzbot+70f4e455dee59ab40c80@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=70f4e455dee59ab40c80 Reported-by: Zheng Zheng Closes: https://lore.kernel.org/all/CAO-4RZ2nS7ToE6rJxbTJM7CXHVY84YL4zqysFZA7=UzYg3SB0g@mail.gmail.com/ Cc: stable@vger.kernel.org Signed-off-by: Song jeonghak --- Testing details: next-20261126 with lockdep in QEMU, lock_nolock filesystems made with mkfs.gfs2 3.5.1 (-r 32), statfs() after mount. before after 2 rgrps, statfs_quantum=0 BUG (3 of 3) ok (3 of 3) 9 rgrps, statfs_quantum=0 BUG (3 of 3) ok (3 of 3) 9 rgrps, tune/statfs_slow=1 BUG (3 of 3) ok (3 of 3) 9 rgrps, remount,statfs_quantum=0 BUG ok 63 rgrps, statfs_quantum=0 BUG ok 64, 65 and 96 rgrps, statfs_quantum=0 no return ok in ~78 s 1 rgrp (rindex edited by hand) ok ok default mount ok ok The BUG stops at 63 resource groups: with 64 or more, the first pass fills all 64 holder slots, and the first holder is released just before the walk requests it again, so statfs() keeps going instead. After the change, the values from the slow path match those from the default mount, also after creating and deleting files and writing 40 MiB. No lockdep or other warnings were seen. Not tested with lock_dlm. Zheng, your report mentions that the reproducer depends on earlier state; on next-20261126 a mount with statfs_quantum=0 (or writing 1 to tune/statfs_slow) followed by one statfs() was enough. fs/gfs2/super.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 77a1f0a28e04..f1f687c43a99 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -884,6 +884,7 @@ static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host { struct gfs2_rgrpd *rgd_next; struct gfs2_holder *gha, *gh; + struct gfs2_rgrpd *rgd_first; unsigned int slots = 64; unsigned int x; int done; @@ -897,6 +898,7 @@ static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host gfs2_holder_mark_uninitialized(gha + x); rgd_next = gfs2_rgrpd_get_first(sdp); + rgd_first = rgd_next; for (;;) { done = 1; @@ -928,6 +930,9 @@ static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host GL_ASYNC, gh); rgd_next = gfs2_rgrpd_get_next(rgd_next); + /* gfs2_rgrpd_get_next() wraps around */ + if (rgd_next == rgd_first) + rgd_next = NULL; done = 0; } -- 2.43.0