mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	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 <laoar.shao@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20220409125958.92629-4-laoar.shao@gmail.com
This commit is contained in:
		
							parent
							
								
									b858ba8c52
								
							
						
					
					
						commit
						a777e18f1b
					
				
					 8 changed files with 3 additions and 23 deletions
				
			
		|  | @ -17,7 +17,6 @@ | ||||||
| #include <linux/magic.h> | #include <linux/magic.h> | ||||||
| #include <net/if.h> | #include <net/if.h> | ||||||
| #include <sys/mount.h> | #include <sys/mount.h> | ||||||
| #include <sys/resource.h> |  | ||||||
| #include <sys/stat.h> | #include <sys/stat.h> | ||||||
| #include <sys/vfs.h> | #include <sys/vfs.h> | ||||||
| 
 | 
 | ||||||
|  | @ -119,13 +118,6 @@ static bool is_bpffs(char *path) | ||||||
| 	return (unsigned long)st_fs.f_type == BPF_FS_MAGIC; | 	return (unsigned long)st_fs.f_type == BPF_FS_MAGIC; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void set_max_rlimit(void) |  | ||||||
| { |  | ||||||
| 	struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY }; |  | ||||||
| 
 |  | ||||||
| 	setrlimit(RLIMIT_MEMLOCK, &rinf); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static int | static int | ||||||
| mnt_fs(const char *target, const char *type, char *buff, size_t bufflen) | mnt_fs(const char *target, const char *type, char *buff, size_t bufflen) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -1136,8 +1136,6 @@ static int do_probe(int argc, char **argv) | ||||||
| 	__u32 ifindex = 0; | 	__u32 ifindex = 0; | ||||||
| 	char *ifname; | 	char *ifname; | ||||||
| 
 | 
 | ||||||
| 	set_max_rlimit(); |  | ||||||
| 
 |  | ||||||
| 	while (argc) { | 	while (argc) { | ||||||
| 		if (is_prefix(*argv, "kernel")) { | 		if (is_prefix(*argv, "kernel")) { | ||||||
| 			if (target != COMPONENT_UNSPEC) { | 			if (target != COMPONENT_UNSPEC) { | ||||||
|  |  | ||||||
|  | @ -507,9 +507,9 @@ int main(int argc, char **argv) | ||||||
| 		 * It will still be rejected if users use LIBBPF_STRICT_ALL | 		 * It will still be rejected if users use LIBBPF_STRICT_ALL | ||||||
| 		 * mode for loading generated skeleton. | 		 * mode for loading generated skeleton. | ||||||
| 		 */ | 		 */ | ||||||
| 		ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS); | 		libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS); | ||||||
| 		if (ret) | 	} else { | ||||||
| 			p_err("failed to enable libbpf strict mode: %d", ret); | 		libbpf_set_strict_mode(LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	argc -= optind; | 	argc -= optind; | ||||||
|  |  | ||||||
|  | @ -102,8 +102,6 @@ int detect_common_prefix(const char *arg, ...); | ||||||
| void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); | void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); | ||||||
| void usage(void) __noreturn; | void usage(void) __noreturn; | ||||||
| 
 | 
 | ||||||
| void set_max_rlimit(void); |  | ||||||
| 
 |  | ||||||
| int mount_tracefs(const char *target); | int mount_tracefs(const char *target); | ||||||
| 
 | 
 | ||||||
| struct obj_ref { | struct obj_ref { | ||||||
|  |  | ||||||
|  | @ -1342,8 +1342,6 @@ static int do_create(int argc, char **argv) | ||||||
| 		goto exit; | 		goto exit; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	set_max_rlimit(); |  | ||||||
| 
 |  | ||||||
| 	fd = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, &attr); | 	fd = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, &attr); | ||||||
| 	if (fd < 0) { | 	if (fd < 0) { | ||||||
| 		p_err("map create failed: %s", strerror(errno)); | 		p_err("map create failed: %s", strerror(errno)); | ||||||
|  |  | ||||||
|  | @ -108,7 +108,6 @@ int build_obj_refs_table(struct hashmap **map, enum bpf_obj_type type) | ||||||
| 		p_err("failed to create hashmap for PID references"); | 		p_err("failed to create hashmap for PID references"); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| 	set_max_rlimit(); |  | ||||||
| 
 | 
 | ||||||
| 	skel = pid_iter_bpf__open(); | 	skel = pid_iter_bpf__open(); | ||||||
| 	if (!skel) { | 	if (!skel) { | ||||||
|  |  | ||||||
|  | @ -1604,8 +1604,6 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	set_max_rlimit(); |  | ||||||
| 
 |  | ||||||
| 	if (verifier_logs) | 	if (verifier_logs) | ||||||
| 		/* log_level1 + log_level2 + stats, but not stable UAPI */ | 		/* log_level1 + log_level2 + stats, but not stable UAPI */ | ||||||
| 		open_opts.kernel_log_level = 1 + 2 + 4; | 		open_opts.kernel_log_level = 1 + 2 + 4; | ||||||
|  | @ -2303,7 +2301,6 @@ static int do_profile(int argc, char **argv) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	set_max_rlimit(); |  | ||||||
| 	err = profiler_bpf__load(profile_obj); | 	err = profiler_bpf__load(profile_obj); | ||||||
| 	if (err) { | 	if (err) { | ||||||
| 		p_err("failed to load profile_obj"); | 		p_err("failed to load profile_obj"); | ||||||
|  |  | ||||||
|  | @ -501,8 +501,6 @@ static int do_register(int argc, char **argv) | ||||||
| 	if (libbpf_get_error(obj)) | 	if (libbpf_get_error(obj)) | ||||||
| 		return -1; | 		return -1; | ||||||
| 
 | 
 | ||||||
| 	set_max_rlimit(); |  | ||||||
| 
 |  | ||||||
| 	if (bpf_object__load(obj)) { | 	if (bpf_object__load(obj)) { | ||||||
| 		bpf_object__close(obj); | 		bpf_object__close(obj); | ||||||
| 		return -1; | 		return -1; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Yafang Shao
						Yafang Shao