All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs
@ 2022-02-02 22:59 Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 1/6] libbpf: stop using deprecated bpf_map__is_offload_neutral() Andrii Nakryiko
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Andrii Nakryiko @ 2022-02-02 22:59 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Clean up remaining missed uses of deprecated libbpf APIs across samples/bpf,
selftests/bpf, libbpf, and bpftool.

Also fix uninit variable warning in bpftool.

Andrii Nakryiko (6):
  libbpf: stop using deprecated bpf_map__is_offload_neutral()
  bpftool: stop supporting BPF offload-enabled feature probing
  bpftool: fix uninit variable compilation warning
  selftests/bpf: remove usage of deprecated feature probing APIs
  selftests/bpf: redo the switch to new libbpf XDP APIs
  samples/bpf: get rid of bpf_prog_load_xattr() use

 samples/bpf/xdp1_user.c                       | 16 ++++++----
 samples/bpf/xdp_adjust_tail_user.c            | 17 +++++++----
 samples/bpf/xdp_fwd_user.c                    | 15 ++++++----
 samples/bpf/xdp_router_ipv4_user.c            | 17 ++++++-----
 samples/bpf/xdp_rxq_info_user.c               | 16 ++++++----
 samples/bpf/xdp_tx_iptunnel_user.c            | 17 ++++++-----
 tools/bpf/bpftool/common.c                    |  2 +-
 tools/bpf/bpftool/feature.c                   | 29 +++++++++++--------
 tools/lib/bpf/libbpf.c                        |  2 +-
 .../selftests/bpf/prog_tests/xdp_attach.c     | 29 +++++++++----------
 .../bpf/prog_tests/xdp_cpumap_attach.c        |  8 ++---
 .../bpf/prog_tests/xdp_devmap_attach.c        |  8 ++---
 .../selftests/bpf/prog_tests/xdp_info.c       | 14 ++++-----
 .../selftests/bpf/prog_tests/xdp_link.c       | 26 ++++++++---------
 tools/testing/selftests/bpf/test_maps.c       |  2 +-
 tools/testing/selftests/bpf/test_verifier.c   |  4 +--
 .../selftests/bpf/xdp_redirect_multi.c        |  8 ++---
 tools/testing/selftests/bpf/xdping.c          |  4 +--
 18 files changed, 132 insertions(+), 102 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH bpf-next 1/6] libbpf: stop using deprecated bpf_map__is_offload_neutral()
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
@ 2022-02-02 22:59 ` Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing Andrii Nakryiko
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andrii Nakryiko @ 2022-02-02 22:59 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Open-code bpf_map__is_offload_neutral() logic in one place in
to-be-deprecated bpf_prog_load_xattr2.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 1b0936b016d9..81605de8654e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9505,7 +9505,7 @@ static int bpf_prog_load_xattr2(const struct bpf_prog_load_attr *attr,
 	}
 
 	bpf_object__for_each_map(map, obj) {
-		if (!bpf_map__is_offload_neutral(map))
+		if (map->def.type != BPF_MAP_TYPE_PERF_EVENT_ARRAY)
 			map->map_ifindex = attr->ifindex;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 1/6] libbpf: stop using deprecated bpf_map__is_offload_neutral() Andrii Nakryiko
@ 2022-02-02 22:59 ` Andrii Nakryiko
  2022-02-03 10:24   ` Quentin Monnet
  2022-02-02 22:59 ` [PATCH bpf-next 3/6] bpftool: fix uninit variable compilation warning Andrii Nakryiko
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Andrii Nakryiko @ 2022-02-02 22:59 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team, Quentin Monnet

libbpf 1.0 is not going to support passing ifindex to BPF
prog/map/helper feature probing APIs. Remove the support for BPF offload
feature probing.

