On 6/23/25 2:32 PM, Alexei Starovoitov wrote:
On Fri, Jun 20, 2025 at 4:38 AM Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
From: Arnd Bergmann <arnd@xxxxxxxx>
I checked IR and found the following memory allocations which may contribute
excessive stack usage:
attr.coerce1, i32 noundef %uattr_size) local_unnamed_addr #0 align 16 !dbg !19800 {
entry:
%zext_patch.i = alloca [2 x %struct.bpf_insn], align 16, !DIAssignID !19854
%rnd_hi32_patch.i = alloca [4 x %struct.bpf_insn], align 16, !DIAssignID !19855
%cnt.i = alloca i32, align 4, !DIAssignID !19856
%patch.i766 = alloca [3 x %struct.bpf_insn], align 16, !DIAssignID !19857
%chk_and_sdiv.i = alloca [1 x %struct.bpf_insn], align 4, !DIAssignID !19858
%chk_and_smod.i = alloca [1 x %struct.bpf_insn], align 4, !DIAssignID !19859
%chk_and_div.i = alloca [4 x %struct.bpf_insn], align 16, !DIAssignID !19860
%chk_and_mod.i = alloca [4 x %struct.bpf_insn], align 16, !DIAssignID !19861
%chk_and_sdiv343.i = alloca [8 x %struct.bpf_insn], align 16, !DIAssignID !19862
%chk_and_smod472.i = alloca [9 x %struct.bpf_insn], align 16, !DIAssignID !19863
%desc.i = alloca %struct.bpf_jit_poke_descriptor, align 8, !DIAssignID !19864
%target_size.i = alloca i32, align 4, !DIAssignID !19865
%patch.i = alloca [2 x %struct.bpf_insn], align 16, !DIAssignID !19866
%patch355.i = alloca [2 x %struct.bpf_insn], align 16, !DIAssignID !19867
%ja.i = alloca %struct.bpf_insn, align 8, !DIAssignID !19868
%ret_insn.i.i = alloca [8 x i32], align 16, !DIAssignID !19869
%ret_prog.i.i = alloca [8 x i32], align 16, !DIAssignID !19870
%fd.i = alloca i32, align 4, !DIAssignID !19871
%log_true_size = alloca i32, align 4, !DIAssignID !19872
...
So yes, chk_and_{div,mod,sdiv,smod} consumes quite some stack and
can be coverted to runtime allocation but that is not enough for 1280
stack limit, we need to do more conversion from stack to memory
allocation. Will try to have uniform way to convert
'alloca [<num> x %struct.bpf_insn]' to runtime allocation.