Re: BUG: unable to handle kernel paging request in bpf_dispatcher_xdp

From: Jiri Olsa
Date: Sat Dec 10 2022 - 08:06:23 EST


On Fri, Dec 09, 2022 at 04:38:38PM -0800, Paul E. McKenney wrote:
> On Sat, Dec 10, 2022 at 01:06:16AM +0100, Jiri Olsa wrote:
> > On Fri, Dec 09, 2022 at 03:34:45PM -0800, Jakub Kicinski wrote:
> > > On Sat, 10 Dec 2022 00:32:07 +0100 Daniel Borkmann wrote:
> > > > fwiw, these should not be necessary, Documentation/RCU/checklist.rst :
> > > >
> > > > [...] One example of non-obvious pairing is the XDP feature in networking,
> > > > which calls BPF programs from network-driver NAPI (softirq) context. BPF
> > > > relies heavily on RCU protection for its data structures, but because the
> > > > BPF program invocation happens entirely within a single local_bh_disable()
> > > > section in a NAPI poll cycle, this usage is safe. The reason that this usage
> > > > is safe is that readers can use anything that disables BH when updaters use
> > > > call_rcu() or synchronize_rcu(). [...]
> > >
> > > FWIW I sent a link to the thread to Paul and he confirmed
> > > the RCU will wait for just the BH.
> >
> > so IIUC we can omit the rcu_read_lock/unlock on bpf_prog_run_xdp side
> >
> > Paul,
> > any thoughts on what we can use in here to synchronize bpf_dispatcher_change_prog
> > with bpf_prog_run_xdp callers?
> >
> > with synchronize_rcu_tasks I'm getting splats like:
> > https://lore.kernel.org/bpf/20221209153445.22182ca5@xxxxxxxxxx/T/#m0a869f93404a2744884d922bc96d497ffe8f579f
> >
> > synchronize_rcu_tasks_rude seems to work (patch below), but it also sounds special ;-)
>
> It sounds like we are all talking past each other, leaving me no
> choice but to supply a wall of text:
>
> It is quite true that synchronize_rcu_tasks_rude() will wait
> for bh-disabled regions of code, just like synchronize_rcu()
> and synchronize_rcu_tasks() will. However, please note that
> synchronize_rcu_tasks() never waits on any of the idle tasks. So the
> usual approach in tracing is to do both a synchronize_rcu_tasks() and
> synchronize_rcu_tasks_rude(). One way of overlapping the resulting
> pair of grace periods is to use synchronize_rcu_mult().
>
> But none of these permit readers to sleep. That is what
> synchronize_rcu_tasks_trace() is for, but unlike both
> synchronize_rcu_tasks() and synchronize_rcu_tasks_rude(),
> you must explicitly mark the readers with rcu_read_lock_trace()
> and rcu_read_unlock_trace(). This is used to protect sleepable
> BPF programs.
>
> Now, synchronize_rcu() will also wait on bh-disabled lines of code, with
> the exception of such code in the exception path, way deep in the idle
> loop, early in the CPU-online process, or late in the CPU-offline process.
> You can recognize the first two categories of code by the noinstr tags
> on the functions.
>
> And yes, synchronize_rcu_rude() is quite special. ;-)
>
> Does this help, or am I simply adding to the confusion?

I see, so as Alexei said to synchronize bpf_prog_run_xdp callers,
we should be able to use just synchronize_rcu, because it's allways
called just in bh-disabled code

thanks,
jirka