Skip to content

Commit a777e18

Browse files
laoaranakryiko
authored andcommitted
bpftool: 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. libbpf_set_strict_mode always return 0, so we don't need to check whether the return value is 0 or not. Signed-off-by: Yafang Shao <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b858ba8 commit a777e18

File tree

8 files changed

+3
-23
lines changed

8 files changed

+3
-23
lines changed

tools/bpf/bpftool/common.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <linux/magic.h>
1818
#include <net/if.h>
1919
#include <sys/mount.h>
20-
#include <sys/resource.h>
2120
#include <sys/stat.h>
2221
#include <sys/vfs.h>
2322

@@ -119,13 +118,6 @@ static bool is_bpffs(char *path)
119118
return (unsigned long)st_fs.f_type == BPF_FS_MAGIC;
120119
}
121120

122-
void set_max_rlimit(void)
123-
{
124-
struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };
125-
126-
setrlimit(RLIMIT_MEMLOCK, &rinf);
127-
}
128-
129121
static int
130122
mnt_fs(const char *target, const char *type, char *buff, size_t bufflen)
131123
{

tools/bpf/bpftool/feature.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,6 @@ static int do_probe(int argc, char **argv)
11361136
__u32 ifindex = 0;
11371137
char *ifname;
11381138

1139-
set_max_rlimit();
1140-
11411139
while (argc) {
11421140
if (is_prefix(*argv, "kernel")) {
11431141
if (target != COMPONENT_UNSPEC) {

tools/bpf/bpftool/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,9 @@ int main(int argc, char **argv)
507507
* It will still be rejected if users use LIBBPF_STRICT_ALL
508508
* mode for loading generated skeleton.
509509
*/
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);
513513
}
514514

515515
argc -= optind;

tools/bpf/bpftool/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ int detect_common_prefix(const char *arg, ...);
102102
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
103103
void usage(void) __noreturn;
104104

105-
void set_max_rlimit(void);
106-
107105
int mount_tracefs(const char *target);
108106

109107
struct obj_ref {

tools/bpf/bpftool/map.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,6 @@ static int do_create(int argc, char **argv)
13421342
goto exit;
13431343
}
13441344

1345-
set_max_rlimit();
1346-
13471345
fd = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, &attr);
13481346
if (fd < 0) {
13491347
p_err("map create failed: %s", strerror(errno));

tools/bpf/bpftool/pids.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ int build_obj_refs_table(struct hashmap **map, enum bpf_obj_type type)
108108
p_err("failed to create hashmap for PID references");
109109
return -1;
110110
}
111-
set_max_rlimit();
112111

113112
skel = pid_iter_bpf__open();
114113
if (!skel) {

tools/bpf/bpftool/prog.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,8 +1604,6 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
16041604
}
16051605
}
16061606

1607-
set_max_rlimit();
1608-
16091607
if (verifier_logs)
16101608
/* log_level1 + log_level2 + stats, but not stable UAPI */
16111609
open_opts.kernel_log_level = 1 + 2 + 4;
@@ -2303,7 +2301,6 @@ static int do_profile(int argc, char **argv)
23032301
}
23042302
}
23052303

2306-
set_max_rlimit();
23072304
err = profiler_bpf__load(profile_obj);
23082305
if (err) {
23092306
p_err("failed to load profile_obj");

tools/bpf/bpftool/struct_ops.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,6 @@ static int do_register(int argc, char **argv)
501501
if (libbpf_get_error(obj))
502502
return -1;
503503

504-
set_max_rlimit();
505-
506504
if (bpf_object__load(obj)) {
507505
bpf_object__close(obj);
508506
return -1;

0 commit comments

Comments
 (0)