Re: [PATCH bpf-next 1/2] bpf: Reduce stack frame size by using env->insn_buf for bpf insns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 2, 2025, at 07:33, Yonghong Song wrote:
> Arnd Bergmann reported an issue ([1]) where clang compiler (less than
> llvm18) may trigger an error where the stack frame size exceeds the 
> limit.
> I can reproduce the error like below:
>   kernel/bpf/verifier.c:24491:5: error: stack frame size (2552) exceeds 
> limit (1280) in 'bpf_check'
>       [-Werror,-Wframe-larger-than]
>   kernel/bpf/verifier.c:19921:12: error: stack frame size (1368) 
> exceeds limit (1280) in 'do_check'
>       [-Werror,-Wframe-larger-than]
>
> Use env->insn_buf for bpf insns instead of putting these insns on the
> stack. This can resolve the above 'bpf_check' error. The 'do_check' error
> will be resolved in the next patch.
>
>   [1] https://lore.kernel.org/bpf/20250620113846.3950478-1-arnd@xxxxxxxxxx/
>
> Reported-by: Arnd Bergmann <arnd@xxxxxxxxxx>
> Signed-off-by: Yonghong Song <yonghong.song@xxxxxxxxx>

I have confirmed that the fix addresses the issue in bpf_check().
In the worst case I see on an arm64 (clang-15, kasan) randconfigs,
the bpf_stack usage goes down from 1680 bytes to 1024.

On powerpc64 (clang-15, allmodconfig, kasan), I see an even larger
reduction from from 2112 bytes to 1200 for bpf_check().

Tested-by: Arnd Bergmann <arnd@xxxxxxxx>

However, I still see 1952 bytes used in do_check() on powerpc64
allmodconfig. This number is much lower in newer clang versions,
I see 1888 bytes for clang-19 but only 1232 bytes for clang-20
and -21. Roughly a third of the 1952 bytes seems to come from
each one of do_check_insn() and is_state_visited(), but I haven't
found where exactly the stack is consumed there. This may be
a powerpc specific issue since on arm64 the same function needs
less than 1KB stack space.

I also tried turning off individual sanitizers (kasan, array-bounts,
trace-pc, ...) and they each seem to have a notable impact on
the total stack usage of powerpc64 do_check(), i.e. it's
not just a problem triggered by kasan or one particular other
option.

      Arnd




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux