From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm <linux-mm@kvack.org>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Subject: [PATCH] mm: Warn mmput() from memory reclaim context.
Date: Fri, 17 Jul 2020 00:30:34 +0900 [thread overview]
Message-ID: <20200716153034.4935-1-penguin-kernel@I-love.SAKURA.ne.jp> (raw)
syzbot is reporting that mmput() from shrinker function has a risk of
deadlock [1], for delayed_uprobe_add() from update_ref_ctr() calls
kzalloc(GFP_KERNEL) with delayed_uprobe_lock held, and
uprobe_clear_state() from __mmput() also holds delayed_uprobe_lock.
However, it took 18 months to hit this race for the third time, for
mmput() invokes __mmput() only when ->mm_users dropped to 0. If we
always warn like might_sleep(), we can detect the possibility of
deadlock more easier.
For now, I inlined the check under CONFIG_PROVE_LOCKING. If we find
more locations, we could introduce a macro like might_sleep().
[1] https://syzkaller.appspot.com/bug?id=bc9e7303f537c41b2b0cc2dfcea3fc42964c2d45
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
kernel/fork.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/fork.c b/kernel/fork.c
index efc5493203ae..8717ce50ff0d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1109,6 +1109,10 @@ static inline void __mmput(struct mm_struct *mm)
void mmput(struct mm_struct *mm)
{
might_sleep();
+#ifdef CONFIG_PROVE_LOCKING
+ /* Calling mmput() from shrinker context can deadlock. */
+ WARN_ON(current->flags & PF_MEMALLOC);
+#endif
if (atomic_dec_and_test(&mm->mm_users))
__mmput(mm);
--
2.18.4
next reply other threads:[~2020-07-16 15:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-16 15:30 Tetsuo Handa [this message]
2020-07-16 19:45 ` David Rientjes
2020-07-16 22:04 ` Tetsuo Handa
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=20200716153034.4935-1-penguin-kernel@I-love.SAKURA.ne.jp \
--to=penguin-kernel@i-love.sakura.ne.jp \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
/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