Clean up leftover uses of deprecated APIs
Subsystems (6)
Andrii Nakryiko
maintainercover Clean up leftover uses of deprecated APIs
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(-)
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 1/6 libbpf: stop using deprecated bpf_map__is_offload_neutral()
Open-code bpf_map__is_offload_neutral() logic in one place in to-be-deprecated bpf_prog_load_xattr2.
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
@@ -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; }
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 2/6 bpftool: stop supporting BPF offload-enabled feature probing
In reply to Andrii Nakryikolibbpf 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.
--- tools/bpf/bpftool/feature.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
tools/bpf/bpftool/feature.c +17 -12
@@ -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
Signature · 1 line
2.30.2
Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
2022-02-02 14:59 UTC-0800 ~ Andrii Nakryiko <[email protected]>
Quoted 55 lines
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 <[email protected]>Signed-off-by Andrii Nakryiko <[email protected]>--- tools/bpf/bpftool/feature.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)tools/bpf/bpftool/feature.c +11
-11@@ -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) {
tools/bpf/bpftool/feature.c probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type, · line 578
Quoted 10 lines
tools/bpf/bpftool/feature.c +6
-1- 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
Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
Hi Quentin and Andrii,
Sorry for late reply.
Quoted 8 lines · Quentin Monnet
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?
Signature · 2 lines
Regards, Niklas Söderlund
Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
2022-02-16 11:37 UTC+0100 ~ Niklas Söderlund <[email protected]>
Quoted 13 lines
Hi Quentin and Andrii,
Sorry for late reply.
Quoted 8 lines · Quentin Monnet
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.)
Quoted 10 lines
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()andbpf_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.
Quoted 4 lines
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
Re: [PATCH bpf-next 2/6] bpftool: stop supporting BPF offload-enabled feature probing
Hi Quentin,
Thanks for your feedback.
Quoted 29 lines · Quentin Monnet
2022-02-16 11:37 UTC+0100 ~ Niklas Söderlund <[email protected]>
Quoted 13 lines
Hi Quentin and Andrii,
Sorry for late reply.
Quoted 8 lines · Quentin Monnet
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.)
Quoted 10 lines
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()andbpf_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?
Quoted 4 lines
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.
Quoted 11 lines
Quoted 5 lines
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?
Quoted 2 lines
Quentin
Signature · 2 lines
Regards, Niklas Söderlund
Andrii Nakryiko
maintainerPATCH 3/6 bpftool: fix uninit variable compilation warning
In reply to Andrii NakryikoNewer 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.
--- tools/bpf/bpftool/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/common.c +1 -1
@@ -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 ;
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 4/6 selftests/bpf: remove usage of deprecated feature probing APIs
In reply to Andrii NakryikoSwitch to libbpf_probe_*() APIs instead of the deprecated ones.
--- tools/testing/selftests/bpf/test_maps.c | 2 +- tools/testing/selftests/bpf/test_verifier.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/test_maps.c +1 -1
@@ -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++;
tools/testing/selftests/bpf/test_verifier.c +2 -2
@@ -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;
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 5/6 selftests/bpf: redo the switch to new libbpf XDP APIs
In reply to Andrii NakryikoSwitch 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.
--- .../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(-)
tools/testing/selftests/bpf/prog_tests/xdp_attach.c +13 -16
@@ -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:
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +4 -4
@@ -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);
tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c +4 -4
@@ -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);
tools/testing/selftests/bpf/prog_tests/xdp_info.c +7 -7
@@ -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); }
tools/testing/selftests/bpf/prog_tests/xdp_link.c +13 -13
@@ -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;
tools/testing/selftests/bpf/xdp_redirect_multi.c +4 -4
@@ -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;
tools/testing/selftests/bpf/xdping.c +2 -2
@@ -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; }
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 6/6 samples/bpf: get rid of bpf_prog_load_xattr() use
In reply to Andrii NakryikoRemove all the remaining uses of deprecated bpf_prog_load_xattr() API.
--- 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(-)
samples/bpf/xdp1_user.c +11 -5
@@ -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" );
samples/bpf/xdp_adjust_tail_user.c +12 -5
@@ -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" );
samples/bpf/xdp_fwd_user.c +9 -6
@@ -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:
samples/bpf/xdp_router_ipv4_user.c +10 -7
@@ -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" );
samples/bpf/xdp_rxq_info_user.c +11 -5
@@ -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" );
samples/bpf/xdp_tx_iptunnel_user.c +10 -7
@@ -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" );
Signature · 1 line
2.30.2
2022-02-02 14:59 UTC-0800 ~ Andrii Nakryiko <[email protected]>
Quoted 4 lines
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.
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 13 lines · 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 deprecatedbpf_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 APIssamples/bpf: get rid ofbpf_prog_load_xattr()use
Quoted 1 line
[...]
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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html