From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
"Puranjay Mohan" <puranjay@kernel.org>
Cc: <bpf@vger.kernel.org>, "Puranjay Mohan" <puranjay12@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Martin KaFai Lau" <martin.lau@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Mykyta Yatsenko" <mykyta.yatsenko5@gmail.com>,
<kernel-team@meta.com>, "Liam R. Howlett" <liam@infradead.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Pedro Falcato" <pfalcato@suse.de>,
"David Hildenbrand" <david@kernel.org>,
"Jann Horn" <jannh@google.com>, <linux-mm@kvack.org>,
"Chris Mason" <mason@kernel.org>
Subject: Re: [PATCH bpf v6 2/3] bpf: switch task_vma iterator from mmap_lock to per-VMA locks
Date: Mon, 23 Nov 2026 00:40:32 +0000 [thread overview]
Message-ID: <DN267JUKDRNS.2VMV07CQ58R4X@gmail.com> (raw)
In-Reply-To: <awGZWsCp6v63H_py@gremlin>
On Sat, Nov 21, 2026 at 05:40 AM Lorenzo Stoakes (ARM) <ljs@kernel.org> wrote:
> This is buggy and can result in deadlock. You need to revert it or restrict
> which contexts it can be called in.
Yeah. It's a bug though very much theoretical.
A revert would bring back an actual deadlock that people hit in production.
So here is that.
> I'm a little surprised you didn't cc- or even ping mm or the VMA team here, we
> are always willing to help and it's clearly sub-optimal to write duplicative,
> open-coded VMA traversal in BPF.
Fair point. Will cc mm next time.
> It's not really sensible to alter core mm to accommodate this at this stage, so
> probably the best course is to disallow this code path for softirq context, or
> you could look into patching the x86 code.
A softirq check is not enough. A tracing prog can run in task context
with pgd_lock held and irqs on:
pgd_alloc()
spin_lock(&pgd_lock)
queued_spin_lock_slowpath()
trace_contention_end() <- pgd_lock is held
tp_btf/contention_end prog
bpf_iter_task_vma_next()
lock_vma_under_rcu()
vma_start_read()
mmdrop(other_mm) <- last put takes pgd_lock again
Equally theoretical deadlock, but since we're discussing hypothetical bugs...
can vma_start_read() use mmdrop_async() like free_signal_struct() ?
It changes only the last put of other_mm in err_unstable.
_destroy() already calls mmput_async() from the same contexts,
so the fix costs nothing to mm afaict.
We can fix it on bpf side, but below fix is much cleaner.
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index d7c6a94..a3333ed 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -43,6 +43,7 @@ static inline void smp_mb__after_mmgrab(void)
}
extern void __mmdrop(struct mm_struct *mm);
+void mmdrop_async(struct mm_struct *mm);
static inline void mmdrop(struct mm_struct *mm)
{
diff --git a/kernel/fork.c b/kernel/fork.c
index 5efceb8..177d5c0 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -752,7 +752,7 @@ static void mmdrop_async_fn(struct work_struct *work)
__mmdrop(mm);
}
-static void mmdrop_async(struct mm_struct *mm)
+void mmdrop_async(struct mm_struct *mm)
{
if (unlikely(atomic_dec_and_test(&mm->mm_count))) {
INIT_WORK(&mm->async_put_work, mmdrop_async_fn);
diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
index 834bbf8..6b9a1bb 100644
--- a/mm/mmap_lock.c
+++ b/mm/mmap_lock.c
@@ -306,11 +306,11 @@ err_unstable:
*/
other_mm = vma->vm_mm; /* use a copy as vma can be freed after we drop vm_refcnt */
/* __mmdrop() is a heavy operation, do it after dropping RCU lock. */
rcu_read_unlock();
mmgrab(other_mm);
vma_refcount_put(vma);
- mmdrop(other_mm);
+ mmdrop_async(other_mm);
return NULL;
}
prev parent reply other threads:[~2026-11-23 0:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260408154539.3832150-1-puranjay@kernel.org>
[not found] ` <20260408154539.3832150-3-puranjay@kernel.org>
2026-11-21 13:40 ` [PATCH bpf v6 2/3] bpf: switch task_vma iterator from mmap_lock to per-VMA locks Lorenzo Stoakes (ARM)
2026-11-23 0:40 ` Alexei Starovoitov [this message]
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=DN267JUKDRNS.2VMV07CQ58R4X@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=david@kernel.org \
--cc=eddyz87@gmail.com \
--cc=jannh@google.com \
--cc=kernel-team@meta.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=pfalcato@suse.de \
--cc=puranjay12@gmail.com \
--cc=puranjay@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.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