From: Alessandro Zanni <alessandro.zanni87@gmail.com>
To: agruenba@redhat.com
Cc: Alessandro Zanni <alessandro.zanni87@gmail.com>,
linux-kernel@vger.kernel.org, gfs2@lists.linux.dev,
syzbot+642d0561f78362d67d3f@syzkaller.appspotmail.com
Subject: [PATCH] fs: gfs2: fix sleeping function called from invalid context
Date: Wed, 29 Apr 2026 10:15:14 +0200 [thread overview]
Message-ID: <20260429081516.566812-1-alessandro.zanni87@gmail.com> (raw)
The issue arises on a PREEMPT kernel because gfs2_quota_init
calls gfs2_qd_search_bucket while holding a bit spinlock and
triggering a "sleeping function called from invalid context"
bug.
This patch refactors the quota initialization by splitting the
lock into separate locks, moving the search outside the atomic
section and using RCU lock for a safe access without holding the
bit spinlock.
Modifications of this patch:
1. Use rcu_read_lock() around the invocation of the function
gfs2_qd_search_bucket() for the search.
2. Add the spin_lock() around the insertion into the hash table
and lists.
3. Remove the usage of unused spin_unlock().
Fixes: de0d95c26c41c ("gfs2: Check quota consistency on mount")
Reported-by: syzbot+642d0561f78362d67d3f@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=642d0561f78362d67d3f
Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
---
fs/gfs2/quota.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 5290865f27f1..48516cbc8b49 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -1456,17 +1456,15 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
qd->qd_slot = slot;
qd->qd_slot_ref = 1;
- spin_lock(&qd_lock);
- spin_lock_bucket(hash);
+ rcu_read_lock();
old_qd = gfs2_qd_search_bucket(hash, sdp, qc_id);
+ rcu_read_unlock();
if (old_qd) {
fs_err(sdp, "Corruption found in quota_change%u"
"file: duplicate identifier in "
"slot %u\n",
sdp->sd_jdesc->jd_jid, slot);
- spin_unlock_bucket(hash);
- spin_unlock(&qd_lock);
qd_put(old_qd);
gfs2_glock_put(qd->qd_gl);
@@ -1480,6 +1478,8 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
continue;
}
+ spin_lock(&qd_lock);
+ spin_lock_bucket(hash);
BUG_ON(test_and_set_bit(slot, sdp->sd_quota_bitmap));
list_add(&qd->qd_list, &sdp->sd_quota_list);
atomic_inc(&sdp->sd_quota_count);
--
2.47.3
next reply other threads:[~2026-04-29 8:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 8:15 Alessandro Zanni [this message]
2026-05-01 13:08 ` [PATCH] fs: gfs2: fix sleeping function called from invalid context Alexander Aring
2026-05-04 11:27 ` Andreas Gruenbacher
2026-05-11 15:06 ` Alessandro Zanni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260429081516.566812-1-alessandro.zanni87@gmail.com \
--to=alessandro.zanni87@gmail.com \
--cc=agruenba@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+642d0561f78362d67d3f@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox