* [PATCH bpf-next 07/10] selftests/bpf: extend test_section_names with type_(from|to)_str
From: Julia Kartseva @ 2019-08-28 21:03 UTC (permalink / raw)
To: rdna, bpf, ast, daniel, netdev, kernel-team; +Cc: Julia Kartseva
In-Reply-To: <cover.1567024943.git.hex@fb.com>
Test bpf enum stringification helpers:
libbpf_(prog|map|attach)_type_(from|to)_str
Signed-off-by: Julia Kartseva <hex@fb.com>
---
.../selftests/bpf/test_section_names.c | 149 +++++++++++++++++-
1 file changed, 147 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_section_names.c b/tools/testing/selftests/bpf/test_section_names.c
index 29833aeaf0de..564585a07592 100644
--- a/tools/testing/selftests/bpf/test_section_names.c
+++ b/tools/testing/selftests/bpf/test_section_names.c
@@ -202,7 +202,137 @@ static int test_attach_type_by_name(const struct sec_name_test *test)
return 0;
}
-static int run_test_case(const struct sec_name_test *test)
+static int test_prog_type_from_to_str(void)
+{
+ enum bpf_prog_type type, actual_type;
+ const char *str;
+ int rc;
+
+ for (type = BPF_PROG_TYPE_UNSPEC; type < __MAX_BPF_PROG_TYPE; type++) {
+ rc = libbpf_prog_type_to_str(type, &str);
+ if (rc) {
+ warnx("prog_type_to_str: unexpected rc=%d for type %d",
+ rc, type);
+ return rc;
+ }
+
+ rc = libbpf_prog_type_from_str(str, &actual_type);
+ if (rc) {
+ warnx("prog_type_from_str: unexpected rc=%d for str %s",
+ rc, str);
+ return rc;
+ }
+
+ if (actual_type != type) {
+ warnx("prog: unexpected prog_type for str %s, %d != %d",
+ str, actual_type, type);
+ return -EINVAL;
+ }
+ }
+
+ rc = libbpf_prog_type_to_str(__MAX_BPF_PROG_TYPE, &str);
+ if (!rc) {
+ warnx("prog: unexpected result for __MAX_BPF_PROG_TYPE");
+ return -EINVAL;
+ }
+
+ rc = libbpf_prog_type_from_str("NonExistent", &type);
+ if (!rc) {
+ warnx("prog: unexpected result for non existent key");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int test_map_type_from_to_str(void)
+{
+ enum bpf_map_type type, actual_type;
+ const char *str;
+ int rc;
+
+ for (type = BPF_MAP_TYPE_UNSPEC; type < __MAX_BPF_MAP_TYPE; type++) {
+ rc = libbpf_map_type_to_str(type, &str);
+ if (rc) {
+ warnx("map_type_to_str: unexpected rc=%d for type %d",
+ rc, type);
+ return rc;
+ }
+
+ rc = libbpf_map_type_from_str(str, &actual_type);
+ if (rc) {
+ warnx("map_type_from_str: unexpected rc=%d for str %s",
+ rc, str);
+ return rc;
+ }
+
+ if (actual_type != type) {
+ warnx("map: unexpected map_type for str %s, %d != %d",
+ str, actual_type, type);
+ return -EINVAL;
+ }
+ }
+
+ rc = libbpf_map_type_to_str(__MAX_BPF_MAP_TYPE, &str);
+ if (!rc) {
+ warnx("map: unexpected result for __MAX_BPF_MAP_TYPE");
+ return -EINVAL;
+ }
+
+ rc = libbpf_map_type_from_str("NonExistent", &type);
+ if (!rc) {
+ warnx("map: unexpected result for non existent key");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int test_attach_type_from_to_str(void)
+{
+ enum bpf_attach_type type, actual_type;
+ const char *str;
+ int rc;
+
+ for (type = BPF_CGROUP_INET_INGRESS; type < __MAX_BPF_ATTACH_TYPE;
+ type++) {
+ rc = libbpf_attach_type_to_str(type, &str);
+ if (rc) {
+ warnx("attach: unexpected rc=%d for type %d",
+ rc, type);
+ return rc;
+ }
+
+ rc = libbpf_attach_type_from_str(str, &actual_type);
+ if (rc) {
+ warnx("attach: unexpected rc=%d for str %s",
+ rc, str);
+ return rc;
+ }
+
+ if (actual_type != type) {
+ warnx("attach: unexpected type for str %s, %d != %d",
+ str, actual_type, type);
+ return -EINVAL;
+ }
+ }
+
+ rc = libbpf_attach_type_to_str(__MAX_BPF_ATTACH_TYPE, &str);
+ if (!rc) {
+ warnx("attach: unexpected result for __MAX_BPF_ATTACH_TYPE");
+ return -EINVAL;
+ }
+
+ rc = libbpf_attach_type_from_str("NonExistent", &type);
+ if (!rc) {
+ warnx("attach: unexpected result for non existent key");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int run_sec_name_test_case(const struct sec_name_test *test)
{
if (test_prog_type_by_name(test))
return -1;
@@ -218,11 +348,26 @@ static int run_tests(void)
int i;
for (i = 0; i < ARRAY_SIZE(tests); ++i) {
- if (run_test_case(&tests[i]))
+ if (run_sec_name_test_case(&tests[i]))
++fails;
else
++passes;
}
+
+ if (test_prog_type_from_to_str())
+ ++fails;
+ else
+ ++passes;
+
+ if (test_map_type_from_to_str())
+ ++fails;
+ else
+ ++passes;
+
+ if (test_attach_type_from_to_str())
+ ++fails;
+ else
+ ++passes;
printf("Summary: %d PASSED, %d FAILED\n", passes, fails);
return fails ? -1 : 0;
}
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 08/10] selftests/bpf: rename test_section_names to test_section_and_type_names
From: Julia Kartseva @ 2019-08-28 21:03 UTC (permalink / raw)
To: rdna, bpf, ast, daniel, netdev, kernel-team; +Cc: Julia Kartseva
In-Reply-To: <cover.1567024943.git.hex@fb.com>
Change the test name after extending it with enum stringification
helpers.
Signed-off-by: Julia Kartseva <hex@fb.com>
---
tools/testing/selftests/bpf/Makefile | 2 +-
.../bpf/test_section_and_type_names.c | 378 ++++++++++++++++++
.../selftests/bpf/test_section_names.c | 378 ------------------
3 files changed, 379 insertions(+), 379 deletions(-)
create mode 100644 tools/testing/selftests/bpf/test_section_and_type_names.c
delete mode 100644 tools/testing/selftests/bpf/test_section_names.c
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 1faad0c3c3c9..8212a6240297 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -26,7 +26,7 @@ LDLIBS += -lcap -lelf -lrt -lpthread
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
- test_cgroup_storage test_select_reuseport test_section_names \
+ test_cgroup_storage test_select_reuseport test_section_and_type_names \
test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
test_btf_dump test_cgroup_attach xdping test_sockopt test_sockopt_sk \
test_sockopt_multi test_sockopt_inherit test_tcp_rtt
diff --git a/tools/testing/selftests/bpf/test_section_and_type_names.c b/tools/testing/selftests/bpf/test_section_and_type_names.c
new file mode 100644
index 000000000000..564585a07592
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_section_and_type_names.c
@@ -0,0 +1,378 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018 Facebook
+
+#include <err.h>
+#include <bpf/libbpf.h>
+
+#include "bpf_util.h"
+
+struct sec_name_test {
+ const char sec_name[32];
+ struct {
+ int rc;
+ enum bpf_prog_type prog_type;
+ enum bpf_attach_type expected_attach_type;
+ } expected_load;
+ struct {
+ int rc;
+ enum bpf_attach_type attach_type;
+ } expected_attach;
+};
+
+static struct sec_name_test tests[] = {
+ {"InvAliD", {-EINVAL, 0, 0}, {-EINVAL, 0} },
+ {"cgroup", {-EINVAL, 0, 0}, {-EINVAL, 0} },
+ {"socket", {0, BPF_PROG_TYPE_SOCKET_FILTER, 0}, {-EINVAL, 0} },
+ {"kprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
+ {"kretprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
+ {"classifier", {0, BPF_PROG_TYPE_SCHED_CLS, 0}, {-EINVAL, 0} },
+ {"action", {0, BPF_PROG_TYPE_SCHED_ACT, 0}, {-EINVAL, 0} },
+ {"tracepoint/", {0, BPF_PROG_TYPE_TRACEPOINT, 0}, {-EINVAL, 0} },
+ {
+ "raw_tracepoint/",
+ {0, BPF_PROG_TYPE_RAW_TRACEPOINT, 0},
+ {-EINVAL, 0},
+ },
+ {"xdp", {0, BPF_PROG_TYPE_XDP, 0}, {-EINVAL, 0} },
+ {"perf_event", {0, BPF_PROG_TYPE_PERF_EVENT, 0}, {-EINVAL, 0} },
+ {"lwt_in", {0, BPF_PROG_TYPE_LWT_IN, 0}, {-EINVAL, 0} },
+ {"lwt_out", {0, BPF_PROG_TYPE_LWT_OUT, 0}, {-EINVAL, 0} },
+ {"lwt_xmit", {0, BPF_PROG_TYPE_LWT_XMIT, 0}, {-EINVAL, 0} },
+ {"lwt_seg6local", {0, BPF_PROG_TYPE_LWT_SEG6LOCAL, 0}, {-EINVAL, 0} },
+ {
+ "cgroup_skb/ingress",
+ {0, BPF_PROG_TYPE_CGROUP_SKB, 0},
+ {0, BPF_CGROUP_INET_INGRESS},
+ },
+ {
+ "cgroup_skb/egress",
+ {0, BPF_PROG_TYPE_CGROUP_SKB, 0},
+ {0, BPF_CGROUP_INET_EGRESS},
+ },
+ {"cgroup/skb", {0, BPF_PROG_TYPE_CGROUP_SKB, 0}, {-EINVAL, 0} },
+ {
+ "cgroup/sock",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK, 0},
+ {0, BPF_CGROUP_INET_SOCK_CREATE},
+ },
+ {
+ "cgroup/post_bind4",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET4_POST_BIND},
+ {0, BPF_CGROUP_INET4_POST_BIND},
+ },
+ {
+ "cgroup/post_bind6",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET6_POST_BIND},
+ {0, BPF_CGROUP_INET6_POST_BIND},
+ },
+ {
+ "cgroup/dev",
+ {0, BPF_PROG_TYPE_CGROUP_DEVICE, 0},
+ {0, BPF_CGROUP_DEVICE},
+ },
+ {"sockops", {0, BPF_PROG_TYPE_SOCK_OPS, 0}, {0, BPF_CGROUP_SOCK_OPS} },
+ {
+ "sk_skb/stream_parser",
+ {0, BPF_PROG_TYPE_SK_SKB, 0},
+ {0, BPF_SK_SKB_STREAM_PARSER},
+ },
+ {
+ "sk_skb/stream_verdict",
+ {0, BPF_PROG_TYPE_SK_SKB, 0},
+ {0, BPF_SK_SKB_STREAM_VERDICT},
+ },
+ {"sk_skb", {0, BPF_PROG_TYPE_SK_SKB, 0}, {-EINVAL, 0} },
+ {"sk_msg", {0, BPF_PROG_TYPE_SK_MSG, 0}, {0, BPF_SK_MSG_VERDICT} },
+ {"lirc_mode2", {0, BPF_PROG_TYPE_LIRC_MODE2, 0}, {0, BPF_LIRC_MODE2} },
+ {
+ "flow_dissector",
+ {0, BPF_PROG_TYPE_FLOW_DISSECTOR, 0},
+ {0, BPF_FLOW_DISSECTOR},
+ },
+ {
+ "cgroup/bind4",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_BIND},
+ {0, BPF_CGROUP_INET4_BIND},
+ },
+ {
+ "cgroup/bind6",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_BIND},
+ {0, BPF_CGROUP_INET6_BIND},
+ },
+ {
+ "cgroup/connect4",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_CONNECT},
+ {0, BPF_CGROUP_INET4_CONNECT},
+ },
+ {
+ "cgroup/connect6",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_CONNECT},
+ {0, BPF_CGROUP_INET6_CONNECT},
+ },
+ {
+ "cgroup/sendmsg4",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_SENDMSG},
+ {0, BPF_CGROUP_UDP4_SENDMSG},
+ },
+ {
+ "cgroup/sendmsg6",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_SENDMSG},
+ {0, BPF_CGROUP_UDP6_SENDMSG},
+ },
+ {
+ "cgroup/recvmsg4",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_RECVMSG},
+ {0, BPF_CGROUP_UDP4_RECVMSG},
+ },
+ {
+ "cgroup/recvmsg6",
+ {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_RECVMSG},
+ {0, BPF_CGROUP_UDP6_RECVMSG},
+ },
+ {
+ "cgroup/sysctl",
+ {0, BPF_PROG_TYPE_CGROUP_SYSCTL, BPF_CGROUP_SYSCTL},
+ {0, BPF_CGROUP_SYSCTL},
+ },
+ {
+ "cgroup/getsockopt",
+ {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_GETSOCKOPT},
+ {0, BPF_CGROUP_GETSOCKOPT},
+ },
+ {
+ "cgroup/setsockopt",
+ {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT},
+ {0, BPF_CGROUP_SETSOCKOPT},
+ },
+};
+
+static int test_prog_type_by_name(const struct sec_name_test *test)
+{
+ enum bpf_attach_type expected_attach_type;
+ enum bpf_prog_type prog_type;
+ int rc;
+
+ rc = libbpf_prog_type_by_name(test->sec_name, &prog_type,
+ &expected_attach_type);
+
+ if (rc != test->expected_load.rc) {
+ warnx("prog: unexpected rc=%d for %s", rc, test->sec_name);
+ return -1;
+ }
+
+ if (rc)
+ return 0;
+
+ if (prog_type != test->expected_load.prog_type) {
+ warnx("prog: unexpected prog_type=%d for %s", prog_type,
+ test->sec_name);
+ return -1;
+ }
+
+ if (expected_attach_type != test->expected_load.expected_attach_type) {
+ warnx("prog: unexpected expected_attach_type=%d for %s",
+ expected_attach_type, test->sec_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int test_attach_type_by_name(const struct sec_name_test *test)
+{
+ enum bpf_attach_type attach_type;
+ int rc;
+
+ rc = libbpf_attach_type_by_name(test->sec_name, &attach_type);
+
+ if (rc != test->expected_attach.rc) {
+ warnx("attach: unexpected rc=%d for %s", rc, test->sec_name);
+ return -1;
+ }
+
+ if (rc)
+ return 0;
+
+ if (attach_type != test->expected_attach.attach_type) {
+ warnx("attach: unexpected attach_type=%d for %s", attach_type,
+ test->sec_name);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int test_prog_type_from_to_str(void)
+{
+ enum bpf_prog_type type, actual_type;
+ const char *str;
+ int rc;
+
+ for (type = BPF_PROG_TYPE_UNSPEC; type < __MAX_BPF_PROG_TYPE; type++) {
+ rc = libbpf_prog_type_to_str(type, &str);
+ if (rc) {
+ warnx("prog_type_to_str: unexpected rc=%d for type %d",
+ rc, type);
+ return rc;
+ }
+
+ rc = libbpf_prog_type_from_str(str, &actual_type);
+ if (rc) {
+ warnx("prog_type_from_str: unexpected rc=%d for str %s",
+ rc, str);
+ return rc;
+ }
+
+ if (actual_type != type) {
+ warnx("prog: unexpected prog_type for str %s, %d != %d",
+ str, actual_type, type);
+ return -EINVAL;
+ }
+ }
+
+ rc = libbpf_prog_type_to_str(__MAX_BPF_PROG_TYPE, &str);
+ if (!rc) {
+ warnx("prog: unexpected result for __MAX_BPF_PROG_TYPE");
+ return -EINVAL;
+ }
+
+ rc = libbpf_prog_type_from_str("NonExistent", &type);
+ if (!rc) {
+ warnx("prog: unexpected result for non existent key");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int test_map_type_from_to_str(void)
+{
+ enum bpf_map_type type, actual_type;
+ const char *str;
+ int rc;
+
+ for (type = BPF_MAP_TYPE_UNSPEC; type < __MAX_BPF_MAP_TYPE; type++) {
+ rc = libbpf_map_type_to_str(type, &str);
+ if (rc) {
+ warnx("map_type_to_str: unexpected rc=%d for type %d",
+ rc, type);
+ return rc;
+ }
+
+ rc = libbpf_map_type_from_str(str, &actual_type);
+ if (rc) {
+ warnx("map_type_from_str: unexpected rc=%d for str %s",
+ rc, str);
+ return rc;
+ }
+
+ if (actual_type != type) {
+ warnx("map: unexpected map_type for str %s, %d != %d",
+ str, actual_type, type);
+ return -EINVAL;
+ }
+ }
+
+ rc = libbpf_map_type_to_str(__MAX_BPF_MAP_TYPE, &str);
+ if (!rc) {
+ warnx("map: unexpected result for __MAX_BPF_MAP_TYPE");
+ return -EINVAL;
+ }
+
+ rc = libbpf_map_type_from_str("NonExistent", &type);
+ if (!rc) {
+ warnx("map: unexpected result for non existent key");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int test_attach_type_from_to_str(void)
+{
+ enum bpf_attach_type type, actual_type;
+ const char *str;
+ int rc;
+
+ for (type = BPF_CGROUP_INET_INGRESS; type < __MAX_BPF_ATTACH_TYPE;
+ type++) {
+ rc = libbpf_attach_type_to_str(type, &str);
+ if (rc) {
+ warnx("attach: unexpected rc=%d for type %d",
+ rc, type);
+ return rc;
+ }
+
+ rc = libbpf_attach_type_from_str(str, &actual_type);
+ if (rc) {
+ warnx("attach: unexpected rc=%d for str %s",
+ rc, str);
+ return rc;
+ }
+
+ if (actual_type != type) {
+ warnx("attach: unexpected type for str %s, %d != %d",
+ str, actual_type, type);
+ return -EINVAL;
+ }
+ }
+
+ rc = libbpf_attach_type_to_str(__MAX_BPF_ATTACH_TYPE, &str);
+ if (!rc) {
+ warnx("attach: unexpected result for __MAX_BPF_ATTACH_TYPE");
+ return -EINVAL;
+ }
+
+ rc = libbpf_attach_type_from_str("NonExistent", &type);
+ if (!rc) {
+ warnx("attach: unexpected result for non existent key");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int run_sec_name_test_case(const struct sec_name_test *test)
+{
+ if (test_prog_type_by_name(test))
+ return -1;
+ if (test_attach_type_by_name(test))
+ return -1;
+ return 0;
+}
+
+static int run_tests(void)
+{
+ int passes = 0;
+ int fails = 0;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i) {
+ if (run_sec_name_test_case(&tests[i]))
+ ++fails;
+ else
+ ++passes;
+ }
+
+ if (test_prog_type_from_to_str())
+ ++fails;
+ else
+ ++passes;
+
+ if (test_map_type_from_to_str())
+ ++fails;
+ else
+ ++passes;
+
+ if (test_attach_type_from_to_str())
+ ++fails;
+ else
+ ++passes;
+ printf("Summary: %d PASSED, %d FAILED\n", passes, fails);
+ return fails ? -1 : 0;
+}
+
+int main(int argc, char **argv)
+{
+ return run_tests();
+}
diff --git a/tools/testing/selftests/bpf/test_section_names.c b/tools/testing/selftests/bpf/test_section_names.c
deleted file mode 100644
index 564585a07592..000000000000
--- a/tools/testing/selftests/bpf/test_section_names.c
+++ /dev/null
@@ -1,378 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (c) 2018 Facebook
-
-#include <err.h>
-#include <bpf/libbpf.h>
-
-#include "bpf_util.h"
-
-struct sec_name_test {
- const char sec_name[32];
- struct {
- int rc;
- enum bpf_prog_type prog_type;
- enum bpf_attach_type expected_attach_type;
- } expected_load;
- struct {
- int rc;
- enum bpf_attach_type attach_type;
- } expected_attach;
-};
-
-static struct sec_name_test tests[] = {
- {"InvAliD", {-EINVAL, 0, 0}, {-EINVAL, 0} },
- {"cgroup", {-EINVAL, 0, 0}, {-EINVAL, 0} },
- {"socket", {0, BPF_PROG_TYPE_SOCKET_FILTER, 0}, {-EINVAL, 0} },
- {"kprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
- {"kretprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
- {"classifier", {0, BPF_PROG_TYPE_SCHED_CLS, 0}, {-EINVAL, 0} },
- {"action", {0, BPF_PROG_TYPE_SCHED_ACT, 0}, {-EINVAL, 0} },
- {"tracepoint/", {0, BPF_PROG_TYPE_TRACEPOINT, 0}, {-EINVAL, 0} },
- {
- "raw_tracepoint/",
- {0, BPF_PROG_TYPE_RAW_TRACEPOINT, 0},
- {-EINVAL, 0},
- },
- {"xdp", {0, BPF_PROG_TYPE_XDP, 0}, {-EINVAL, 0} },
- {"perf_event", {0, BPF_PROG_TYPE_PERF_EVENT, 0}, {-EINVAL, 0} },
- {"lwt_in", {0, BPF_PROG_TYPE_LWT_IN, 0}, {-EINVAL, 0} },
- {"lwt_out", {0, BPF_PROG_TYPE_LWT_OUT, 0}, {-EINVAL, 0} },
- {"lwt_xmit", {0, BPF_PROG_TYPE_LWT_XMIT, 0}, {-EINVAL, 0} },
- {"lwt_seg6local", {0, BPF_PROG_TYPE_LWT_SEG6LOCAL, 0}, {-EINVAL, 0} },
- {
- "cgroup_skb/ingress",
- {0, BPF_PROG_TYPE_CGROUP_SKB, 0},
- {0, BPF_CGROUP_INET_INGRESS},
- },
- {
- "cgroup_skb/egress",
- {0, BPF_PROG_TYPE_CGROUP_SKB, 0},
- {0, BPF_CGROUP_INET_EGRESS},
- },
- {"cgroup/skb", {0, BPF_PROG_TYPE_CGROUP_SKB, 0}, {-EINVAL, 0} },
- {
- "cgroup/sock",
- {0, BPF_PROG_TYPE_CGROUP_SOCK, 0},
- {0, BPF_CGROUP_INET_SOCK_CREATE},
- },
- {
- "cgroup/post_bind4",
- {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET4_POST_BIND},
- {0, BPF_CGROUP_INET4_POST_BIND},
- },
- {
- "cgroup/post_bind6",
- {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET6_POST_BIND},
- {0, BPF_CGROUP_INET6_POST_BIND},
- },
- {
- "cgroup/dev",
- {0, BPF_PROG_TYPE_CGROUP_DEVICE, 0},
- {0, BPF_CGROUP_DEVICE},
- },
- {"sockops", {0, BPF_PROG_TYPE_SOCK_OPS, 0}, {0, BPF_CGROUP_SOCK_OPS} },
- {
- "sk_skb/stream_parser",
- {0, BPF_PROG_TYPE_SK_SKB, 0},
- {0, BPF_SK_SKB_STREAM_PARSER},
- },
- {
- "sk_skb/stream_verdict",
- {0, BPF_PROG_TYPE_SK_SKB, 0},
- {0, BPF_SK_SKB_STREAM_VERDICT},
- },
- {"sk_skb", {0, BPF_PROG_TYPE_SK_SKB, 0}, {-EINVAL, 0} },
- {"sk_msg", {0, BPF_PROG_TYPE_SK_MSG, 0}, {0, BPF_SK_MSG_VERDICT} },
- {"lirc_mode2", {0, BPF_PROG_TYPE_LIRC_MODE2, 0}, {0, BPF_LIRC_MODE2} },
- {
- "flow_dissector",
- {0, BPF_PROG_TYPE_FLOW_DISSECTOR, 0},
- {0, BPF_FLOW_DISSECTOR},
- },
- {
- "cgroup/bind4",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_BIND},
- {0, BPF_CGROUP_INET4_BIND},
- },
- {
- "cgroup/bind6",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_BIND},
- {0, BPF_CGROUP_INET6_BIND},
- },
- {
- "cgroup/connect4",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_CONNECT},
- {0, BPF_CGROUP_INET4_CONNECT},
- },
- {
- "cgroup/connect6",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_CONNECT},
- {0, BPF_CGROUP_INET6_CONNECT},
- },
- {
- "cgroup/sendmsg4",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_SENDMSG},
- {0, BPF_CGROUP_UDP4_SENDMSG},
- },
- {
- "cgroup/sendmsg6",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_SENDMSG},
- {0, BPF_CGROUP_UDP6_SENDMSG},
- },
- {
- "cgroup/recvmsg4",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_RECVMSG},
- {0, BPF_CGROUP_UDP4_RECVMSG},
- },
- {
- "cgroup/recvmsg6",
- {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_RECVMSG},
- {0, BPF_CGROUP_UDP6_RECVMSG},
- },
- {
- "cgroup/sysctl",
- {0, BPF_PROG_TYPE_CGROUP_SYSCTL, BPF_CGROUP_SYSCTL},
- {0, BPF_CGROUP_SYSCTL},
- },
- {
- "cgroup/getsockopt",
- {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_GETSOCKOPT},
- {0, BPF_CGROUP_GETSOCKOPT},
- },
- {
- "cgroup/setsockopt",
- {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT},
- {0, BPF_CGROUP_SETSOCKOPT},
- },
-};
-
-static int test_prog_type_by_name(const struct sec_name_test *test)
-{
- enum bpf_attach_type expected_attach_type;
- enum bpf_prog_type prog_type;
- int rc;
-
- rc = libbpf_prog_type_by_name(test->sec_name, &prog_type,
- &expected_attach_type);
-
- if (rc != test->expected_load.rc) {
- warnx("prog: unexpected rc=%d for %s", rc, test->sec_name);
- return -1;
- }
-
- if (rc)
- return 0;
-
- if (prog_type != test->expected_load.prog_type) {
- warnx("prog: unexpected prog_type=%d for %s", prog_type,
- test->sec_name);
- return -1;
- }
-
- if (expected_attach_type != test->expected_load.expected_attach_type) {
- warnx("prog: unexpected expected_attach_type=%d for %s",
- expected_attach_type, test->sec_name);
- return -1;
- }
-
- return 0;
-}
-
-static int test_attach_type_by_name(const struct sec_name_test *test)
-{
- enum bpf_attach_type attach_type;
- int rc;
-
- rc = libbpf_attach_type_by_name(test->sec_name, &attach_type);
-
- if (rc != test->expected_attach.rc) {
- warnx("attach: unexpected rc=%d for %s", rc, test->sec_name);
- return -1;
- }
-
- if (rc)
- return 0;
-
- if (attach_type != test->expected_attach.attach_type) {
- warnx("attach: unexpected attach_type=%d for %s", attach_type,
- test->sec_name);
- return -1;
- }
-
- return 0;
-}
-
-static int test_prog_type_from_to_str(void)
-{
- enum bpf_prog_type type, actual_type;
- const char *str;
- int rc;
-
- for (type = BPF_PROG_TYPE_UNSPEC; type < __MAX_BPF_PROG_TYPE; type++) {
- rc = libbpf_prog_type_to_str(type, &str);
- if (rc) {
- warnx("prog_type_to_str: unexpected rc=%d for type %d",
- rc, type);
- return rc;
- }
-
- rc = libbpf_prog_type_from_str(str, &actual_type);
- if (rc) {
- warnx("prog_type_from_str: unexpected rc=%d for str %s",
- rc, str);
- return rc;
- }
-
- if (actual_type != type) {
- warnx("prog: unexpected prog_type for str %s, %d != %d",
- str, actual_type, type);
- return -EINVAL;
- }
- }
-
- rc = libbpf_prog_type_to_str(__MAX_BPF_PROG_TYPE, &str);
- if (!rc) {
- warnx("prog: unexpected result for __MAX_BPF_PROG_TYPE");
- return -EINVAL;
- }
-
- rc = libbpf_prog_type_from_str("NonExistent", &type);
- if (!rc) {
- warnx("prog: unexpected result for non existent key");
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int test_map_type_from_to_str(void)
-{
- enum bpf_map_type type, actual_type;
- const char *str;
- int rc;
-
- for (type = BPF_MAP_TYPE_UNSPEC; type < __MAX_BPF_MAP_TYPE; type++) {
- rc = libbpf_map_type_to_str(type, &str);
- if (rc) {
- warnx("map_type_to_str: unexpected rc=%d for type %d",
- rc, type);
- return rc;
- }
-
- rc = libbpf_map_type_from_str(str, &actual_type);
- if (rc) {
- warnx("map_type_from_str: unexpected rc=%d for str %s",
- rc, str);
- return rc;
- }
-
- if (actual_type != type) {
- warnx("map: unexpected map_type for str %s, %d != %d",
- str, actual_type, type);
- return -EINVAL;
- }
- }
-
- rc = libbpf_map_type_to_str(__MAX_BPF_MAP_TYPE, &str);
- if (!rc) {
- warnx("map: unexpected result for __MAX_BPF_MAP_TYPE");
- return -EINVAL;
- }
-
- rc = libbpf_map_type_from_str("NonExistent", &type);
- if (!rc) {
- warnx("map: unexpected result for non existent key");
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int test_attach_type_from_to_str(void)
-{
- enum bpf_attach_type type, actual_type;
- const char *str;
- int rc;
-
- for (type = BPF_CGROUP_INET_INGRESS; type < __MAX_BPF_ATTACH_TYPE;
- type++) {
- rc = libbpf_attach_type_to_str(type, &str);
- if (rc) {
- warnx("attach: unexpected rc=%d for type %d",
- rc, type);
- return rc;
- }
-
- rc = libbpf_attach_type_from_str(str, &actual_type);
- if (rc) {
- warnx("attach: unexpected rc=%d for str %s",
- rc, str);
- return rc;
- }
-
- if (actual_type != type) {
- warnx("attach: unexpected type for str %s, %d != %d",
- str, actual_type, type);
- return -EINVAL;
- }
- }
-
- rc = libbpf_attach_type_to_str(__MAX_BPF_ATTACH_TYPE, &str);
- if (!rc) {
- warnx("attach: unexpected result for __MAX_BPF_ATTACH_TYPE");
- return -EINVAL;
- }
-
- rc = libbpf_attach_type_from_str("NonExistent", &type);
- if (!rc) {
- warnx("attach: unexpected result for non existent key");
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int run_sec_name_test_case(const struct sec_name_test *test)
-{
- if (test_prog_type_by_name(test))
- return -1;
- if (test_attach_type_by_name(test))
- return -1;
- return 0;
-}
-
-static int run_tests(void)
-{
- int passes = 0;
- int fails = 0;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(tests); ++i) {
- if (run_sec_name_test_case(&tests[i]))
- ++fails;
- else
- ++passes;
- }
-
- if (test_prog_type_from_to_str())
- ++fails;
- else
- ++passes;
-
- if (test_map_type_from_to_str())
- ++fails;
- else
- ++passes;
-
- if (test_attach_type_from_to_str())
- ++fails;
- else
- ++passes;
- printf("Summary: %d PASSED, %d FAILED\n", passes, fails);
- return fails ? -1 : 0;
-}
-
-int main(int argc, char **argv)
-{
- return run_tests();
-}
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 10/10] tools/bpftool: use libbpf_attach_type_to_str helper
From: Julia Kartseva @ 2019-08-28 21:03 UTC (permalink / raw)
To: rdna, bpf, ast, daniel, netdev, kernel-team; +Cc: Julia Kartseva
In-Reply-To: <cover.1567024943.git.hex@fb.com>
Replace lookup in `attach_type_strings` with
libbpf_attach_type_to_str helper for cgroup (cgroup.c)
and non-cgroup (prog.c) attach types.
Signed-off-by: Julia Kartseva <hex@fb.com>
---
tools/bpf/bpftool/cgroup.c | 60 +++++++++++++++++++++-----------------
tools/bpf/bpftool/prog.c | 20 +++++++------
2 files changed, 45 insertions(+), 35 deletions(-)
diff --git a/tools/bpf/bpftool/cgroup.c b/tools/bpf/bpftool/cgroup.c
index 1ef45e55039e..1b53218b06e7 100644
--- a/tools/bpf/bpftool/cgroup.c
+++ b/tools/bpf/bpftool/cgroup.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <bpf.h>
+#include <libbpf.h>
#include "main.h"
@@ -31,35 +32,37 @@
static unsigned int query_flags;
-static const char * const attach_type_strings[] = {
- [BPF_CGROUP_INET_INGRESS] = "ingress",
- [BPF_CGROUP_INET_EGRESS] = "egress",
- [BPF_CGROUP_INET_SOCK_CREATE] = "sock_create",
- [BPF_CGROUP_SOCK_OPS] = "sock_ops",
- [BPF_CGROUP_DEVICE] = "device",
- [BPF_CGROUP_INET4_BIND] = "bind4",
- [BPF_CGROUP_INET6_BIND] = "bind6",
- [BPF_CGROUP_INET4_CONNECT] = "connect4",
- [BPF_CGROUP_INET6_CONNECT] = "connect6",
- [BPF_CGROUP_INET4_POST_BIND] = "post_bind4",
- [BPF_CGROUP_INET6_POST_BIND] = "post_bind6",
- [BPF_CGROUP_UDP4_SENDMSG] = "sendmsg4",
- [BPF_CGROUP_UDP6_SENDMSG] = "sendmsg6",
- [BPF_CGROUP_SYSCTL] = "sysctl",
- [BPF_CGROUP_UDP4_RECVMSG] = "recvmsg4",
- [BPF_CGROUP_UDP6_RECVMSG] = "recvmsg6",
- [BPF_CGROUP_GETSOCKOPT] = "getsockopt",
- [BPF_CGROUP_SETSOCKOPT] = "setsockopt",
- [__MAX_BPF_ATTACH_TYPE] = NULL,
+static const enum bpf_attach_type cgroup_attach_types[] = {
+ BPF_CGROUP_INET_INGRESS,
+ BPF_CGROUP_INET_EGRESS,
+ BPF_CGROUP_INET_SOCK_CREATE,
+ BPF_CGROUP_SOCK_OPS,
+ BPF_CGROUP_DEVICE,
+ BPF_CGROUP_INET4_BIND,
+ BPF_CGROUP_INET6_BIND,
+ BPF_CGROUP_INET4_CONNECT,
+ BPF_CGROUP_INET6_CONNECT,
+ BPF_CGROUP_INET4_POST_BIND,
+ BPF_CGROUP_INET6_POST_BIND,
+ BPF_CGROUP_UDP4_SENDMSG,
+ BPF_CGROUP_UDP6_SENDMSG,
+ BPF_CGROUP_SYSCTL,
+ BPF_CGROUP_UDP4_RECVMSG,
+ BPF_CGROUP_UDP6_RECVMSG,
+ BPF_CGROUP_GETSOCKOPT,
+ BPF_CGROUP_SETSOCKOPT,
};
static enum bpf_attach_type parse_attach_type(const char *str)
{
enum bpf_attach_type type;
+ const char *atype_str;
+ unsigned int i;
- for (type = 0; type < __MAX_BPF_ATTACH_TYPE; type++) {
- if (attach_type_strings[type] &&
- is_prefix(str, attach_type_strings[type]))
+ for (i = 0; i < ARRAY_SIZE(cgroup_attach_types); i++) {
+ type = cgroup_attach_types[i];
+ if (!libbpf_attach_type_to_str(type, &atype_str) &&
+ is_prefix(str, atype_str))
return type;
}
@@ -120,7 +123,7 @@ static int count_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type)
static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type,
int level)
{
- const char *attach_flags_str;
+ const char *attach_flags_str, *atype_str;
__u32 prog_ids[1024] = {0};
__u32 prog_cnt, iter;
__u32 attach_flags;
@@ -136,6 +139,11 @@ static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type,
if (prog_cnt == 0)
return 0;
+ ret = libbpf_attach_type_to_str(type, &atype_str);
+
+ if (ret)
+ return 0;
+
switch (attach_flags) {
case BPF_F_ALLOW_MULTI:
attach_flags_str = "multi";
@@ -152,8 +160,8 @@ static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type,
}
for (iter = 0; iter < prog_cnt; iter++)
- show_bpf_prog(prog_ids[iter], attach_type_strings[type],
- attach_flags_str, level);
+ show_bpf_prog(prog_ids[iter], atype_str, attach_flags_str,
+ level);
return 0;
}
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 8bbb24339a52..4dfec67e22fa 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -25,21 +25,23 @@
#include "main.h"
#include "xlated_dumper.h"
-static const char * const attach_type_strings[] = {
- [BPF_SK_SKB_STREAM_PARSER] = "stream_parser",
- [BPF_SK_SKB_STREAM_VERDICT] = "stream_verdict",
- [BPF_SK_MSG_VERDICT] = "msg_verdict",
- [BPF_FLOW_DISSECTOR] = "flow_dissector",
- [__MAX_BPF_ATTACH_TYPE] = NULL,
+static const enum bpf_attach_type attach_types[] = {
+ BPF_SK_SKB_STREAM_PARSER,
+ BPF_SK_SKB_STREAM_VERDICT,
+ BPF_SK_MSG_VERDICT,
+ BPF_FLOW_DISSECTOR,
};
static enum bpf_attach_type parse_attach_type(const char *str)
{
enum bpf_attach_type type;
+ const char *atype_str;
+ unsigned int i;
- for (type = 0; type < __MAX_BPF_ATTACH_TYPE; type++) {
- if (attach_type_strings[type] &&
- is_prefix(str, attach_type_strings[type]))
+ for (i = 0; type < ARRAY_SIZE(attach_types); i++) {
+ type = attach_types[i];
+ if (!libbpf_attach_type_to_str(type, &atype_str) &&
+ is_prefix(str, atype_str))
return type;
}
--
2.17.1
^ permalink raw reply related
* [PATCH bpf-next 09/10] tools/bpftool: use libbpf_(prog|map)_type_to_str helpers
From: Julia Kartseva @ 2019-08-28 21:03 UTC (permalink / raw)
To: rdna, bpf, ast, daniel, netdev, kernel-team; +Cc: Julia Kartseva
In-Reply-To: <cover.1567024943.git.hex@fb.com>
Replace lookup in (prog|map)_type_name arrays with
libbpf_(prog|map)_type_to_str helpers.
Use __MAX_BPF_(PROG|MAP)_TYPE enum values as loop bounds.
Signed-off-by: Julia Kartseva <hex@fb.com>
---
tools/bpf/bpftool/feature.c | 47 ++++++++++++++--------
tools/bpf/bpftool/main.h | 33 ---------------
tools/bpf/bpftool/map.c | 80 ++++++++++---------------------------
tools/bpf/bpftool/prog.c | 11 ++---
4 files changed, 59 insertions(+), 112 deletions(-)
diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index 03bdc5b3ac49..e9416005e721 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -462,7 +462,7 @@ probe_prog_type(enum bpf_prog_type prog_type, bool *supported_types,
const char *define_prefix, __u32 ifindex)
{
char feat_name[128], plain_desc[128], define_name[128];
- const char *plain_comment = "eBPF program_type ";
+ const char *ptype_name, *plain_comment = "eBPF program_type ";
size_t maxlen;
bool res;
@@ -480,16 +480,21 @@ probe_prog_type(enum bpf_prog_type prog_type, bool *supported_types,
supported_types[prog_type] |= res;
+ if (libbpf_prog_type_to_str(prog_type, &ptype_name)) {
+ p_info("program type name does not exist");
+ return;
+ }
+
maxlen = sizeof(plain_desc) - strlen(plain_comment) - 1;
- if (strlen(prog_type_name[prog_type]) > maxlen) {
+ if (strlen(ptype_name) > maxlen) {
p_info("program type name too long");
return;
}
- sprintf(feat_name, "have_%s_prog_type", prog_type_name[prog_type]);
- sprintf(define_name, "%s_prog_type", prog_type_name[prog_type]);
+ sprintf(feat_name, "have_%s_prog_type", ptype_name);
+ sprintf(define_name, "%s_prog_type", ptype_name);
uppercase(define_name, sizeof(define_name));
- sprintf(plain_desc, "%s%s", plain_comment, prog_type_name[prog_type]);
+ sprintf(plain_desc, "%s%s", plain_comment, ptype_name);
print_bool_feature(feat_name, plain_desc, define_name, res,
define_prefix);
}
@@ -499,22 +504,27 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix,
__u32 ifindex)
{
char feat_name[128], plain_desc[128], define_name[128];
- const char *plain_comment = "eBPF map_type ";
+ const char *mtype_name, *plain_comment = "eBPF map_type ";
size_t maxlen;
bool res;
res = bpf_probe_map_type(map_type, ifindex);
+ if (libbpf_map_type_to_str(map_type, &mtype_name)) {
+ p_info("map type name does not exist");
+ return;
+ }
+
maxlen = sizeof(plain_desc) - strlen(plain_comment) - 1;
- if (strlen(map_type_name[map_type]) > maxlen) {
+ if (strlen(mtype_name) > maxlen) {
p_info("map type name too long");
return;
}
- sprintf(feat_name, "have_%s_map_type", map_type_name[map_type]);
- sprintf(define_name, "%s_map_type", map_type_name[map_type]);
+ sprintf(feat_name, "have_%s_map_type", mtype_name);
+ sprintf(define_name, "%s_map_type", mtype_name);
uppercase(define_name, sizeof(define_name));
- sprintf(plain_desc, "%s%s", plain_comment, map_type_name[map_type]);
+ sprintf(plain_desc, "%s%s", plain_comment, mtype_name);
print_bool_feature(feat_name, plain_desc, define_name, res,
define_prefix);
}
@@ -523,11 +533,16 @@ static void
probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
const char *define_prefix, __u32 ifindex)
{
- const char *ptype_name = prog_type_name[prog_type];
+ const char *ptype_name;
char feat_name[128];
unsigned int id;
bool res;
+ if (libbpf_prog_type_to_str(prog_type, &ptype_name)) {
+ p_info("map type name does not exist");
+ return;
+ }
+
if (ifindex)
/* Only test helpers for offload-able program types */
switch (prog_type) {
@@ -689,7 +704,7 @@ static int do_probe(int argc, char **argv)
"/*** eBPF program types ***/",
define_prefix);
- for (i = BPF_PROG_TYPE_UNSPEC + 1; i < ARRAY_SIZE(prog_type_name); i++)
+ for (i = BPF_PROG_TYPE_UNSPEC + 1; i < __MAX_BPF_PROG_TYPE; i++)
probe_prog_type(i, supported_types, define_prefix, ifindex);
print_end_then_start_section("map_types",
@@ -697,7 +712,7 @@ static int do_probe(int argc, char **argv)
"/*** eBPF map types ***/",
define_prefix);
- for (i = BPF_MAP_TYPE_UNSPEC + 1; i < map_type_name_size; i++)
+ for (i = BPF_MAP_TYPE_UNSPEC + 1; i < __MAX_BPF_MAP_TYPE; i++)
probe_map_type(i, define_prefix, ifindex);
print_end_then_start_section("helpers",
@@ -720,9 +735,9 @@ static int do_probe(int argc, char **argv)
" %sBPF__PROG_TYPE_ ## prog_type ## __HELPER_ ## helper\n",
define_prefix, define_prefix, define_prefix,
define_prefix);
- for (i = BPF_PROG_TYPE_UNSPEC + 1; i < ARRAY_SIZE(prog_type_name); i++)
- probe_helpers_for_progtype(i, supported_types[i],
- define_prefix, ifindex);
+ for (i = BPF_PROG_TYPE_UNSPEC + 1; i <= __MAX_BPF_PROG_TYPE; i++)
+ probe_helpers_for_progtype(i, supported_types[i], define_prefix,
+ ifindex);
exit_close_json:
if (json_output) {
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index af9ad56c303a..bb840d900fb4 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -48,39 +48,6 @@
"\t {-m|--mapcompat} | {-n|--nomount} }"
#define HELP_SPEC_MAP \
"MAP := { id MAP_ID | pinned FILE }"
-
-static const char * const prog_type_name[] = {
- [BPF_PROG_TYPE_UNSPEC] = "unspec",
- [BPF_PROG_TYPE_SOCKET_FILTER] = "socket_filter",
- [BPF_PROG_TYPE_KPROBE] = "kprobe",
- [BPF_PROG_TYPE_SCHED_CLS] = "sched_cls",
- [BPF_PROG_TYPE_SCHED_ACT] = "sched_act",
- [BPF_PROG_TYPE_TRACEPOINT] = "tracepoint",
- [BPF_PROG_TYPE_XDP] = "xdp",
- [BPF_PROG_TYPE_PERF_EVENT] = "perf_event",
- [BPF_PROG_TYPE_CGROUP_SKB] = "cgroup_skb",
- [BPF_PROG_TYPE_CGROUP_SOCK] = "cgroup_sock",
- [BPF_PROG_TYPE_LWT_IN] = "lwt_in",
- [BPF_PROG_TYPE_LWT_OUT] = "lwt_out",
- [BPF_PROG_TYPE_LWT_XMIT] = "lwt_xmit",
- [BPF_PROG_TYPE_SOCK_OPS] = "sock_ops",
- [BPF_PROG_TYPE_SK_SKB] = "sk_skb",
- [BPF_PROG_TYPE_CGROUP_DEVICE] = "cgroup_device",
- [BPF_PROG_TYPE_SK_MSG] = "sk_msg",
- [BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint",
- [BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr",
- [BPF_PROG_TYPE_LWT_SEG6LOCAL] = "lwt_seg6local",
- [BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2",
- [BPF_PROG_TYPE_SK_REUSEPORT] = "sk_reuseport",
- [BPF_PROG_TYPE_FLOW_DISSECTOR] = "flow_dissector",
- [BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl",
- [BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE] = "raw_tracepoint_writable",
- [BPF_PROG_TYPE_CGROUP_SOCKOPT] = "cgroup_sockopt",
-};
-
-extern const char * const map_type_name[];
-extern const size_t map_type_name_size;
-
enum bpf_obj_type {
BPF_OBJ_UNKNOWN,
BPF_OBJ_PROG,
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index de61d73b9030..ca3760b5c33e 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -16,42 +16,12 @@
#include <sys/stat.h>
#include <bpf.h>
+#include <libbpf.h>
#include "btf.h"
#include "json_writer.h"
#include "main.h"
-const char * const map_type_name[] = {
- [BPF_MAP_TYPE_UNSPEC] = "unspec",
- [BPF_MAP_TYPE_HASH] = "hash",
- [BPF_MAP_TYPE_ARRAY] = "array",
- [BPF_MAP_TYPE_PROG_ARRAY] = "prog_array",
- [BPF_MAP_TYPE_PERF_EVENT_ARRAY] = "perf_event_array",
- [BPF_MAP_TYPE_PERCPU_HASH] = "percpu_hash",
- [BPF_MAP_TYPE_PERCPU_ARRAY] = "percpu_array",
- [BPF_MAP_TYPE_STACK_TRACE] = "stack_trace",
- [BPF_MAP_TYPE_CGROUP_ARRAY] = "cgroup_array",
- [BPF_MAP_TYPE_LRU_HASH] = "lru_hash",
- [BPF_MAP_TYPE_LRU_PERCPU_HASH] = "lru_percpu_hash",
- [BPF_MAP_TYPE_LPM_TRIE] = "lpm_trie",
- [BPF_MAP_TYPE_ARRAY_OF_MAPS] = "array_of_maps",
- [BPF_MAP_TYPE_HASH_OF_MAPS] = "hash_of_maps",
- [BPF_MAP_TYPE_DEVMAP] = "devmap",
- [BPF_MAP_TYPE_DEVMAP_HASH] = "devmap_hash",
- [BPF_MAP_TYPE_SOCKMAP] = "sockmap",
- [BPF_MAP_TYPE_CPUMAP] = "cpumap",
- [BPF_MAP_TYPE_XSKMAP] = "xskmap",
- [BPF_MAP_TYPE_SOCKHASH] = "sockhash",
- [BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage",
- [BPF_MAP_TYPE_REUSEPORT_SOCKARRAY] = "reuseport_sockarray",
- [BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE] = "percpu_cgroup_storage",
- [BPF_MAP_TYPE_QUEUE] = "queue",
- [BPF_MAP_TYPE_STACK] = "stack",
- [BPF_MAP_TYPE_SK_STORAGE] = "sk_storage",
-};
-
-const size_t map_type_name_size = ARRAY_SIZE(map_type_name);
-
static bool map_is_per_cpu(__u32 type)
{
return type == BPF_MAP_TYPE_PERCPU_HASH ||
@@ -71,17 +41,6 @@ static bool map_is_map_of_progs(__u32 type)
return type == BPF_MAP_TYPE_PROG_ARRAY;
}
-static int map_type_from_str(const char *type)
-{
- unsigned int i;
-
- for (i = 0; i < ARRAY_SIZE(map_type_name); i++)
- /* Don't allow prefixing in case of possible future shadowing */
- if (map_type_name[i] && !strcmp(map_type_name[i], type))
- return i;
- return -1;
-}
-
static void *alloc_value(struct bpf_map_info *info)
{
if (map_is_per_cpu(info->type))
@@ -481,6 +440,8 @@ static int parse_elem(char **argv, struct bpf_map_info *info,
static int show_map_close_json(int fd, struct bpf_map_info *info)
{
+ const char *ptype_name, *mtype_name;
+ enum bpf_prog_type prog_type;
char *memlock, *frozen_str;
int frozen = 0;
@@ -488,11 +449,10 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
frozen_str = get_fdinfo(fd, "frozen");
jsonw_start_object(json_wtr);
-
jsonw_uint_field(json_wtr, "id", info->id);
- if (info->type < ARRAY_SIZE(map_type_name))
- jsonw_string_field(json_wtr, "type",
- map_type_name[info->type]);
+
+ if (!libbpf_map_type_to_str(info->type, &mtype_name))
+ jsonw_string_field(json_wtr, "type", mtype_name);
else
jsonw_uint_field(json_wtr, "type", info->type);
@@ -517,11 +477,11 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
char *owner_jited = get_fdinfo(fd, "owner_jited");
if (owner_prog_type) {
- unsigned int prog_type = atoi(owner_prog_type);
+ prog_type = atoi(owner_prog_type);
- if (prog_type < ARRAY_SIZE(prog_type_name))
+ if (!libbpf_prog_type_to_str(prog_type, &ptype_name))
jsonw_string_field(json_wtr, "owner_prog_type",
- prog_type_name[prog_type]);
+ ptype_name);
else
jsonw_uint_field(json_wtr, "owner_prog_type",
prog_type);
@@ -563,6 +523,7 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
static int show_map_close_plain(int fd, struct bpf_map_info *info)
{
+ const char *mtype_name, *ptype_name;
char *memlock, *frozen_str;
int frozen = 0;
@@ -570,8 +531,9 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info)
frozen_str = get_fdinfo(fd, "frozen");
printf("%u: ", info->id);
- if (info->type < ARRAY_SIZE(map_type_name))
- printf("%s ", map_type_name[info->type]);
+
+ if (!libbpf_map_type_to_str(info->type, &mtype_name))
+ printf("%s ", mtype_name);
else
printf("type %u ", info->type);
@@ -596,10 +558,8 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info)
printf("\n\t");
if (owner_prog_type) {
unsigned int prog_type = atoi(owner_prog_type);
-
- if (prog_type < ARRAY_SIZE(prog_type_name))
- printf("owner_prog_type %s ",
- prog_type_name[prog_type]);
+ if (!libbpf_prog_type_to_str(prog_type, &ptype_name))
+ printf("owner_prog_type %s ", ptype_name);
else
printf("owner_prog_type %d ", prog_type);
}
@@ -772,6 +732,7 @@ static int do_dump(int argc, char **argv)
unsigned int num_elems = 0;
__u32 len = sizeof(info);
json_writer_t *btf_wtr;
+ const char *mtype_name;
struct btf *btf = NULL;
int err;
int fd;
@@ -813,10 +774,14 @@ static int do_dump(int argc, char **argv)
}
}
+ if (libbpf_map_type_to_str(info.type, &mtype_name)) {
+ p_info("map type name does not exist");
+ goto exit_free;
+ }
if (info.type == BPF_MAP_TYPE_REUSEPORT_SOCKARRAY &&
info.value_size != 8)
p_info("Warning: cannot read values from %s map with value_size != 8",
- map_type_name[info.type]);
+ mtype_name);
while (true) {
err = bpf_map_get_next_key(fd, prev_key, key);
if (err) {
@@ -1150,8 +1115,7 @@ static int do_create(int argc, char **argv)
return -1;
}
- attr.map_type = map_type_from_str(*argv);
- if ((int)attr.map_type < 0) {
+ if (libbpf_map_type_from_str(*argv, &attr.map_type)) {
p_err("unrecognized map type: %s", *argv);
return -1;
}
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 66f04a4846a5..8bbb24339a52 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -196,13 +196,13 @@ static void show_prog_maps(int fd, u32 num_maps)
static void print_prog_json(struct bpf_prog_info *info, int fd)
{
+ const char *ptype_name;
char *memlock;
jsonw_start_object(json_wtr);
jsonw_uint_field(json_wtr, "id", info->id);
- if (info->type < ARRAY_SIZE(prog_type_name))
- jsonw_string_field(json_wtr, "type",
- prog_type_name[info->type]);
+ if (!libbpf_prog_type_to_str(info->type, &ptype_name))
+ jsonw_string_field(json_wtr, "type", ptype_name);
else
jsonw_uint_field(json_wtr, "type", info->type);
@@ -270,11 +270,12 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
static void print_prog_plain(struct bpf_prog_info *info, int fd)
{
+ const char *ptype_name;
char *memlock;
printf("%u: ", info->id);
- if (info->type < ARRAY_SIZE(prog_type_name))
- printf("%s ", prog_type_name[info->type]);
+ if (!libbpf_prog_type_to_str(info->type, &ptype_name))
+ printf("%s ", ptype_name);
else
printf("type %u ", info->type);
--
2.17.1
^ permalink raw reply related
* Re: [PATCH v2 0/2] Update ethernet compatible string for SiFive FU540
From: David Miller @ 2019-08-28 21:06 UTC (permalink / raw)
To: yash.shah
Cc: netdev, devicetree, linux-kernel, linux-riscv, robh+dt,
mark.rutland, nicolas.ferre, palmer, paul.walmsley, ynezz,
sachin.ghadi
In-Reply-To: <1566882364-23891-1-git-send-email-yash.shah@sifive.com>
From: Yash Shah <yash.shah@sifive.com>
Date: Tue, 27 Aug 2019 10:36:02 +0530
> This patch series renames the compatible property to a more appropriate
> string. The patchset is based on Linux-5.3-rc6 and tested on SiFive
> Unleashed board
You should always base changes off of "net" or "net-next" and be explicitly
in your Subject lines which of those two trees your changes are for f.e.:
Subject: [PATCH v2 net-next N/M] ...
>
> Change history:
> Since v1:
> - Dropped PATCH3 because it's already merged
> - Change the reference url in the patch descriptions to point to a
> 'lore.kernel.org' link instead of 'lkml.org'
Series applied to 'net'.
^ permalink raw reply
* Re: [PATCH bpf-next 03/10] tools/bpf: handle __MAX_BPF_(PROG|MAP)_TYPE in switch statements
From: Arnaldo Carvalho de Melo @ 2019-08-28 21:19 UTC (permalink / raw)
To: Julia Kartseva; +Cc: rdna, bpf, ast, daniel, netdev, kernel-team
In-Reply-To: <1895f7dfe2a8067f6397ff565edf20130a28aa91.1567024943.git.hex@fb.com>
Em Wed, Aug 28, 2019 at 02:03:06PM -0700, Julia Kartseva escreveu:
> Add cases to switch statements in probe_load, bpf_prog_type__needs_kver
> bpf_probe_map_type to fix enumeration value not handled in switch
> compilation error.
> prog_type_name array in bpftool/main.h doesn't have __MAX_BPF_PROG_TYPE
> entity, same for map, so probe won't be called.
Shouldn't this be added when adding that __MAX_BPF_PROG_TYPE value to
the enum? Otherwise the build will fail when __MAX_BPF_PROG_TYPE is
added but not handled in the switches.
I.e. the tree should build patch by patch, not just at the end of patch
series.
- Arnaldo
> Signed-off-by: Julia Kartseva <hex@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 1 +
> tools/lib/bpf/libbpf_probes.c | 2 ++
> 2 files changed, 3 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 2233f919dd88..72e6e5eb397f 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3580,6 +3580,7 @@ static bool bpf_prog_type__needs_kver(enum bpf_prog_type type)
> case BPF_PROG_TYPE_PERF_EVENT:
> case BPF_PROG_TYPE_CGROUP_SYSCTL:
> case BPF_PROG_TYPE_CGROUP_SOCKOPT:
> + case __MAX_BPF_PROG_TYPE:
> return false;
> case BPF_PROG_TYPE_KPROBE:
> default:
> diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c
> index 4b0b0364f5fc..8f2ba6a457ac 100644
> --- a/tools/lib/bpf/libbpf_probes.c
> +++ b/tools/lib/bpf/libbpf_probes.c
> @@ -102,6 +102,7 @@ probe_load(enum bpf_prog_type prog_type, const struct bpf_insn *insns,
> case BPF_PROG_TYPE_FLOW_DISSECTOR:
> case BPF_PROG_TYPE_CGROUP_SYSCTL:
> case BPF_PROG_TYPE_CGROUP_SOCKOPT:
> + case __MAX_BPF_PROG_TYPE:
> default:
> break;
> }
> @@ -250,6 +251,7 @@ bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex)
> case BPF_MAP_TYPE_XSKMAP:
> case BPF_MAP_TYPE_SOCKHASH:
> case BPF_MAP_TYPE_REUSEPORT_SOCKARRAY:
> + case __MAX_BPF_MAP_TYPE:
> default:
> break;
> }
> --
> 2.17.1
--
- Arnaldo
^ permalink raw reply
* Re: [PATCH v1 1/5] mdev: Introduce sha1 based mdev alias
From: Alex Williamson @ 2019-08-28 21:25 UTC (permalink / raw)
To: Parav Pandit; +Cc: jiri, kwankhede, cohuck, davem, kvm, linux-kernel, netdev
In-Reply-To: <20190827191654.41161-2-parav@mellanox.com>
On Tue, 27 Aug 2019 14:16:50 -0500
Parav Pandit <parav@mellanox.com> wrote:
> Some vendor drivers want an identifier for an mdev device that is
> shorter than the UUID, due to length restrictions in the consumers of
> that identifier.
>
> Add a callback that allows a vendor driver to request an alias of a
> specified length to be generated for an mdev device. If generated,
> that alias is checked for collisions.
>
> It is an optional attribute.
> mdev alias is generated using sha1 from the mdev name.
>
> Signed-off-by: Parav Pandit <parav@mellanox.com>
>
> ---
> Changelog:
>
> v0->v1:
> - Moved alias length check outside of the parent lock
> - Moved alias and digest allocation from kvzalloc to kzalloc
> - &alias[0] changed to alias
> - alias_length check is nested under get_alias_length callback check
> - Changed comments to start with an empty line
> - Fixed cleaunup of hash if mdev_bus_register() fails
> - Added comment where alias memory ownership is handed over to mdev device
> - Updated commit log to indicate motivation for this feature
> ---
> drivers/vfio/mdev/mdev_core.c | 110 ++++++++++++++++++++++++++++++-
> drivers/vfio/mdev/mdev_private.h | 5 +-
> drivers/vfio/mdev/mdev_sysfs.c | 13 ++--
> include/linux/mdev.h | 4 ++
> 4 files changed, 122 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
> index b558d4cfd082..62d29f57fe0c 100644
> --- a/drivers/vfio/mdev/mdev_core.c
> +++ b/drivers/vfio/mdev/mdev_core.c
> @@ -10,9 +10,11 @@
> #include <linux/module.h>
> #include <linux/device.h>
> #include <linux/slab.h>
> +#include <linux/mm.h>
> #include <linux/uuid.h>
> #include <linux/sysfs.h>
> #include <linux/mdev.h>
> +#include <crypto/hash.h>
>
> #include "mdev_private.h"
>
> @@ -27,6 +29,8 @@ static struct class_compat *mdev_bus_compat_class;
> static LIST_HEAD(mdev_list);
> static DEFINE_MUTEX(mdev_list_lock);
>
> +static struct crypto_shash *alias_hash;
> +
> struct device *mdev_parent_dev(struct mdev_device *mdev)
> {
> return mdev->parent->dev;
> @@ -150,6 +154,16 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
> if (!ops || !ops->create || !ops->remove || !ops->supported_type_groups)
> return -EINVAL;
>
> + if (ops->get_alias_length) {
> + unsigned int digest_size;
> + unsigned int aligned_len;
> +
> + aligned_len = roundup(ops->get_alias_length(), 2);
> + digest_size = crypto_shash_digestsize(alias_hash);
> + if (aligned_len / 2 > digest_size)
> + return -EINVAL;
> + }
> +
> dev = get_device(dev);
> if (!dev)
> return -EINVAL;
> @@ -259,6 +273,7 @@ static void mdev_device_free(struct mdev_device *mdev)
> mutex_unlock(&mdev_list_lock);
>
> dev_dbg(&mdev->dev, "MDEV: destroying\n");
> + kfree(mdev->alias);
> kfree(mdev);
> }
>
> @@ -269,18 +284,88 @@ static void mdev_device_release(struct device *dev)
> mdev_device_free(mdev);
> }
>
> -int mdev_device_create(struct kobject *kobj,
> - struct device *dev, const guid_t *uuid)
> +static const char *
> +generate_alias(const char *uuid, unsigned int max_alias_len)
> +{
> + struct shash_desc *hash_desc;
> + unsigned int digest_size;
> + unsigned char *digest;
> + unsigned int alias_len;
> + char *alias;
> + int ret = 0;
> +
> + /*
> + * Align to multiple of 2 as bin2hex will generate
> + * even number of bytes.
> + */
> + alias_len = roundup(max_alias_len, 2);
> + alias = kzalloc(alias_len + 1, GFP_KERNEL);
> + if (!alias)
> + return NULL;
> +
> + /* Allocate and init descriptor */
> + hash_desc = kvzalloc(sizeof(*hash_desc) +
> + crypto_shash_descsize(alias_hash),
> + GFP_KERNEL);
> + if (!hash_desc)
> + goto desc_err;
> +
> + hash_desc->tfm = alias_hash;
> +
> + digest_size = crypto_shash_digestsize(alias_hash);
> +
> + digest = kzalloc(digest_size, GFP_KERNEL);
> + if (!digest) {
> + ret = -ENOMEM;
> + goto digest_err;
> + }
> + crypto_shash_init(hash_desc);
> + crypto_shash_update(hash_desc, uuid, UUID_STRING_LEN);
> + crypto_shash_final(hash_desc, digest);
All of these can fail and many, if not most, of the callers appear
that they might test the return value. Thanks,
Alex
> + bin2hex(alias, digest, min_t(unsigned int, digest_size, alias_len / 2));
> + /*
> + * When alias length is odd, zero out and additional last byte
> + * that bin2hex has copied.
> + */
> + if (max_alias_len % 2)
> + alias[max_alias_len] = 0;
> +
> + kfree(digest);
> + kvfree(hash_desc);
> + return alias;
> +
> +digest_err:
> + kvfree(hash_desc);
> +desc_err:
> + kfree(alias);
> + return NULL;
> +}
> +
> +int mdev_device_create(struct kobject *kobj, struct device *dev,
> + const char *uuid_str, const guid_t *uuid)
> {
> int ret;
> struct mdev_device *mdev, *tmp;
> struct mdev_parent *parent;
> struct mdev_type *type = to_mdev_type(kobj);
> + const char *alias = NULL;
>
> parent = mdev_get_parent(type->parent);
> if (!parent)
> return -EINVAL;
>
> + if (parent->ops->get_alias_length) {
> + unsigned int alias_len;
> +
> + alias_len = parent->ops->get_alias_length();
> + if (alias_len) {
> + alias = generate_alias(uuid_str, alias_len);
> + if (!alias) {
> + ret = -ENOMEM;
> + goto alias_fail;
> + }
> + }
> + }
> mutex_lock(&mdev_list_lock);
>
> /* Check for duplicate */
> @@ -300,6 +385,12 @@ int mdev_device_create(struct kobject *kobj,
> }
>
> guid_copy(&mdev->uuid, uuid);
> + mdev->alias = alias;
> + /*
> + * At this point alias memory is owned by the mdev.
> + * Mark it NULL, so that only mdev can free it.
> + */
> + alias = NULL;
> list_add(&mdev->next, &mdev_list);
> mutex_unlock(&mdev_list_lock);
>
> @@ -346,6 +437,8 @@ int mdev_device_create(struct kobject *kobj,
> up_read(&parent->unreg_sem);
> put_device(&mdev->dev);
> mdev_fail:
> + kfree(alias);
> +alias_fail:
> mdev_put_parent(parent);
> return ret;
> }
> @@ -406,7 +499,17 @@ EXPORT_SYMBOL(mdev_get_iommu_device);
>
> static int __init mdev_init(void)
> {
> - return mdev_bus_register();
> + int ret;
> +
> + alias_hash = crypto_alloc_shash("sha1", 0, 0);
> + if (!alias_hash)
> + return -ENOMEM;
> +
> + ret = mdev_bus_register();
> + if (ret)
> + crypto_free_shash(alias_hash);
> +
> + return ret;
> }
>
> static void __exit mdev_exit(void)
> @@ -415,6 +518,7 @@ static void __exit mdev_exit(void)
> class_compat_unregister(mdev_bus_compat_class);
>
> mdev_bus_unregister();
> + crypto_free_shash(alias_hash);
> }
>
> module_init(mdev_init)
> diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
> index 7d922950caaf..cf1c0d9842c6 100644
> --- a/drivers/vfio/mdev/mdev_private.h
> +++ b/drivers/vfio/mdev/mdev_private.h
> @@ -33,6 +33,7 @@ struct mdev_device {
> struct kobject *type_kobj;
> struct device *iommu_device;
> bool active;
> + const char *alias;
> };
>
> #define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
> @@ -57,8 +58,8 @@ void parent_remove_sysfs_files(struct mdev_parent *parent);
> int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
> void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
>
> -int mdev_device_create(struct kobject *kobj,
> - struct device *dev, const guid_t *uuid);
> +int mdev_device_create(struct kobject *kobj, struct device *dev,
> + const char *uuid_str, const guid_t *uuid);
> int mdev_device_remove(struct device *dev);
>
> #endif /* MDEV_PRIVATE_H */
> diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
> index 7570c7602ab4..43afe0e80b76 100644
> --- a/drivers/vfio/mdev/mdev_sysfs.c
> +++ b/drivers/vfio/mdev/mdev_sysfs.c
> @@ -63,15 +63,18 @@ static ssize_t create_store(struct kobject *kobj, struct device *dev,
> return -ENOMEM;
>
> ret = guid_parse(str, &uuid);
> - kfree(str);
> if (ret)
> - return ret;
> + goto err;
>
> - ret = mdev_device_create(kobj, dev, &uuid);
> + ret = mdev_device_create(kobj, dev, str, &uuid);
> if (ret)
> - return ret;
> + goto err;
>
> - return count;
> + ret = count;
> +
> +err:
> + kfree(str);
> + return ret;
> }
>
> MDEV_TYPE_ATTR_WO(create);
> diff --git a/include/linux/mdev.h b/include/linux/mdev.h
> index 0ce30ca78db0..f036fe9854ee 100644
> --- a/include/linux/mdev.h
> +++ b/include/linux/mdev.h
> @@ -72,6 +72,9 @@ struct device *mdev_get_iommu_device(struct device *dev);
> * @mmap: mmap callback
> * @mdev: mediated device structure
> * @vma: vma structure
> + * @get_alias_length: Generate alias for the mdevs of this parent based on the
> + * mdev device name when it returns non zero alias length.
> + * It is optional.
> * Parent device that support mediated device should be registered with mdev
> * module with mdev_parent_ops structure.
> **/
> @@ -92,6 +95,7 @@ struct mdev_parent_ops {
> long (*ioctl)(struct mdev_device *mdev, unsigned int cmd,
> unsigned long arg);
> int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
> + unsigned int (*get_alias_length)(void);
> };
>
> /* interface for exporting mdev supported type attributes */
^ permalink raw reply
* Re: [PATCH net] netdevsim: Restore per-network namespace accounting for fib entries
From: David Ahern @ 2019-08-28 21:26 UTC (permalink / raw)
To: Jiri Pirko, David Ahern; +Cc: davem, netdev
In-Reply-To: <20190828103718.GF2312@nanopsycho>
On 8/28/19 4:37 AM, Jiri Pirko wrote:
> Tue, Aug 06, 2019 at 09:15:17PM CEST, dsahern@kernel.org wrote:
>> From: David Ahern <dsahern@gmail.com>
>>
>> Prior to the commit in the fixes tag, the resource controller in netdevsim
>> tracked fib entries and rules per network namespace. Restore that behavior.
>
> David, please help me understand. If the counters are per-device, not
> per-netns, they are both the same. If we have device (devlink instance)
> is in a netns and take only things happening in this netns into account,
> it should count exactly the same amount of fib entries, doesn't it?
if you are only changing where the counters are stored - net_generic vs
devlink private - then yes, they should be equivalent.
>
> I re-thinked the devlink netns patchset and currently I'm going in
> slightly different direction. I'm having netns as an attribute of
> devlink reload. So all the port netdevices and everything gets
> re-instantiated into new netns. Works fine with mlxsw. There we also
> re-register the fib notifier.
>
> I think that this can work for your usecase in netdevsim too:
> 1) devlink instance is registering a fib notifier to track all fib
> entries in a namespace it belongs to. The counters are per-device -
> counting fib entries in a namespace the device is in.
> 2) another devlink instance can do the same tracking in the same
> namespace. No problem, it's a separate counter, but the numbers are
> the same. One can set different limits to different devlink
> instances, but you can have only one. That is the bahaviour you have
> now.
> 3) on devlink reload, netdevsim re-instantiates ports and re-registers
> fib notifier
> 4) on devlink reload with netns change, all should be fine as the
> re-registered fib nofitier replays the entries. The ports are
> re-instatiated in new netns.
>
> This way, we would get consistent behaviour between netdevsim and real
> devices (mlxsw), correct devlink-netns implementation (you also
> suggested to move ports to the namespace). Everyone should be happy.
>
> What do you think?
>
Right now, registering the fib notifier walks all namespaces. That is
not a scalable solution. Are you changing that to replay only a given
netns? Are you changing the notifiers to be per-namespace?
Also, you are still allowing devlink instances to be created within a
namespace?
^ permalink raw reply
* Re: [PATCH bpf-next 01/10] bpf: introduce __MAX_BPF_PROG_TYPE and __MAX_BPF_MAP_TYPE enum values
From: Alexei Starovoitov @ 2019-08-28 21:33 UTC (permalink / raw)
To: Julia Kartseva; +Cc: rdna, bpf, ast, daniel, netdev, kernel-team
In-Reply-To: <43989d37be938b7d284028481e63df0a0471e29f.1567024943.git.hex@fb.com>
On Wed, Aug 28, 2019 at 02:03:04PM -0700, Julia Kartseva wrote:
> Similar to __MAX_BPF_ATTACH_TYPE identifying the number of elements in
> bpf_attach_type enum, add tailing enum values __MAX_BPF_PROG_TYPE
> and __MAX_BPF_MAP_TYPE to simplify e.g. iteration over enums values in
> the case when new values are added.
>
> Signed-off-by: Julia Kartseva <hex@fb.com>
> ---
> include/uapi/linux/bpf.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 5d2fb183ee2d..9b681bb82211 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -136,8 +136,11 @@ enum bpf_map_type {
> BPF_MAP_TYPE_STACK,
> BPF_MAP_TYPE_SK_STORAGE,
> BPF_MAP_TYPE_DEVMAP_HASH,
> + __MAX_BPF_MAP_TYPE
> };
>
> +#define MAX_BPF_MAP_TYPE __MAX_BPF_MAP_TYPE
> +
> /* Note that tracing related programs such as
> * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
> * are not subject to a stable API since kernel internal data
> @@ -173,8 +176,11 @@ enum bpf_prog_type {
> BPF_PROG_TYPE_CGROUP_SYSCTL,
> BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
> BPF_PROG_TYPE_CGROUP_SOCKOPT,
> + __MAX_BPF_PROG_TYPE
> };
>
> +#define MAX_BPF_PROG_TYPE __MAX_BPF_PROG_TYPE
> +
This came up before and my position is still the same.
I'm against this type of band-aid in uapi.
'bpftool feature probe' can easily discover all supported
prog and map types already.
^ permalink raw reply
* Re: [PATCH v1 1/5] mdev: Introduce sha1 based mdev alias
From: Alex Williamson @ 2019-08-28 21:34 UTC (permalink / raw)
To: Parav Pandit; +Cc: jiri, kwankhede, cohuck, davem, kvm, linux-kernel, netdev
In-Reply-To: <20190828152544.16ba2617@x1.home>
On Wed, 28 Aug 2019 15:25:44 -0600
Alex Williamson <alex.williamson@redhat.com> wrote:
> On Tue, 27 Aug 2019 14:16:50 -0500
> Parav Pandit <parav@mellanox.com> wrote:
> > module_init(mdev_init)
> > diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
> > index 7d922950caaf..cf1c0d9842c6 100644
> > --- a/drivers/vfio/mdev/mdev_private.h
> > +++ b/drivers/vfio/mdev/mdev_private.h
> > @@ -33,6 +33,7 @@ struct mdev_device {
> > struct kobject *type_kobj;
> > struct device *iommu_device;
> > bool active;
> > + const char *alias;
Nit, put this above active to avoid creating a hole in the structure.
Thanks,
Alex
^ permalink raw reply
* Re: [PATCH v1 2/5] mdev: Make mdev alias unique among all mdevs
From: Alex Williamson @ 2019-08-28 21:36 UTC (permalink / raw)
To: Parav Pandit; +Cc: jiri, kwankhede, cohuck, davem, kvm, linux-kernel, netdev
In-Reply-To: <20190827191654.41161-3-parav@mellanox.com>
On Tue, 27 Aug 2019 14:16:51 -0500
Parav Pandit <parav@mellanox.com> wrote:
> Mdev alias should be unique among all the mdevs, so that when such alias
> is used by the mdev users to derive other objects, there is no
> collision in a given system.
>
> Signed-off-by: Parav Pandit <parav@mellanox.com>
>
> ---
> Changelog:
> v0->v1:
> - Fixed inclusiong of alias for NULL check
> - Added ratelimited debug print for sha1 hash collision error
> ---
> drivers/vfio/mdev/mdev_core.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
> index 62d29f57fe0c..4b9899e40665 100644
> --- a/drivers/vfio/mdev/mdev_core.c
> +++ b/drivers/vfio/mdev/mdev_core.c
> @@ -375,6 +375,13 @@ int mdev_device_create(struct kobject *kobj, struct device *dev,
> ret = -EEXIST;
> goto mdev_fail;
> }
> + if (tmp->alias && alias && strcmp(tmp->alias, alias) == 0) {
Nit, test if the device we adding has an alias before the device we're
testing against. The compiler can better optimize keeping alias hot.
Thanks,
Alex
> + mutex_unlock(&mdev_list_lock);
> + ret = -EEXIST;
> + dev_dbg_ratelimited(dev, "Hash collision in alias creation for UUID %pUl\n",
> + uuid);
> + goto mdev_fail;
> + }
> }
>
> mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
^ permalink raw reply
* Re: [PATCH v2] riscv: add support for SECCOMP and SECCOMP_FILTER
From: David Abdurachmanov @ 2019-08-28 21:37 UTC (permalink / raw)
To: Kees Cook
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Oleg Nesterov,
Andy Lutomirski, Will Drewry, Shuah Khan, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
David Abdurachmanov, Thomas Gleixner, Allison Randal,
Alexios Zavras, Anup Patel, Vincent Chen, Alan Kao, linux-riscv,
linux-kernel, linux-kselftest, netdev, bpf, me
In-Reply-To: <201908251451.73C6812E8@keescook>
On Wed, Aug 28, 2019 at 10:36 AM Kees Cook <keescook@chromium.org> wrote:
>
> On Thu, Aug 22, 2019 at 01:55:22PM -0700, David Abdurachmanov wrote:
> > This patch was extensively tested on Fedora/RISCV (applied by default on
> > top of 5.2-rc7 kernel for <2 months). The patch was also tested with 5.3-rc
> > on QEMU and SiFive Unleashed board.
>
> Oops, I see the mention of QEMU here. Where's the best place to find
> instructions on creating a qemu riscv image/environment?
Examples from what I personally use:
https://github.com/riscv/meta-riscv
https://fedoraproject.org/wiki/Architectures/RISC-V/Installing#Boot_with_libvirt
(might be outdated)
If you are running machine with a properly working libvirt/QEMU setup:
VIRTBUILDER_IMAGE=fedora-rawhide-developer-20190703n0
FIRMWARE=fw_payload-uboot-qemu-virt-smode.elf
wget https://dl.fedoraproject.org/pub/alt/risc-v/disk-images/fedora/rawhide/20190703.n.0/Developer/$FIRMWARE
echo riscv > /tmp/rootpw
virt-builder \
--verbose \
--source https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/index
\
--no-check-signature \
--arch riscv64 \
--size 10G \
--format raw \
--hostname fedora-riscv \
-o disk \
--root-password file:/tmp/rootpw \
${VIRTBUILDER_IMAGE}
sudo virt-install \
--name fedora-riscv \
--arch riscv64 \
--vcpus 4 \
--memory 3048 \
--import \
--disk path=$PWD/disk \
--boot kernel=$PWD/${FIRMWARE} \
--network network=default \
--graphics none \
--serial log.file=/tmp/fedora-riscv.serial.log \
--noautoconsole
The following does incl. SECCOMP v2 patch on top of 5.2-rc7 kernel.
>
> > There is one failing kernel selftest: global.user_notification_signal
>
> This test has been fragile (and is not arch-specific), so as long as
> everything else is passing, I would call this patch ready to go. :)
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
>
> --
> Kees Cook
^ permalink raw reply
* Re: [PATCH v2] riscv: add support for SECCOMP and SECCOMP_FILTER
From: David Abdurachmanov @ 2019-08-28 21:39 UTC (permalink / raw)
To: Kees Cook
Cc: Paul Walmsley, Tycho Andersen, Palmer Dabbelt, Albert Ou,
Oleg Nesterov, Andy Lutomirski, Will Drewry, Shuah Khan,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, David Abdurachmanov, Thomas Gleixner,
Allison Randal, Alexios Zavras, Anup Patel, Vincent Chen,
Alan Kao, linux-riscv, linux-kernel, linux-kselftest, netdev, bpf,
me
In-Reply-To: <201908251446.04BCB8C@keescook>
On Wed, Aug 28, 2019 at 10:36 AM Kees Cook <keescook@chromium.org> wrote:
>
> On Fri, Aug 23, 2019 at 05:30:53PM -0700, Paul Walmsley wrote:
> > On Thu, 22 Aug 2019, David Abdurachmanov wrote:
> >
> > > There is one failing kernel selftest: global.user_notification_signal
> >
> > Is this the only failing test? Or are the rest of the selftests skipped
> > when this test fails, and no further tests are run, as seems to be shown
> > here:
> >
> > https://lore.kernel.org/linux-riscv/CADnnUqcmDMRe1f+3jG8SPR6jRrnBsY8VVD70VbKEm0NqYeoicA@mail.gmail.com/
> >
> > For example, looking at the source, I'd naively expect to see the
> > user_notification_closed_listener test result -- which follows right
> > after the failing test in the selftest source. But there aren't any
> > results?
> >
> > Also - could you follow up with the author of this failing test to see if
> > we can get some more clarity about what might be going wrong here? It
> > appears that the failing test was added in commit 6a21cc50f0c7f ("seccomp:
> > add a return code to trap to userspace") by Tycho Andersen
> > <tycho@tycho.ws>.
>
> So, the original email says the riscv series is tested on top of 5.2-rc7,
> but just for fun, can you confirm that you're building a tree that includes
> 9dd3fcb0ab73 ("selftests/seccomp: Handle namespace failures gracefully")? I
> assume it does, but I suspect something similar is happening, where the
> environment is slightly different than expected and the test stalls.
>
> Does it behave the same way under emulation (i.e. can I hope to
> reproduce this myself?)
This was tested in 5.2-rc7 and later in 5.3-rc with the same behavior.
Also VM or physical HW doesn't matter, same result.
>
> --
> Kees Cook
^ permalink raw reply
* Re: [PATCH net-next] ipv6: shrink struct ipv6_mc_socklist
From: David Miller @ 2019-08-28 21:43 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet
In-Reply-To: <20190827070812.150106-1-edumazet@google.com>
From: Eric Dumazet <edumazet@google.com>
Date: Tue, 27 Aug 2019 00:08:12 -0700
> Remove two holes on 64bit arches, to bring the size
> to one cache line exactly.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Applied.
^ permalink raw reply
* Re: [PATCH net v2] net/sched: pfifo_fast: fix wrong dereference when qdisc is reset
From: David Miller @ 2019-08-28 21:46 UTC (permalink / raw)
To: dcaratti; +Cc: xiyou.wangcong, jhs, jiri, netdev, pabeni, sbrivio, shuali
In-Reply-To: <783231162b9d32faaf5df34ad8ad437b0031bd31.1566901438.git.dcaratti@redhat.com>
From: Davide Caratti <dcaratti@redhat.com>
Date: Tue, 27 Aug 2019 12:29:09 +0200
> Now that 'TCQ_F_CPUSTATS' bit can be cleared, depending on the value of
> 'TCQ_F_NOLOCK' bit in the parent qdisc, we need to be sure that per-cpu
> counters are present when 'reset()' is called for pfifo_fast qdiscs.
> Otherwise, the following script:
...
> can generate the following splat:
...
> Fix this by testing the value of 'TCQ_F_CPUSTATS' bit in 'qdisc->flags',
> before dereferencing 'qdisc->cpu_qstats'.
>
> Changes since v1:
> - coding style improvements, thanks to Stefano Brivio
>
> Fixes: 8a53e616de29 ("net: sched: when clearing NOLOCK, clear TCQ_F_CPUSTATS, too")
> CC: Paolo Abeni <pabeni@redhat.com>
> Reported-by: Li Shuang <shuali@redhat.com>
> Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Applied and queued up for v5.2 -stable.
^ permalink raw reply
* Re: [PATCH net] mld: fix memory leak in mld_del_delrec()
From: David Miller @ 2019-08-28 21:48 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet, syzkaller
In-Reply-To: <20190827103312.180258-1-edumazet@google.com>
From: Eric Dumazet <edumazet@google.com>
Date: Tue, 27 Aug 2019 03:33:12 -0700
> Similar to the fix done for IPv4 in commit e5b1c6c6277d
> ("igmp: fix memory leak in igmpv3_del_delrec()"), we need to
> make sure mca_tomb and mca_sources are not blindly overwritten.
>
> Using swap() then a call to ip6_mc_clear_src() will take care
> of the missing free.
...
> Fixes: 1666d49e1d41 ("mld: do not remove mld souce list info when set link down")
> Fixes: 9c8bb163ae78 ("igmp, mld: Fix memory leak in igmpv3/mld_del_delrec()")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>
Applied and queued up for -stable.
^ permalink raw reply
* Re: [PATCH] arcnet: capmode: remove redundant assignment to pointer pkt
From: David Miller @ 2019-08-28 21:49 UTC (permalink / raw)
To: colin.king; +Cc: m.grzeschik, netdev, kernel-janitors, linux-kernel
In-Reply-To: <20190827112954.26677-1-colin.king@canonical.com>
Please fix the typo spotted by Sergei.
^ permalink raw reply
* Re: [PATCH] wimax/i2400m: remove redundant assignment to variable result
From: David Miller @ 2019-08-28 21:49 UTC (permalink / raw)
To: colin.king
Cc: inaky.perez-gonzalez, linux-wimax, netdev, kernel-janitors,
linux-kernel
In-Reply-To: <20190827114739.27305-1-colin.king@canonical.com>
From: Colin King <colin.king@canonical.com>
Date: Tue, 27 Aug 2019 12:47:39 +0100
> From: Colin Ian King <colin.king@canonical.com>
>
> Variable result is being assigned a value that is never read and result
> is being re-assigned a little later on. The assignment is redundant
> and hence can be removed.
>
> Addresses-Coverity: ("Ununsed value")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Applied to net-next.
^ permalink raw reply
* Re: [PATCH net-next] phy: mdio-bcm-iproc: use devm_platform_ioremap_resource() to simplify code
From: David Miller @ 2019-08-28 21:51 UTC (permalink / raw)
To: yuehaibing
Cc: andrew, f.fainelli, hkallweit1, rjui, sbranden,
bcm-kernel-feedback-list, netdev, linux-arm-kernel, linux-kernel
In-Reply-To: <20190827134616.11396-1-yuehaibing@huawei.com>
From: YueHaibing <yuehaibing@huawei.com>
Date: Tue, 27 Aug 2019 21:46:16 +0800
> Use devm_platform_ioremap_resource() to simplify the code a bit.
> This is detected by coccinelle.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Applied.
^ permalink raw reply
* Re: [PATCH net-next] phy: mdio-hisi-femac: use devm_platform_ioremap_resource() to simplify code
From: David Miller @ 2019-08-28 21:51 UTC (permalink / raw)
To: yuehaibing; +Cc: andrew, f.fainelli, hkallweit1, netdev, linux-kernel
In-Reply-To: <20190827134722.14332-1-yuehaibing@huawei.com>
From: YueHaibing <yuehaibing@huawei.com>
Date: Tue, 27 Aug 2019 21:47:22 +0800
> Use devm_platform_ioremap_resource() to simplify the code a bit.
> This is detected by coccinelle.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Applied.
^ permalink raw reply
* Re: [PATCH net-next] phy: mdio-moxart: use devm_platform_ioremap_resource() to simplify code
From: David Miller @ 2019-08-28 21:51 UTC (permalink / raw)
To: yuehaibing; +Cc: andrew, f.fainelli, hkallweit1, netdev, linux-kernel
In-Reply-To: <20190827134804.14888-1-yuehaibing@huawei.com>
From: YueHaibing <yuehaibing@huawei.com>
Date: Tue, 27 Aug 2019 21:48:04 +0800
> Use devm_platform_ioremap_resource() to simplify the code a bit.
> This is detected by coccinelle.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Applied.
^ permalink raw reply
* Re: [PATCH net-next] phy: mdio-sun4i: use devm_platform_ioremap_resource() to simplify code
From: David Miller @ 2019-08-28 21:51 UTC (permalink / raw)
To: yuehaibing
Cc: andrew, f.fainelli, hkallweit1, mripard, wens, netdev,
linux-arm-kernel, linux-kernel
In-Reply-To: <20190827135032.14620-1-yuehaibing@huawei.com>
From: YueHaibing <yuehaibing@huawei.com>
Date: Tue, 27 Aug 2019 21:50:32 +0800
> Use devm_platform_ioremap_resource() to simplify the code a bit.
> This is detected by coccinelle.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Applied.
^ permalink raw reply
* Re: [PATCH net-next] phy: mdio-mux-meson-g12a: use devm_platform_ioremap_resource() to simplify code
From: David Miller @ 2019-08-28 21:51 UTC (permalink / raw)
To: yuehaibing
Cc: andrew, f.fainelli, hkallweit1, khilman, netdev, linux-arm-kernel,
linux-amlogic, linux-kernel
In-Reply-To: <20190827134940.14944-1-yuehaibing@huawei.com>
From: YueHaibing <yuehaibing@huawei.com>
Date: Tue, 27 Aug 2019 21:49:40 +0800
> Use devm_platform_ioremap_resource() to simplify the code a bit.
> This is detected by coccinelle.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Applied.
^ permalink raw reply
* Re: [PATCH v2 0/3] Add NETIF_F_HW_BR_CAP feature
From: Horatiu Vultur @ 2019-08-28 21:53 UTC (permalink / raw)
To: Andrew Lunn
Cc: roopa, nikolay, davem, UNGLinuxDriver, alexandre.belloni,
allan.nielsen, f.fainelli, netdev, linux-kernel, bridge
In-Reply-To: <20190827131824.GC11471@lunn.ch>
The 08/27/2019 15:18, Andrew Lunn wrote:
> External E-Mail
>
>
> > That sounds like a great idea. I was expecting to add this logic in the
> > set_rx_mode function of the driver. But unfortunetly, I got the calls to
> > this function before the dev->promiscuity is updated or not to get the
> > call at all. For example in case the port is member of a bridge and I try
> > to enable the promisc mode.
>
> Hi Horatiu
Hi Andrew,
>
> What about the notifier? Is it called in all the conditions you need
> to know about?
I had a look also over this but without any luck. I can get good
information from this, like knowing when a port is added or removed from
the bridge(NETDEV_CHANGEUPPER). But not in case the promisc is change by
an application(eg. tcpdump). In this case if port is part of the bridge
and then promisc is enable, then there is no callback to the driver or
any notifications.
>
> Or, you could consider adding a new switchdev call to pass this
> information to any switchdev driver which is interested in the
> information.
Having this new switchdev call and listening for NETDEV_CHANGEUPPER
seems to be enough to know when a port needs to go in promisc mode.
>
> At the moment, the DSA driver core does not pass onto the driver it
> should put a port into promisc mode. So pcap etc, will only see
> traffic directed to the CPU, not all the traffic ingressing the
> interface. If you put the needed core infrastructure into place, we
> could plumb it down from the DSA core to DSA drivers.
>
> Having said that, i don't actually know if the Marvell switches
> support this. Forward using the ATU and send a copy to the CPU? What
> switches tend to support is port mirroring, sending all the traffic
> out another port. A couple of DSA drivers support that, via TC.
>
> Andrew
>
--
/Horatiu
^ permalink raw reply
* Re: [PATCH V3 net 1/2] openvswitch: Properly set L4 keys on "later" IP fragments
From: David Miller @ 2019-08-28 21:54 UTC (permalink / raw)
To: gvrose8192; +Cc: netdev, pshelar, joe
In-Reply-To: <1566917890-22304-1-git-send-email-gvrose8192@gmail.com>
From: Greg Rose <gvrose8192@gmail.com>
Date: Tue, 27 Aug 2019 07:58:09 -0700
> When IP fragments are reassembled before being sent to conntrack, the
> key from the last fragment is used. Unless there are reordering
> issues, the last fragment received will not contain the L4 ports, so the
> key for the reassembled datagram won't contain them. This patch updates
> the key once we have a reassembled datagram.
>
> The handle_fragments() function works on L3 headers so we pull the L3/L4
> flow key update code from key_extract into a new function
> 'key_extract_l3l4'. Then we add a another new function
> ovs_flow_key_update_l3l4() and export it so that it is accessible by
> handle_fragments() for conntrack packet reassembly.
>
> Co-authored by: Justin Pettit <jpettit@ovn.org>
> Signed-off-by: Greg Rose <gvrose8192@gmail.com>
Applied with Co-authored-by fixed.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox