Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Remove preempt_disable in bpf_try_get_buffers

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

authored by

Tao Chen and committed by
Andrii Nakryiko
4223bf83 d47cc4de

-3
-3
kernel/bpf/helpers.c
··· 774 774 { 775 775 int nest_level; 776 776 777 - preempt_disable(); 778 777 nest_level = this_cpu_inc_return(bpf_bprintf_nest_level); 779 778 if (WARN_ON_ONCE(nest_level > MAX_BPRINTF_NEST_LEVEL)) { 780 779 this_cpu_dec(bpf_bprintf_nest_level); 781 - preempt_enable(); 782 780 return -EBUSY; 783 781 } 784 782 *bufs = this_cpu_ptr(&bpf_bprintf_bufs[nest_level - 1]); ··· 789 791 if (WARN_ON_ONCE(this_cpu_read(bpf_bprintf_nest_level) == 0)) 790 792 return; 791 793 this_cpu_dec(bpf_bprintf_nest_level); 792 - preempt_enable(); 793 794 } 794 795 795 796 void bpf_bprintf_cleanup(struct bpf_bprintf_data *data)