Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'bpf: RLIMIT_MEMLOCK cleanups'

Yafang Shao says:

====================

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.

This patchset cleanups the usage of RLIMIT_MEMLOCK in tools/bpf/,
tools/testing/selftests/bpf and samples/bpf. The file
tools/testing/selftests/bpf/bpf_rlimit.h is removed. The included header
sys/resource.h is removed from many files as it is useless in these files.

- v4: Squash patches and use customary subject prefixes. (Andrii)
- v3: Get rid of bpf_rlimit.h and fix some typos (Andrii)
- v2: Use libbpf_set_strict_mode instead. (Andrii)
- v1: https://lore.kernel.org/bpf/20220320060815.7716-2-laoar.shao@gmail.com/
====================

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

+57 -142
-1
samples/bpf/cpustat_user.c
··· 13 13 #include <sys/types.h> 14 14 #include <sys/stat.h> 15 15 #include <sys/time.h> 16 - #include <sys/resource.h> 17 16 #include <sys/wait.h> 18 17 19 18 #include <bpf/bpf.h>
+3 -2
samples/bpf/hbm.c
··· 34 34 #include <stdio.h> 35 35 #include <stdlib.h> 36 36 #include <assert.h> 37 - #include <sys/resource.h> 38 37 #include <sys/time.h> 39 38 #include <unistd.h> 40 39 #include <errno.h> ··· 45 46 #include <bpf/bpf.h> 46 47 #include <getopt.h> 47 48 48 - #include "bpf_rlimit.h" 49 49 #include "cgroup_helpers.h" 50 50 #include "hbm.h" 51 51 #include "bpf_util.h" ··· 507 509 if (optind < argc) 508 510 prog = argv[optind]; 509 511 printf("HBM prog: %s\n", prog != NULL ? prog : "NULL"); 512 + 513 + /* Use libbpf 1.0 API mode */ 514 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 510 515 511 516 return run_bpf_prog(prog, cg_id); 512 517 }
-1
samples/bpf/ibumad_user.c
··· 19 19 #include <sys/types.h> 20 20 #include <limits.h> 21 21 22 - #include <sys/resource.h> 23 22 #include <getopt.h> 24 23 #include <net/if.h> 25 24
-1
samples/bpf/map_perf_test_user.c
··· 13 13 #include <signal.h> 14 14 #include <string.h> 15 15 #include <time.h> 16 - #include <sys/resource.h> 17 16 #include <arpa/inet.h> 18 17 #include <errno.h> 19 18
-1
samples/bpf/offwaketime_user.c
··· 8 8 #include <linux/perf_event.h> 9 9 #include <errno.h> 10 10 #include <stdbool.h> 11 - #include <sys/resource.h> 12 11 #include <bpf/libbpf.h> 13 12 #include <bpf/bpf.h> 14 13 #include "trace_helpers.h"
-1
samples/bpf/sockex2_user.c
··· 7 7 #include "sock_example.h" 8 8 #include <unistd.h> 9 9 #include <arpa/inet.h> 10 - #include <sys/resource.h> 11 10 12 11 struct pair { 13 12 __u64 packets;
-1
samples/bpf/sockex3_user.c
··· 6 6 #include "sock_example.h" 7 7 #include <unistd.h> 8 8 #include <arpa/inet.h> 9 - #include <sys/resource.h> 10 9 11 10 struct flow_key_record { 12 11 __be32 src;
-1
samples/bpf/spintest_user.c
··· 3 3 #include <unistd.h> 4 4 #include <string.h> 5 5 #include <assert.h> 6 - #include <sys/resource.h> 7 6 #include <bpf/libbpf.h> 8 7 #include <bpf/bpf.h> 9 8 #include "trace_helpers.h"
-1
samples/bpf/syscall_tp_user.c
··· 8 8 #include <string.h> 9 9 #include <linux/perf_event.h> 10 10 #include <errno.h> 11 - #include <sys/resource.h> 12 11 #include <bpf/libbpf.h> 13 12 #include <bpf/bpf.h> 14 13
-1
samples/bpf/task_fd_query_user.c
··· 10 10 #include <fcntl.h> 11 11 #include <linux/bpf.h> 12 12 #include <sys/ioctl.h> 13 - #include <sys/resource.h> 14 13 #include <sys/types.h> 15 14 #include <sys/stat.h> 16 15 #include <linux/perf_event.h>
-1
samples/bpf/test_lru_dist.c
··· 13 13 #include <sched.h> 14 14 #include <sys/wait.h> 15 15 #include <sys/stat.h> 16 - #include <sys/resource.h> 17 16 #include <fcntl.h> 18 17 #include <stdlib.h> 19 18 #include <time.h>
-1
samples/bpf/test_map_in_map_user.c
··· 2 2 /* 3 3 * Copyright (c) 2017 Facebook 4 4 */ 5 - #include <sys/resource.h> 6 5 #include <sys/socket.h> 7 6 #include <arpa/inet.h> 8 7 #include <stdint.h>
-1
samples/bpf/test_overhead_user.c
··· 16 16 #include <linux/bpf.h> 17 17 #include <string.h> 18 18 #include <time.h> 19 - #include <sys/resource.h> 20 19 #include <bpf/bpf.h> 21 20 #include <bpf/libbpf.h> 22 21
-1
samples/bpf/tracex2_user.c
··· 4 4 #include <stdlib.h> 5 5 #include <signal.h> 6 6 #include <string.h> 7 - #include <sys/resource.h> 8 7 9 8 #include <bpf/bpf.h> 10 9 #include <bpf/libbpf.h>
-1
samples/bpf/tracex3_user.c
··· 7 7 #include <unistd.h> 8 8 #include <stdbool.h> 9 9 #include <string.h> 10 - #include <sys/resource.h> 11 10 12 11 #include <bpf/bpf.h> 13 12 #include <bpf/libbpf.h>
-1
samples/bpf/tracex4_user.c
··· 8 8 #include <stdbool.h> 9 9 #include <string.h> 10 10 #include <time.h> 11 - #include <sys/resource.h> 12 11 13 12 #include <bpf/bpf.h> 14 13 #include <bpf/libbpf.h>
-1
samples/bpf/tracex5_user.c
··· 7 7 #include <sys/prctl.h> 8 8 #include <bpf/bpf.h> 9 9 #include <bpf/libbpf.h> 10 - #include <sys/resource.h> 11 10 #include "trace_helpers.h" 12 11 13 12 #ifdef __mips__
-1
samples/bpf/tracex6_user.c
··· 8 8 #include <stdio.h> 9 9 #include <stdlib.h> 10 10 #include <sys/ioctl.h> 11 - #include <sys/resource.h> 12 11 #include <sys/time.h> 13 12 #include <sys/types.h> 14 13 #include <sys/wait.h>
-1
samples/bpf/xdp1_user.c
··· 11 11 #include <string.h> 12 12 #include <unistd.h> 13 13 #include <libgen.h> 14 - #include <sys/resource.h> 15 14 #include <net/if.h> 16 15 17 16 #include "bpf_util.h"
-1
samples/bpf/xdp_adjust_tail_user.c
··· 14 14 #include <stdlib.h> 15 15 #include <string.h> 16 16 #include <net/if.h> 17 - #include <sys/resource.h> 18 17 #include <arpa/inet.h> 19 18 #include <netinet/ether.h> 20 19 #include <unistd.h>
-1
samples/bpf/xdp_monitor_user.c
··· 17 17 #include <ctype.h> 18 18 #include <unistd.h> 19 19 #include <locale.h> 20 - #include <sys/resource.h> 21 20 #include <getopt.h> 22 21 #include <net/if.h> 23 22 #include <time.h>
-1
samples/bpf/xdp_redirect_cpu_user.c
··· 21 21 #include <string.h> 22 22 #include <unistd.h> 23 23 #include <locale.h> 24 - #include <sys/resource.h> 25 24 #include <sys/sysinfo.h> 26 25 #include <getopt.h> 27 26 #include <net/if.h>
-1
samples/bpf/xdp_redirect_map_multi_user.c
··· 15 15 #include <net/if.h> 16 16 #include <unistd.h> 17 17 #include <libgen.h> 18 - #include <sys/resource.h> 19 18 #include <sys/ioctl.h> 20 19 #include <sys/types.h> 21 20 #include <sys/socket.h>
-1
samples/bpf/xdp_redirect_user.c
··· 18 18 #include <unistd.h> 19 19 #include <libgen.h> 20 20 #include <getopt.h> 21 - #include <sys/resource.h> 22 21 #include <bpf/bpf.h> 23 22 #include <bpf/libbpf.h> 24 23 #include "bpf_util.h"
-1
samples/bpf/xdp_router_ipv4_user.c
··· 22 22 #include <sys/syscall.h> 23 23 #include "bpf_util.h" 24 24 #include <bpf/libbpf.h> 25 - #include <sys/resource.h> 26 25 #include <libgen.h> 27 26 #include <getopt.h> 28 27 #include <pthread.h>
-1
samples/bpf/xdp_rxq_info_user.c
··· 14 14 #include <string.h> 15 15 #include <unistd.h> 16 16 #include <locale.h> 17 - #include <sys/resource.h> 18 17 #include <getopt.h> 19 18 #include <net/if.h> 20 19 #include <time.h>
-1
samples/bpf/xdp_sample_pkts_user.c
··· 12 12 #include <signal.h> 13 13 #include <bpf/libbpf.h> 14 14 #include <bpf/bpf.h> 15 - #include <sys/resource.h> 16 15 #include <libgen.h> 17 16 #include <linux/if_link.h> 18 17
-1
samples/bpf/xdp_sample_user.c
··· 25 25 #include <string.h> 26 26 #include <sys/ioctl.h> 27 27 #include <sys/mman.h> 28 - #include <sys/resource.h> 29 28 #include <sys/signalfd.h> 30 29 #include <sys/sysinfo.h> 31 30 #include <sys/timerfd.h>
-1
samples/bpf/xdp_tx_iptunnel_user.c
··· 10 10 #include <stdlib.h> 11 11 #include <string.h> 12 12 #include <net/if.h> 13 - #include <sys/resource.h> 14 13 #include <arpa/inet.h> 15 14 #include <netinet/ether.h> 16 15 #include <unistd.h>
+2 -7
samples/bpf/xdpsock_user.c
··· 25 25 #include <string.h> 26 26 #include <sys/capability.h> 27 27 #include <sys/mman.h> 28 - #include <sys/resource.h> 29 28 #include <sys/socket.h> 30 29 #include <sys/types.h> 31 30 #include <sys/un.h> ··· 1885 1886 { 1886 1887 struct __user_cap_header_struct hdr = { _LINUX_CAPABILITY_VERSION_3, 0 }; 1887 1888 struct __user_cap_data_struct data[2] = { { 0 } }; 1888 - struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; 1889 1889 bool rx = false, tx = false; 1890 1890 struct sched_param schparam; 1891 1891 struct xsk_umem_info *umem; ··· 1915 1917 data[1].effective, data[1].inheritable, data[1].permitted); 1916 1918 } 1917 1919 } else { 1918 - if (setrlimit(RLIMIT_MEMLOCK, &r)) { 1919 - fprintf(stderr, "ERROR: setrlimit(RLIMIT_MEMLOCK) \"%s\"\n", 1920 - strerror(errno)); 1921 - exit(EXIT_FAILURE); 1922 - } 1920 + /* Use libbpf 1.0 API mode */ 1921 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 1923 1922 1924 1923 if (opt_num_xsks > 1) 1925 1924 load_xdp_program(argv, &obj);
+2 -5
samples/bpf/xsk_fwd.c
··· 10 10 #include <stdlib.h> 11 11 #include <string.h> 12 12 #include <sys/mman.h> 13 - #include <sys/resource.h> 14 13 #include <sys/socket.h> 15 14 #include <sys/types.h> 16 15 #include <time.h> ··· 130 131 bpool_init(struct bpool_params *params, 131 132 struct xsk_umem_config *umem_cfg) 132 133 { 133 - struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; 134 134 u64 n_slabs, n_slabs_reserved, n_buffers, n_buffers_reserved; 135 135 u64 slabs_size, slabs_reserved_size; 136 136 u64 buffers_size, buffers_reserved_size; ··· 138 140 u8 *p; 139 141 int status; 140 142 141 - /* mmap prep. */ 142 - if (setrlimit(RLIMIT_MEMLOCK, &r)) 143 - return NULL; 143 + /* Use libbpf 1.0 API mode */ 144 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 144 145 145 146 /* bpool internals dimensioning. */ 146 147 n_slabs = (params->n_buffers + params->n_buffers_per_slab - 1) /
-8
tools/bpf/bpftool/common.c
··· 17 17 #include <linux/magic.h> 18 18 #include <net/if.h> 19 19 #include <sys/mount.h> 20 - #include <sys/resource.h> 21 20 #include <sys/stat.h> 22 21 #include <sys/vfs.h> 23 22 ··· 116 117 return false; 117 118 118 119 return (unsigned long)st_fs.f_type == BPF_FS_MAGIC; 119 - } 120 - 121 - void set_max_rlimit(void) 122 - { 123 - struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY }; 124 - 125 - setrlimit(RLIMIT_MEMLOCK, &rinf); 126 120 } 127 121 128 122 static int
-2
tools/bpf/bpftool/feature.c
··· 1136 1136 __u32 ifindex = 0; 1137 1137 char *ifname; 1138 1138 1139 - set_max_rlimit(); 1140 - 1141 1139 while (argc) { 1142 1140 if (is_prefix(*argv, "kernel")) { 1143 1141 if (target != COMPONENT_UNSPEC) {
+3 -3
tools/bpf/bpftool/main.c
··· 507 507 * It will still be rejected if users use LIBBPF_STRICT_ALL 508 508 * mode for loading generated skeleton. 509 509 */ 510 - ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS); 511 - if (ret) 512 - p_err("failed to enable libbpf strict mode: %d", ret); 510 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS); 511 + } else { 512 + libbpf_set_strict_mode(LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK); 513 513 } 514 514 515 515 argc -= optind;
-2
tools/bpf/bpftool/main.h
··· 102 102 void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); 103 103 void usage(void) __noreturn; 104 104 105 - void set_max_rlimit(void); 106 - 107 105 int mount_tracefs(const char *target); 108 106 109 107 struct obj_ref {
-2
tools/bpf/bpftool/map.c
··· 1342 1342 goto exit; 1343 1343 } 1344 1344 1345 - set_max_rlimit(); 1346 - 1347 1345 fd = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, &attr); 1348 1346 if (fd < 0) { 1349 1347 p_err("map create failed: %s", strerror(errno));
-1
tools/bpf/bpftool/pids.c
··· 108 108 p_err("failed to create hashmap for PID references"); 109 109 return -1; 110 110 } 111 - set_max_rlimit(); 112 111 113 112 skel = pid_iter_bpf__open(); 114 113 if (!skel) {
-3
tools/bpf/bpftool/prog.c
··· 1604 1604 } 1605 1605 } 1606 1606 1607 - set_max_rlimit(); 1608 - 1609 1607 if (verifier_logs) 1610 1608 /* log_level1 + log_level2 + stats, but not stable UAPI */ 1611 1609 open_opts.kernel_log_level = 1 + 2 + 4; ··· 2301 2303 } 2302 2304 } 2303 2305 2304 - set_max_rlimit(); 2305 2306 err = profiler_bpf__load(profile_obj); 2306 2307 if (err) { 2307 2308 p_err("failed to load profile_obj");
-2
tools/bpf/bpftool/struct_ops.c
··· 501 501 if (libbpf_get_error(obj)) 502 502 return -1; 503 503 504 - set_max_rlimit(); 505 - 506 504 if (bpf_object__load(obj)) { 507 505 bpf_object__close(obj); 508 506 return -1;
+2 -16
tools/bpf/runqslower/runqslower.c
··· 4 4 #include <stdio.h> 5 5 #include <stdlib.h> 6 6 #include <string.h> 7 - #include <sys/resource.h> 8 7 #include <time.h> 9 8 #include <bpf/libbpf.h> 10 9 #include <bpf/bpf.h> ··· 87 88 return vfprintf(stderr, format, args); 88 89 } 89 90 90 - static int bump_memlock_rlimit(void) 91 - { 92 - struct rlimit rlim_new = { 93 - .rlim_cur = RLIM_INFINITY, 94 - .rlim_max = RLIM_INFINITY, 95 - }; 96 - 97 - return setrlimit(RLIMIT_MEMLOCK, &rlim_new); 98 - } 99 - 100 91 void handle_event(void *ctx, int cpu, void *data, __u32 data_sz) 101 92 { 102 93 const struct runq_event *e = data; ··· 122 133 123 134 libbpf_set_print(libbpf_print_fn); 124 135 125 - err = bump_memlock_rlimit(); 126 - if (err) { 127 - fprintf(stderr, "failed to increase rlimit: %d", err); 128 - return 1; 129 - } 136 + /* Use libbpf 1.0 API mode */ 137 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 130 138 131 139 obj = runqslower_bpf__open(); 132 140 if (!obj) {
-1
tools/testing/selftests/bpf/bench.c
··· 8 8 #include <fcntl.h> 9 9 #include <pthread.h> 10 10 #include <sys/sysinfo.h> 11 - #include <sys/resource.h> 12 11 #include <signal.h> 13 12 #include "bench.h" 14 13 #include "testing_helpers.h"
-28
tools/testing/selftests/bpf/bpf_rlimit.h
··· 1 - #include <sys/resource.h> 2 - #include <stdio.h> 3 - 4 - static __attribute__((constructor)) void bpf_rlimit_ctor(void) 5 - { 6 - struct rlimit rlim_old, rlim_new = { 7 - .rlim_cur = RLIM_INFINITY, 8 - .rlim_max = RLIM_INFINITY, 9 - }; 10 - 11 - getrlimit(RLIMIT_MEMLOCK, &rlim_old); 12 - /* For the sake of running the test cases, we temporarily 13 - * set rlimit to infinity in order for kernel to focus on 14 - * errors from actual test cases and not getting noise 15 - * from hitting memlock limits. The limit is on per-process 16 - * basis and not a global one, hence destructor not really 17 - * needed here. 18 - */ 19 - if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) { 20 - perror("Unable to lift memlock rlimit"); 21 - /* Trying out lower limit, but expect potential test 22 - * case failures from this! 23 - */ 24 - rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20); 25 - rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20); 26 - setrlimit(RLIMIT_MEMLOCK, &rlim_new); 27 - } 28 - }
+2 -4
tools/testing/selftests/bpf/flow_dissector_load.c
··· 11 11 #include <bpf/bpf.h> 12 12 #include <bpf/libbpf.h> 13 13 14 - #include "bpf_rlimit.h" 15 14 #include "flow_dissector_load.h" 16 15 17 16 const char *cfg_pin_path = "/sys/fs/bpf/flow_dissector"; ··· 24 25 int prog_fd, ret; 25 26 struct bpf_object *obj; 26 27 27 - ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 28 - if (ret) 29 - error(1, 0, "failed to enable libbpf strict mode: %d", ret); 28 + /* Use libbpf 1.0 API mode */ 29 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 30 30 31 31 ret = bpf_flow_load(&obj, cfg_path_name, cfg_prog_name, 32 32 cfg_map_name, NULL, &prog_fd, NULL);
+3 -1
tools/testing/selftests/bpf/get_cgroup_id_user.c
··· 20 20 21 21 #include "cgroup_helpers.h" 22 22 #include "testing_helpers.h" 23 - #include "bpf_rlimit.h" 24 23 25 24 #define CHECK(condition, tag, format...) ({ \ 26 25 int __ret = !!(condition); \ ··· 65 66 cgroup_fd = cgroup_setup_and_join(TEST_CGROUP); 66 67 if (CHECK(cgroup_fd < 0, "cgroup_setup_and_join", "err %d errno %d\n", cgroup_fd, errno)) 67 68 return 1; 69 + 70 + /* Use libbpf 1.0 API mode */ 71 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 68 72 69 73 err = bpf_prog_test_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd); 70 74 if (CHECK(err, "bpf_prog_test_load", "err %d errno %d\n", err, errno))
-1
tools/testing/selftests/bpf/prog_tests/btf.c
··· 8 8 #include <linux/filter.h> 9 9 #include <linux/unistd.h> 10 10 #include <bpf/bpf.h> 11 - #include <sys/resource.h> 12 11 #include <libelf.h> 13 12 #include <gelf.h> 14 13 #include <string.h>
+3 -1
tools/testing/selftests/bpf/test_cgroup_storage.c
··· 6 6 #include <stdlib.h> 7 7 #include <sys/sysinfo.h> 8 8 9 - #include "bpf_rlimit.h" 10 9 #include "bpf_util.h" 11 10 #include "cgroup_helpers.h" 12 11 #include "testing_helpers.h" ··· 50 51 printf("Not enough memory for per-cpu area (%d cpus)\n", nproc); 51 52 goto err; 52 53 } 54 + 55 + /* Use libbpf 1.0 API mode */ 56 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 53 57 54 58 map_fd = bpf_map_create(BPF_MAP_TYPE_CGROUP_STORAGE, NULL, sizeof(key), 55 59 sizeof(value), 0, NULL);
+3 -1
tools/testing/selftests/bpf/test_dev_cgroup.c
··· 15 15 16 16 #include "cgroup_helpers.h" 17 17 #include "testing_helpers.h" 18 - #include "bpf_rlimit.h" 19 18 20 19 #define DEV_CGROUP_PROG "./dev_cgroup.o" 21 20 ··· 26 27 int error = EXIT_FAILURE; 27 28 int prog_fd, cgroup_fd; 28 29 __u32 prog_cnt; 30 + 31 + /* Use libbpf 1.0 API mode */ 32 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 29 33 30 34 if (bpf_prog_test_load(DEV_CGROUP_PROG, BPF_PROG_TYPE_CGROUP_DEVICE, 31 35 &obj, &prog_fd)) {
+3 -1
tools/testing/selftests/bpf/test_lpm_map.c
··· 26 26 #include <bpf/bpf.h> 27 27 28 28 #include "bpf_util.h" 29 - #include "bpf_rlimit.h" 30 29 31 30 struct tlpm_node { 32 31 struct tlpm_node *next; ··· 789 790 790 791 /* we want predictable, pseudo random tests */ 791 792 srand(0xf00ba1); 793 + 794 + /* Use libbpf 1.0 API mode */ 795 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 792 796 793 797 test_lpm_basic(); 794 798 test_lpm_order();
+3 -1
tools/testing/selftests/bpf/test_lru_map.c
··· 18 18 #include <bpf/libbpf.h> 19 19 20 20 #include "bpf_util.h" 21 - #include "bpf_rlimit.h" 22 21 #include "../../../include/linux/filter.h" 23 22 24 23 #define LOCAL_FREE_TARGET (128) ··· 876 877 nr_cpus = bpf_num_possible_cpus(); 877 878 assert(nr_cpus != -1); 878 879 printf("nr_cpus:%d\n\n", nr_cpus); 880 + 881 + /* Use libbpf 1.0 API mode */ 882 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 879 883 880 884 for (f = 0; f < ARRAY_SIZE(map_flags); f++) { 881 885 unsigned int tgt_free = (map_flags[f] & BPF_F_NO_COMMON_LRU) ?
+3 -1
tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
··· 15 15 #include <bpf/bpf.h> 16 16 #include <bpf/libbpf.h> 17 17 18 - #include "bpf_rlimit.h" 19 18 #include "cgroup_helpers.h" 20 19 21 20 #define CGROUP_PATH "/skb_cgroup_test" ··· 158 159 fprintf(stderr, "Usage: %s iface prog_id\n", argv[0]); 159 160 exit(EXIT_FAILURE); 160 161 } 162 + 163 + /* Use libbpf 1.0 API mode */ 164 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 161 165 162 166 cgfd = cgroup_setup_and_join(CGROUP_PATH); 163 167 if (cgfd < 0)
+3 -1
tools/testing/selftests/bpf/test_sock.c
··· 14 14 15 15 #include "cgroup_helpers.h" 16 16 #include <bpf/bpf_endian.h> 17 - #include "bpf_rlimit.h" 18 17 #include "bpf_util.h" 19 18 20 19 #define CG_PATH "/foo" ··· 539 540 cgfd = cgroup_setup_and_join(CG_PATH); 540 541 if (cgfd < 0) 541 542 goto err; 543 + 544 + /* Use libbpf 1.0 API mode */ 545 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 542 546 543 547 if (run_tests(cgfd)) 544 548 goto err;
+3 -1
tools/testing/selftests/bpf/test_sock_addr.c
··· 19 19 #include <bpf/libbpf.h> 20 20 21 21 #include "cgroup_helpers.h" 22 - #include "bpf_rlimit.h" 23 22 #include "bpf_util.h" 24 23 25 24 #ifndef ENOTSUPP ··· 1416 1417 cgfd = cgroup_setup_and_join(CG_PATH); 1417 1418 if (cgfd < 0) 1418 1419 goto err; 1420 + 1421 + /* Use libbpf 1.0 API mode */ 1422 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 1419 1423 1420 1424 if (run_tests(cgfd)) 1421 1425 goto err;
+3 -2
tools/testing/selftests/bpf/test_sockmap.c
··· 18 18 #include <sched.h> 19 19 20 20 #include <sys/time.h> 21 - #include <sys/resource.h> 22 21 #include <sys/types.h> 23 22 #include <sys/sendfile.h> 24 23 ··· 36 37 #include <bpf/libbpf.h> 37 38 38 39 #include "bpf_util.h" 39 - #include "bpf_rlimit.h" 40 40 #include "cgroup_helpers.h" 41 41 42 42 int running; ··· 2014 2016 return cg_fd; 2015 2017 cg_created = 1; 2016 2018 } 2019 + 2020 + /* Use libbpf 1.0 API mode */ 2021 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 2017 2022 2018 2023 if (test == SELFTESTS) { 2019 2024 err = test_selftest(cg_fd, &options);
+3 -1
tools/testing/selftests/bpf/test_sysctl.c
··· 14 14 #include <bpf/libbpf.h> 15 15 16 16 #include <bpf/bpf_endian.h> 17 - #include "bpf_rlimit.h" 18 17 #include "bpf_util.h" 19 18 #include "cgroup_helpers.h" 20 19 #include "testing_helpers.h" ··· 1616 1617 cgfd = cgroup_setup_and_join(CG_PATH); 1617 1618 if (cgfd < 0) 1618 1619 goto err; 1620 + 1621 + /* Use libbpf 1.0 API mode */ 1622 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 1619 1623 1620 1624 if (run_tests(cgfd)) 1621 1625 goto err;
+3 -1
tools/testing/selftests/bpf/test_tag.c
··· 20 20 #include <bpf/bpf.h> 21 21 22 22 #include "../../../include/linux/filter.h" 23 - #include "bpf_rlimit.h" 24 23 #include "testing_helpers.h" 25 24 26 25 static struct bpf_insn prog[BPF_MAXINSNS]; ··· 187 188 LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC); 188 189 uint32_t tests = 0; 189 190 int i, fd_map; 191 + 192 + /* Use libbpf 1.0 API mode */ 193 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 190 194 191 195 fd_map = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(int), 192 196 sizeof(int), 1, &opts);
+3 -1
tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c
··· 15 15 #include <bpf/bpf.h> 16 16 #include <bpf/libbpf.h> 17 17 18 - #include "bpf_rlimit.h" 19 18 #include "cgroup_helpers.h" 20 19 21 20 static int start_server(const struct sockaddr *addr, socklen_t len, bool dual) ··· 233 234 fprintf(stderr, "Usage: %s prog_id\n", argv[0]); 234 235 exit(1); 235 236 } 237 + 238 + /* Use libbpf 1.0 API mode */ 239 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 236 240 237 241 results = get_map_fd_by_prog_id(atoi(argv[1]), &xdp); 238 242 if (results < 0) {
-1
tools/testing/selftests/bpf/test_tcpnotify_user.c
··· 19 19 #include <linux/perf_event.h> 20 20 #include <linux/err.h> 21 21 22 - #include "bpf_rlimit.h" 23 22 #include "bpf_util.h" 24 23 #include "cgroup_helpers.h" 25 24
+3 -2
tools/testing/selftests/bpf/test_verifier_log.c
··· 11 11 12 12 #include <bpf/bpf.h> 13 13 14 - #include "bpf_rlimit.h" 15 - 16 14 #define LOG_SIZE (1 << 20) 17 15 18 16 #define err(str...) printf("ERROR: " str) ··· 138 140 int i; 139 141 140 142 memset(log, 1, LOG_SIZE); 143 + 144 + /* Use libbpf 1.0 API mode */ 145 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 141 146 142 147 /* Test incorrect attr */ 143 148 printf("Test log_level 0...\n");
-1
tools/testing/selftests/bpf/xdp_redirect_multi.c
··· 10 10 #include <net/if.h> 11 11 #include <unistd.h> 12 12 #include <libgen.h> 13 - #include <sys/resource.h> 14 13 #include <sys/ioctl.h> 15 14 #include <sys/types.h> 16 15 #include <sys/socket.h>
+2 -6
tools/testing/selftests/bpf/xdping.c
··· 12 12 #include <string.h> 13 13 #include <unistd.h> 14 14 #include <libgen.h> 15 - #include <sys/resource.h> 16 15 #include <net/if.h> 17 16 #include <sys/types.h> 18 17 #include <sys/socket.h> ··· 88 89 { 89 90 __u32 mode_flags = XDP_FLAGS_DRV_MODE | XDP_FLAGS_SKB_MODE; 90 91 struct addrinfo *a, hints = { .ai_family = AF_INET }; 91 - struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; 92 92 __u16 count = XDPING_DEFAULT_COUNT; 93 93 struct pinginfo pinginfo = { 0 }; 94 94 const char *optstr = "c:I:NsS"; ··· 165 167 freeaddrinfo(a); 166 168 } 167 169 168 - if (setrlimit(RLIMIT_MEMLOCK, &r)) { 169 - perror("setrlimit(RLIMIT_MEMLOCK)"); 170 - return 1; 171 - } 170 + /* Use libbpf 1.0 API mode */ 171 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 172 172 173 173 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); 174 174
+2 -4
tools/testing/selftests/bpf/xdpxceiver.c
··· 90 90 #include <string.h> 91 91 #include <stddef.h> 92 92 #include <sys/mman.h> 93 - #include <sys/resource.h> 94 93 #include <sys/types.h> 95 94 #include <sys/queue.h> 96 95 #include <time.h> ··· 1447 1448 1448 1449 int main(int argc, char **argv) 1449 1450 { 1450 - struct rlimit _rlim = { RLIM_INFINITY, RLIM_INFINITY }; 1451 1451 struct pkt_stream *pkt_stream_default; 1452 1452 struct ifobject *ifobj_tx, *ifobj_rx; 1453 1453 struct test_spec test; 1454 1454 u32 i, j; 1455 1455 1456 - if (setrlimit(RLIMIT_MEMLOCK, &_rlim)) 1457 - exit_with_error(errno); 1456 + /* Use libbpf 1.0 API mode */ 1457 + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); 1458 1458 1459 1459 ifobj_tx = ifobject_create(); 1460 1460 if (!ifobj_tx)