* [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and instruction set extensions
@ 2022-01-04 17:57 Paul Chaignon
2022-01-04 17:59 ` [PATCH bpf-next 1/3] bpftool: Refactor misc. feature probe Paul Chaignon
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Paul Chaignon @ 2022-01-04 17:57 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, Quentin Monnet
This patchset adds feature probes for bounded loops and instruction set
extensions. The first patch refactors the existing miscellaneous probe
to avoid code duplication in subsequent patches.
The four miscellaneous probes were tested on kernels 4.9, 4.19, and 5.4.
The feature probe for bounded loops was previously submitted as part of
patchset https://lore.kernel.org/bpf/20211217211135.GA42088@Mem/T/.
Paul Chaignon (3):
bpftool: Refactor misc. feature probe
bpftool: Probe for bounded loop support
bpftool: Probe for instruction set extensions
tools/bpf/bpftool/feature.c | 109 +++++++++++++++++++++++++++++++-----
1 file changed, 94 insertions(+), 15 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH bpf-next 1/3] bpftool: Refactor misc. feature probe
2022-01-04 17:57 [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and instruction set extensions Paul Chaignon
@ 2022-01-04 17:59 ` Paul Chaignon
2022-01-04 17:59 ` [PATCH bpf-next 2/3] bpftool: Probe for bounded loop support Paul Chaignon
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Paul Chaignon @ 2022-01-04 17:59 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, Quentin Monnet
There is currently a single miscellaneous feature probe,
HAVE_LARGE_INSN_LIMIT, to check for the 1M instructions limit in the
verifier. Subsequent patches will add additional miscellaneous probes,
which follow the same pattern at the existing probe. This patch
therefore refactors the probe to avoid code duplication in subsequent
patches.
The BPF program type and the checked error numbers in the
HAVE_LARGE_INSN_LIMIT probe are changed to better generalize to other
probes. The feature probe retains its current behavior despite those
changes.
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Paul Chaignon <paul@isovalent.com>
---
tools/bpf/bpftool/feature.c | 45 ++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 16 deletions(-)
diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index 6719b9282eca..3da97a02f455 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -642,6 +642,30 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
printf("\n");
}
+static void
+probe_misc_feature(struct bpf_insn *insns, size_t len,
+ const char *define_prefix, __u32 ifindex,
+ const char *feat_name, const char *plain_name,
+ const char *define_name)
+{
+ LIBBPF_OPTS(bpf_prog_load_opts, opts,
+ .prog_ifindex = ifindex,
+ );
+ bool res;
+ int fd;
+
+ errno = 0;
+ fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL",
+ insns, len, &opts);
+ res = fd >= 0 || !errno;
+
+ if (fd >= 0)
+ close(fd);
+
+ print_bool_feature(feat_name, plain_name, define_name, res,
+ define_prefix);
+}
+
/*
* Probe for availability of kernel commit (5.3):
*
@@ -649,29 +673,18 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
*/
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;
+ 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;
- 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);
-
- print_bool_feature("have_large_insn_limit",
+ probe_misc_feature(insns, ARRAY_SIZE(insns),
+ define_prefix, ifindex,
+ "have_large_insn_limit",
"Large program size limit",
- "LARGE_INSN_LIMIT",
- res, define_prefix);
+ "LARGE_INSN_LIMIT");
}
static void
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next 2/3] bpftool: Probe for bounded loop support
2022-01-04 17:57 [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and instruction set extensions Paul Chaignon
2022-01-04 17:59 ` [PATCH bpf-next 1/3] bpftool: Refactor misc. feature probe Paul Chaignon
@ 2022-01-04 17:59 ` Paul Chaignon
2022-01-04 18:00 ` [PATCH bpf-next 3/3] bpftool: Probe for instruction set extensions Paul Chaignon
2022-01-05 12:40 ` [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and " patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Paul Chaignon @ 2022-01-04 17:59 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, Quentin Monnet
This patch introduces a new probe to check whether the verifier supports
bounded loops as introduced in commit 2589726d12a1 ("bpf: introduce
bounded loops"). This patch will allow BPF users such as Cilium to probe
for loop support on startup and only unconditionally unroll loops on
older kernels.
The results are displayed as part of the miscellaneous section, as shown
below.
$ bpftool feature probe | grep loops
Bounded loop support is available
$ bpftool feature probe macro | grep LOOPS
#define HAVE_BOUNDED_LOOPS
$ bpftool feature probe -j | jq .misc
{
"have_large_insn_limit": true,
"have_bounded_loops": true
}
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Paul Chaignon <paul@isovalent.com>
---
tools/bpf/bpftool/feature.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index 3da97a02f455..03579d113042 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -687,6 +687,27 @@ static void probe_large_insn_limit(const char *define_prefix, __u32 ifindex)
"LARGE_INSN_LIMIT");
}
+/*
+ * Probe for bounded loop support introduced in commit 2589726d12a1
+ * ("bpf: introduce bounded loops").
+ */
+static void
+probe_bounded_loops(const char *define_prefix, __u32 ifindex)
+{
+ struct bpf_insn insns[4] = {
+ BPF_MOV64_IMM(BPF_REG_0, 10),
+ BPF_ALU64_IMM(BPF_SUB, BPF_REG_0, 1),
+ BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, -2),
+ BPF_EXIT_INSN()
+ };
+
+ probe_misc_feature(insns, ARRAY_SIZE(insns),
+ define_prefix, ifindex,
+ "have_bounded_loops",
+ "Bounded loop support",
+ "BOUNDED_LOOPS");
+}
+
static void
section_system_config(enum probe_component target, const char *define_prefix)
{
@@ -801,6 +822,7 @@ static void section_misc(const char *define_prefix, __u32 ifindex)
"/*** eBPF misc features ***/",
define_prefix);
probe_large_insn_limit(define_prefix, ifindex);
+ probe_bounded_loops(define_prefix, ifindex);
print_end_section();
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next 3/3] bpftool: Probe for instruction set extensions
2022-01-04 17:57 [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and instruction set extensions Paul Chaignon
2022-01-04 17:59 ` [PATCH bpf-next 1/3] bpftool: Refactor misc. feature probe Paul Chaignon
2022-01-04 17:59 ` [PATCH bpf-next 2/3] bpftool: Probe for bounded loop support Paul Chaignon
@ 2022-01-04 18:00 ` Paul Chaignon
2022-01-05 12:40 ` [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and " patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Paul Chaignon @ 2022-01-04 18:00 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, Quentin Monnet
This patch introduces new probes to check whether the kernel supports
instruction set extensions v2 and v3. The first introduced eBPF
instructions BPF_J{LT,LE,SLT,SLE} in commit 92b31a9af73b ("bpf: add
BPF_J{LT,LE,SLT,SLE} instructions"). The second introduces 32-bit
variants of all jump instructions in commit 092ed0968bb6 ("bpf:
verifier support JMP32").
These probes are useful for userspace BPF projects that want to use newer
instruction set extensions on newer kernels, to reduce the programs'
sizes or their complexity. LLVM already provides an mcpu=probe option to
automatically probe the kernel and select the newest-supported
instruction set extension. That is however not flexible enough for all
use cases. For example, in Cilium, we only want to use the v3
instruction set extension on v5.10+, even though it is supported on all
kernels v5.1+.
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Paul Chaignon <paul@isovalent.com>
---
tools/bpf/bpftool/feature.c | 44 +++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index 03579d113042..e999159fa28d 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -708,6 +708,48 @@ probe_bounded_loops(const char *define_prefix, __u32 ifindex)
"BOUNDED_LOOPS");
}
+/*
+ * Probe for the v2 instruction set extension introduced in commit 92b31a9af73b
+ * ("bpf: add BPF_J{LT,LE,SLT,SLE} instructions").
+ */
+static void
+probe_v2_isa_extension(const char *define_prefix, __u32 ifindex)
+{
+ struct bpf_insn insns[4] = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_JMP_IMM(BPF_JLT, BPF_REG_0, 0, 1),
+ BPF_MOV64_IMM(BPF_REG_0, 1),
+ BPF_EXIT_INSN()
+ };
+
+ probe_misc_feature(insns, ARRAY_SIZE(insns),
+ define_prefix, ifindex,
+ "have_v2_isa_extension",
+ "ISA extension v2",
+ "V2_ISA_EXTENSION");
+}
+
+/*
+ * Probe for the v3 instruction set extension introduced in commit 092ed0968bb6
+ * ("bpf: verifier support JMP32").
+ */
+static void
+probe_v3_isa_extension(const char *define_prefix, __u32 ifindex)
+{
+ struct bpf_insn insns[4] = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_JMP32_IMM(BPF_JLT, BPF_REG_0, 0, 1),
+ BPF_MOV64_IMM(BPF_REG_0, 1),
+ BPF_EXIT_INSN()
+ };
+
+ probe_misc_feature(insns, ARRAY_SIZE(insns),
+ define_prefix, ifindex,
+ "have_v3_isa_extension",
+ "ISA extension v3",
+ "V3_ISA_EXTENSION");
+}
+
static void
section_system_config(enum probe_component target, const char *define_prefix)
{
@@ -823,6 +865,8 @@ static void section_misc(const char *define_prefix, __u32 ifindex)
define_prefix);
probe_large_insn_limit(define_prefix, ifindex);
probe_bounded_loops(define_prefix, ifindex);
+ probe_v2_isa_extension(define_prefix, ifindex);
+ probe_v3_isa_extension(define_prefix, ifindex);
print_end_section();
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and instruction set extensions
2022-01-04 17:57 [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and instruction set extensions Paul Chaignon
` (2 preceding siblings ...)
2022-01-04 18:00 ` [PATCH bpf-next 3/3] bpftool: Probe for instruction set extensions Paul Chaignon
@ 2022-01-05 12:40 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-05 12:40 UTC (permalink / raw)
To: Paul Chaignon; +Cc: ast, daniel, andrii, bpf, quentin
Hello:
This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Tue, 4 Jan 2022 18:57:54 +0100 you wrote:
> This patchset adds feature probes for bounded loops and instruction set
> extensions. The first patch refactors the existing miscellaneous probe
> to avoid code duplication in subsequent patches.
>
> The four miscellaneous probes were tested on kernels 4.9, 4.19, and 5.4.
>
> The feature probe for bounded loops was previously submitted as part of
> patchset https://lore.kernel.org/bpf/20211217211135.GA42088@Mem/T/.
>
> [...]
Here is the summary with links:
- [bpf-next,1/3] bpftool: Refactor misc. feature probe
https://git.kernel.org/bpf/bpf-next/c/b22bf1b9979a
- [bpf-next,2/3] bpftool: Probe for bounded loop support
https://git.kernel.org/bpf/bpf-next/c/c04fb2b0bd92
- [bpf-next,3/3] bpftool: Probe for instruction set extensions
https://git.kernel.org/bpf/bpf-next/c/0fd800b2456c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-05 12:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-04 17:57 [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and instruction set extensions Paul Chaignon
2022-01-04 17:59 ` [PATCH bpf-next 1/3] bpftool: Refactor misc. feature probe Paul Chaignon
2022-01-04 17:59 ` [PATCH bpf-next 2/3] bpftool: Probe for bounded loop support Paul Chaignon
2022-01-04 18:00 ` [PATCH bpf-next 3/3] bpftool: Probe for instruction set extensions Paul Chaignon
2022-01-05 12:40 ` [PATCH bpf-next 0/3] bpftool: Probes for bounded loops and " patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.