History

libbpf: Reduce bpf_core_apply_relo_insn() stack usage.

Reduce bpf_core_apply_relo_insn() stack usage and bump BPF_CORE_SPEC_MAX_LEN limit back to 64.

Alexei Starovoitov committed 4 years ago

Commit 78c1f8d1 parent 0bf40544 files · +61 −46Browse files

Showing the changes to kernel (1 of 4 files). Show all

Unified · Split

kernel/bpf/btf.c+10−1
@@ -6742,8 +6742,16 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo, · 6741 unmodified lines
67426742 {
67436743 bool need_cands = relo->kind != BPF_CORE_TYPE_ID_LOCAL;
67446744 struct bpf_core_cand_list cands = {};
6745+ struct bpf_core_spec *specs;
67456746 int err;
67466747
6748+ /* ~4k of temp memory necessary to convert LLVM spec like "0:1:0:5"
6749+ * into arrays of btf_ids of struct fields and array indices.
6750+ */
6751+ specs = kcalloc(3, sizeof(*specs), GFP_KERNEL);
6752+ if (!specs)
6753+ return -ENOMEM;
6754+
67476755 if (need_cands) {
67486756 struct bpf_cand_cache *cc;
67496757 int i;
@@ -6779,8 +6787,9 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo, · 29 unmodified lines
67796787 }
67806788
67816789 err = bpf_core_apply_relo_insn((void *)ctx->log, insn, relo->insn_off / 8,
6782− relo, relo_idx, ctx->btf, &cands);
6790+ relo, relo_idx, ctx->btf, &cands, specs);
67836791 out:
6792+ kfree(specs);
67846793 if (need_cands) {
67856794 kfree(cands.cands);
67866795 mutex_unlock(&cand_cache_mutex);