Cc: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/bpf/bpftool/feature.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index e999159fa28d..9c894b1447de 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -487,17 +487,12 @@ probe_prog_type(enum bpf_prog_type prog_type, bool *supported_types,
 	size_t maxlen;
 	bool res;
 
-	if (ifindex)
-		/* Only test offload-able program types */
-		switch (prog_type) {
-		case BPF_PROG_TYPE_SCHED_CLS:
-		case BPF_PROG_TYPE_XDP:
-			break;
-		default:
-			return;
-		}
+	if (ifindex) {
+		p_info("BPF offload feature probing is not supported");
+		return;
+	}
 
-	res = bpf_probe_prog_type(prog_type, ifindex);
+	res = libbpf_probe_bpf_prog_type(prog_type, NULL);
 #ifdef USE_LIBCAP
 	/* Probe may succeed even if program load fails, for unprivileged users
 	 * check that we did not fail because of insufficient permissions
@@ -535,7 +530,12 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix,
 	size_t maxlen;
 	bool res;
 
-	res = bpf_probe_map_type(map_type, ifindex);
+	if (ifindex) {
+		p_info("BPF offload feature probing is not supported");
+		return;
+	}
+
+	res = libbpf_probe_bpf_map_type(map_type, NULL);
 
 	/* Probe result depends on the success of map creation, no additional
 	 * check required for unprivileged users
@@ -567,7 +567,12 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
 	bool res = false;
 
 	if (supported_type) {
-		res = bpf_probe_helper(id, prog_type, ifindex);
+		if (ifindex) {
+			p_info("BPF offload feature probing is not supported");
+			return;
+		}
+
+		res = libbpf_probe_bpf_helper(prog_type, id, NULL);
 #ifdef USE_LIBCAP
 		/* Probe may succeed even if program load fails, for
 		 * unprivileged users check that we did not fail because of
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH bpf-next 3/6] bpftool: fix uninit variable compilation warning
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 1/6] libbpf: stop using deprecated bpf_map__is_offload_neutral() Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing Andrii Nakryiko
@ 2022-02-02 22:59 ` Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 4/6] selftests/bpf: remove usage of deprecated feature probing APIs Andrii Nakryiko
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andrii Nakryiko @ 2022-02-02 22:59 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Newer GCC complains about capturing the address of unitialized variable.
While there is nothing wrong with the code (the variable is filled out
by the kernel), initialize the variable anyway to make compiler happy.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/bpf/bpftool/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 111dff809c7b..606743c6db41 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -310,7 +310,7 @@ void get_prog_full_name(const struct bpf_prog_info *prog_info, int prog_fd,
 {
 	const char *prog_name = prog_info->name;
 	const struct btf_type *func_type;
-	const struct bpf_func_info finfo;
+	const struct bpf_func_info finfo = {};
 	struct bpf_prog_info info = {};
 	__u32 info_len = sizeof(info);
 	struct btf *prog_btf = NULL;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH bpf-next 4/6] selftests/bpf: remove usage of deprecated feature probing APIs
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
                   ` (2 preceding siblings ...)
  2022-02-02 22:59 ` [PATCH bpf-next 3/6] bpftool: fix uninit variable compilation warning Andrii Nakryiko
@ 2022-02-02 22:59 ` Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 5/6] selftests/bpf: redo the switch to new libbpf XDP APIs Andrii Nakryiko
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andrii Nakryiko @ 2022-02-02 22:59 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Switch to libbpf_probe_*() APIs instead of the deprecated ones.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/testing/selftests/bpf/test_maps.c     | 2 +-
 tools/testing/selftests/bpf/test_verifier.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index 50f7e74ca0b9..cbebfaa7c1e8 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -738,7 +738,7 @@ static void test_sockmap(unsigned int tasks, void *data)
 			    sizeof(key), sizeof(value),
 			    6, NULL);
 	if (fd < 0) {
-		if (!bpf_probe_map_type(BPF_MAP_TYPE_SOCKMAP, 0)) {
+		if (!libbpf_probe_bpf_map_type(BPF_MAP_TYPE_SOCKMAP, NULL)) {
 			printf("%s SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP)\n",
 			       __func__);
 			skips++;
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 29bbaa58233c..c73fbada5e67 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -456,7 +456,7 @@ static int probe_filter_length(const struct bpf_insn *fp)
 
 static bool skip_unsupported_map(enum bpf_map_type map_type)
 {
-	if (!bpf_probe_map_type(map_type, 0)) {
+	if (!libbpf_probe_bpf_map_type(map_type, NULL)) {
 		printf("SKIP (unsupported map type %d)\n", map_type);
 		skips++;
 		return true;
@@ -1176,7 +1176,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
 	 * bpf_probe_prog_type won't give correct answer
 	 */
 	if (fd_prog < 0 && prog_type != BPF_PROG_TYPE_TRACING &&
-	    !bpf_probe_prog_type(prog_type, 0)) {
+	    !libbpf_probe_bpf_prog_type(prog_type, NULL)) {
 		printf("SKIP (unsupported program type %d)\n", prog_type);
 		skips++;
 		goto close_fds;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH bpf-next 5/6] selftests/bpf: redo the switch to new libbpf XDP APIs
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
                   ` (3 preceding siblings ...)
  2022-02-02 22:59 ` [PATCH bpf-next 4/6] selftests/bpf: remove usage of deprecated feature probing APIs Andrii Nakryiko
@ 2022-02-02 22:59 ` Andrii Nakryiko
  2022-02-02 22:59 ` [PATCH bpf-next 6/6] samples/bpf: get rid of bpf_prog_load_xattr() use Andrii Nakryiko
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andrii Nakryiko @ 2022-02-02 22:59 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Switch to using new bpf_xdp_*() APIs across all selftests. Take
advantage of a more straightforward and user-friendly semantics of
old_prog_fd (0 means "don't care") in few places.

This is a redo of 544356524dd6 ("selftests/bpf: switch to new libbpf XDP
APIs"), which was previously reverted to minimize conflicts during bpf
and bpf-next tree merge.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 .../selftests/bpf/prog_tests/xdp_attach.c     | 29 +++++++++----------
 .../bpf/prog_tests/xdp_cpumap_attach.c        |  8 ++---
 .../bpf/prog_tests/xdp_devmap_attach.c        |  8 ++---
 .../selftests/bpf/prog_tests/xdp_info.c       | 14 ++++-----
 .../selftests/bpf/prog_tests/xdp_link.c       | 26 ++++++++---------
 .../selftests/bpf/xdp_redirect_multi.c        |  8 ++---
 tools/testing/selftests/bpf/xdping.c          |  4 +--
 7 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_attach.c
index c6fa390e3aa1..62aa3edda5e6 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_attach.c
@@ -11,8 +11,7 @@ void serial_test_xdp_attach(void)
 	const char *file = "./test_xdp.o";
 	struct bpf_prog_info info = {};
 	int err, fd1, fd2, fd3;
-	DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts,
-			    .old_fd = -1);
+	LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
 
 	len = sizeof(info);
 
@@ -38,49 +37,47 @@ void serial_test_xdp_attach(void)
 	if (CHECK_FAIL(err))
 		goto out_2;
 
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd1, XDP_FLAGS_REPLACE,
-				       &opts);
+	err = bpf_xdp_attach(IFINDEX_LO, fd1, XDP_FLAGS_REPLACE, &opts);
 	if (CHECK(err, "load_ok", "initial load failed"))
 		goto out_close;
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
 	if (CHECK(err || id0 != id1, "id1_check",
 		  "loaded prog id %u != id1 %u, err %d", id0, id1, err))
 		goto out_close;
 
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd2, XDP_FLAGS_REPLACE,
-				       &opts);
+	err = bpf_xdp_attach(IFINDEX_LO, fd2, XDP_FLAGS_REPLACE, &opts);
 	if (CHECK(!err, "load_fail", "load with expected id didn't fail"))
 		goto out;
 
