[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <450751b2-5bc4-4c76-b9ca-019b87b96074@paulmck-laptop>
Date: Mon, 17 Nov 2025 15:46:21 -0800
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Amery Hung <ameryhung@...il.com>, bpf <bpf@...r.kernel.org>,
Network Development <netdev@...r.kernel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Martin KaFai Lau <martin.lau@...nel.org>,
Kumar Kartikeya Dwivedi <memxor@...il.com>,
KP Singh <kpsingh@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>, Song Liu <song@...nel.org>,
Kernel Team <kernel-team@...a.com>
Subject: Re: [PATCH v2 bpf-next 4/4] bpf: Replace bpf memory allocator with
kmalloc_nolock() in local storage
On Mon, Nov 17, 2025 at 03:36:08PM -0800, Alexei Starovoitov wrote:
> On Mon, Nov 17, 2025 at 12:37 PM Amery Hung <ameryhung@...il.com> wrote:
> >
> > On Fri, Nov 14, 2025 at 6:01 PM Alexei Starovoitov
> > <alexei.starovoitov@...il.com> wrote:
> > >
> > > On Fri, Nov 14, 2025 at 12:13 PM Amery Hung <ameryhung@...il.com> wrote:
> > > >
> > > >
> > > > - if (smap->bpf_ma) {
> > > > + if (smap->use_kmalloc_nolock) {
> > > > rcu_barrier_tasks_trace();
> > > > - if (!rcu_trace_implies_rcu_gp())
> > > > - rcu_barrier();
> > > > - bpf_mem_alloc_destroy(&smap->selem_ma);
> > > > - bpf_mem_alloc_destroy(&smap->storage_ma);
> > > > + rcu_barrier();
> > >
> > > Why unconditional rcu_barrier() ?
> > > It's implied in rcu_barrier_tasks_trace().
> >
> > Hmm, I am not sure.
> >
> > > What am I missing?
> >
> > I hit a UAF in v1 in bpf_selem_free_rcu() when running selftests and
> > making rcu_barrier() unconditional addressed it. I think the bug was
> > due to map_free() not waiting for bpf_selem_free_rcu() (an RCU
> > callback) to finish.
> >
> > Looking at rcu_barrier() and rcu_barrier_tasks_trace(), they pass
> > different rtp to rcu_barrier_tasks_generic() so I think both are
> > needed to make sure in-flight RCU and RCU tasks trace callbacks are
> > done.
> >
> > Not an expert in RCU so I might be wrong and it was something else.
>
> Paul,
>
> Please help us here.
> Does rcu_barrier_tasks_trace() imply rcu_barrier() ?
I am sorry, but no, it does not.
If latency proves to be an issue, one approach is to invoke rcu_barrier()
and rcu_barrier_tasks_trace() each in its own workqueue handler. But as
always, I suggest invoking them one after the other to see if a latency
problem really exists before adding complexity.
Except that rcu_barrier_tasks_trace() is never invoked by rcu_barrier(),
only rcu_barrier_tasks() and rcu_barrier_tasks_trace(). So do you really
mean rcu_barrier()? Or rcu_barrier_tasks()?
Either way, rcu_barrier_tasks() and rcu_barrier_tasks_trace() are also
independent of each other in the sense that if you need tw wait on
callbacks from both call_rcu_tasks() and call_rcu_tasks_trace(), you
need both rcu_barrier_tasks() and rcu_barrier_tasks_trace() to be invoked.
Thanx, Paul
Powered by blists - more mailing lists