Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chuanhua Han" <hanchuanhua802@gmail.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: "Chuanhua Han" <hanchuanhua@xiaomi.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>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>, "Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Barry Song" <baohua@kernel.org>,
	linux-mm@kvack.org, bpf@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] mm/mmap_lock: add try_lock_next_vma()
Date: Sat, 05 Dec 2026 03:56:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-251025@kernel.org> (raw)
In-Reply-To: <20261205033951.1811578-2-hanchuanhua802@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm: try_lock_next_vma() runs synchronous mmdrop() under RCU
  read lock
--

commit fd43adadc737249dfd917dd44af112219f9309df
Author: Chuanhua Han <hanchuanhua@xiaomi.com>

mm/mmap_lock: add try_lock_next_vma()

This commit adds try_lock_next_vma() to iterate and read-lock VMAs under
RCU without falling back to mmap_lock, skipping any VMA whose lock cannot
be taken.

> diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
> index 073c5125b4247..8933735d7bad9 100644
> --- a/mm/mmap_lock.c
> +++ b/mm/mmap_lock.c
> @@ -523,6 +523,68 @@ struct vm_area_struct *lock_next_vma(struct vma_rcu_iter *rvmi,
>  	return vma;
>  }

[ ... ]

> +struct vm_area_struct *try_lock_next_vma(struct mm_struct *mm,
> +					 struct vma_iterator *vmi,
> +					 unsigned long from_addr,
> +					 unsigned long end)
> +{
> +	struct vm_area_struct *vma, *locked;
> +	unsigned long found_from;
> +
> +	RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "no rcu read lock held");
> +
> +	while ((vma = vma_find(vmi, end))) {
> +		/* the lowest address of interest where it was found */
> +		found_from = max(from_addr, vma_iter_addr(vmi));
> +
> +		/* vma_start_read() leaves RCU on failure: keep the caller's */
> +		rcu_read_lock();
> +		locked = vma_start_read(mm, vma);

[Severity: High]
Can vma_start_read() still run synchronous mmdrop() while the caller's
RCU read lock is held?

The commit message relies on commit 44926897b6c2 ("mm/vma: drop mm
asynchronously in vma_start_read()"), which is not in this tree.
vma_start_read() still drops other_mm synchronously:

mm/mmap_lock.c:vma_start_read() {
    ...
err_unstable:
    ...
	rcu_read_unlock();
	mmgrab(other_mm);
	vma_refcount_put(vma);
	mmdrop(other_mm);
    ...
}

Because try_lock_next_vma() takes a nested rcu_read_lock(), that single
rcu_read_unlock() leaves the caller's RCU read lock held across
mmdrop(other_mm).  If the VMA was reused by another mm whose last
reference drops here, __mmdrop() runs synchronously under RCU.

In non-sleepable contexts such as the BPF task_vma iterator, __mmdrop()
-> mm_free_pgd() -> pgd_free() -> pgd_dtor() on x86 takes plain
spin_lock(&pgd_lock), deadlocking on the same CPU if entered from softirq
or a tracepoint while pgd_lock is held (and sleeping on CONFIG_PREEMPT_RT).

cleanup_lazy_tlbs() also issues synchronous cross-CPU IPIs under RCU.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205033951.1811578-1-hanchuanhua802@gmail.com?part=1


  reply	other threads:[~2026-12-05  3:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  3:39 [RFC PATCH 0/2] mm: add try_lock_next_vma() and use it in the BPF task_vma iterator Chuanhua Han
2026-12-05  3:39 ` [RFC PATCH 1/2] mm/mmap_lock: add try_lock_next_vma() Chuanhua Han
2026-12-05  3:56   ` sashiko-bot [this message]
2026-12-05  4:15   ` bot+bpf-ci
2026-12-05  3:39 ` [RFC PATCH 2/2] bpf: use try_lock_next_vma() in the task_vma iterator Chuanhua Han
2026-12-05  4:11   ` sashiko-bot

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=sashiko-outbox-251025@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=baohua@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=david@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=hanchuanhua802@gmail.com \
    --cc=hanchuanhua@xiaomi.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jannh@google.com \
    --cc=jolsa@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=pfalcato@suse.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=song@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@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