-	opts.old_fd = fd1;
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd2, 0, &opts);
+	opts.old_prog_fd = fd1;
+	err = bpf_xdp_attach(IFINDEX_LO, fd2, 0, &opts);
 	if (CHECK(err, "replace_ok", "replace valid old_fd failed"))
 		goto out;
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
 	if (CHECK(err || id0 != id2, "id2_check",
 		  "loaded prog id %u != id2 %u, err %d", id0, id2, err))
 		goto out_close;
 
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd3, 0, &opts);
+	err = bpf_xdp_attach(IFINDEX_LO, fd3, 0, &opts);
 	if (CHECK(!err, "replace_fail", "replace invalid old_fd didn't fail"))
 		goto out;
 
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 0, &opts);
+	err = bpf_xdp_detach(IFINDEX_LO, 0, &opts);
 	if (CHECK(!err, "remove_fail", "remove invalid old_fd didn't fail"))
 		goto out;
 
-	opts.old_fd = fd2;
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 0, &opts);
+	opts.old_prog_fd = fd2;
+	err = bpf_xdp_detach(IFINDEX_LO, 0, &opts);
 	if (CHECK(err, "remove_ok", "remove valid old_fd failed"))
 		goto out;
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
 	if (CHECK(err || id0 != 0, "unload_check",
 		  "loaded prog id %u != 0, err %d", id0, err))
 		goto out_close;
 out:
-	bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0);
+	bpf_xdp_detach(IFINDEX_LO, 0, NULL);
 out_close:
 	bpf_object__close(obj3);
 out_2:
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
index 13aabb3b6cf2..b353e1f3acb5 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
@@ -24,11 +24,11 @@ void test_xdp_with_cpumap_helpers(void)
 		return;
 
 	prog_fd = bpf_program__fd(skel->progs.xdp_redir_prog);
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL);
 	if (!ASSERT_OK(err, "Generic attach of program with 8-byte CPUMAP"))
 		goto out_close;
 
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
 	ASSERT_OK(err, "XDP program detach");
 
 	prog_fd = bpf_program__fd(skel->progs.xdp_dummy_cm);
@@ -46,9 +46,9 @@ void test_xdp_with_cpumap_helpers(void)
 	ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to cpumap entry prog_id");
 
 	/* can not attach BPF_XDP_CPUMAP program to a device */
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL);
 	if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_CPUMAP program"))
-		bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
+		bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
 
 	val.qsize = 192;
 	val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog);
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
index 2a784ccd3136..463a72fc3e70 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
@@ -26,11 +26,11 @@ static void test_xdp_with_devmap_helpers(void)
 		return;
 
 	dm_fd = bpf_program__fd(skel->progs.xdp_redir_prog);
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL);
 	if (!ASSERT_OK(err, "Generic attach of program with 8-byte devmap"))
 		goto out_close;
 
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
 	ASSERT_OK(err, "XDP program detach");
 
 	dm_fd = bpf_program__fd(skel->progs.xdp_dummy_dm);
@@ -48,9 +48,9 @@ static void test_xdp_with_devmap_helpers(void)
 	ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to devmap entry prog_id");
 
 	/* can not attach BPF_XDP_DEVMAP program to a device */
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL);
 	if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_DEVMAP program"))
-		bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
+		bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
 
 	val.ifindex = 1;
 	val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog);
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_info.c b/tools/testing/selftests/bpf/prog_tests/xdp_info.c
index abe48e82e1dc..0d01ff6cb91a 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_info.c
@@ -14,13 +14,13 @@ void serial_test_xdp_info(void)
 
 	/* Get prog_id for XDP_ATTACHED_NONE mode */
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &prog_id);
 	if (CHECK(err, "get_xdp_none", "errno=%d\n", errno))
 		return;
 	if (CHECK(prog_id, "prog_id_none", "unexpected prog_id=%u\n", prog_id))
 		return;
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_query_id(IFINDEX_LO, XDP_FLAGS_SKB_MODE, &prog_id);
 	if (CHECK(err, "get_xdp_none_skb", "errno=%d\n", errno))
 		return;
 	if (CHECK(prog_id, "prog_id_none_skb", "unexpected prog_id=%u\n",
@@ -37,32 +37,32 @@ void serial_test_xdp_info(void)
 	if (CHECK(err, "get_prog_info", "errno=%d\n", errno))
 		goto out_close;
 
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL);
 	if (CHECK(err, "set_xdp_skb", "errno=%d\n", errno))
 		goto out_close;
 
 	/* Get prog_id for single prog mode */
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &prog_id);
 	if (CHECK(err, "get_xdp", "errno=%d\n", errno))
 		goto out;
 	if (CHECK(prog_id != info.id, "prog_id", "prog_id not available\n"))
 		goto out;
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_SKB_MODE);
+	err = bpf_xdp_query_id(IFINDEX_LO, XDP_FLAGS_SKB_MODE, &prog_id);
 	if (CHECK(err, "get_xdp_skb", "errno=%d\n", errno))
 		goto out;
 	if (CHECK(prog_id != info.id, "prog_id_skb", "prog_id not available\n"))
 		goto out;
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_DRV_MODE);
+	err = bpf_xdp_query_id(IFINDEX_LO, XDP_FLAGS_DRV_MODE, &prog_id);
 	if (CHECK(err, "get_xdp_drv", "errno=%d\n", errno))
 		goto out;
 	if (CHECK(prog_id, "prog_id_drv", "unexpected prog_id=%u\n", prog_id))
 		goto out;
 
 out:
-	bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0);
+	bpf_xdp_detach(IFINDEX_LO, 0, NULL);
 out_close:
 	bpf_object__close(obj);
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_link.c b/tools/testing/selftests/bpf/prog_tests/xdp_link.c
index b2b357f8c74c..3e9d5c5521f0 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_link.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_link.c
@@ -8,9 +8,9 @@
 
 void serial_test_xdp_link(void)
 {
-	DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, .old_fd = -1);
 	struct test_xdp_link *skel1 = NULL, *skel2 = NULL;
 	__u32 id1, id2, id0 = 0, prog_fd1, prog_fd2;
+	LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
 	struct bpf_link_info link_info;
 	struct bpf_prog_info prog_info;
 	struct bpf_link *link;
@@ -41,12 +41,12 @@ void serial_test_xdp_link(void)
 	id2 = prog_info.id;
 
 	/* set initial prog attachment */
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts);
+	err = bpf_xdp_attach(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts);
 	if (!ASSERT_OK(err, "fd_attach"))
 		goto cleanup;
 
 	/* validate prog ID */
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
 	if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val"))
 		goto cleanup;
 
