]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
libbpf: Add probe for large INSN limit
authorMichal Rostecki <mrostecki@opensuse.org>
Wed, 8 Jan 2020 16:23:52 +0000 (17:23 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 8 Jan 2020 18:31:35 +0000 (19:31 +0100)
Introduce a new probe which checks whether kernel has large maximum
program size which was increased in the following commit:

c04c0d2b968a ("bpf: increase complexity limit and maximum program size")

Based on the similar check in Cilium[0], authored by Daniel Borkmann.

  [0] https://github.com/cilium/cilium/commit/657d0f585afd26232cfa5d4e70b6f64d2ea91596

Co-authored-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Link: https://lore.kernel.org/bpf/20200108162428.25014-2-mrostecki@opensuse.org
tools/lib/bpf/libbpf.h
tools/lib/bpf/libbpf.map
tools/lib/bpf/libbpf_probes.c

index fe592ef48f1bfaf2dcb2d2bdb3374f543c7aeab2..26bf539f1b3ce02c72a33861c44a34f9eaa06a10 100644 (file)
@@ -521,6 +521,7 @@ LIBBPF_API bool bpf_probe_prog_type(enum bpf_prog_type prog_type,
 LIBBPF_API bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex);
 LIBBPF_API bool bpf_probe_helper(enum bpf_func_id id,
                                 enum bpf_prog_type prog_type, __u32 ifindex);
+LIBBPF_API bool bpf_probe_large_insn_limit(__u32 ifindex);
 
 /*
  * Get bpf_prog_info in continuous memory
index e9713a57424325c6e69092e0390c42f89bd17f45..b300d74c921a1a6a857fc2df48b4f47c8da3c608 100644 (file)
@@ -219,6 +219,7 @@ LIBBPF_0.0.7 {
                bpf_object__detach_skeleton;
                bpf_object__load_skeleton;
                bpf_object__open_skeleton;
+               bpf_probe_large_insn_limit;
                bpf_prog_attach_xattr;
                bpf_program__attach;
                bpf_program__name;
index a9eb8b322671fb7ab1b9bb459e5419c799dfd008..221e6ad970123d3666bc702ec3fc6477d178eead 100644 (file)
@@ -321,3 +321,24 @@ bool bpf_probe_helper(enum bpf_func_id id, enum bpf_prog_type prog_type,
 
        return res;
 }
+
+/*
+ * Probe for availability of kernel commit (5.3):
+ *
+ * c04c0d2b968a ("bpf: increase complexity limit and maximum program size")
+ */
+bool bpf_probe_large_insn_limit(__u32 ifindex)
+{
+       struct bpf_insn insns[BPF_MAXINSNS + 1];
+       int i;
+
+       for (i = 0; i < BPF_MAXINSNS; i++)
+               insns[i] = BPF_MOV64_IMM(BPF_REG_0, 1);
+       insns[BPF_MAXINSNS] = BPF_EXIT_INSN();
+
+       errno = 0;
+       probe_load(BPF_PROG_TYPE_SCHED_CLS, insns, ARRAY_SIZE(insns), NULL, 0,
+                  ifindex);
+
+       return errno != E2BIG && errno != EINVAL;
+}