Skip to content

Commit e967a20

Browse files
anakryikoborkmann
authored andcommitted
bpftool: Reimplement large insn size limit feature probing
Reimplement bpf_probe_large_insn_limit() in bpftool, as that libbpf API is scheduled for deprecation in v0.8. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Dave Marchevsky <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 5a8ea82 commit e967a20

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

tools/bpf/bpftool/feature.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,32 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
642642
printf("\n");
643643
}
644644

645-
static void
646-
probe_large_insn_limit(const char *define_prefix, __u32 ifindex)
645+
/*
646+
* Probe for availability of kernel commit (5.3):
647+
*
648+
* c04c0d2b968a ("bpf: increase complexity limit and maximum program size")
649+
*/
650+
static void probe_large_insn_limit(const char *define_prefix, __u32 ifindex)
647651
{
652+
LIBBPF_OPTS(bpf_prog_load_opts, opts,
653+
.prog_ifindex = ifindex,
654+
);
655+
struct bpf_insn insns[BPF_MAXINSNS + 1];
648656
bool res;
657+
int i, fd;
658+
659+
for (i = 0; i < BPF_MAXINSNS; i++)
660+
insns[i] = BPF_MOV64_IMM(BPF_REG_0, 1);
661+
insns[BPF_MAXINSNS] = BPF_EXIT_INSN();
662+
663+
errno = 0;
664+
fd = bpf_prog_load(BPF_PROG_TYPE_SCHED_CLS, NULL, "GPL",
665+
insns, ARRAY_SIZE(insns), &opts);
666+
res = fd >= 0 || (errno != E2BIG && errno != EINVAL);
667+
668+
if (fd >= 0)
669+
close(fd);
649670

650-
res = bpf_probe_large_insn_limit(ifindex);
651671
print_bool_feature("have_large_insn_limit",
652672
"Large program size limit",
653673
"LARGE_INSN_LIMIT",

0 commit comments

Comments
 (0)