* [PATCH bpf-next v3 1/5] selftests/bpf: skip sockmap in test_maps if kernel doesn't have support
2019-01-28 17:21 [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Stanislav Fomichev
@ 2019-01-28 17:21 ` Stanislav Fomichev
2019-01-28 17:21 ` [PATCH bpf-next v3 2/5] selftests/bpf: skip verifier tests for unsupported program types Stanislav Fomichev
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2019-01-28 17:21 UTC (permalink / raw)
To: netdev; +Cc: davem, ast, daniel, Stanislav Fomichev
Use recently introduced bpf_probe_map_type() to skip test_sockmap()
if map creation fails. The skipped test is indicated in the output.
Example:
test_sockmap SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP)
Fork 1024 tasks to 'test_update_delete'
...
test_sockmap SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP)
Fork 1024 tasks to 'test_update_delete'
...
test_maps: OK, 2 SKIPPED
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/test_maps.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index e2b9eee37187..e542c8e09073 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -32,6 +32,8 @@
#define ENOTSUPP 524
#endif
+static int skips;
+
static int map_flags;
#define CHECK(condition, tag, format...) ({ \
@@ -725,6 +727,15 @@ static void test_sockmap(int tasks, void *data)
sizeof(key), sizeof(value),
6, 0);
if (fd < 0) {
+ if (!bpf_probe_map_type(BPF_MAP_TYPE_SOCKMAP, 0)) {
+ printf("%s SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP)\n",
+ __func__);
+ skips++;
+ for (i = 0; i < 6; i++)
+ close(sfd[i]);
+ return;
+ }
+
printf("Failed to create sockmap %i\n", fd);
goto out_sockmap;
}
@@ -1702,6 +1713,6 @@ int main(void)
map_flags = BPF_F_NO_PREALLOC;
run_all_tests();
- printf("test_maps: OK\n");
+ printf("test_maps: OK, %d SKIPPED\n", skips);
return 0;
}
--
2.20.1.495.gaa96b0ce6b-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH bpf-next v3 2/5] selftests/bpf: skip verifier tests for unsupported program types
2019-01-28 17:21 [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Stanislav Fomichev
2019-01-28 17:21 ` [PATCH bpf-next v3 1/5] selftests/bpf: skip sockmap in test_maps if kernel doesn't have support Stanislav Fomichev
@ 2019-01-28 17:21 ` Stanislav Fomichev
2019-01-28 17:21 ` [PATCH bpf-next v3 3/5] selftests/bpf: skip verifier tests for unsupported map types Stanislav Fomichev
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2019-01-28 17:21 UTC (permalink / raw)
To: netdev; +Cc: davem, ast, daniel, Stanislav Fomichev
Use recently introduced bpf_probe_prog_type() to skip tests in the
test_verifier() if bpf_verify_program() fails. The skipped test is
indicated in the output.
Example:
...
679/p bpf_get_stack return R0 within range SKIP (unsupported program
type 5)
680/p ld_abs: invalid op 1 OK
...
Summary: 863 PASSED, 165 SKIPPED, 3 FAILED
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/test_verifier.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index c5e22422a852..2a36f9f2ee8f 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -34,6 +34,7 @@
#include <linux/if_ether.h>
#include <bpf/bpf.h>
+#include <bpf/libbpf.h>
#ifdef HAVE_GENHDR
# include "autoconf.h"
@@ -59,6 +60,7 @@
#define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
static bool unpriv_disabled = false;
+static int skips;
struct bpf_test {
const char *descr;
@@ -598,6 +600,11 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
pflags |= BPF_F_ANY_ALIGNMENT;
fd_prog = bpf_verify_program(prog_type, prog, prog_len, pflags,
"GPL", 0, bpf_vlog, sizeof(bpf_vlog), 1);
+ if (fd_prog < 0 && !bpf_probe_prog_type(prog_type, 0)) {
+ printf("SKIP (unsupported program type %d)\n", prog_type);
+ skips++;
+ goto close_fds;
+ }
expected_ret = unpriv && test->result_unpriv != UNDEF ?
test->result_unpriv : test->result;
@@ -751,7 +758,7 @@ static bool test_as_unpriv(struct bpf_test *test)
static int do_test(bool unpriv, unsigned int from, unsigned int to)
{
- int i, passes = 0, errors = 0, skips = 0;
+ int i, passes = 0, errors = 0;
for (i = from; i < to; i++) {
struct bpf_test *test = &tests[i];
--
2.20.1.495.gaa96b0ce6b-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH bpf-next v3 3/5] selftests/bpf: skip verifier tests for unsupported map types
2019-01-28 17:21 [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Stanislav Fomichev
2019-01-28 17:21 ` [PATCH bpf-next v3 1/5] selftests/bpf: skip sockmap in test_maps if kernel doesn't have support Stanislav Fomichev
2019-01-28 17:21 ` [PATCH bpf-next v3 2/5] selftests/bpf: skip verifier tests for unsupported program types Stanislav Fomichev
@ 2019-01-28 17:21 ` Stanislav Fomichev
2019-01-28 17:21 ` [PATCH bpf-next v3 4/5] selftests/bpf: mark verifier test that uses bpf_trace_printk as BPF_PROG_TYPE_TRACEPOINT Stanislav Fomichev
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2019-01-28 17:21 UTC (permalink / raw)
To: netdev; +Cc: davem, ast, daniel, Stanislav Fomichev
Use recently introduced bpf_probe_map_type() to skip tests in the
test_verifier if map creation (create_map) fails. It's handled
explicitly for each fixup, i.e. if bpf_create_map returns negative fd,
we probe the kernel for the appropriate map support and skip the
test is map type is not supported.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/test_verifier.c | 36 +++++++++++++++++++--
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 2a36f9f2ee8f..97188dbe80bd 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -265,6 +265,16 @@ static int probe_filter_length(const struct bpf_insn *fp)
return len + 1;
}
+static bool skip_unsupported_map(enum bpf_map_type map_type)
+{
+ if (!bpf_probe_map_type(map_type, 0)) {
+ printf("SKIP (unsupported map type %d)\n", map_type);
+ skips++;
+ return true;
+ }
+ return false;
+}
+
static int create_map(uint32_t type, uint32_t size_key,
uint32_t size_value, uint32_t max_elem)
{
@@ -272,8 +282,11 @@ static int create_map(uint32_t type, uint32_t size_key,
fd = bpf_create_map(type, size_key, size_value, max_elem,
type == BPF_MAP_TYPE_HASH ? BPF_F_NO_PREALLOC : 0);
- if (fd < 0)
+ if (fd < 0) {
+ if (skip_unsupported_map(type))
+ return -1;
printf("Failed to create hash map '%s'!\n", strerror(errno));
+ }
return fd;
}
@@ -323,6 +336,8 @@ static int create_prog_array(enum bpf_prog_type prog_type, uint32_t max_elem,
mfd = bpf_create_map(BPF_MAP_TYPE_PROG_ARRAY, sizeof(int),
sizeof(int), max_elem, 0);
if (mfd < 0) {
+ if (skip_unsupported_map(BPF_MAP_TYPE_PROG_ARRAY))
+ return -1;
printf("Failed to create prog array '%s'!\n", strerror(errno));
return -1;
}
@@ -353,15 +368,20 @@ static int create_map_in_map(void)
inner_map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(int),
sizeof(int), 1, 0);
if (inner_map_fd < 0) {
+ if (skip_unsupported_map(BPF_MAP_TYPE_ARRAY))
+ return -1;
printf("Failed to create array '%s'!\n", strerror(errno));
return inner_map_fd;
}
outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL,
sizeof(int), inner_map_fd, 1, 0);
- if (outer_map_fd < 0)
+ if (outer_map_fd < 0) {
+ if (skip_unsupported_map(BPF_MAP_TYPE_ARRAY_OF_MAPS))
+ return -1;
printf("Failed to create array of maps '%s'!\n",
strerror(errno));
+ }
close(inner_map_fd);
@@ -376,9 +396,12 @@ static int create_cgroup_storage(bool percpu)
fd = bpf_create_map(type, sizeof(struct bpf_cgroup_storage_key),
TEST_DATA_LEN, 0, 0);
- if (fd < 0)
+ if (fd < 0) {
+ if (skip_unsupported_map(type))
+ return -1;
printf("Failed to create cgroup storage '%s'!\n",
strerror(errno));
+ }
return fd;
}
@@ -582,6 +605,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
int run_errs, run_successes;
int map_fds[MAX_NR_MAPS];
const char *expected_err;
+ int fixup_skips;
__u32 pflags;
int i, err;
@@ -590,7 +614,13 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
if (!prog_type)
prog_type = BPF_PROG_TYPE_SOCKET_FILTER;
+ fixup_skips = skips;
do_test_fixup(test, prog_type, prog, map_fds);
+ /* If there were some map skips during fixup due to missing bpf
+ * features, skip this test.
+ */
+ if (fixup_skips != skips)
+ return;
prog_len = probe_filter_length(prog);
pflags = 0;
--
2.20.1.495.gaa96b0ce6b-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH bpf-next v3 4/5] selftests/bpf: mark verifier test that uses bpf_trace_printk as BPF_PROG_TYPE_TRACEPOINT
2019-01-28 17:21 [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Stanislav Fomichev
` (2 preceding siblings ...)
2019-01-28 17:21 ` [PATCH bpf-next v3 3/5] selftests/bpf: skip verifier tests for unsupported map types Stanislav Fomichev
@ 2019-01-28 17:21 ` Stanislav Fomichev
2019-01-28 17:21 ` [PATCH bpf-next v3 5/5] bpf: BPF_PROG_TYPE_CGROUP_{SKB,SOCK,SOCK_ADDR} require cgroups enabled Stanislav Fomichev
2019-01-31 9:40 ` [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Daniel Borkmann
5 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2019-01-28 17:21 UTC (permalink / raw)
To: netdev; +Cc: davem, ast, daniel, Stanislav Fomichev
We don't have this helper if the kernel was compiled without
CONFIG_BPF_EVENTS. Setting prog_type to BPF_PROG_TYPE_TRACEPOINT
let's verifier correctly skip this test based on the missing
prog_type support in the kernel.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/verifier/unpriv.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/bpf/verifier/unpriv.c b/tools/testing/selftests/bpf/verifier/unpriv.c
index dca58cf1a4ab..3e046695fad7 100644
--- a/tools/testing/selftests/bpf/verifier/unpriv.c
+++ b/tools/testing/selftests/bpf/verifier/unpriv.c
@@ -76,6 +76,7 @@
.errstr_unpriv = "unknown func bpf_trace_printk#6",
.result_unpriv = REJECT,
.result = ACCEPT,
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
},
{
"unpriv: pass pointer to helper function",
--
2.20.1.495.gaa96b0ce6b-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH bpf-next v3 5/5] bpf: BPF_PROG_TYPE_CGROUP_{SKB,SOCK,SOCK_ADDR} require cgroups enabled
2019-01-28 17:21 [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Stanislav Fomichev
` (3 preceding siblings ...)
2019-01-28 17:21 ` [PATCH bpf-next v3 4/5] selftests/bpf: mark verifier test that uses bpf_trace_printk as BPF_PROG_TYPE_TRACEPOINT Stanislav Fomichev
@ 2019-01-28 17:21 ` Stanislav Fomichev
2019-01-31 9:40 ` [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Daniel Borkmann
5 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2019-01-28 17:21 UTC (permalink / raw)
To: netdev; +Cc: davem, ast, daniel, Stanislav Fomichev
There is no way to exercise appropriate attach points without cgroups
enabled. This lets test_verifier correctly skip tests for these
prog_types if kernel was compiled without BPF cgroup support.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
include/linux/bpf_types.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h
index 44d9ab4809bd..08bf2f1fe553 100644
--- a/include/linux/bpf_types.h
+++ b/include/linux/bpf_types.h
@@ -6,9 +6,11 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_SOCKET_FILTER, sk_filter)
BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_CLS, tc_cls_act)
BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_ACT, tc_cls_act)
BPF_PROG_TYPE(BPF_PROG_TYPE_XDP, xdp)
+#ifdef CONFIG_CGROUP_BPF
BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SKB, cg_skb)
BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SOCK, cg_sock)
BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SOCK_ADDR, cg_sock_addr)
+#endif
BPF_PROG_TYPE(BPF_PROG_TYPE_LWT_IN, lwt_in)
BPF_PROG_TYPE(BPF_PROG_TYPE_LWT_OUT, lwt_out)
BPF_PROG_TYPE(BPF_PROG_TYPE_LWT_XMIT, lwt_xmit)
--
2.20.1.495.gaa96b0ce6b-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing
2019-01-28 17:21 [PATCH bpf-next v3 0/5] skip verifier/map tests if kernel support is missing Stanislav Fomichev
` (4 preceding siblings ...)
2019-01-28 17:21 ` [PATCH bpf-next v3 5/5] bpf: BPF_PROG_TYPE_CGROUP_{SKB,SOCK,SOCK_ADDR} require cgroups enabled Stanislav Fomichev
@ 2019-01-31 9:40 ` Daniel Borkmann
5 siblings, 0 replies; 7+ messages in thread
From: Daniel Borkmann @ 2019-01-31 9:40 UTC (permalink / raw)
To: Stanislav Fomichev, netdev; +Cc: davem, ast
On 01/28/2019 06:21 PM, Stanislav Fomichev wrote:
> If test_maps/test_verifier is running against the kernel which doesn't
> have _all_ BPF features enabled, it fails with an error. This patch
> series tries to probe kernel support for each failed test and skip
> it instead. This lets users run BPF selftests in the not-all-bpf-yes
> environments and received correct PASS/NON-PASS result.
>
> See https://www.spinics.net/lists/netdev/msg539331.html for more
> context.
>
> The series goes like this:
>
> * patch #1 skips sockmap tests in test_maps.c if BPF_MAP_TYPE_SOCKMAP
> map is not supported (if bpf_create_map fails, we probe the kernel
> for support)
> * patch #2 skips verifier tests if test->prog_type is not supported (if
> bpf_verify_program fails, we probe the kernel for support)
> * patch #3 skips verifier tests if test fixup map is not supported (if
> create_map fails, we probe the kernel for support)
> * next patches fix various small issues that arise from the first four:
> * patch #4 sets "unknown func bpf_trace_printk#6" prog_type to
> BPF_PROG_TYPE_TRACEPOINT so it is correctly skipped in
> CONFIG_BPF_EVENTS=n case
> * patch #5 exposes BPF_PROG_TYPE_CGROUP_{SKB,SOCK,SOCK_ADDR} only when
> CONFIG_CGROUP_BPF=y, this makes verifier correctly skip appropriate
> tests
>
> v3 changes:
> * rebased on top of Quentin's series which adds probes to libbpf
>
> v2 changes:
> * don't sprinkle "ifdef CONFIG_CGROUP_BPF" all around net/core/filter.c,
> doing it only in the bpf_types.h is enough to disable
> BPF_PROG_TYPE_CGROUP_{SKB,SOCK,SOCK_ADDR} prog types for non-cgroup
> enabled kernels
>
> Stanislav Fomichev (5):
> selftests/bpf: skip sockmap in test_maps if kernel doesn't have
> support
> selftests/bpf: skip verifier tests for unsupported program types
> selftests/bpf: skip verifier tests for unsupported map types
> selftests/bpf: mark verifier test that uses bpf_trace_printk as
> BPF_PROG_TYPE_TRACEPOINT
> bpf: BPF_PROG_TYPE_CGROUP_{SKB,SOCK,SOCK_ADDR} require cgroups enabled
>
> include/linux/bpf_types.h | 2 +
> tools/testing/selftests/bpf/test_maps.c | 13 +++++-
> tools/testing/selftests/bpf/test_verifier.c | 45 +++++++++++++++++--
> tools/testing/selftests/bpf/verifier/unpriv.c | 1 +
> 4 files changed, 56 insertions(+), 5 deletions(-)
>
Applied, thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread