Skip to content

Commit

Permalink
bpftool: Reimplement large insn size limit feature probing
Browse files Browse the repository at this point in the history
Reimplement bpf_probe_large_insn_limit() in bpftool, as that libbpf API
is scheduled for deprecation in v0.8.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Dave Marchevsky <davemarchevsky@fb.com>
Link: https://lore.kernel.org/bpf/20211217171202.3352835-4-andrii@kernel.org
  • Loading branch information
Andrii Nakryiko authored and Daniel Borkmann committed Dec 17, 2021
1 parent 5a8ea82 commit e967a20
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions tools/bpf/bpftool/feature.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,32 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
printf("\n");
}

static void
probe_large_insn_limit(const char *define_prefix, __u32 ifindex)
/*
* Probe for availability of kernel commit (5.3):
*
* c04c0d2b968a ("bpf: increase complexity limit and maximum program size")
*/
static void probe_large_insn_limit(const char *define_prefix, __u32 ifindex)
{
LIBBPF_OPTS(bpf_prog_load_opts, opts,
.prog_ifindex = ifindex,
);
struct bpf_insn insns[BPF_MAXINSNS + 1];
bool res;
int i, fd;

for (i = 0; i < BPF_MAXINSNS; i++)
insns[i] = BPF_MOV64_IMM(BPF_REG_0, 1);
insns[BPF_MAXINSNS] = BPF_EXIT_INSN();

errno = 0;
fd = bpf_prog_load(BPF_PROG_TYPE_SCHED_CLS, NULL, "GPL",
insns, ARRAY_SIZE(insns), &opts);
res = fd >= 0 || (errno != E2BIG && errno != EINVAL);

if (fd >= 0)
close(fd);

res = bpf_probe_large_insn_limit(ifindex);
print_bool_feature("have_large_insn_limit",
"Large program size limit",
"LARGE_INSN_LIMIT",
Expand Down

0 comments on commit e967a20

Please sign in to comment.