@@ -55,14 +55,14 @@ void serial_test_xdp_link(void)
 	if (!ASSERT_ERR_PTR(link, "link_attach_should_fail")) {
 		bpf_link__destroy(link);
 		/* best-effort detach prog */
-		opts.old_fd = prog_fd1;
-		bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, XDP_FLAGS_REPLACE, &opts);
+		opts.old_prog_fd = prog_fd1;
+		bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts);
 		goto cleanup;
 	}
 
 	/* detach BPF program */
-	opts.old_fd = prog_fd1;
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, XDP_FLAGS_REPLACE, &opts);
+	opts.old_prog_fd = prog_fd1;
+	err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts);
 	if (!ASSERT_OK(err, "prog_detach"))
 		goto cleanup;
 
@@ -73,23 +73,23 @@ void serial_test_xdp_link(void)
 	skel1->links.xdp_handler = link;
 
 	/* validate prog ID */
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
 	if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val"))
 		goto cleanup;
 
 	/* BPF prog attach is not allowed to replace BPF link */
-	opts.old_fd = prog_fd1;
-	err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts);
+	opts.old_prog_fd = prog_fd1;
+	err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts);
 	if (!ASSERT_ERR(err, "prog_attach_fail"))
 		goto cleanup;
 
 	/* Can't force-update when BPF link is active */
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd2, 0);
+	err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, 0, NULL);
 	if (!ASSERT_ERR(err, "prog_update_fail"))
 		goto cleanup;
 
 	/* Can't force-detach when BPF link is active */
-	err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0);
+	err = bpf_xdp_detach(IFINDEX_LO, 0, NULL);
 	if (!ASSERT_ERR(err, "prog_detach_fail"))
 		goto cleanup;
 
@@ -109,7 +109,7 @@ void serial_test_xdp_link(void)
 		goto cleanup;
 	skel2->links.xdp_handler = link;
 
-	err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
+	err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
 	if (!ASSERT_OK(err, "id2_check_err") || !ASSERT_EQ(id0, id2, "id2_check_val"))
 		goto cleanup;
 
diff --git a/tools/testing/selftests/bpf/xdp_redirect_multi.c b/tools/testing/selftests/bpf/xdp_redirect_multi.c
index 51c8224b4ccc..aaedbf4955c3 100644
--- a/tools/testing/selftests/bpf/xdp_redirect_multi.c
+++ b/tools/testing/selftests/bpf/xdp_redirect_multi.c
@@ -32,12 +32,12 @@ static void int_exit(int sig)
 	int i;
 
 	for (i = 0; ifaces[i] > 0; i++) {
-		if (bpf_get_link_xdp_id(ifaces[i], &prog_id, xdp_flags)) {
-			printf("bpf_get_link_xdp_id failed\n");
+		if (bpf_xdp_query_id(ifaces[i], xdp_flags, &prog_id)) {
+			printf("bpf_xdp_query_id failed\n");
 			exit(1);
 		}
 		if (prog_id)
-			bpf_set_link_xdp_fd(ifaces[i], -1, xdp_flags);
+			bpf_xdp_detach(ifaces[i], xdp_flags, NULL);
 	}
 
 	exit(0);
@@ -210,7 +210,7 @@ int main(int argc, char **argv)
 		}
 
 		/* bind prog_fd to each interface */
-		ret = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags);
+		ret = bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL);
 		if (ret) {
 			printf("Set xdp fd failed on %d\n", ifindex);
 			goto err_out;
diff --git a/tools/testing/selftests/bpf/xdping.c b/tools/testing/selftests/bpf/xdping.c
index baa870a759a2..c567856fd1bc 100644
--- a/tools/testing/selftests/bpf/xdping.c
+++ b/tools/testing/selftests/bpf/xdping.c
@@ -29,7 +29,7 @@ static __u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
 
 static void cleanup(int sig)
 {
-	bpf_set_link_xdp_fd(ifindex, -1, xdp_flags);
+	bpf_xdp_detach(ifindex, xdp_flags, NULL);
 	if (sig)
 		exit(1);
 }
@@ -203,7 +203,7 @@ int main(int argc, char **argv)
 
 	printf("XDP setup disrupts network connectivity, hit Ctrl+C to quit\n");
 
-	if (bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags) < 0) {
+	if (bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL) < 0) {
 		fprintf(stderr, "Link set xdp fd failed for %s\n", ifname);
 		goto done;
 	}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH bpf-next 6/6] samples/bpf: get rid of bpf_prog_load_xattr() use
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
                   ` (4 preceding siblings ...)
  2022-02-02 22:59 ` [PATCH bpf-next 5/6] selftests/bpf: redo the switch to new libbpf XDP APIs Andrii Nakryiko
