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
6742{6742{
6743 bool need_cands = relo->kind != BPF_CORE_TYPE_ID_LOCAL;6743 bool need_cands = relo->kind != BPF_CORE_TYPE_ID_LOCAL;
6744 struct bpf_core_cand_list cands = {};6744 struct bpf_core_cand_list cands = {};
6745 struct bpf_core_spec *specs;
6745 int err;6746 int err;
6746 6747
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
6747 if (need_cands) {6755 if (need_cands) {
6748 struct bpf_cand_cache *cc;6756 struct bpf_cand_cache *cc;
6749 int i;6757 int i;
@@ -6779,8 +6787,9 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo, · 29 unmodified lines
6779 }6787 }
6780 6788
6781 err = bpf_core_apply_relo_insn((void *)ctx->log, insn, relo->insn_off / 8,6789 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);
6783out:6791out:
6792 kfree(specs);
6784 if (need_cands) {6793 if (need_cands) {
6785 kfree(cands.cands);6794 kfree(cands.cands);
6786 mutex_unlock(&cand_cache_mutex);6795 mutex_unlock(&cand_cache_mutex);