Re: [PATCH bpf-next v1 6/8] bpf: Introduce bpf_per_cpu_ptr()
From: Andrii Nakryiko <hidden>
Date: 2020-08-22 07:55:23
Also in:
bpf, linux-kselftest, lkml
On Sat, Aug 22, 2020 at 12:49 AM Hao Luo [off-list ref] wrote:
On Fri, Aug 21, 2020 at 8:31 PM Andrii Nakryiko [off-list ref] wrote:quoted
On Fri, Aug 21, 2020 at 8:26 PM Andrii Nakryiko [off-list ref] wrote:quoted
On Wed, Aug 19, 2020 at 3:42 PM Hao Luo [off-list ref] wrote:quoted
Add bpf_per_cpu_ptr() to help bpf programs access percpu vars. bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the kernel except that it may return NULL. This happens when the cpu parameter is out of range. So the caller must check the returned value. Signed-off-by: Hao Luo <redacted> ---The logic looks correct, few naming nits, but otherwise: Acked-by: Andrii Nakryiko <redacted>quoted
include/linux/bpf.h | 3 ++ include/linux/btf.h | 11 +++++++ include/uapi/linux/bpf.h | 14 +++++++++ kernel/bpf/btf.c | 10 ------- kernel/bpf/verifier.c | 64 ++++++++++++++++++++++++++++++++++++++-- kernel/trace/bpf_trace.c | 18 +++++++++++ 6 files changed, 107 insertions(+), 13 deletions(-)[...]quoted
btw, having bpf_this_cpu_ptr(const void *ptr) seems worthwhile as well, WDYT?It's probably not a good idea, IMHO. How does it interact with preemption? Should we treat it as __this_cpu_ptr()? If so, I feel it's easy to be misused, if the bpf program is called in a preemptible context. Btw, is bpf programs always called with preemption disabled? How about interrupts? I haven't thought about these questions before but I think they matter as we start to have more ways for bpf programs to interact with the kernel.
non-sleepable BPF is always disabling CPU migration, so there is no problem with this_cpu_ptr. For sleepable not sure, but we can disable this helper for sleepable BPF programs, if that's a problem.
Best, Hao