Skip to content

Commit b858ba8

Browse files
laoaranakryiko
authored andcommitted
selftests/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK
We have switched to memcg-based memory accouting and thus the rlimit is not needed any more. LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK was introduced in libbpf for backward compatibility, so we can use it instead now. After this change, the header tools/testing/selftests/bpf/bpf_rlimit.h can be removed. This patch also removes the useless header sys/resource.h from many files in tools/testing/selftests/bpf/. Signed-off-by: Yafang Shao <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b25acda commit b858ba8

21 files changed

+45
-61
lines changed

tools/testing/selftests/bpf/bench.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <fcntl.h>
99
#include <pthread.h>
1010
#include <sys/sysinfo.h>
11-
#include <sys/resource.h>
1211
#include <signal.h>
1312
#include "bench.h"
1413
#include "testing_helpers.h"

tools/testing/selftests/bpf/bpf_rlimit.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

tools/testing/selftests/bpf/flow_dissector_load.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <bpf/bpf.h>
1212
#include <bpf/libbpf.h>
1313

14-
#include "bpf_rlimit.h"
1514
#include "flow_dissector_load.h"
1615

1716
const char *cfg_pin_path = "/sys/fs/bpf/flow_dissector";
@@ -25,9 +24,8 @@ static void load_and_attach_program(void)
2524
int prog_fd, ret;
2625
struct bpf_object *obj;
2726

28-
ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
29-
if (ret)
30-
error(1, 0, "failed to enable libbpf strict mode: %d", ret);
27+
/* Use libbpf 1.0 API mode */
28+
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
3129

3230
ret = bpf_flow_load(&obj, cfg_path_name, cfg_prog_name,
3331
cfg_map_name, NULL, &prog_fd, NULL);

tools/testing/selftests/bpf/get_cgroup_id_user.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "cgroup_helpers.h"
2222
#include "testing_helpers.h"
23-
#include "bpf_rlimit.h"
2423

2524
#define CHECK(condition, tag, format...) ({ \
2625
int __ret = !!(condition); \
@@ -67,6 +66,9 @@ int main(int argc, char **argv)
6766
if (CHECK(cgroup_fd < 0, "cgroup_setup_and_join", "err %d errno %d\n", cgroup_fd, errno))
6867
return 1;
6968

69+
/* Use libbpf 1.0 API mode */
70+
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
71+
7072
err = bpf_prog_test_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd);
7173
if (CHECK(err, "bpf_prog_test_load", "err %d errno %d\n", err, errno))
7274
goto cleanup_cgroup_env;

tools/testing/selftests/bpf/prog_tests/btf.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <linux/filter.h>
99
#include <linux/unistd.h>
1010
#include <bpf/bpf.h>
11-
#include <sys/resource.h>
1211
#include <libelf.h>
1312
#include <gelf.h>
1413
#include <string.h>

tools/testing/selftests/bpf/test_cgroup_storage.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <stdlib.h>
77
#include <sys/sysinfo.h>
88

9-
#include "bpf_rlimit.h"
109
#include "bpf_util.h"
1110
#include "cgroup_helpers.h"
1211
#include "testing_helpers.h"
@@ -52,6 +51,9 @@ int main(int argc, char **argv)
5251
goto err;
5352
}
5453

54+
/* Use libbpf 1.0 API mode */
55+
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
56+
5557
map_fd = bpf_map_create(BPF_MAP_TYPE_CGROUP_STORAGE, NULL, sizeof(key),
5658
sizeof(value), 0, NULL);
5759
if (map_fd < 0) {

tools/testing/selftests/bpf/test_dev_cgroup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "cgroup_helpers.h"
1717
#include "testing_helpers.h"
18-
#include "bpf_rlimit.h"
1918

2019
#define DEV_CGROUP_PROG "./dev_cgroup.o"
2120

@@ -28,6 +27,9 @@ int main(int argc, char **argv)
2827
int prog_fd, cgroup_fd;
2928
__u32 prog_cnt;
3029

30+
/* Use libbpf 1.0 API mode */
31+
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
32+
3133
if (bpf_prog_test_load(DEV_CGROUP_PROG, BPF_PROG_TYPE_CGROUP_DEVICE,
3234
&obj, &prog_fd)) {
3335
printf("Failed to load DEV_CGROUP program\n");

tools/testing/selftests/bpf/test_lpm_map.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <bpf/bpf.h>
2727

2828
#include "bpf_util.h"
29-
#include "bpf_rlimit.h"
3029

3130
struct tlpm_node {
3231
struct tlpm_node *next;
@@ -791,6 +790,9 @@ int main(void)
791790
/* we want predictable, pseudo random tests */
792791
srand(0xf00ba1);
793792

793+
/* Use libbpf 1.0 API mode */
794+
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
795+
794796
test_lpm_basic();
795797
test_lpm_order();
796798

tools/testing/selftests/bpf/test_lru_map.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <bpf/libbpf.h>
1919

2020
#include "bpf_util.h"
21-
#include "bpf_rlimit.h"
2221
#include "../../../include/linux/filter.h"
2322

2423
#define LOCAL_FREE_TARGET (128)
@@ -878,6 +877,9 @@ int main(int argc, char **argv)
878877
assert(nr_cpus != -1);
879878
printf("nr_cpus:%d\n\n", nr_cpus);
880879

880+
/* Use libbpf 1.0 API mode */
881+
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
882+
881883
for (f = 0; f < ARRAY_SIZE(map_flags); f++) {
882884
unsigned int tgt_free = (map_flags[f] & BPF_F_NO_COMMON_LRU) ?
883885
PERCPU_FREE_TARGET : LOCAL_FREE_TARGET;

tools/testing/selftests/bpf/test_skb_cgroup_id_user.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <bpf/bpf.h>
1616
#include <bpf/libbpf.h>
1717

18-
#include "bpf_rlimit.h"
1918
#include "cgroup_helpers.h"
2019

2120
#define CGROUP_PATH "/skb_cgroup_test"
@@ -160,6 +159,9 @@ int main(int argc, char **argv)
160159
exit(EXIT_FAILURE);
161160
}
162161

162+
/* Use libbpf 1.0 API mode */
163+
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
164+
163165
cgfd = cgroup_setup_and_join(CGROUP_PATH);
164166
if (cgfd < 0)
165167
goto err;

0 commit comments

Comments
 (0)