@ 2022-02-02 22:59 ` Andrii Nakryiko
  2022-02-03 10:25 ` [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Quentin Monnet
  2022-02-03 15:40 ` patchwork-bot+netdevbpf
  7 siblings, 0 replies; 13+ messages in thread
From: Andrii Nakryiko @ 2022-02-02 22:59 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

Remove all the remaining uses of deprecated bpf_prog_load_xattr() API.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 samples/bpf/xdp1_user.c            | 16 +++++++++++-----
 samples/bpf/xdp_adjust_tail_user.c | 17 ++++++++++++-----
 samples/bpf/xdp_fwd_user.c         | 15 +++++++++------
 samples/bpf/xdp_router_ipv4_user.c | 17 ++++++++++-------
 samples/bpf/xdp_rxq_info_user.c    | 16 +++++++++++-----
 samples/bpf/xdp_tx_iptunnel_user.c | 17 ++++++++++-------
 6 files changed, 63 insertions(+), 35 deletions(-)

diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
index 3ec8ad9c1750..631f0cabe139 100644
--- a/samples/bpf/xdp1_user.c
+++ b/samples/bpf/xdp1_user.c
@@ -79,13 +79,11 @@ static void usage(const char *prog)
 
 int main(int argc, char **argv)
 {
-	struct bpf_prog_load_attr prog_load_attr = {
-		.prog_type	= BPF_PROG_TYPE_XDP,
-	};
 	struct bpf_prog_info info = {};
 	__u32 info_len = sizeof(info);
 	const char *optstr = "FSN";
 	int prog_fd, map_fd, opt;
+	struct bpf_program *prog;
 	struct bpf_object *obj;
 	struct bpf_map *map;
 	char filename[256];
@@ -123,11 +121,19 @@ int main(int argc, char **argv)
 	}
 
 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
-	prog_load_attr.file = filename;
+	obj = bpf_object__open_file(filename, NULL);
+	if (libbpf_get_error(obj))
+		return 1;
+
+	prog = bpf_object__next_program(obj, NULL);
+	bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
 
-	if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
+	err = bpf_object__load(obj);
+	if (err)
 		return 1;
 
+	prog_fd = bpf_program__fd(prog);
+
 	map = bpf_object__next_map(obj, NULL);
 	if (!map) {
 		printf("finding a map in obj file failed\n");
diff --git a/samples/bpf/xdp_adjust_tail_user.c b/samples/bpf/xdp_adjust_tail_user.c
index 6c61d5f570fb..b3f6e49676ed 100644
--- a/samples/bpf/xdp_adjust_tail_user.c
+++ b/samples/bpf/xdp_adjust_tail_user.c
@@ -82,15 +82,13 @@ static void usage(const char *cmd)
 
 int main(int argc, char **argv)
 {
-	struct bpf_prog_load_attr prog_load_attr = {
-		.prog_type	= BPF_PROG_TYPE_XDP,
-	};
 	unsigned char opt_flags[256] = {};
 	const char *optstr = "i:T:P:SNFh";
 	struct bpf_prog_info info = {};
 	__u32 info_len = sizeof(info);
 	unsigned int kill_after_s = 0;
 	int i, prog_fd, map_fd, opt;
+	struct bpf_program *prog;
 	struct bpf_object *obj;
 	__u32 max_pckt_size = 0;
 	__u32 key = 0;
@@ -148,11 +146,20 @@ int main(int argc, char **argv)
 	}
 
 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
-	prog_load_attr.file = filename;
 
-	if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
+	obj = bpf_object__open_file(filename, NULL);
+	if (libbpf_get_error(obj))
 		return 1;
 
+	prog = bpf_object__next_program(obj, NULL);
+	bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
+
+	err = bpf_object__load(obj);
+	if (err)
+		return 1;
+
+	prog_fd = bpf_program__fd(prog);
+
 	/* static global var 'max_pcktsz' is accessible from .data section */
 	if (max_pckt_size) {
 		map_fd = bpf_object__find_map_fd_by_name(obj, "xdp_adju.data");
diff --git a/samples/bpf/xdp_fwd_user.c b/samples/bpf/xdp_fwd_user.c
index 79ccd9891924..1828487bae9a 100644
--- a/samples/bpf/xdp_fwd_user.c
+++ b/samples/bpf/xdp_fwd_user.c
@@ -75,14 +75,11 @@ static void usage(const char *prog)
 
 int main(int argc, char **argv)
 {
-	struct bpf_prog_load_attr prog_load_attr = {
-		.prog_type	= BPF_PROG_TYPE_XDP,
-	};
 	const char *prog_name = "xdp_fwd";
 	struct bpf_program *prog = NULL;
 	struct bpf_program *pos;
 	const char *sec_name;
-	int prog_fd, map_fd = -1;
+	int prog_fd = -1, map_fd = -1;
 	char filename[PATH_MAX];
 	struct bpf_object *obj;
 	int opt, i, idx, err;
@@ -119,7 +116,6 @@ int main(int argc, char **argv)
 
 	if (attach) {
 		snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
-		prog_load_attr.file = filename;
 
 		if (access(filename, O_RDONLY) < 0) {
 			printf("error accessing file %s: %s\n",
@@ -127,7 +123,14 @@ int main(int argc, char **argv)
 			return 1;
 		}
 
-		err = bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd);
+		obj = bpf_object__open_file(filename, NULL);
+		if (libbpf_get_error(obj))
+			return 1;
+
+		prog = bpf_object__next_program(obj, NULL);
+		bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
+
+		err = bpf_object__load(obj);
 		if (err) {
 			printf("Does kernel support devmap lookup?\n");
 			/* If not, the error message will be:
diff --git a/samples/bpf/xdp_router_ipv4_user.c b/samples/bpf/xdp_router_ipv4_user.c
index 2d565ba54b8c..6dae87d83e1c 100644
--- a/samples/bpf/xdp_router_ipv4_user.c
+++ b/samples/bpf/xdp_router_ipv4_user.c
@@ -640,12 +640,10 @@ static void usage(const char *prog)
 
 int main(int ac, char **argv)
 {
-	struct bpf_prog_load_attr prog_load_attr = {
-		.prog_type	= BPF_PROG_TYPE_XDP,
-	};
 	struct bpf_prog_info info = {};
 	__u32 info_len = sizeof(info);
 	const char *optstr = "SF";
+	struct bpf_program *prog;
 	struct bpf_object *obj;
 	char filename[256];
 	char **ifname_list;
@@ -653,7 +651,6 @@ int main(int ac, char **argv)
 	int err, i = 1;
 
 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
-	prog_load_attr.file = filename;
 
 	total_ifindex = ac - 1;
 	ifname_list = (argv + 1);
@@ -684,14 +681,20 @@ int main(int ac, char **argv)
 		return 1;
 	}
 
-	if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
+	obj = bpf_object__open_file(filename, NULL);
+	if (libbpf_get_error(obj))
 		return 1;
 
+	prog = bpf_object__next_program(obj, NULL);
+	bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
+
 	printf("\n******************loading bpf file*********************\n");
-	if (!prog_fd) {
-		printf("bpf_prog_load_xattr: %s\n", strerror(errno));
+	err = bpf_object__load(obj);
+	if (err) {
+		printf("bpf_object__load(): %s\n", strerror(errno));
 		return 1;
 	}
+	prog_fd = bpf_program__fd(prog);
 
 	lpm_map_fd = bpf_object__find_map_fd_by_name(obj, "lpm_map");
 	rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt");
diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c
index fb2532d13aac..f2d90cba5164 100644
--- a/samples/bpf/xdp_rxq_info_user.c
+++ b/samples/bpf/xdp_rxq_info_user.c
@@ -450,14 +450,12 @@ static void stats_poll(int interval, int action, __u32 cfg_opt)
 int main(int argc, char **argv)
 {
 	__u32 cfg_options= NO_TOUCH ; /* Default: Don't touch packet memory */
-	struct bpf_prog_load_attr prog_load_attr = {
-		.prog_type	= BPF_PROG_TYPE_XDP,
-	};
 	struct bpf_prog_info info = {};
 	__u32 info_len = sizeof(info);
 	int prog_fd, map_fd, opt, err;
 	bool use_separators = true;
 	struct config cfg = { 0 };
+	struct bpf_program *prog;
 	struct bpf_object *obj;
 	struct bpf_map *map;
 	char filename[256];
@@ -471,11 +469,19 @@ int main(int argc, char **argv)
 	char *action_str = NULL;
 
 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
-	prog_load_attr.file = filename;
 
-	if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
+	obj = bpf_object__open_file(filename, NULL);
+	if (libbpf_get_error(obj))
 		return EXIT_FAIL;
 
+	prog = bpf_object__next_program(obj, NULL);
+	bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
+
+	err = bpf_object__load(obj);
+	if (err)
+		return EXIT_FAIL;
+	prog_fd = bpf_program__fd(prog);
+
 	map =  bpf_object__find_map_by_name(obj, "config_map");
 	stats_global_map = bpf_object__find_map_by_name(obj, "stats_global_map");
 	rx_queue_index_map = bpf_object__find_map_by_name(obj, "rx_queue_index_map");
diff --git a/samples/bpf/xdp_tx_iptunnel_user.c b/samples/bpf/xdp_tx_iptunnel_user.c
index 7370c03c96fc..2e811e4331cc 100644
--- a/samples/bpf/xdp_tx_iptunnel_user.c
+++ b/samples/bpf/xdp_tx_iptunnel_user.c
@@ -152,9 +152,6 @@ static int parse_ports(const char *port_str, int *min_port, int *max_port)
 
 int main(int argc, char **argv)
 {
-	struct bpf_prog_load_attr prog_load_attr = {
-		.prog_type	= BPF_PROG_TYPE_XDP,
-	};
 	int min_port = 0, max_port = 0, vip2tnl_map_fd;
 	const char *optstr = "i:a:p:s:d:m:T:P:FSNh";
 	unsigned char opt_flags[256] = {};
@@ -162,6 +159,7 @@ int main(int argc, char **argv)
 	__u32 info_len = sizeof(info);
 	unsigned int kill_after_s = 0;
 	struct iptnl_info tnl = {};
+	struct bpf_program *prog;
 	struct bpf_object *obj;
 	struct vip vip = {};
 	char filename[256];
@@ -259,15 +257,20 @@ int main(int argc, char **argv)
 	}
 
 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
-	prog_load_attr.file = filename;
 
-	if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
+	obj = bpf_object__open_file(filename, NULL);
+	if (libbpf_get_error(obj))
 		return 1;
 
-	if (!prog_fd) {
-		printf("bpf_prog_load_xattr: %s\n", strerror(errno));
+	prog = bpf_object__next_program(obj, NULL);
+	bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
+
+	err = bpf_object__load(obj);
+	if (err) {
+		printf("bpf_object__load(): %s\n", strerror(errno));
 		return 1;
 	}
+	prog_fd = bpf_program__fd(prog);
 
 	rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt");
 	vip2tnl_map_fd = bpf_object__find_map_fd_by_name(obj, "vip2tnl");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
  2022-02-02 22:59 ` [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing Andrii Nakryiko
@ 2022-02-03 10:24   ` Quentin Monnet
  2022-02-16 10:37     ` Niklas Söderlund
  0 siblings, 1 reply; 13+ messages in thread
From: Quentin Monnet @ 2022-02-03 10:24 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, ast, daniel
  Cc: kernel-team, Simon Horman, David Beckett

2022-02-02 14:59 UTC-0800 ~ Andrii Nakryiko <andrii@kernel.org>
> libbpf 1.0 is not going to support passing ifindex to BPF
> prog/map/helper feature probing APIs. Remove the support for BPF offload
> feature probing.
> 
> Cc: Quentin Monnet <quentin@isovalent.com>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  tools/bpf/bpftool/feature.c | 29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
> index e999159fa28d..9c894b1447de 100644
> --- a/tools/bpf/bpftool/feature.c
> +++ b/tools/bpf/bpftool/feature.c
> @@ -487,17 +487,12 @@ probe_prog_type(enum bpf_prog_type prog_type, bool *supported_types,
>  	size_t maxlen;
>  	bool res;
>  
> -	if (ifindex)
> -		/* Only test offload-able program types */
> -		switch (prog_type) {
> -		case BPF_PROG_TYPE_SCHED_CLS:
> -		case BPF_PROG_TYPE_XDP:
> -			break;
> -		default:
> -			return;
> -		}
> +	if (ifindex) {
> +		p_info("BPF offload feature probing is not supported");
> +		return;
> +	}
>  
> -	res = bpf_probe_prog_type(prog_type, ifindex);
> +	res = libbpf_probe_bpf_prog_type(prog_type, NULL);
>  #ifdef USE_LIBCAP
>  	/* Probe may succeed even if program load fails, for unprivileged users
>  	 * check that we did not fail because of insufficient permissions
> @@ -535,7 +530,12 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix,
>  	size_t maxlen;
>  	bool res;
>  
> -	res = bpf_probe_map_type(map_type, ifindex);
> +	if (ifindex) {
> +		p_info("BPF offload feature probing is not supported");
> +		return;
> +	}
> +
> +	res = libbpf_probe_bpf_map_type(map_type, NULL);
>  
>  	/* Probe result depends on the success of map creation, no additional
>  	 * check required for unprivileged users
> @@ -567,7 +567,12 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
>  	bool res = false;
>  
>  	if (supported_type) {
> -		res = bpf_probe_helper(id, prog_type, ifindex);
> +		if (ifindex) {
> +			p_info("BPF offload feature probing is not supported");
> +			return;
> +		}
> +
> +		res = libbpf_probe_bpf_helper(prog_type, id, NULL);
>  #ifdef USE_LIBCAP
>  		/* Probe may succeed even if program load fails, for
>  		 * unprivileged users check that we did not fail because of

Thanks for the Cc. This feature was added for Netronome's SmartNICs and
I don't work with them anymore, so no objection from me (if anything,
that's one more incentive to finalise the new versioning scheme and have
this change under a new major version number!).

+Cc Simon, David: Hi! If you folks are still using bpftool to probe
eBPF-related features supported by the NICs, we'll have to move the
probes to bpftool.

Quentin

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
                   ` (5 preceding siblings ...)
  2022-02-02 22:59 ` [PATCH bpf-next 6/6] samples/bpf: get rid of bpf_prog_load_xattr() use Andrii Nakryiko
@ 2022-02-03 10:25 ` Quentin Monnet
  2022-02-03 15:40 ` patchwork-bot+netdevbpf
  7 siblings, 0 replies; 13+ messages in thread
From: Quentin Monnet @ 2022-02-03 10:25 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, ast, daniel; +Cc: kernel-team

2022-02-02 14:59 UTC-0800 ~ Andrii Nakryiko <andrii@kernel.org>
> Clean up remaining missed uses of deprecated libbpf APIs across samples/bpf,
> selftests/bpf, libbpf, and bpftool.
> 
> Also fix uninit variable warning in bpftool.

Looks all good.

Reviewed-by: Quentin Monnet <quentin@isovalent.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs
  2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
                   ` (6 preceding siblings ...)
  2022-02-03 10:25 ` [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Quentin Monnet
@ 2022-02-03 15:40 ` patchwork-bot+netdevbpf
  7 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-03 15:40 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team

Hello:

This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Wed, 2 Feb 2022 14:59:10 -0800 you wrote:
> Clean up remaining missed uses of deprecated libbpf APIs across samples/bpf,
> selftests/bpf, libbpf, and bpftool.
> 
> Also fix uninit variable warning in bpftool.
> 
> Andrii Nakryiko (6):
>   libbpf: stop using deprecated bpf_map__is_offload_neutral()
>   bpftool: stop supporting BPF offload-enabled feature probing
>   bpftool: fix uninit variable compilation warning
>   selftests/bpf: remove usage of deprecated feature probing APIs
>   selftests/bpf: redo the switch to new libbpf XDP APIs
>   samples/bpf: get rid of bpf_prog_load_xattr() use
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/6] libbpf: stop using deprecated bpf_map__is_offload_neutral()
    https://git.kernel.org/bpf/bpf-next/c/a5dd9589f0ab
  - [bpf-next,2/6] bpftool: stop supporting BPF offload-enabled feature probing
    https://git.kernel.org/bpf/bpf-next/c/1a56c18e6c2e
  - [bpf-next,3/6] bpftool: fix uninit variable compilation warning
    https://git.kernel.org/bpf/bpf-next/c/a9a8ac592e47
  - [bpf-next,4/6] selftests/bpf: remove usage of deprecated feature probing APIs
    https://git.kernel.org/bpf/bpf-next/c/32e608f82946
  - [bpf-next,5/6] selftests/bpf: redo the switch to new libbpf XDP APIs
    https://git.kernel.org/bpf/bpf-next/c/e4e284a8c0d9
  - [bpf-next,6/6] samples/bpf: get rid of bpf_prog_load_xattr() use
    https://git.kernel.org/bpf/bpf-next/c/1e4edb6d8c4f

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] 13+ messages in thread

* Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
  2022-02-03 10:24   ` Quentin Monnet
@ 2022-02-16 10:37     ` Niklas Söderlund
  2022-02-16 11:47       ` Quentin Monnet
  0 siblings, 1 reply; 13+ messages in thread
From: Niklas Söderlund @ 2022-02-16 10:37 UTC (permalink / raw)
  To: Quentin Monnet, Andrii Nakryiko
  Cc: bpf, ast, daniel, kernel-team, Simon Horman, David Beckett

Hi Quentin and Andrii,

Sorry for late reply.

On 2022-02-03 10:24:57 +0000, Quentin Monnet wrote:
> Thanks for the Cc. This feature was added for Netronome's SmartNICs 
> and I don't work with them anymore, so no objection from me (if 
> anything, that's one more incentive to finalise the new versioning 
> scheme and have this change under a new major version number!).
> 
> +Cc Simon, David: Hi! If you folks are still using bpftool to probe
> eBPF-related features supported by the NICs, we'll have to move the
> probes to bpftool.

We do use this feature and it is something we would like to keep.

Do I understand the situation correctly that in order to keep the 
functionality in bpftool the functionality of bpf_probe_prog_type(), 
bpf_probe_map_type() and bpf_probe_helper() needs to me moved from 
libbpf to bpftool and used if probing an NIC's features (ifindex 
provided) while using the new libbpf functions if not? And the reason 
for this being that libbpf going forward will not support probing of NIC 
features?

Is this something that can be added to this series as to avoid a release 
where this feature is missing?

-- 
Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
  2022-02-16 10:37     ` Niklas Söderlund
@ 2022-02-16 11:47       ` Quentin Monnet
  2022-02-16 15:40         ` Niklas Söderlund
  0 siblings, 1 reply; 13+ messages in thread
From: Quentin Monnet @ 2022-02-16 11:47 UTC (permalink / raw)
  To: Niklas Söderlund, Andrii Nakryiko
  Cc: bpf, ast, daniel, kernel-team, Simon Horman, David Beckett

2022-02-16 11:37 UTC+0100 ~ Niklas Söderlund <niklas.soderlund@corigine.com>
> Hi Quentin and Andrii,
> 
> Sorry for late reply.
> 
> On 2022-02-03 10:24:57 +0000, Quentin Monnet wrote:
>> Thanks for the Cc. This feature was added for Netronome's SmartNICs 
>> and I don't work with them anymore, so no objection from me (if 
>> anything, that's one more incentive to finalise the new versioning 
>> scheme and have this change under a new major version number!).
>>
>> +Cc Simon, David: Hi! If you folks are still using bpftool to probe
>> eBPF-related features supported by the NICs, we'll have to move the
>> probes to bpftool.

(I'm realising we forgot to remove the documentation for the "dev NAME"
option from the documentation, by the way.)

> 
> We do use this feature and it is something we would like to keep.
> 
> Do I understand the situation correctly that in order to keep the 
> functionality in bpftool the functionality of bpf_probe_prog_type(), 
> bpf_probe_map_type() and bpf_probe_helper() needs to me moved from 
> libbpf to bpftool and used if probing an NIC's features (ifindex 
> provided) while using the new libbpf functions if not? And the reason 
> for this being that libbpf going forward will not support probing of NIC 
> features?

This is correct. Given that the SmartNICs do not support as many
features as the kernel, it should be simpler versions of the probes in
bpftool, dedicated to probing the NIC; for probing the system, it should
keep using libbpf's probes which have a better chance to remain up-to-date.

> 
> Is this something that can be added to this series as to avoid a release 
> where this feature is missing?
> 

This series has already been merged into bpf-next (this is commit
1a56c18e6c2e). I'm afraid there will be a bpftool version without the
feature, because we just updated and bumped bpftool's version number on
top of that :/ (9910a74d6ebf ("bpftool: Update versioning scheme, align
on libbpf's version number")).

Quentin

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
  2022-02-16 11:47       ` Quentin Monnet
@ 2022-02-16 15:40         ` Niklas Söderlund
  0 siblings, 0 replies; 13+ messages in thread
From: Niklas Söderlund @ 2022-02-16 15:40 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Andrii Nakryiko, bpf, ast, daniel, kernel-team, Simon Horman,
	David Beckett

Hi Quentin,

Thanks for your feedback.

On 2022-02-16 11:47:33 +0000, Quentin Monnet wrote:
> 2022-02-16 11:37 UTC+0100 ~ Niklas Söderlund <niklas.soderlund@corigine.com>
> > Hi Quentin and Andrii,
> > 
> > Sorry for late reply.
> > 
> > On 2022-02-03 10:24:57 +0000, Quentin Monnet wrote:
> >> Thanks for the Cc. This feature was added for Netronome's SmartNICs 
> >> and I don't work with them anymore, so no objection from me (if 
> >> anything, that's one more incentive to finalise the new versioning 
> >> scheme and have this change under a new major version number!).
> >>
> >> +Cc Simon, David: Hi! If you folks are still using bpftool to probe
> >> eBPF-related features supported by the NICs, we'll have to move the
> >> probes to bpftool.
> 
> (I'm realising we forgot to remove the documentation for the "dev NAME"
> option from the documentation, by the way.)
> 
> > 
> > We do use this feature and it is something we would like to keep.
> > 
> > Do I understand the situation correctly that in order to keep the 
> > functionality in bpftool the functionality of bpf_probe_prog_type(), 
> > bpf_probe_map_type() and bpf_probe_helper() needs to me moved from 
> > libbpf to bpftool and used if probing an NIC's features (ifindex 
> > provided) while using the new libbpf functions if not? And the reason 
> > for this being that libbpf going forward will not support probing of NIC 
> > features?
> 
> This is correct. Given that the SmartNICs do not support as many
> features as the kernel, it should be simpler versions of the probes in
> bpftool, dedicated to probing the NIC; for probing the system, it should
> keep using libbpf's probes which have a better chance to remain up-to-date.

I agree, I will see what I can do. If you submit a patch to update the 
documentation in-between could you please CC me so I can restore it 
together with the feature later on.

> 
> > 
> > Is this something that can be added to this series as to avoid a release 
> > where this feature is missing?
> > 
> 
> This series has already been merged into bpf-next (this is commit
> 1a56c18e6c2e). I'm afraid there will be a bpftool version without the
> feature, because we just updated and bumped bpftool's version number on
> top of that :/ (9910a74d6ebf ("bpftool: Update versioning scheme, align
> on libbpf's version number")).

Do you think it would make sens to add a Fixes tag to a patch restoring 
the feature so in case it miss v5.18 it can be backported easily?

> 
> Quentin

-- 
Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-02-16 15:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 22:59 [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Andrii Nakryiko
2022-02-02 22:59 ` [PATCH bpf-next 1/6] libbpf: stop using deprecated bpf_map__is_offload_neutral() Andrii Nakryiko
2022-02-02 22:59 ` [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing Andrii Nakryiko
2022-02-03 10:24   ` Quentin Monnet
2022-02-16 10:37     ` Niklas Söderlund
2022-02-16 11:47       ` Quentin Monnet
2022-02-16 15:40         ` Niklas Söderlund
2022-02-02 22:59 ` [PATCH bpf-next 3/6] bpftool: fix uninit variable compilation warning Andrii Nakryiko
2022-02-02 22:59 ` [PATCH bpf-next 4/6] selftests/bpf: remove usage of deprecated feature probing APIs Andrii Nakryiko
2022-02-02 22:59 ` [PATCH bpf-next 5/6] selftests/bpf: redo the switch to new libbpf XDP APIs Andrii Nakryiko
2022-02-02 22:59 ` [PATCH bpf-next 6/6] samples/bpf: get rid of bpf_prog_load_xattr() use Andrii Nakryiko
2022-02-03 10:25 ` [PATCH bpf-next 0/6] Clean up leftover uses of deprecated APIs Quentin Monnet
2022-02-03 15:40 ` 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.