From: Andrea Righi <arighi@nvidia.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] bpf: arena: Flush stale TLB entries before reusing ranges
Date: Sun, 20 Sep 2026 08:07:30 +0200 [thread overview]
Message-ID: <aq94IibsdiJpcvSg@gpd4> (raw)
In-Reply-To: <DLJOGC7M106N.33I0V3YRNYB8E@gmail.com>
Hi Alexei,
On Sat, Sep 19, 2026 at 11:21:43PM +0000, Alexei Starovoitov wrote:
> On Sun, Sep 20, 2026 at 12:46 AM Andrea Righi <arighi@nvidia.com> wrote:
> > @@ -911,11 +910,17 @@ static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt,
> > zap_pages(arena, full_uaddr, 1);
> > __free_page(page);
> > }
> > +
> > + ret = raw_res_spin_lock_irqsave(&arena->spinlock, flags);
> > + if (ret)
> > + goto defer_publish;
> > + range_tree_set(&arena->rt, pgoff, page_cnt);
> > + raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
>
> Now the ptes are cleared in one locked section and the range is set in
> another, and arena_vm_fault() can get in between. It doesn't look at
> the range tree to decide. It does vmalloc_to_page(), sees no page,
> range_tree_clear() of an already clear range returns 0, so it allocates
> a page and installs it into the kernel pte. Then the code above marks
> that range free. The next bpf_arena_alloc_pages() that picks it hits
> WARN_ON_ONCE(pte_page(old) != d->arena->scratch_page)
> in apply_range_set_cb(), returns NULL, puts t
> he range back into the
> tree, and the next call does the same. All it takes is user space
> touching the page while the prog frees it.
You're right, I missed that range_tree_clear() succeeds even when the range is
already clear, so arena_vm_fault() populates the range during the
teardown-to-publish window, leaving the range marked free with a valid PTE
installed.
>
> iirc Emil has patches that address this issue differently.
Thanks for catching this! I'll sync with Emil.
-Andrea
prev parent reply other threads:[~2026-09-20 6:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 22:46 Andrea Righi
2026-09-19 23:21 ` Alexei Starovoitov
2026-09-20 6:07 ` Andrea Righi [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=aq94IibsdiJpcvSg@gpd4 \
--to=arighi@nvidia.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@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
all inboxes | Powered by JetHome®