From: bot+bpf-ci@kernel.org
To: alexei.starovoitov@gmail.com,bpf@vger.kernel.org
Cc: daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,oleg@redhat.com,peterz@infradead.org,mhiramat@kernel.org,jolsa@kernel.org,akpm@linux-foundation.org,liam@infradead.org,ljs@kernel.org,surenb@google.com,david@kernel.org,vbabka@kernel.org,jannh@google.com,hughd@google.com,kees@kernel.org,mingo@redhat.com,tglx@kernel.org,x86@kernel.org,linux-trace-kernel@vger.kernel.org,linux-mm@kvack.org,linux-perf-users@vger.kernel.org,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next 5/9] uprobes: Don't sleep on mmap_lock under dup_mmap_sem
Date: Thu, 22 Oct 2026 02:37:29 +0000 (UTC) [thread overview]
Message-ID: <778cae554b4280123e66d54fd1a7a92759259acc26f80e41c8779fce9b268ac7@mail.kernel.org> (raw)
In-Reply-To: <20261022015712.1297331-6-alexei.starovoitov@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3333 bytes --]
> uprobes: Don't sleep on mmap_lock under dup_mmap_sem
TL;DR: Question, possibly not a bug: uprobe_dup_mmap() edits oldmm page tables
inside dup_mmap() before vma_start_write(), so it may race with per-VMA read
lockers (page fault, MADV_DONTNEED); the review suspects it is safe.
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
[ ... ]
> void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
> {
> + struct uprobe_walk *walk;
> + struct map_info *info;
> +
> + list_for_each_entry(walk, &uprobe_walks, list) {
> + /*
> + * fork() that is being killed fails in copy_process().
> + * There will be no child. Leave oldmm to the walk.
> + */
> + if (fatal_signal_pending(current))
> + break;
> + for (info = walk->busy; info; info = info->next)
> + if (info->mm == oldmm)
> + register_one_mm(walk, info, true);
> + }
> +
A subsystem pattern flags this call as potentially concerning, so this may
not be a bug.
uprobe_dup_mmap() is called from dup_mmap() with mmap_write_lock_killable()
held on oldmm, and before the copy loop reaches vma_start_write_killable()
on each vma:
dup_mmap()
mmap_write_lock_killable(oldmm)
uprobe_dup_mmap(oldmm, mm)
register_one_mm(walk, info, true)
install_breakpoint() / remove_breakpoint()
set_swbp() / set_orig_insn()
uprobe_write()
get_user_pages_remote()
folio_walk_start() + __uprobe_write()
collapse_pte_mapped_thp() (unregister path)
try_collapse_pte_mapped_thp()
pmdp_collapse_flush() + pte_free_defer()
...
vma_start_write_killable(mpnt)
The guide for the VMA locking code says to report functions that hold
mmap_write_lock and access page tables or PTE pages before calling
vma_start_write(vma), because other threads of the forking process may
still hold per-VMA read locks on the same vma, for example in a page fault
or in MADV_DONTNEED with CONFIG_PT_RECLAIM.
Can uprobe_write() and collapse_pte_mapped_thp() run against oldmm here
while another thread of the forking process holds a per-VMA read lock on
the same vma?
For context, the existing register_for_each_vma() -> register_one_mm()
walk already did this with only mmap_write_lock held. What this patch adds
is a second caller of that code inside dup_mmap(), which did no page table
access on oldmm before vma_start_write().
On the other side, uprobe_write() takes the page table lock through
folio_walk_start() and retries when fw.page does not match the expected
page, and try_collapse_pte_mapped_thp() re-checks pmd_same() under the
locks before pmdp_collapse_flush(). khugepaged's retract_page_tables()
also retracts page tables without mmap_lock at all. So it may be that
this access is safe without the per-VMA write lock.
Could you confirm whether the vma_start_write() rule is meant to apply to
the uprobe_write() path called from uprobe_dup_mmap()?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/39710454342
next prev parent reply other threads:[~2026-10-22 2:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 1:57 [PATCH bpf-next 0/9] uprobes: Don't stall fork() when mmap_lock is busy Alexei Starovoitov
2026-10-22 1:57 ` [PATCH bpf-next 1/9] mm: Bring back mmap_write_trylock() Alexei Starovoitov
2026-10-22 1:57 ` [PATCH bpf-next 2/9] uprobes: Don't run exit_mmap() under dup_mmap_sem Alexei Starovoitov
2026-10-22 1:57 ` [PATCH bpf-next 3/9] uprobes/x86: Finish an unoptimization which failed half-way Alexei Starovoitov
2026-10-22 2:57 ` Gregory Price (Meta)
2026-10-23 7:13 ` Jiri Olsa
2026-10-22 1:57 ` [PATCH bpf-next 4/9] uprobes/x86: Don't WARN if an optimized probe can't be written Alexei Starovoitov
2026-10-22 2:37 ` bot+bpf-ci
2026-10-22 17:56 ` Jann Horn
2026-10-22 19:33 ` Liam R. Howlett
2026-10-23 14:06 ` Lorenzo Stoakes (ARM)
2026-10-23 7:13 ` Jiri Olsa
2026-10-22 1:57 ` [PATCH bpf-next 5/9] uprobes: Don't sleep on mmap_lock under dup_mmap_sem Alexei Starovoitov
2026-10-22 2:37 ` bot+bpf-ci [this message]
2026-10-22 23:11 ` Andrii Nakryiko
2026-10-22 1:57 ` [PATCH bpf-next 6/9] uprobes: Don't sleep on mmap_lock with dup_mmap_sem held in dup_mmap() Alexei Starovoitov
2026-10-22 18:42 ` Jann Horn
2026-10-23 20:51 ` David Hildenbrand (Arm)
2026-10-27 15:38 ` Lorenzo Stoakes (ARM)
2026-10-22 1:57 ` [PATCH bpf-next 7/9] fork: Let the new task point to its mm before uprobes can find it Alexei Starovoitov
2026-10-27 16:08 ` Lorenzo Stoakes (ARM)
2026-10-22 1:57 ` [PATCH bpf-next 8/9] uprobes: Don't leak the breakpoints if the unregistering task is killed Alexei Starovoitov
2026-10-22 1:57 ` [PATCH bpf-next 9/9] selftests/bpf: Test uprobes and fork() with busy mmap_lock Alexei Starovoitov
2026-10-22 2:37 ` bot+bpf-ci
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=778cae554b4280123e66d54fd1a7a92759259acc26f80e41c8779fce9b268ac7@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=david@kernel.org \
--cc=eddyz87@gmail.com \
--cc=hughd@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=jannh@google.com \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=vbabka@kernel.org \
--cc=x86@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®