All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Puranjay Mohan <puranjay@kernel.org>,
	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 18:36:47 +0000	[thread overview]
Message-ID: <awSELWmIo2LA3bM8@gremlin> (raw)
In-Reply-To: <DN267JUKDRNS.2VMV07CQ58R4X@gmail.com>

On Mon, Nov 23, 2026 at 12:40:32AM +0000, Alexei Starovoitov wrote:
> 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.

I'm not sure it's really theoretical. Especially given your second possible cause.

> 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.

Thanks!

>
> > 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...

Yikes :) again this seems like something that can really happen, even if it
might need you to be rather unlucky.

>
> 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.

Yup this is the suggested AI patch also :)

I'd want to do it slightly differently from that however in some of the details.

Sigh. It sucks for core mm to have to retrospectively address this, but I also
don't want to cause unnecessary horror in the caller.

Probably then mm doing this is the right way to fix it, so let me have a look at
this and send a patch.

But yeah, let's also revisit this open code and have the VMA API give you what
you need properly as a follow-up.

--
Cheers, Lorenzo


  reply	other threads:[~2026-11-23 18:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 15:45 [PATCH bpf v6 0/3] bpf: fix and improve open-coded task_vma iterator Puranjay Mohan
2026-04-08 15:45 ` [PATCH bpf v6 1/3] bpf: fix mm lifecycle in " Puranjay Mohan
2026-04-08 15:45 ` [PATCH bpf v6 2/3] bpf: switch task_vma iterator from mmap_lock to per-VMA locks Puranjay Mohan
2026-11-21 13:40   ` Lorenzo Stoakes (ARM)
2026-11-23  0:40     ` Alexei Starovoitov
2026-11-23 18:36       ` Lorenzo Stoakes (ARM) [this message]
2026-11-24  6:28         ` Alexei Starovoitov
2026-04-08 15:45 ` [PATCH bpf v6 3/3] bpf: return VMA snapshot from task_vma iterator Puranjay Mohan
2026-04-09 13:15   ` Mykyta Yatsenko
2026-04-10 19:10 ` [PATCH bpf v6 0/3] bpf: fix and improve open-coded " patchwork-bot+netdevbpf

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=awSELWmIo2LA3bM8@gremlin \
    --to=ljs@kernel.org \
    --cc=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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.