bpf: bpftool: fix print error when show bpf map
Subsystems (7)
PATCH 1/1 bpf: bpftool: fix print error when show bpf map
If there is no btf_id or frozen, it will not show the pids, but the pids doesn't depends on any one of them.
Below is the result after this change,
$ ./bpftool map show 2: lpm_trie flags 0x1 key 8B value 8B max_entries 1 memlock 4096B pids systemd(1) 3: lpm_trie flags 0x1 key 20B value 8B max_entries 1 memlock 4096B pids systemd(1)
While before this change, the 'pids systemd(1)' can't be displayed.
--- tools/bpf/bpftool/map.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tools/bpf/bpftool/map.c +2 -5
@@ -620,17 +620,14 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info) u32_as_hash_field(info->id))printf ("\n\tpinned %s" , (char *)entry->value); } -printf ("\n" );if (frozen_str) { frozen =atoi (frozen_str);free (frozen_str); } -if (!info->btf_id && !frozen) -return 0 ; - -printf ("\t" ); +if (info->btf_id || frozen) +printf ("\n\t" );if (info->btf_id)printf ("btf_id %d" , info->btf_id);
Signature · 1 line
2.17.1
PATCH 1/1 bpf: selftests: cleanup RLIMIT_MEMLOCK
Since we have alread switched to memcg-based memory accouting and control, we don't need RLIMIT_MEMLOCK any more.
---RLIMIT_MEMLOCK is still used in bpftool and libbpf, but it may be useful for backward compatibility, so I don't cleanup them.
--- tools/testing/selftests/bpf/bpf_rlimit.h | 28 ------------------- .../selftests/bpf/flow_dissector_load.c | 1 - .../selftests/bpf/get_cgroup_id_user.c | 1 - .../selftests/bpf/map_tests/sk_storage_map.c | 15 ---------- .../selftests/bpf/test_cgroup_storage.c | 1 - tools/testing/selftests/bpf/test_dev_cgroup.c | 1 - tools/testing/selftests/bpf/test_lpm_map.c | 1 - tools/testing/selftests/bpf/test_lru_map.c | 1 - .../selftests/bpf/test_skb_cgroup_id_user.c | 1 - tools/testing/selftests/bpf/test_sock.c | 1 - tools/testing/selftests/bpf/test_sock_addr.c | 1 - tools/testing/selftests/bpf/test_sockmap.c | 1 - tools/testing/selftests/bpf/test_sysctl.c | 1 - tools/testing/selftests/bpf/test_tag.c | 1 - .../bpf/test_tcp_check_syncookie_user.c | 1 - .../selftests/bpf/test_tcpnotify_user.c | 1 - .../testing/selftests/bpf/test_verifier_log.c | 2 -- tools/testing/selftests/bpf/xdping.c | 7 ----- tools/testing/selftests/bpf/xdpxceiver.c | 5 ---- 19 files changed, 71 deletions(-) delete mode 100644 tools/testing/selftests/bpf/bpf_rlimit.h
tools/testing/selftests/bpf/bpf_rlimit.h deleted +0 -28
@@ -1,28 +0,0 @@ -#include <sys/resource.h> -#include <stdio.h> - -static __attribute__((constructor))void bpf_rlimit_ctor (void ) -{ -struct rlimit rlim_old, rlim_new = { - .rlim_cur =RLIM_INFINITY , - .rlim_max =RLIM_INFINITY , - }; - -getrlimit (RLIMIT_MEMLOCK , &rlim_old); -/* For the sake of running the test cases, we temporarily -* set rlimit to infinity in order for kernel to focus on -* errors from actual test cases and not getting noise -* from hitting memlock limits. The limit is on per-process -* basis and not a global one, hence destructor not really -* needed here. -*/ -if (setrlimit (RLIMIT_MEMLOCK , &rlim_new) <0 ) { -perror ("Unable to lift memlock rlimit" ); -/* Trying out lower limit, but expect potential test -* case failures from this! -*/ - rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL <<20 ); - rlim_new.rlim_max = rlim_old.rlim_max + (1UL <<20 ); -setrlimit (RLIMIT_MEMLOCK , &rlim_new); - } -}
tools/testing/selftests/bpf/flow_dissector_load.c +0 -1
@@ -11,7 +11,6 @@#include <bpf/bpf.h> #include <bpf/libbpf.h> -#include "bpf_rlimit.h" #include "flow_dissector_load.h" const char *cfg_pin_path ="/sys/fs/bpf/flow_dissector" ;
tools/testing/selftests/bpf/get_cgroup_id_user.c +0 -1
@@ -20,7 +20,6 @@#include "cgroup_helpers.h" #include "testing_helpers.h" -#include "bpf_rlimit.h" #define CHECK(condition, tag, format...) ({ \ int __ret = !!(condition); \
tools/testing/selftests/bpf/map_tests/sk_storage_map.c +0 -15
@@ -3,7 +3,6 @@#include <linux/compiler.h> #include <linux/err.h> -#include <sys/resource.h> #include <sys/socket.h> #include <sys/types.h> #include <linux/btf.h>
@@ -395,11 +394,8 @@ static void stop_handler(int signum)static void test_sk_storage_map_stress_free (void ) { -struct rlimit rlim_old, rlim_new = {};int err; -getrlimit (RLIMIT_NOFILE , &rlim_old); -signal (SIGTERM , stop_handler);signal (SIGINT , stop_handler);if (runtime_s >0 ) {
@@ -407,14 +403,6 @@ static void test_sk_storage_map_stress_free(void)alarm (runtime_s); } -if (rlim_old.rlim_cur < nr_sk_threads * nr_sk_per_thread) { - rlim_new.rlim_cur = nr_sk_threads * nr_sk_per_thread +128 ; - rlim_new.rlim_max = rlim_new.rlim_cur +128 ; - err =setrlimit (RLIMIT_NOFILE , &rlim_new); -CHECK (err,"setrlimit(RLIMIT_NOFILE)" ,"rlim_new:%lu errno:%d" , - rlim_new.rlim_cur, errno); - } - err =do_sk_storage_map_stress_free ();signal (SIGTERM ,SIG_DFL );
@@ -424,9 +412,6 @@ static void test_sk_storage_map_stress_free(void)alarm (0 ); } -if (rlim_new.rlim_cur) -setrlimit (RLIMIT_NOFILE , &rlim_old); -CHECK (err,"test_sk_storage_map_stress_free" ,"err:%d\n" , err); }
tools/testing/selftests/bpf/test_cgroup_storage.c +0 -1
@@ -6,7 +6,6 @@#include <stdlib.h> #include <sys/sysinfo.h> -#include "bpf_rlimit.h" #include "cgroup_helpers.h" #include "testing_helpers.h"
tools/testing/selftests/bpf/test_dev_cgroup.c +0 -1
@@ -15,7 +15,6 @@#include "cgroup_helpers.h" #include "testing_helpers.h" -#include "bpf_rlimit.h" #define DEV_CGROUP_PROG "./dev_cgroup.o"
tools/testing/selftests/bpf/test_lpm_map.c +0 -1
@@ -26,7 +26,6 @@#include <bpf/bpf.h> #include "bpf_util.h" -#include "bpf_rlimit.h" struct tlpm_node {struct tlpm_node *next;
tools/testing/selftests/bpf/test_lru_map.c +0 -1
@@ -18,7 +18,6 @@#include <bpf/libbpf.h> #include "bpf_util.h" -#include "bpf_rlimit.h" #include "../../../include/linux/filter.h" #define LOCAL_FREE_TARGET (128)
tools/testing/selftests/bpf/test_skb_cgroup_id_user.c +0 -1
@@ -15,7 +15,6 @@#include <bpf/bpf.h> #include <bpf/libbpf.h> -#include "bpf_rlimit.h" #include "cgroup_helpers.h" #define CGROUP_PATH "/skb_cgroup_test"
tools/testing/selftests/bpf/test_sock.c +0 -1
@@ -14,7 +14,6 @@#include "cgroup_helpers.h" #include <bpf/bpf_endian.h> -#include "bpf_rlimit.h" #include "bpf_util.h" #define CG_PATH "/foo"
tools/testing/selftests/bpf/test_sock_addr.c +0 -1
@@ -19,7 +19,6 @@#include <bpf/libbpf.h> #include "cgroup_helpers.h" -#include "bpf_rlimit.h" #include "bpf_util.h" #ifndef ENOTSUPP
tools/testing/selftests/bpf/test_sockmap.c +0 -1
@@ -37,7 +37,6 @@#include <bpf/libbpf.h> #include "bpf_util.h" -#include "bpf_rlimit.h" #include "cgroup_helpers.h" int running;
tools/testing/selftests/bpf/test_sysctl.c +0 -1
@@ -14,7 +14,6 @@#include <bpf/libbpf.h> #include <bpf/bpf_endian.h> -#include "bpf_rlimit.h" #include "bpf_util.h" #include "cgroup_helpers.h" #include "testing_helpers.h"
tools/testing/selftests/bpf/test_tag.c +0 -1
@@ -20,7 +20,6 @@#include <bpf/bpf.h> #include "../../../include/linux/filter.h" -#include "bpf_rlimit.h" #include "testing_helpers.h" static struct bpf_insn prog[BPF_MAXINSNS ];
tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +0 -1
@@ -15,7 +15,6 @@#include <bpf/bpf.h> #include <bpf/libbpf.h> -#include "bpf_rlimit.h" #include "cgroup_helpers.h" static int start_server (const struct sockaddr *addr,socklen_t len)
tools/testing/selftests/bpf/test_tcpnotify_user.c +0 -1
@@ -19,7 +19,6 @@#include <linux/perf_event.h> #include <linux/err.h> -#include "bpf_rlimit.h" #include "bpf_util.h" #include "cgroup_helpers.h"
tools/testing/selftests/bpf/test_verifier_log.c +0 -2
@@ -11,8 +11,6 @@#include <bpf/bpf.h> -#include "bpf_rlimit.h" -#define LOG_SIZE (1 << 20) #define err(str...) printf("ERROR: " str)
tools/testing/selftests/bpf/xdping.c +0 -7
@@ -12,7 +12,6 @@#include <string.h> #include <unistd.h> #include <libgen.h> -#include <sys/resource.h> #include <net/if.h> #include <sys/types.h> #include <sys/socket.h>
@@ -89,7 +88,6 @@ int main(int argc, char **argv) {__u32 mode_flags =XDP_FLAGS_DRV_MODE |XDP_FLAGS_SKB_MODE ;struct addrinfo *a, hints = { .ai_family =AF_INET }; -struct rlimit r = {RLIM_INFINITY ,RLIM_INFINITY };__u16 count =XDPING_DEFAULT_COUNT ;struct pinginfo pinginfo = {0 };const char *optstr ="c:I:NsS" ;
@@ -167,11 +165,6 @@ int main(int argc, char **argv)freeaddrinfo (a); } -if (setrlimit (RLIMIT_MEMLOCK , &r)) { -perror ("setrlimit(RLIMIT_MEMLOCK)" ); -return 1 ; - } -snprintf (filename,sizeof (filename),"%s_kern.o" , argv[0 ]);if (bpf_prog_test_load (filename,BPF_PROG_TYPE_XDP , &obj, &prog_fd)) {
tools/testing/selftests/bpf/xdpxceiver.c +0 -5
@@ -90,7 +90,6 @@#include <string.h> #include <stddef.h> #include <sys/mman.h> -#include <sys/resource.h> #include <sys/types.h> #include <sys/queue.h> #include <time.h>
@@ -1448,15 +1447,11 @@ static void ifobject_delete(struct ifobject *ifobj)int main (int argc,char **argv) { -struct rlimit _rlim = {RLIM_INFINITY ,RLIM_INFINITY };struct pkt_stream *pkt_stream_default;struct ifobject *ifobj_tx, *ifobj_rx;struct test_spec test;u32 i, j; -if (setrlimit (RLIMIT_MEMLOCK , &_rlim)) -exit_with_error (errno); - ifobj_tx =ifobject_create ();if (!ifobj_tx)exit_with_error (ENOMEM );
Signature · 1 line
2.17.1
Re: [PATCH] bpf: selftests: cleanup RLIMIT_MEMLOCK
Quoted 6 lines · Yafang Shao
Since we have alread switched to memcg-based memory accouting and control, we don't need
RLIMIT_MEMLOCKany more.
Quoted 6 lines
Signed-off-by Yafang Shao <[email protected]>Cc Roman Gushchin <[email protected]>---
RLIMIT_MEMLOCKis still used in bpftool and libbpf, but it may be useful for backward compatibility, so I don't cleanup them.
Hi Yafang!
As I remember, we haven’t cleaned selftests up with the same logic: it’s nice to be able to run the same version of tests on older kernels.
Thanks!
Re: [PATCH] bpf: selftests: cleanup RLIMIT_MEMLOCK
Quoted 10 lines · Roman Gushchin
Quoted 10 lines · Yafang Shao
Since we have alread switched to memcg-based memory accouting and control, we don't need
RLIMIT_MEMLOCKany more.Signed-off-by Yafang Shao <[email protected]>Cc Roman Gushchin <[email protected]>
Quoted 8 lines
Quoted 3 lines
---
RLIMIT_MEMLOCKis still used in bpftool and libbpf, but it may be useful for backward compatibility, so I don't cleanup them.Hi Yafang!
As I remember, we haven’t cleaned selftests up with the same logic: it’s nice to be able to run the same version of tests on older kernels.
It should be fine, at least for test_progs and test_progs-no_alu32. Libbpf now does this automatically if running in "libbpf 1.0" mode.
Yafang, please make sure that all the test binaries you are cleaning up have libbpf_set_strict_mode(LIBBPF_STRICT_ALL) (test_progs does already). You might need to clean up some SEC() definitions, in case we still missed some non-conforming ones, though.
Quoted 1 line
Thanks!
Re: [PATCH] bpf: selftests: cleanup RLIMIT_MEMLOCK
Quoted 18 lines · Andrii Nakryiko
Quoted 14 lines · Roman Gushchin
Quoted 13 lines
Quoted 3 lines · Yafang Shao
Since we have alread switched to memcg-based memory accouting and control, we don't need
RLIMIT_MEMLOCKany more.Signed-off-by Yafang Shao <[email protected]>Cc Roman Gushchin <[email protected]>---
RLIMIT_MEMLOCKis still used in bpftool and libbpf, but it may be useful for backward compatibility, so I don't cleanup them.
Quoted 7 lines
Quoted 4 lines
Hi Yafang!
As I remember, we haven’t cleaned selftests up with the same logic: it’s nice to be able to run the same version of tests on older kernels.
It should be fine, at least for
test_progsand test_progs-no_alu32. Libbpf now does this automatically if running in "libbpf 1.0" mode.
Didn’t know this, thanks! Do we link all tests with it?
Quoted 5 lines
Yafang, please make sure that all the test binaries you are cleaning up have
libbpf_set_strict_mode(LIBBPF_STRICT_ALL)(test_progsdoes already). You might need to clean up someSEC()definitions, in case we still missed some non-conforming ones, though.
If so, no objections to the patch from my side.
Thank you!
Re: [PATCH] bpf: selftests: cleanup RLIMIT_MEMLOCK
Quoted 21 lines · Roman Gushchin
Quoted 21 lines · Andrii Nakryiko
Quoted 16 lines · Roman Gushchin
Quoted 7 lines
Quoted 3 lines · Yafang Shao
Since we have alread switched to memcg-based memory accouting and control, we don't need
RLIMIT_MEMLOCKany more.Quoted 6 lines
Signed-off-by Yafang Shao <[email protected]>Cc Roman Gushchin <[email protected]>---
RLIMIT_MEMLOCKis still used in bpftool and libbpf, but it may be useful for backward compatibility, so I don't cleanup them.Hi Yafang!
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
As I remember, we haven’t cleaned selftests up with the same logic: it’s nice to be able to run the same version of tests on older kernels.
It should be fine, at least for
test_progsand test_progs-no_alu32. Libbpf now does this automatically if running in "libbpf 1.0" mode.Didn’t know this, thanks! Do we link all tests with it?
Yep, every selftest inevitably relies on libbpf. We just need to make sure to enable that 1.0 mode with libbpf_set_strict_mode() call.
Quoted 10 lines
Quoted 6 lines
Yafang, please make sure that all the test binaries you are cleaning up have
libbpf_set_strict_mode(LIBBPF_STRICT_ALL)(test_progsdoes already). You might need to clean up someSEC()definitions, in case we still missed some non-conforming ones, though.If so, no objections to the patch from my side.
Thank you!
Re: [PATCH] bpf: selftests: cleanup RLIMIT_MEMLOCK
In reply to Andrii NakryikoQuoted 21 lines · Andrii Nakryiko
Quoted 10 lines · Roman Gushchin
Quoted 10 lines · Yafang Shao
Since we have alread switched to memcg-based memory accouting and control, we don't need
RLIMIT_MEMLOCKany more.Signed-off-by Yafang Shao <[email protected]>Cc Roman Gushchin <[email protected]>Quoted 8 lines
Quoted 3 lines
---
RLIMIT_MEMLOCKis still used in bpftool and libbpf, but it may be useful for backward compatibility, so I don't cleanup them.Hi Yafang!
As I remember, we haven’t cleaned selftests up with the same logic: it’s nice to be able to run the same version of tests on older kernels.
Quoted 8 lines
It should be fine, at least for
test_progsand test_progs-no_alu32. Libbpf now does this automatically if running in "libbpf 1.0" mode.Yafang, please make sure that all the test binaries you are cleaning up have
libbpf_set_strict_mode(LIBBPF_STRICT_ALL)(test_progsdoes already). You might need to clean up someSEC()definitions, in case we still missed some non-conforming ones, though.
Thanks for the suggestion. I will do it.
Signature · 2 lines
Thanks Yafang
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 12 lines · On Sun, 20 Mar 2022 06:08:14 +0000 you wrote:
If there is no
btf_idor frozen, it will not show the pids, but the pids doesn't depends on any one of them.Below is the result after this change,
$ ./bpftool map show 2: lpm_trie flags 0x1 key 8B value 8B max_entries 1 memlock 4096B pids systemd(1) 3: lpm_trie flags 0x1 key 20B value 8B max_entries 1 memlock 4096B pids systemd(1)
Quoted 1 line
[...]
Here is the summary with links:
- bpf: bpftool: fix print error when show bpf map
https://git.kernel.org/bpf/bpf-next/c/1824d8ea75f2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html