]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf: Remove preempt_disable in bpf_try_get_buffers
authorTao Chen <chen.dylane@linux.dev>
Tue, 19 Aug 2025 12:56:38 +0000 (20:56 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 22 Aug 2025 18:44:09 +0000 (11:44 -0700)
Now BPF program will run with migration disabled, so it is safe
to access this_cpu_inc_return(bpf_bprintf_nest_level).

Fixes: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf")
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250819125638.2544715-1-chen.dylane@linux.dev
kernel/bpf/helpers.c

index cdffd74ddbe65d880af82419f872bf25976da28c..401b4932cc49f69f3d4cc5bbfc9c7afb84847fb3 100644 (file)
@@ -774,11 +774,9 @@ int bpf_try_get_buffers(struct bpf_bprintf_buffers **bufs)
 {
        int nest_level;
 
-       preempt_disable();
        nest_level = this_cpu_inc_return(bpf_bprintf_nest_level);
        if (WARN_ON_ONCE(nest_level > MAX_BPRINTF_NEST_LEVEL)) {
                this_cpu_dec(bpf_bprintf_nest_level);
-               preempt_enable();
                return -EBUSY;
        }
        *bufs = this_cpu_ptr(&bpf_bprintf_bufs[nest_level - 1]);
@@ -791,7 +789,6 @@ void bpf_put_buffers(void)
        if (WARN_ON_ONCE(this_cpu_read(bpf_bprintf_nest_level) == 0))
                return;
        this_cpu_dec(bpf_bprintf_nest_level);
-       preempt_enable();
 }
 
 void bpf_bprintf_cleanup(struct bpf_bprintf_data *data)