diff options
| author | Jani Nikula <jani.nikula@intel.com> | 2025-06-09 12:40:46 +0300 | 
|---|---|---|
| committer | Jani Nikula <jani.nikula@intel.com> | 2025-06-09 12:40:46 +0300 | 
| commit | 34c55367af96f62e89221444f04487440ebc6487 (patch) | |
| tree | fdb36ba67d7dea09455b55037e26043b7e051ef9 /tools/lib/bpf/libbpf.c | |
| parent | 7247efca0dcbc8ac6147db9200ed1549c0662465 (diff) | |
| parent | 19272b37aa4f83ca52bdf9c16d5d81bdd1354494 (diff) | |
| download | linux-34c55367af96f62e89221444f04487440ebc6487.tar.xz | |
Merge drm/drm-next into drm-intel-next
Sync to v6.16-rc1, among other things to get the fixed size GENMASK_U*()
and BIT_U*() macros.
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
| -rw-r--r-- | tools/lib/bpf/libbpf.c | 87 | 
1 files changed, 48 insertions, 39 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 6b85060f07b3..e9c641a2fb20 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -60,6 +60,8 @@  #define BPF_FS_MAGIC		0xcafe4a11  #endif +#define MAX_EVENT_NAME_LEN	64 +  #define BPF_FS_DEFAULT_PATH "/sys/fs/bpf"  #define BPF_INSN_SZ (sizeof(struct bpf_insn)) @@ -284,7 +286,7 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)  	old_errno = errno;  	va_start(args, format); -	__libbpf_pr(level, format, args); +	print_fn(level, format, args);  	va_end(args);  	errno = old_errno; @@ -896,7 +898,7 @@ bpf_object__add_programs(struct bpf_object *obj, Elf_Data *sec_data,  			return -LIBBPF_ERRNO__FORMAT;  		} -		if (sec_off + prog_sz > sec_sz) { +		if (sec_off + prog_sz > sec_sz || sec_off + prog_sz < sec_off) {  			pr_warn("sec '%s': program at offset %zu crosses section boundary\n",  				sec_name, sec_off);  			return -LIBBPF_ERRNO__FORMAT; @@ -1725,15 +1727,6 @@ static Elf64_Sym *find_elf_var_sym(const struct bpf_object *obj, const char *nam  	return ERR_PTR(-ENOENT);  } -/* Some versions of Android don't provide memfd_create() in their libc - * implementation, so avoid complications and just go straight to Linux - * syscall. - */ -static int sys_memfd_create(const char *name, unsigned flags) -{ -	return syscall(__NR_memfd_create, name, flags); -} -  #ifndef MFD_CLOEXEC  #define MFD_CLOEXEC 0x0001U  #endif @@ -9455,6 +9448,30 @@ int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log  	return 0;  } +struct bpf_func_info *bpf_program__func_info(const struct bpf_program *prog) +{ +	if (prog->func_info_rec_size != sizeof(struct bpf_func_info)) +		return libbpf_err_ptr(-EOPNOTSUPP); +	return prog->func_info; +} + +__u32 bpf_program__func_info_cnt(const struct bpf_program *prog) +{ +	return prog->func_info_cnt; +} + +struct bpf_line_info *bpf_program__line_info(const struct bpf_program *prog) +{ +	if (prog->line_info_rec_size != sizeof(struct bpf_line_info)) +		return libbpf_err_ptr(-EOPNOTSUPP); +	return prog->line_info; +} + +__u32 bpf_program__line_info_cnt(const struct bpf_program *prog) +{ +	return prog->line_info_cnt; +} +  #define SEC_DEF(sec_pfx, ptype, atype, flags, ...) {			    \  	.sec = (char *)sec_pfx,						    \  	.prog_type = BPF_PROG_TYPE_##ptype,				    \ @@ -11121,16 +11138,16 @@ static const char *tracefs_available_filter_functions_addrs(void)  			     : TRACEFS"/available_filter_functions_addrs";  } -static void gen_kprobe_legacy_event_name(char *buf, size_t buf_sz, -					 const char *kfunc_name, size_t offset) +static void gen_probe_legacy_event_name(char *buf, size_t buf_sz, +					const char *name, size_t offset)  {  	static int index = 0;  	int i; -	snprintf(buf, buf_sz, "libbpf_%u_%s_0x%zx_%d", getpid(), kfunc_name, offset, -		 __sync_fetch_and_add(&index, 1)); +	snprintf(buf, buf_sz, "libbpf_%u_%d_%s_0x%zx", getpid(), +		 __sync_fetch_and_add(&index, 1), name, offset); -	/* sanitize binary_path in the probe name */ +	/* sanitize name in the probe name */  	for (i = 0; buf[i]; i++) {  		if (!isalnum(buf[i]))  			buf[i] = '_'; @@ -11255,9 +11272,9 @@ int probe_kern_syscall_wrapper(int token_fd)  		return pfd >= 0 ? 1 : 0;  	} else { /* legacy mode */ -		char probe_name[128]; +		char probe_name[MAX_EVENT_NAME_LEN]; -		gen_kprobe_legacy_event_name(probe_name, sizeof(probe_name), syscall_name, 0); +		gen_probe_legacy_event_name(probe_name, sizeof(probe_name), syscall_name, 0);  		if (add_kprobe_event_legacy(probe_name, false, syscall_name, 0) < 0)  			return 0; @@ -11313,10 +11330,10 @@ bpf_program__attach_kprobe_opts(const struct bpf_program *prog,  					    func_name, offset,  					    -1 /* pid */, 0 /* ref_ctr_off */);  	} else { -		char probe_name[256]; +		char probe_name[MAX_EVENT_NAME_LEN]; -		gen_kprobe_legacy_event_name(probe_name, sizeof(probe_name), -					     func_name, offset); +		gen_probe_legacy_event_name(probe_name, sizeof(probe_name), +					    func_name, offset);  		legacy_probe = strdup(probe_name);  		if (!legacy_probe) @@ -11860,20 +11877,6 @@ static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, stru  	return ret;  } -static void gen_uprobe_legacy_event_name(char *buf, size_t buf_sz, -					 const char *binary_path, uint64_t offset) -{ -	int i; - -	snprintf(buf, buf_sz, "libbpf_%u_%s_0x%zx", getpid(), binary_path, (size_t)offset); - -	/* sanitize binary_path in the probe name */ -	for (i = 0; buf[i]; i++) { -		if (!isalnum(buf[i])) -			buf[i] = '_'; -	} -} -  static inline int add_uprobe_event_legacy(const char *probe_name, bool retprobe,  					  const char *binary_path, size_t offset)  { @@ -12297,13 +12300,14 @@ bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid,  		pfd = perf_event_open_probe(true /* uprobe */, retprobe, binary_path,  					    func_offset, pid, ref_ctr_off);  	} else { -		char probe_name[PATH_MAX + 64]; +		char probe_name[MAX_EVENT_NAME_LEN];  		if (ref_ctr_off)  			return libbpf_err_ptr(-EINVAL); -		gen_uprobe_legacy_event_name(probe_name, sizeof(probe_name), -					     binary_path, func_offset); +		gen_probe_legacy_event_name(probe_name, sizeof(probe_name), +					    strrchr(binary_path, '/') ? : binary_path, +					    func_offset);  		legacy_probe = strdup(probe_name);  		if (!legacy_probe) @@ -13371,7 +13375,6 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt,  	attr.config = PERF_COUNT_SW_BPF_OUTPUT;  	attr.type = PERF_TYPE_SOFTWARE;  	attr.sample_type = PERF_SAMPLE_RAW; -	attr.sample_period = sample_period;  	attr.wakeup_events = sample_period;  	p.attr = &attr; @@ -14099,6 +14102,12 @@ int bpf_object__attach_skeleton(struct bpf_object_skeleton *s)  		}  		link = map_skel->link; +		if (!link) { +			pr_warn("map '%s': BPF map skeleton link is uninitialized\n", +				bpf_map__name(map)); +			continue; +		} +  		if (*link)  			continue;  | 
