Commit be18010e authored by Kefeng Wang's avatar Kefeng Wang Committed by Daniel Borkmann

tools, bpf: Rename pr_warning to pr_warn to align with kernel logging

For kernel logging macros, pr_warning() is completely removed and
replaced by pr_warn(). By using pr_warn() in tools/lib/bpf/ for
symmetry to kernel logging macros, we could eventually drop the
use of pr_warning() in the whole kernel tree.
Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20191021055532.185245-1-wangkefeng.wang@huawei.com
parent ab81e203
...@@ -390,14 +390,14 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) ...@@ -390,14 +390,14 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)
GElf_Ehdr ehdr; GElf_Ehdr ehdr;
if (elf_version(EV_CURRENT) == EV_NONE) { if (elf_version(EV_CURRENT) == EV_NONE) {
pr_warning("failed to init libelf for %s\n", path); pr_warn("failed to init libelf for %s\n", path);
return ERR_PTR(-LIBBPF_ERRNO__LIBELF); return ERR_PTR(-LIBBPF_ERRNO__LIBELF);
} }
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
err = -errno; err = -errno;
pr_warning("failed to open %s: %s\n", path, strerror(errno)); pr_warn("failed to open %s: %s\n", path, strerror(errno));
return ERR_PTR(err); return ERR_PTR(err);
} }
...@@ -405,19 +405,19 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) ...@@ -405,19 +405,19 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)
elf = elf_begin(fd, ELF_C_READ, NULL); elf = elf_begin(fd, ELF_C_READ, NULL);
if (!elf) { if (!elf) {
pr_warning("failed to open %s as ELF file\n", path); pr_warn("failed to open %s as ELF file\n", path);
goto done; goto done;
} }
if (!gelf_getehdr(elf, &ehdr)) { if (!gelf_getehdr(elf, &ehdr)) {
pr_warning("failed to get EHDR from %s\n", path); pr_warn("failed to get EHDR from %s\n", path);
goto done; goto done;
} }
if (!btf_check_endianness(&ehdr)) { if (!btf_check_endianness(&ehdr)) {
pr_warning("non-native ELF endianness is not supported\n"); pr_warn("non-native ELF endianness is not supported\n");
goto done; goto done;
} }
if (!elf_rawdata(elf_getscn(elf, ehdr.e_shstrndx), NULL)) { if (!elf_rawdata(elf_getscn(elf, ehdr.e_shstrndx), NULL)) {
pr_warning("failed to get e_shstrndx from %s\n", path); pr_warn("failed to get e_shstrndx from %s\n", path);
goto done; goto done;
} }
...@@ -427,20 +427,20 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) ...@@ -427,20 +427,20 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)
idx++; idx++;
if (gelf_getshdr(scn, &sh) != &sh) { if (gelf_getshdr(scn, &sh) != &sh) {
pr_warning("failed to get section(%d) header from %s\n", pr_warn("failed to get section(%d) header from %s\n",
idx, path); idx, path);
goto done; goto done;
} }
name = elf_strptr(elf, ehdr.e_shstrndx, sh.sh_name); name = elf_strptr(elf, ehdr.e_shstrndx, sh.sh_name);
if (!name) { if (!name) {
pr_warning("failed to get section(%d) name from %s\n", pr_warn("failed to get section(%d) name from %s\n",
idx, path); idx, path);
goto done; goto done;
} }
if (strcmp(name, BTF_ELF_SEC) == 0) { if (strcmp(name, BTF_ELF_SEC) == 0) {
btf_data = elf_getdata(scn, 0); btf_data = elf_getdata(scn, 0);
if (!btf_data) { if (!btf_data) {
pr_warning("failed to get section(%d, %s) data from %s\n", pr_warn("failed to get section(%d, %s) data from %s\n",
idx, name, path); idx, name, path);
goto done; goto done;
} }
...@@ -448,7 +448,7 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) ...@@ -448,7 +448,7 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)
} else if (btf_ext && strcmp(name, BTF_EXT_ELF_SEC) == 0) { } else if (btf_ext && strcmp(name, BTF_EXT_ELF_SEC) == 0) {
btf_ext_data = elf_getdata(scn, 0); btf_ext_data = elf_getdata(scn, 0);
if (!btf_ext_data) { if (!btf_ext_data) {
pr_warning("failed to get section(%d, %s) data from %s\n", pr_warn("failed to get section(%d, %s) data from %s\n",
idx, name, path); idx, name, path);
goto done; goto done;
} }
...@@ -600,9 +600,9 @@ int btf__load(struct btf *btf) ...@@ -600,9 +600,9 @@ int btf__load(struct btf *btf)
log_buf, log_buf_size, false); log_buf, log_buf_size, false);
if (btf->fd < 0) { if (btf->fd < 0) {
err = -errno; err = -errno;
pr_warning("Error loading BTF: %s(%d)\n", strerror(errno), errno); pr_warn("Error loading BTF: %s(%d)\n", strerror(errno), errno);
if (*log_buf) if (*log_buf)
pr_warning("%s\n", log_buf); pr_warn("%s\n", log_buf);
goto done; goto done;
} }
...@@ -707,7 +707,7 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, ...@@ -707,7 +707,7 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
if (snprintf(container_name, max_name, "____btf_map_%s", map_name) == if (snprintf(container_name, max_name, "____btf_map_%s", map_name) ==
max_name) { max_name) {
pr_warning("map:%s length of '____btf_map_%s' is too long\n", pr_warn("map:%s length of '____btf_map_%s' is too long\n",
map_name, map_name); map_name, map_name);
return -EINVAL; return -EINVAL;
} }
...@@ -721,13 +721,13 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, ...@@ -721,13 +721,13 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
container_type = btf__type_by_id(btf, container_id); container_type = btf__type_by_id(btf, container_id);
if (!container_type) { if (!container_type) {
pr_warning("map:%s cannot find BTF type for container_id:%u\n", pr_warn("map:%s cannot find BTF type for container_id:%u\n",
map_name, container_id); map_name, container_id);
return -EINVAL; return -EINVAL;
} }
if (!btf_is_struct(container_type) || btf_vlen(container_type) < 2) { if (!btf_is_struct(container_type) || btf_vlen(container_type) < 2) {
pr_warning("map:%s container_name:%s is an invalid container struct\n", pr_warn("map:%s container_name:%s is an invalid container struct\n",
map_name, container_name); map_name, container_name);
return -EINVAL; return -EINVAL;
} }
...@@ -737,24 +737,24 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, ...@@ -737,24 +737,24 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
key_size = btf__resolve_size(btf, key->type); key_size = btf__resolve_size(btf, key->type);
if (key_size < 0) { if (key_size < 0) {
pr_warning("map:%s invalid BTF key_type_size\n", map_name); pr_warn("map:%s invalid BTF key_type_size\n", map_name);
return key_size; return key_size;
} }
if (expected_key_size != key_size) { if (expected_key_size != key_size) {
pr_warning("map:%s btf_key_type_size:%u != map_def_key_size:%u\n", pr_warn("map:%s btf_key_type_size:%u != map_def_key_size:%u\n",
map_name, (__u32)key_size, expected_key_size); map_name, (__u32)key_size, expected_key_size);
return -EINVAL; return -EINVAL;
} }
value_size = btf__resolve_size(btf, value->type); value_size = btf__resolve_size(btf, value->type);
if (value_size < 0) { if (value_size < 0) {
pr_warning("map:%s invalid BTF value_type_size\n", map_name); pr_warn("map:%s invalid BTF value_type_size\n", map_name);
return value_size; return value_size;
} }
if (expected_value_size != value_size) { if (expected_value_size != value_size) {
pr_warning("map:%s btf_value_type_size:%u != map_def_value_size:%u\n", pr_warn("map:%s btf_value_type_size:%u != map_def_value_size:%u\n",
map_name, (__u32)value_size, expected_value_size); map_name, (__u32)value_size, expected_value_size);
return -EINVAL; return -EINVAL;
} }
......
...@@ -428,7 +428,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) ...@@ -428,7 +428,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
/* type loop, but resolvable through fwd declaration */ /* type loop, but resolvable through fwd declaration */
if (btf_is_composite(t) && through_ptr && t->name_off != 0) if (btf_is_composite(t) && through_ptr && t->name_off != 0)
return 0; return 0;
pr_warning("unsatisfiable type cycle, id:[%u]\n", id); pr_warn("unsatisfiable type cycle, id:[%u]\n", id);
return -ELOOP; return -ELOOP;
} }
...@@ -636,7 +636,7 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) ...@@ -636,7 +636,7 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id)
if (id == cont_id) if (id == cont_id)
return; return;
if (t->name_off == 0) { if (t->name_off == 0) {
pr_warning("anonymous struct/union loop, id:[%u]\n", pr_warn("anonymous struct/union loop, id:[%u]\n",
id); id);
return; return;
} }
...@@ -782,7 +782,7 @@ static int btf_align_of(const struct btf *btf, __u32 id) ...@@ -782,7 +782,7 @@ static int btf_align_of(const struct btf *btf, __u32 id)
return align; return align;
} }
default: default:
pr_warning("unsupported BTF_KIND:%u\n", btf_kind(t)); pr_warn("unsupported BTF_KIND:%u\n", btf_kind(t));
return 1; return 1;
} }
} }
...@@ -1067,7 +1067,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, ...@@ -1067,7 +1067,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
* chain, restore stack, emit warning, and try to * chain, restore stack, emit warning, and try to
* proceed nevertheless * proceed nevertheless
*/ */
pr_warning("not enough memory for decl stack:%d", err); pr_warn("not enough memory for decl stack:%d", err);
d->decl_stack_cnt = stack_start; d->decl_stack_cnt = stack_start;
return; return;
} }
...@@ -1096,7 +1096,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, ...@@ -1096,7 +1096,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
case BTF_KIND_TYPEDEF: case BTF_KIND_TYPEDEF:
goto done; goto done;
default: default:
pr_warning("unexpected type in decl chain, kind:%u, id:[%u]\n", pr_warn("unexpected type in decl chain, kind:%u, id:[%u]\n",
btf_kind(t), id); btf_kind(t), id);
goto done; goto done;
} }
...@@ -1323,7 +1323,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, ...@@ -1323,7 +1323,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
return; return;
} }
default: default:
pr_warning("unexpected type in decl chain, kind:%u, id:[%u]\n", pr_warn("unexpected type in decl chain, kind:%u, id:[%u]\n",
kind, id); kind, id);
return; return;
} }
......
...@@ -312,7 +312,7 @@ void bpf_program__unload(struct bpf_program *prog) ...@@ -312,7 +312,7 @@ void bpf_program__unload(struct bpf_program *prog)
for (i = 0; i < prog->instances.nr; i++) for (i = 0; i < prog->instances.nr; i++)
zclose(prog->instances.fds[i]); zclose(prog->instances.fds[i]);
} else if (prog->instances.nr != -1) { } else if (prog->instances.nr != -1) {
pr_warning("Internal error: instances.nr is %d\n", pr_warn("Internal error: instances.nr is %d\n",
prog->instances.nr); prog->instances.nr);
} }
...@@ -364,7 +364,7 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx, ...@@ -364,7 +364,7 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx,
const size_t bpf_insn_sz = sizeof(struct bpf_insn); const size_t bpf_insn_sz = sizeof(struct bpf_insn);
if (size == 0 || size % bpf_insn_sz) { if (size == 0 || size % bpf_insn_sz) {
pr_warning("corrupted section '%s', size: %zu\n", pr_warn("corrupted section '%s', size: %zu\n",
section_name, size); section_name, size);
return -EINVAL; return -EINVAL;
} }
...@@ -373,21 +373,21 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx, ...@@ -373,21 +373,21 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx,
prog->section_name = strdup(section_name); prog->section_name = strdup(section_name);
if (!prog->section_name) { if (!prog->section_name) {
pr_warning("failed to alloc name for prog under section(%d) %s\n", pr_warn("failed to alloc name for prog under section(%d) %s\n",
idx, section_name); idx, section_name);
goto errout; goto errout;
} }
prog->pin_name = __bpf_program__pin_name(prog); prog->pin_name = __bpf_program__pin_name(prog);
if (!prog->pin_name) { if (!prog->pin_name) {
pr_warning("failed to alloc pin name for prog under section(%d) %s\n", pr_warn("failed to alloc pin name for prog under section(%d) %s\n",
idx, section_name); idx, section_name);
goto errout; goto errout;
} }
prog->insns = malloc(size); prog->insns = malloc(size);
if (!prog->insns) { if (!prog->insns) {
pr_warning("failed to alloc insns for prog under section %s\n", pr_warn("failed to alloc insns for prog under section %s\n",
section_name); section_name);
goto errout; goto errout;
} }
...@@ -426,7 +426,7 @@ bpf_object__add_program(struct bpf_object *obj, void *data, size_t size, ...@@ -426,7 +426,7 @@ bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
* is still valid, so don't need special treat for * is still valid, so don't need special treat for
* bpf_close_object(). * bpf_close_object().
*/ */
pr_warning("failed to alloc a new program under section '%s'\n", pr_warn("failed to alloc a new program under section '%s'\n",
section_name); section_name);
bpf_program__exit(&prog); bpf_program__exit(&prog);
return -ENOMEM; return -ENOMEM;
...@@ -467,7 +467,7 @@ bpf_object__init_prog_names(struct bpf_object *obj) ...@@ -467,7 +467,7 @@ bpf_object__init_prog_names(struct bpf_object *obj)
obj->efile.strtabidx, obj->efile.strtabidx,
sym.st_name); sym.st_name);
if (!name) { if (!name) {
pr_warning("failed to get sym name string for prog %s\n", pr_warn("failed to get sym name string for prog %s\n",
prog->section_name); prog->section_name);
return -LIBBPF_ERRNO__LIBELF; return -LIBBPF_ERRNO__LIBELF;
} }
...@@ -477,14 +477,14 @@ bpf_object__init_prog_names(struct bpf_object *obj) ...@@ -477,14 +477,14 @@ bpf_object__init_prog_names(struct bpf_object *obj)
name = ".text"; name = ".text";
if (!name) { if (!name) {
pr_warning("failed to find sym for prog %s\n", pr_warn("failed to find sym for prog %s\n",
prog->section_name); prog->section_name);
return -EINVAL; return -EINVAL;
} }
prog->name = strdup(name); prog->name = strdup(name);
if (!prog->name) { if (!prog->name) {
pr_warning("failed to allocate memory for prog sym %s\n", pr_warn("failed to allocate memory for prog sym %s\n",
name); name);
return -ENOMEM; return -ENOMEM;
} }
...@@ -514,7 +514,7 @@ static struct bpf_object *bpf_object__new(const char *path, ...@@ -514,7 +514,7 @@ static struct bpf_object *bpf_object__new(const char *path,
obj = calloc(1, sizeof(struct bpf_object) + strlen(path) + 1); obj = calloc(1, sizeof(struct bpf_object) + strlen(path) + 1);
if (!obj) { if (!obj) {
pr_warning("alloc memory failed for %s\n", path); pr_warn("alloc memory failed for %s\n", path);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -581,7 +581,7 @@ static int bpf_object__elf_init(struct bpf_object *obj) ...@@ -581,7 +581,7 @@ static int bpf_object__elf_init(struct bpf_object *obj)
GElf_Ehdr *ep; GElf_Ehdr *ep;
if (obj_elf_valid(obj)) { if (obj_elf_valid(obj)) {
pr_warning("elf init: internal error\n"); pr_warn("elf init: internal error\n");
return -LIBBPF_ERRNO__LIBELF; return -LIBBPF_ERRNO__LIBELF;
} }
...@@ -599,7 +599,7 @@ static int bpf_object__elf_init(struct bpf_object *obj) ...@@ -599,7 +599,7 @@ static int bpf_object__elf_init(struct bpf_object *obj)
err = -errno; err = -errno;
cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));
pr_warning("failed to open %s: %s\n", obj->path, cp); pr_warn("failed to open %s: %s\n", obj->path, cp);
return err; return err;
} }
...@@ -608,13 +608,13 @@ static int bpf_object__elf_init(struct bpf_object *obj) ...@@ -608,13 +608,13 @@ static int bpf_object__elf_init(struct bpf_object *obj)
} }
if (!obj->efile.elf) { if (!obj->efile.elf) {
pr_warning("failed to open %s as ELF file\n", obj->path); pr_warn("failed to open %s as ELF file\n", obj->path);
err = -LIBBPF_ERRNO__LIBELF; err = -LIBBPF_ERRNO__LIBELF;
goto errout; goto errout;
} }
if (!gelf_getehdr(obj->efile.elf, &obj->efile.ehdr)) { if (!gelf_getehdr(obj->efile.elf, &obj->efile.ehdr)) {
pr_warning("failed to get EHDR from %s\n", obj->path); pr_warn("failed to get EHDR from %s\n", obj->path);
err = -LIBBPF_ERRNO__FORMAT; err = -LIBBPF_ERRNO__FORMAT;
goto errout; goto errout;
} }
...@@ -623,7 +623,7 @@ static int bpf_object__elf_init(struct bpf_object *obj) ...@@ -623,7 +623,7 @@ static int bpf_object__elf_init(struct bpf_object *obj)
/* Old LLVM set e_machine to EM_NONE */ /* Old LLVM set e_machine to EM_NONE */
if (ep->e_type != ET_REL || if (ep->e_type != ET_REL ||
(ep->e_machine && ep->e_machine != EM_BPF)) { (ep->e_machine && ep->e_machine != EM_BPF)) {
pr_warning("%s is not an eBPF object file\n", obj->path); pr_warn("%s is not an eBPF object file\n", obj->path);
err = -LIBBPF_ERRNO__FORMAT; err = -LIBBPF_ERRNO__FORMAT;
goto errout; goto errout;
} }
...@@ -645,7 +645,7 @@ static int bpf_object__check_endianness(struct bpf_object *obj) ...@@ -645,7 +645,7 @@ static int bpf_object__check_endianness(struct bpf_object *obj)
#else #else
# error "Unrecognized __BYTE_ORDER__" # error "Unrecognized __BYTE_ORDER__"
#endif #endif
pr_warning("endianness mismatch.\n"); pr_warn("endianness mismatch.\n");
return -LIBBPF_ERRNO__ENDIAN; return -LIBBPF_ERRNO__ENDIAN;
} }
...@@ -663,7 +663,7 @@ bpf_object__init_kversion(struct bpf_object *obj, void *data, size_t size) ...@@ -663,7 +663,7 @@ bpf_object__init_kversion(struct bpf_object *obj, void *data, size_t size)
__u32 kver; __u32 kver;
if (size != sizeof(kver)) { if (size != sizeof(kver)) {
pr_warning("invalid kver section in %s\n", obj->path); pr_warn("invalid kver section in %s\n", obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
memcpy(&kver, data, sizeof(kver)); memcpy(&kver, data, sizeof(kver));
...@@ -705,14 +705,14 @@ static int bpf_object_search_section_size(const struct bpf_object *obj, ...@@ -705,14 +705,14 @@ static int bpf_object_search_section_size(const struct bpf_object *obj,
idx++; idx++;
if (gelf_getshdr(scn, &sh) != &sh) { if (gelf_getshdr(scn, &sh) != &sh) {
pr_warning("failed to get section(%d) header from %s\n", pr_warn("failed to get section(%d) header from %s\n",
idx, obj->path); idx, obj->path);
return -EIO; return -EIO;
} }
sec_name = elf_strptr(elf, ep->e_shstrndx, sh.sh_name); sec_name = elf_strptr(elf, ep->e_shstrndx, sh.sh_name);
if (!sec_name) { if (!sec_name) {
pr_warning("failed to get section(%d) name from %s\n", pr_warn("failed to get section(%d) name from %s\n",
idx, obj->path); idx, obj->path);
return -EIO; return -EIO;
} }
...@@ -722,7 +722,7 @@ static int bpf_object_search_section_size(const struct bpf_object *obj, ...@@ -722,7 +722,7 @@ static int bpf_object_search_section_size(const struct bpf_object *obj,
data = elf_getdata(scn, 0); data = elf_getdata(scn, 0);
if (!data) { if (!data) {
pr_warning("failed to get section(%d) data from %s(%s)\n", pr_warn("failed to get section(%d) data from %s(%s)\n",
idx, name, obj->path); idx, name, obj->path);
return -EIO; return -EIO;
} }
...@@ -783,7 +783,7 @@ int bpf_object__variable_offset(const struct bpf_object *obj, const char *name, ...@@ -783,7 +783,7 @@ int bpf_object__variable_offset(const struct bpf_object *obj, const char *name,
sname = elf_strptr(obj->efile.elf, obj->efile.strtabidx, sname = elf_strptr(obj->efile.elf, obj->efile.strtabidx,
sym.st_name); sym.st_name);
if (!sname) { if (!sname) {
pr_warning("failed to get sym name string for var %s\n", pr_warn("failed to get sym name string for var %s\n",
name); name);
return -EIO; return -EIO;
} }
...@@ -808,7 +808,7 @@ static struct bpf_map *bpf_object__add_map(struct bpf_object *obj) ...@@ -808,7 +808,7 @@ static struct bpf_map *bpf_object__add_map(struct bpf_object *obj)
new_cap = max((size_t)4, obj->maps_cap * 3 / 2); new_cap = max((size_t)4, obj->maps_cap * 3 / 2);
new_maps = realloc(obj->maps, new_cap * sizeof(*obj->maps)); new_maps = realloc(obj->maps, new_cap * sizeof(*obj->maps));
if (!new_maps) { if (!new_maps) {
pr_warning("alloc maps for object failed\n"); pr_warn("alloc maps for object failed\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -849,7 +849,7 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type, ...@@ -849,7 +849,7 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
libbpf_type_to_btf_name[type]); libbpf_type_to_btf_name[type]);
map->name = strdup(map_name); map->name = strdup(map_name);
if (!map->name) { if (!map->name) {
pr_warning("failed to alloc map name\n"); pr_warn("failed to alloc map name\n");
return -ENOMEM; return -ENOMEM;
} }
pr_debug("map '%s' (global data): at sec_idx %d, offset %zu.\n", pr_debug("map '%s' (global data): at sec_idx %d, offset %zu.\n",
...@@ -865,7 +865,7 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type, ...@@ -865,7 +865,7 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type,
*data_buff = malloc(data->d_size); *data_buff = malloc(data->d_size);
if (!*data_buff) { if (!*data_buff) {
zfree(&map->name); zfree(&map->name);
pr_warning("failed to alloc map content buffer\n"); pr_warn("failed to alloc map content buffer\n");
return -ENOMEM; return -ENOMEM;
} }
memcpy(*data_buff, data->d_buf, data->d_size); memcpy(*data_buff, data->d_buf, data->d_size);
...@@ -927,7 +927,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) ...@@ -927,7 +927,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
if (scn) if (scn)
data = elf_getdata(scn, NULL); data = elf_getdata(scn, NULL);
if (!scn || !data) { if (!scn || !data) {
pr_warning("failed to get Elf_Data from map section %d\n", pr_warn("failed to get Elf_Data from map section %d\n",
obj->efile.maps_shndx); obj->efile.maps_shndx);
return -EINVAL; return -EINVAL;
} }
...@@ -955,7 +955,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) ...@@ -955,7 +955,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
map_def_sz = data->d_size / nr_maps; map_def_sz = data->d_size / nr_maps;
if (!data->d_size || (data->d_size % nr_maps) != 0) { if (!data->d_size || (data->d_size % nr_maps) != 0) {
pr_warning("unable to determine map definition size " pr_warn("unable to determine map definition size "
"section %s, %d maps in %zd bytes\n", "section %s, %d maps in %zd bytes\n",
obj->path, nr_maps, data->d_size); obj->path, nr_maps, data->d_size);
return -EINVAL; return -EINVAL;
...@@ -980,7 +980,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) ...@@ -980,7 +980,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
map_name = elf_strptr(obj->efile.elf, obj->efile.strtabidx, map_name = elf_strptr(obj->efile.elf, obj->efile.strtabidx,
sym.st_name); sym.st_name);
if (!map_name) { if (!map_name) {
pr_warning("failed to get map #%d name sym string for obj %s\n", pr_warn("failed to get map #%d name sym string for obj %s\n",
i, obj->path); i, obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
...@@ -991,14 +991,14 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) ...@@ -991,14 +991,14 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
pr_debug("map '%s' (legacy): at sec_idx %d, offset %zu.\n", pr_debug("map '%s' (legacy): at sec_idx %d, offset %zu.\n",
map_name, map->sec_idx, map->sec_offset); map_name, map->sec_idx, map->sec_offset);
if (sym.st_value + map_def_sz > data->d_size) { if (sym.st_value + map_def_sz > data->d_size) {
pr_warning("corrupted maps section in %s: last map \"%s\" too small\n", pr_warn("corrupted maps section in %s: last map \"%s\" too small\n",
obj->path, map_name); obj->path, map_name);
return -EINVAL; return -EINVAL;
} }
map->name = strdup(map_name); map->name = strdup(map_name);
if (!map->name) { if (!map->name) {
pr_warning("failed to alloc map name\n"); pr_warn("failed to alloc map name\n");
return -ENOMEM; return -ENOMEM;
} }
pr_debug("map %d is \"%s\"\n", i, map->name); pr_debug("map %d is \"%s\"\n", i, map->name);
...@@ -1022,7 +1022,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) ...@@ -1022,7 +1022,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
for (b = ((char *)def) + sizeof(struct bpf_map_def); for (b = ((char *)def) + sizeof(struct bpf_map_def);
b < ((char *)def) + map_def_sz; b++) { b < ((char *)def) + map_def_sz; b++) {
if (*b != 0) { if (*b != 0) {
pr_warning("maps section in %s: \"%s\" " pr_warn("maps section in %s: \"%s\" "
"has unrecognized, non-zero " "has unrecognized, non-zero "
"options\n", "options\n",
obj->path, map_name); obj->path, map_name);
...@@ -1069,19 +1069,19 @@ static bool get_map_field_int(const char *map_name, const struct btf *btf, ...@@ -1069,19 +1069,19 @@ static bool get_map_field_int(const char *map_name, const struct btf *btf,
const struct btf_type *arr_t; const struct btf_type *arr_t;
if (!btf_is_ptr(t)) { if (!btf_is_ptr(t)) {
pr_warning("map '%s': attr '%s': expected PTR, got %u.\n", pr_warn("map '%s': attr '%s': expected PTR, got %u.\n",
map_name, name, btf_kind(t)); map_name, name, btf_kind(t));
return false; return false;
} }
arr_t = btf__type_by_id(btf, t->type); arr_t = btf__type_by_id(btf, t->type);
if (!arr_t) { if (!arr_t) {
pr_warning("map '%s': attr '%s': type [%u] not found.\n", pr_warn("map '%s': attr '%s': type [%u] not found.\n",
map_name, name, t->type); map_name, name, t->type);
return false; return false;
} }
if (!btf_is_array(arr_t)) { if (!btf_is_array(arr_t)) {
pr_warning("map '%s': attr '%s': expected ARRAY, got %u.\n", pr_warn("map '%s': attr '%s': expected ARRAY, got %u.\n",
map_name, name, btf_kind(arr_t)); map_name, name, btf_kind(arr_t));
return false; return false;
} }
...@@ -1110,33 +1110,33 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1110,33 +1110,33 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
vlen = btf_vlen(var); vlen = btf_vlen(var);
if (map_name == NULL || map_name[0] == '\0') { if (map_name == NULL || map_name[0] == '\0') {
pr_warning("map #%d: empty name.\n", var_idx); pr_warn("map #%d: empty name.\n", var_idx);
return -EINVAL; return -EINVAL;
} }
if ((__u64)vi->offset + vi->size > data->d_size) { if ((__u64)vi->offset + vi->size > data->d_size) {
pr_warning("map '%s' BTF data is corrupted.\n", map_name); pr_warn("map '%s' BTF data is corrupted.\n", map_name);
return -EINVAL; return -EINVAL;
} }
if (!btf_is_var(var)) { if (!btf_is_var(var)) {
pr_warning("map '%s': unexpected var kind %u.\n", pr_warn("map '%s': unexpected var kind %u.\n",
map_name, btf_kind(var)); map_name, btf_kind(var));
return -EINVAL; return -EINVAL;
} }
if (var_extra->linkage != BTF_VAR_GLOBAL_ALLOCATED && if (var_extra->linkage != BTF_VAR_GLOBAL_ALLOCATED &&
var_extra->linkage != BTF_VAR_STATIC) { var_extra->linkage != BTF_VAR_STATIC) {
pr_warning("map '%s': unsupported var linkage %u.\n", pr_warn("map '%s': unsupported var linkage %u.\n",
map_name, var_extra->linkage); map_name, var_extra->linkage);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
def = skip_mods_and_typedefs(obj->btf, var->type, NULL); def = skip_mods_and_typedefs(obj->btf, var->type, NULL);
if (!btf_is_struct(def)) { if (!btf_is_struct(def)) {
pr_warning("map '%s': unexpected def kind %u.\n", pr_warn("map '%s': unexpected def kind %u.\n",
map_name, btf_kind(var)); map_name, btf_kind(var));
return -EINVAL; return -EINVAL;
} }
if (def->size > vi->size) { if (def->size > vi->size) {
pr_warning("map '%s': invalid def size.\n", map_name); pr_warn("map '%s': invalid def size.\n", map_name);
return -EINVAL; return -EINVAL;
} }
...@@ -1145,7 +1145,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1145,7 +1145,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
return PTR_ERR(map); return PTR_ERR(map);
map->name = strdup(map_name); map->name = strdup(map_name);
if (!map->name) { if (!map->name) {
pr_warning("map '%s': failed to alloc map name.\n", map_name); pr_warn("map '%s': failed to alloc map name.\n", map_name);
return -ENOMEM; return -ENOMEM;
} }
map->libbpf_type = LIBBPF_MAP_UNSPEC; map->libbpf_type = LIBBPF_MAP_UNSPEC;
...@@ -1161,8 +1161,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1161,8 +1161,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
const char *name = btf__name_by_offset(obj->btf, m->name_off); const char *name = btf__name_by_offset(obj->btf, m->name_off);
if (!name) { if (!name) {
pr_warning("map '%s': invalid field #%d.\n", pr_warn("map '%s': invalid field #%d.\n", map_name, i);
map_name, i);
return -EINVAL; return -EINVAL;
} }
if (strcmp(name, "type") == 0) { if (strcmp(name, "type") == 0) {
...@@ -1192,7 +1191,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1192,7 +1191,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
pr_debug("map '%s': found key_size = %u.\n", pr_debug("map '%s': found key_size = %u.\n",
map_name, sz); map_name, sz);
if (map->def.key_size && map->def.key_size != sz) { if (map->def.key_size && map->def.key_size != sz) {
pr_warning("map '%s': conflicting key size %u != %u.\n", pr_warn("map '%s': conflicting key size %u != %u.\n",
map_name, map->def.key_size, sz); map_name, map->def.key_size, sz);
return -EINVAL; return -EINVAL;
} }
...@@ -1202,25 +1201,25 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1202,25 +1201,25 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
t = btf__type_by_id(obj->btf, m->type); t = btf__type_by_id(obj->btf, m->type);
if (!t) { if (!t) {
pr_warning("map '%s': key type [%d] not found.\n", pr_warn("map '%s': key type [%d] not found.\n",
map_name, m->type); map_name, m->type);
return -EINVAL; return -EINVAL;
} }
if (!btf_is_ptr(t)) { if (!btf_is_ptr(t)) {
pr_warning("map '%s': key spec is not PTR: %u.\n", pr_warn("map '%s': key spec is not PTR: %u.\n",
map_name, btf_kind(t)); map_name, btf_kind(t));
return -EINVAL; return -EINVAL;
} }
sz = btf__resolve_size(obj->btf, t->type); sz = btf__resolve_size(obj->btf, t->type);
if (sz < 0) { if (sz < 0) {
pr_warning("map '%s': can't determine key size for type [%u]: %lld.\n", pr_warn("map '%s': can't determine key size for type [%u]: %lld.\n",
map_name, t->type, sz); map_name, t->type, sz);
return sz; return sz;
} }
pr_debug("map '%s': found key [%u], sz = %lld.\n", pr_debug("map '%s': found key [%u], sz = %lld.\n",
map_name, t->type, sz); map_name, t->type, sz);
if (map->def.key_size && map->def.key_size != sz) { if (map->def.key_size && map->def.key_size != sz) {
pr_warning("map '%s': conflicting key size %u != %lld.\n", pr_warn("map '%s': conflicting key size %u != %lld.\n",
map_name, map->def.key_size, sz); map_name, map->def.key_size, sz);
return -EINVAL; return -EINVAL;
} }
...@@ -1235,7 +1234,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1235,7 +1234,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
pr_debug("map '%s': found value_size = %u.\n", pr_debug("map '%s': found value_size = %u.\n",
map_name, sz); map_name, sz);
if (map->def.value_size && map->def.value_size != sz) { if (map->def.value_size && map->def.value_size != sz) {
pr_warning("map '%s': conflicting value size %u != %u.\n", pr_warn("map '%s': conflicting value size %u != %u.\n",
map_name, map->def.value_size, sz); map_name, map->def.value_size, sz);
return -EINVAL; return -EINVAL;
} }
...@@ -1245,25 +1244,25 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1245,25 +1244,25 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
t = btf__type_by_id(obj->btf, m->type); t = btf__type_by_id(obj->btf, m->type);
if (!t) { if (!t) {
pr_warning("map '%s': value type [%d] not found.\n", pr_warn("map '%s': value type [%d] not found.\n",
map_name, m->type); map_name, m->type);
return -EINVAL; return -EINVAL;
} }
if (!btf_is_ptr(t)) { if (!btf_is_ptr(t)) {
pr_warning("map '%s': value spec is not PTR: %u.\n", pr_warn("map '%s': value spec is not PTR: %u.\n",
map_name, btf_kind(t)); map_name, btf_kind(t));
return -EINVAL; return -EINVAL;
} }
sz = btf__resolve_size(obj->btf, t->type); sz = btf__resolve_size(obj->btf, t->type);
if (sz < 0) { if (sz < 0) {
pr_warning("map '%s': can't determine value size for type [%u]: %lld.\n", pr_warn("map '%s': can't determine value size for type [%u]: %lld.\n",
map_name, t->type, sz); map_name, t->type, sz);
return sz; return sz;
} }
pr_debug("map '%s': found value [%u], sz = %lld.\n", pr_debug("map '%s': found value [%u], sz = %lld.\n",
map_name, t->type, sz); map_name, t->type, sz);
if (map->def.value_size && map->def.value_size != sz) { if (map->def.value_size && map->def.value_size != sz) {
pr_warning("map '%s': conflicting value size %u != %lld.\n", pr_warn("map '%s': conflicting value size %u != %lld.\n",
map_name, map->def.value_size, sz); map_name, map->def.value_size, sz);
return -EINVAL; return -EINVAL;
} }
...@@ -1271,7 +1270,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1271,7 +1270,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
map->btf_value_type_id = t->type; map->btf_value_type_id = t->type;
} else { } else {
if (strict) { if (strict) {
pr_warning("map '%s': unknown field '%s'.\n", pr_warn("map '%s': unknown field '%s'.\n",
map_name, name); map_name, name);
return -ENOTSUP; return -ENOTSUP;
} }
...@@ -1281,7 +1280,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1281,7 +1280,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
} }
if (map->def.type == BPF_MAP_TYPE_UNSPEC) { if (map->def.type == BPF_MAP_TYPE_UNSPEC) {
pr_warning("map '%s': map type isn't specified.\n", map_name); pr_warn("map '%s': map type isn't specified.\n", map_name);
return -EINVAL; return -EINVAL;
} }
...@@ -1304,7 +1303,7 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict) ...@@ -1304,7 +1303,7 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict)
if (scn) if (scn)
data = elf_getdata(scn, NULL); data = elf_getdata(scn, NULL);
if (!scn || !data) { if (!scn || !data) {
pr_warning("failed to get Elf_Data from map section %d (%s)\n", pr_warn("failed to get Elf_Data from map section %d (%s)\n",
obj->efile.maps_shndx, MAPS_ELF_SEC); obj->efile.maps_shndx, MAPS_ELF_SEC);
return -EINVAL; return -EINVAL;
} }
...@@ -1322,7 +1321,7 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict) ...@@ -1322,7 +1321,7 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict)
} }
if (!sec) { if (!sec) {
pr_warning("DATASEC '%s' not found.\n", MAPS_ELF_SEC); pr_warn("DATASEC '%s' not found.\n", MAPS_ELF_SEC);
return -ENOENT; return -ENOENT;
} }
...@@ -1466,14 +1465,13 @@ static int bpf_object__init_btf(struct bpf_object *obj, ...@@ -1466,14 +1465,13 @@ static int bpf_object__init_btf(struct bpf_object *obj,
if (btf_data) { if (btf_data) {
obj->btf = btf__new(btf_data->d_buf, btf_data->d_size); obj->btf = btf__new(btf_data->d_buf, btf_data->d_size);
if (IS_ERR(obj->btf)) { if (IS_ERR(obj->btf)) {
pr_warning("Error loading ELF section %s: %d.\n", pr_warn("Error loading ELF section %s: %d.\n",
BTF_ELF_SEC, err); BTF_ELF_SEC, err);
goto out; goto out;
} }
err = btf__finalize_data(obj, obj->btf); err = btf__finalize_data(obj, obj->btf);
if (err) { if (err) {
pr_warning("Error finalizing %s: %d.\n", pr_warn("Error finalizing %s: %d.\n", BTF_ELF_SEC, err);
BTF_ELF_SEC, err);
goto out; goto out;
} }
} }
...@@ -1486,7 +1484,7 @@ static int bpf_object__init_btf(struct bpf_object *obj, ...@@ -1486,7 +1484,7 @@ static int bpf_object__init_btf(struct bpf_object *obj,
obj->btf_ext = btf_ext__new(btf_ext_data->d_buf, obj->btf_ext = btf_ext__new(btf_ext_data->d_buf,
btf_ext_data->d_size); btf_ext_data->d_size);
if (IS_ERR(obj->btf_ext)) { if (IS_ERR(obj->btf_ext)) {
pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n", pr_warn("Error loading ELF section %s: %ld. Ignored and continue.\n",
BTF_EXT_ELF_SEC, PTR_ERR(obj->btf_ext)); BTF_EXT_ELF_SEC, PTR_ERR(obj->btf_ext));
obj->btf_ext = NULL; obj->btf_ext = NULL;
goto out; goto out;
...@@ -1503,7 +1501,7 @@ static int bpf_object__init_btf(struct bpf_object *obj, ...@@ -1503,7 +1501,7 @@ static int bpf_object__init_btf(struct bpf_object *obj,
obj->btf = NULL; obj->btf = NULL;
} }
if (btf_required && !obj->btf) { if (btf_required && !obj->btf) {
pr_warning("BTF is required, but is missing or corrupted.\n"); pr_warn("BTF is required, but is missing or corrupted.\n");
return err == 0 ? -ENOENT : err; return err == 0 ? -ENOENT : err;
} }
return 0; return 0;
...@@ -1521,7 +1519,7 @@ static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj) ...@@ -1521,7 +1519,7 @@ static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj)
err = btf__load(obj->btf); err = btf__load(obj->btf);
if (err) { if (err) {
pr_warning("Error loading %s into kernel: %d.\n", pr_warn("Error loading %s into kernel: %d.\n",
BTF_ELF_SEC, err); BTF_ELF_SEC, err);
btf__free(obj->btf); btf__free(obj->btf);
obj->btf = NULL; obj->btf = NULL;
...@@ -1548,7 +1546,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps) ...@@ -1548,7 +1546,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps)
/* Elf is corrupted/truncated, avoid calling elf_strptr. */ /* Elf is corrupted/truncated, avoid calling elf_strptr. */
if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) { if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) {
pr_warning("failed to get e_shstrndx from %s\n", obj->path); pr_warn("failed to get e_shstrndx from %s\n", obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
...@@ -1559,21 +1557,21 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps) ...@@ -1559,21 +1557,21 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps)
idx++; idx++;
if (gelf_getshdr(scn, &sh) != &sh) { if (gelf_getshdr(scn, &sh) != &sh) {
pr_warning("failed to get section(%d) header from %s\n", pr_warn("failed to get section(%d) header from %s\n",
idx, obj->path); idx, obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
name = elf_strptr(elf, ep->e_shstrndx, sh.sh_name); name = elf_strptr(elf, ep->e_shstrndx, sh.sh_name);
if (!name) { if (!name) {
pr_warning("failed to get section(%d) name from %s\n", pr_warn("failed to get section(%d) name from %s\n",
idx, obj->path); idx, obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
data = elf_getdata(scn, 0); data = elf_getdata(scn, 0);
if (!data) { if (!data) {
pr_warning("failed to get section(%d) data from %s(%s)\n", pr_warn("failed to get section(%d) data from %s(%s)\n",
idx, name, obj->path); idx, name, obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
...@@ -1604,7 +1602,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps) ...@@ -1604,7 +1602,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps)
btf_ext_data = data; btf_ext_data = data;
} else if (sh.sh_type == SHT_SYMTAB) { } else if (sh.sh_type == SHT_SYMTAB) {
if (obj->efile.symbols) { if (obj->efile.symbols) {
pr_warning("bpf: multiple SYMTAB in %s\n", pr_warn("bpf: multiple SYMTAB in %s\n",
obj->path); obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
...@@ -1621,7 +1619,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps) ...@@ -1621,7 +1619,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps)
char *cp = libbpf_strerror_r(-err, errmsg, char *cp = libbpf_strerror_r(-err, errmsg,
sizeof(errmsg)); sizeof(errmsg));
pr_warning("failed to alloc program %s (%s): %s", pr_warn("failed to alloc program %s (%s): %s",
name, obj->path, cp); name, obj->path, cp);
return err; return err;
} }
...@@ -1649,7 +1647,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps) ...@@ -1649,7 +1647,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps)
reloc = reallocarray(reloc, nr_reloc + 1, reloc = reallocarray(reloc, nr_reloc + 1,
sizeof(*obj->efile.reloc)); sizeof(*obj->efile.reloc));
if (!reloc) { if (!reloc) {
pr_warning("realloc failed\n"); pr_warn("realloc failed\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -1667,7 +1665,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps) ...@@ -1667,7 +1665,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps)
} }
if (!obj->efile.strtabidx || obj->efile.strtabidx >= idx) { if (!obj->efile.strtabidx || obj->efile.strtabidx >= idx) {
pr_warning("Corrupted ELF file: index of strtab invalid\n"); pr_warn("Corrupted ELF file: index of strtab invalid\n");
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
err = bpf_object__init_btf(obj, btf_data, btf_ext_data); err = bpf_object__init_btf(obj, btf_data, btf_ext_data);
...@@ -1757,7 +1755,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, ...@@ -1757,7 +1755,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
prog->reloc_desc = malloc(sizeof(*prog->reloc_desc) * nrels); prog->reloc_desc = malloc(sizeof(*prog->reloc_desc) * nrels);
if (!prog->reloc_desc) { if (!prog->reloc_desc) {
pr_warning("failed to alloc memory in relocation\n"); pr_warn("failed to alloc memory in relocation\n");
return -ENOMEM; return -ENOMEM;
} }
prog->nr_reloc = nrels; prog->nr_reloc = nrels;
...@@ -1773,12 +1771,12 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, ...@@ -1773,12 +1771,12 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
GElf_Rel rel; GElf_Rel rel;
if (!gelf_getrel(data, i, &rel)) { if (!gelf_getrel(data, i, &rel)) {
pr_warning("relocation: failed to get %d reloc\n", i); pr_warn("relocation: failed to get %d reloc\n", i);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
if (!gelf_getsym(symbols, GELF_R_SYM(rel.r_info), &sym)) { if (!gelf_getsym(symbols, GELF_R_SYM(rel.r_info), &sym)) {
pr_warning("relocation: symbol %"PRIx64" not found\n", pr_warn("relocation: symbol %"PRIx64" not found\n",
GELF_R_SYM(rel.r_info)); GELF_R_SYM(rel.r_info));
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
...@@ -1796,20 +1794,20 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, ...@@ -1796,20 +1794,20 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
insn_idx, shdr_idx); insn_idx, shdr_idx);
if (shdr_idx >= SHN_LORESERVE) { if (shdr_idx >= SHN_LORESERVE) {
pr_warning("relocation: not yet supported relo for non-static global \'%s\' variable in special section (0x%x) found in insns[%d].code 0x%x\n", pr_warn("relocation: not yet supported relo for non-static global \'%s\' variable in special section (0x%x) found in insns[%d].code 0x%x\n",
name, shdr_idx, insn_idx, name, shdr_idx, insn_idx,
insns[insn_idx].code); insns[insn_idx].code);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
if (!bpf_object__relo_in_known_section(obj, shdr_idx)) { if (!bpf_object__relo_in_known_section(obj, shdr_idx)) {
pr_warning("Program '%s' contains unrecognized relo data pointing to section %u\n", pr_warn("Program '%s' contains unrecognized relo data pointing to section %u\n",
prog->section_name, shdr_idx); prog->section_name, shdr_idx);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
if (insns[insn_idx].code == (BPF_JMP | BPF_CALL)) { if (insns[insn_idx].code == (BPF_JMP | BPF_CALL)) {
if (insns[insn_idx].src_reg != BPF_PSEUDO_CALL) { if (insns[insn_idx].src_reg != BPF_PSEUDO_CALL) {
pr_warning("incorrect bpf_call opcode\n"); pr_warn("incorrect bpf_call opcode\n");
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
prog->reloc_desc[i].type = RELO_CALL; prog->reloc_desc[i].type = RELO_CALL;
...@@ -1820,7 +1818,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, ...@@ -1820,7 +1818,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
} }
if (insns[insn_idx].code != (BPF_LD | BPF_IMM | BPF_DW)) { if (insns[insn_idx].code != (BPF_LD | BPF_IMM | BPF_DW)) {
pr_warning("bpf: relocation: invalid relo for insns[%d].code 0x%x\n", pr_warn("bpf: relocation: invalid relo for insns[%d].code 0x%x\n",
insn_idx, insns[insn_idx].code); insn_idx, insns[insn_idx].code);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
...@@ -1830,12 +1828,12 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, ...@@ -1830,12 +1828,12 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
type = bpf_object__section_to_libbpf_map_type(obj, shdr_idx); type = bpf_object__section_to_libbpf_map_type(obj, shdr_idx);
if (type != LIBBPF_MAP_UNSPEC) { if (type != LIBBPF_MAP_UNSPEC) {
if (GELF_ST_BIND(sym.st_info) == STB_GLOBAL) { if (GELF_ST_BIND(sym.st_info) == STB_GLOBAL) {
pr_warning("bpf: relocation: not yet supported relo for non-static global \'%s\' variable found in insns[%d].code 0x%x\n", pr_warn("bpf: relocation: not yet supported relo for non-static global \'%s\' variable found in insns[%d].code 0x%x\n",
name, insn_idx, insns[insn_idx].code); name, insn_idx, insns[insn_idx].code);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
if (!obj->caps.global_data) { if (!obj->caps.global_data) {
pr_warning("bpf: relocation: kernel does not support global \'%s\' variable access in insns[%d]\n", pr_warn("bpf: relocation: kernel does not support global \'%s\' variable access in insns[%d]\n",
name, insn_idx); name, insn_idx);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
...@@ -1857,7 +1855,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, ...@@ -1857,7 +1855,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
} }
if (map_idx >= nr_maps) { if (map_idx >= nr_maps) {
pr_warning("bpf relocation: map_idx %d larger than %d\n", pr_warn("bpf relocation: map_idx %d larger than %d\n",
(int)map_idx, (int)nr_maps - 1); (int)map_idx, (int)nr_maps - 1);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
...@@ -1985,7 +1983,7 @@ bpf_object__probe_name(struct bpf_object *obj) ...@@ -1985,7 +1983,7 @@ bpf_object__probe_name(struct bpf_object *obj)
ret = bpf_load_program_xattr(&attr, NULL, 0); ret = bpf_load_program_xattr(&attr, NULL, 0);
if (ret < 0) { if (ret < 0) {
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warning("Error in %s():%s(%d). Couldn't load basic 'r0 = 0' BPF program.\n", pr_warn("Error in %s():%s(%d). Couldn't load basic 'r0 = 0' BPF program.\n",
__func__, cp, errno); __func__, cp, errno);
return -errno; return -errno;
} }
...@@ -2026,7 +2024,7 @@ bpf_object__probe_global_data(struct bpf_object *obj) ...@@ -2026,7 +2024,7 @@ bpf_object__probe_global_data(struct bpf_object *obj)
map = bpf_create_map_xattr(&map_attr); map = bpf_create_map_xattr(&map_attr);
if (map < 0) { if (map < 0) {
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warning("Error in %s():%s(%d). Couldn't create simple array map.\n", pr_warn("Error in %s():%s(%d). Couldn't create simple array map.\n",
__func__, cp, errno); __func__, cp, errno);
return -errno; return -errno;
} }
...@@ -2142,7 +2140,7 @@ bpf_object__populate_internal_map(struct bpf_object *obj, struct bpf_map *map) ...@@ -2142,7 +2140,7 @@ bpf_object__populate_internal_map(struct bpf_object *obj, struct bpf_map *map)
err = bpf_map_freeze(map->fd); err = bpf_map_freeze(map->fd);
if (err) { if (err) {
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warning("Error freezing map(%s) as read-only: %s\n", pr_warn("Error freezing map(%s) as read-only: %s\n",
map->name, cp); map->name, cp);
err = 0; err = 0;
} }
...@@ -2182,7 +2180,7 @@ bpf_object__create_maps(struct bpf_object *obj) ...@@ -2182,7 +2180,7 @@ bpf_object__create_maps(struct bpf_object *obj)
if (!nr_cpus) if (!nr_cpus)
nr_cpus = libbpf_num_possible_cpus(); nr_cpus = libbpf_num_possible_cpus();
if (nr_cpus < 0) { if (nr_cpus < 0) {
pr_warning("failed to determine number of system CPUs: %d\n", pr_warn("failed to determine number of system CPUs: %d\n",
nr_cpus); nr_cpus);
err = nr_cpus; err = nr_cpus;
goto err_out; goto err_out;
...@@ -2211,7 +2209,7 @@ bpf_object__create_maps(struct bpf_object *obj) ...@@ -2211,7 +2209,7 @@ bpf_object__create_maps(struct bpf_object *obj)
create_attr.btf_value_type_id)) { create_attr.btf_value_type_id)) {
err = -errno; err = -errno;
cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));
pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n", pr_warn("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
map->name, cp, err); map->name, cp, err);
create_attr.btf_fd = 0; create_attr.btf_fd = 0;
create_attr.btf_key_type_id = 0; create_attr.btf_key_type_id = 0;
...@@ -2227,7 +2225,7 @@ bpf_object__create_maps(struct bpf_object *obj) ...@@ -2227,7 +2225,7 @@ bpf_object__create_maps(struct bpf_object *obj)
err = -errno; err = -errno;
err_out: err_out:
cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));
pr_warning("failed to create map (name: '%s'): %s(%d)\n", pr_warn("failed to create map (name: '%s'): %s(%d)\n",
map->name, cp, err); map->name, cp, err);
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
zclose(obj->maps[j].fd); zclose(obj->maps[j].fd);
...@@ -2253,7 +2251,7 @@ check_btf_ext_reloc_err(struct bpf_program *prog, int err, ...@@ -2253,7 +2251,7 @@ check_btf_ext_reloc_err(struct bpf_program *prog, int err,
void *btf_prog_info, const char *info_name) void *btf_prog_info, const char *info_name)
{ {
if (err != -ENOENT) { if (err != -ENOENT) {
pr_warning("Error in loading %s for sec %s.\n", pr_warn("Error in loading %s for sec %s.\n",
info_name, prog->section_name); info_name, prog->section_name);
return err; return err;
} }
...@@ -2265,13 +2263,13 @@ check_btf_ext_reloc_err(struct bpf_program *prog, int err, ...@@ -2265,13 +2263,13 @@ check_btf_ext_reloc_err(struct bpf_program *prog, int err,
* Some info has already been found but has problem * Some info has already been found but has problem
* in the last btf_ext reloc. Must have to error out. * in the last btf_ext reloc. Must have to error out.
*/ */
pr_warning("Error in relocating %s for sec %s.\n", pr_warn("Error in relocating %s for sec %s.\n",
info_name, prog->section_name); info_name, prog->section_name);
return err; return err;
} }
/* Have problem loading the very first info. Ignore the rest. */ /* Have problem loading the very first info. Ignore the rest. */
pr_warning("Cannot find %s for main program sec %s. Ignore all %s.\n", pr_warn("Cannot find %s for main program sec %s. Ignore all %s.\n",
info_name, prog->section_name, info_name); info_name, prog->section_name, info_name);
return 0; return 0;
} }
...@@ -2473,7 +2471,7 @@ static int bpf_core_spec_parse(const struct btf *btf, ...@@ -2473,7 +2471,7 @@ static int bpf_core_spec_parse(const struct btf *btf,
return sz; return sz;
spec->offset += access_idx * sz; spec->offset += access_idx * sz;
} else { } else {
pr_warning("relo for [%u] %s (at idx %d) captures type [%d] of unexpected kind %d\n", pr_warn("relo for [%u] %s (at idx %d) captures type [%d] of unexpected kind %d\n",
type_id, spec_str, i, id, btf_kind(t)); type_id, spec_str, i, id, btf_kind(t));
return -EINVAL; return -EINVAL;
} }
...@@ -2618,7 +2616,7 @@ static int bpf_core_fields_are_compat(const struct btf *local_btf, ...@@ -2618,7 +2616,7 @@ static int bpf_core_fields_are_compat(const struct btf *local_btf,
targ_id = btf_array(targ_type)->type; targ_id = btf_array(targ_type)->type;
goto recur; goto recur;
default: default:
pr_warning("unexpected kind %d relocated, local [%d], target [%d]\n", pr_warn("unexpected kind %d relocated, local [%d], target [%d]\n",
btf_kind(local_type), local_id, targ_id); btf_kind(local_type), local_id, targ_id);
return 0; return 0;
} }
...@@ -2823,7 +2821,7 @@ static int bpf_core_reloc_insn(struct bpf_program *prog, ...@@ -2823,7 +2821,7 @@ static int bpf_core_reloc_insn(struct bpf_program *prog,
if (targ_spec) { if (targ_spec) {
new_val = targ_spec->offset; new_val = targ_spec->offset;
} else { } else {
pr_warning("prog '%s': patching insn #%d w/ failed reloc, imm %d -> %d\n", pr_warn("prog '%s': patching insn #%d w/ failed reloc, imm %d -> %d\n",
bpf_program__title(prog, false), insn_idx, bpf_program__title(prog, false), insn_idx,
orig_val, -1); orig_val, -1);
new_val = (__u32)-1; new_val = (__u32)-1;
...@@ -2834,7 +2832,7 @@ static int bpf_core_reloc_insn(struct bpf_program *prog, ...@@ -2834,7 +2832,7 @@ static int bpf_core_reloc_insn(struct bpf_program *prog,
new_val = targ_spec ? 1 : 0; new_val = targ_spec ? 1 : 0;
break; break;
default: default:
pr_warning("prog '%s': unknown relo %d at insn #%d'\n", pr_warn("prog '%s': unknown relo %d at insn #%d'\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
relo->kind, insn_idx); relo->kind, insn_idx);
return -EINVAL; return -EINVAL;
...@@ -2853,7 +2851,7 @@ static int bpf_core_reloc_insn(struct bpf_program *prog, ...@@ -2853,7 +2851,7 @@ static int bpf_core_reloc_insn(struct bpf_program *prog,
bpf_program__title(prog, false), bpf_program__title(prog, false),
insn_idx, orig_val, new_val); insn_idx, orig_val, new_val);
} else { } else {
pr_warning("prog '%s': trying to relocate unrecognized insn #%d, code:%x, src:%x, dst:%x, off:%x, imm:%x\n", pr_warn("prog '%s': trying to relocate unrecognized insn #%d, code:%x, src:%x, dst:%x, off:%x, imm:%x\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
insn_idx, insn->code, insn->src_reg, insn->dst_reg, insn_idx, insn->code, insn->src_reg, insn->dst_reg,
insn->off, insn->imm); insn->off, insn->imm);
...@@ -2945,7 +2943,7 @@ static struct btf *bpf_core_find_kernel_btf(void) ...@@ -2945,7 +2943,7 @@ static struct btf *bpf_core_find_kernel_btf(void)
return btf; return btf;
} }
pr_warning("failed to find valid kernel BTF\n"); pr_warn("failed to find valid kernel BTF\n");
return ERR_PTR(-ESRCH); return ERR_PTR(-ESRCH);
} }
...@@ -3077,7 +3075,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog, ...@@ -3077,7 +3075,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog,
err = bpf_core_spec_parse(local_btf, local_id, spec_str, &local_spec); err = bpf_core_spec_parse(local_btf, local_id, spec_str, &local_spec);
if (err) { if (err) {
pr_warning("prog '%s': relo #%d: parsing [%d] %s + %s failed: %d\n", pr_warn("prog '%s': relo #%d: parsing [%d] %s + %s failed: %d\n",
prog_name, relo_idx, local_id, local_name, spec_str, prog_name, relo_idx, local_id, local_name, spec_str,
err); err);
return -EINVAL; return -EINVAL;
...@@ -3090,7 +3088,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog, ...@@ -3090,7 +3088,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog,
if (!hashmap__find(cand_cache, type_key, (void **)&cand_ids)) { if (!hashmap__find(cand_cache, type_key, (void **)&cand_ids)) {
cand_ids = bpf_core_find_cands(local_btf, local_id, targ_btf); cand_ids = bpf_core_find_cands(local_btf, local_id, targ_btf);
if (IS_ERR(cand_ids)) { if (IS_ERR(cand_ids)) {
pr_warning("prog '%s': relo #%d: target candidate search failed for [%d] %s: %ld", pr_warn("prog '%s': relo #%d: target candidate search failed for [%d] %s: %ld",
prog_name, relo_idx, local_id, local_name, prog_name, relo_idx, local_id, local_name,
PTR_ERR(cand_ids)); PTR_ERR(cand_ids));
return PTR_ERR(cand_ids); return PTR_ERR(cand_ids);
...@@ -3114,7 +3112,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog, ...@@ -3114,7 +3112,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog,
bpf_core_dump_spec(LIBBPF_DEBUG, &cand_spec); bpf_core_dump_spec(LIBBPF_DEBUG, &cand_spec);
libbpf_print(LIBBPF_DEBUG, ": %d\n", err); libbpf_print(LIBBPF_DEBUG, ": %d\n", err);
if (err < 0) { if (err < 0) {
pr_warning("prog '%s': relo #%d: matching error: %d\n", pr_warn("prog '%s': relo #%d: matching error: %d\n",
prog_name, relo_idx, err); prog_name, relo_idx, err);
return err; return err;
} }
...@@ -3127,7 +3125,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog, ...@@ -3127,7 +3125,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog,
/* if there are many candidates, they should all /* if there are many candidates, they should all
* resolve to the same offset * resolve to the same offset
*/ */
pr_warning("prog '%s': relo #%d: offset ambiguity: %u != %u\n", pr_warn("prog '%s': relo #%d: offset ambiguity: %u != %u\n",
prog_name, relo_idx, cand_spec.offset, prog_name, relo_idx, cand_spec.offset,
targ_spec.offset); targ_spec.offset);
return -EINVAL; return -EINVAL;
...@@ -3148,7 +3146,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog, ...@@ -3148,7 +3146,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog,
if (j == 0 && !prog->obj->relaxed_core_relocs && if (j == 0 && !prog->obj->relaxed_core_relocs &&
relo->kind != BPF_FIELD_EXISTS) { relo->kind != BPF_FIELD_EXISTS) {
pr_warning("prog '%s': relo #%d: no matching targets found for [%d] %s + %s\n", pr_warn("prog '%s': relo #%d: no matching targets found for [%d] %s + %s\n",
prog_name, relo_idx, local_id, local_name, spec_str); prog_name, relo_idx, local_id, local_name, spec_str);
return -ESRCH; return -ESRCH;
} }
...@@ -3157,7 +3155,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog, ...@@ -3157,7 +3155,7 @@ static int bpf_core_reloc_field(struct bpf_program *prog,
err = bpf_core_reloc_insn(prog, relo, &local_spec, err = bpf_core_reloc_insn(prog, relo, &local_spec,
j ? &targ_spec : NULL); j ? &targ_spec : NULL);
if (err) { if (err) {
pr_warning("prog '%s': relo #%d: failed to patch insn at offset %d: %d\n", pr_warn("prog '%s': relo #%d: failed to patch insn at offset %d: %d\n",
prog_name, relo_idx, relo->insn_off, err); prog_name, relo_idx, relo->insn_off, err);
return -EINVAL; return -EINVAL;
} }
...@@ -3183,8 +3181,7 @@ bpf_core_reloc_fields(struct bpf_object *obj, const char *targ_btf_path) ...@@ -3183,8 +3181,7 @@ bpf_core_reloc_fields(struct bpf_object *obj, const char *targ_btf_path)
else else
targ_btf = bpf_core_find_kernel_btf(); targ_btf = bpf_core_find_kernel_btf();
if (IS_ERR(targ_btf)) { if (IS_ERR(targ_btf)) {
pr_warning("failed to get target BTF: %ld\n", pr_warn("failed to get target BTF: %ld\n", PTR_ERR(targ_btf));
PTR_ERR(targ_btf));
return PTR_ERR(targ_btf); return PTR_ERR(targ_btf);
} }
...@@ -3203,7 +3200,7 @@ bpf_core_reloc_fields(struct bpf_object *obj, const char *targ_btf_path) ...@@ -3203,7 +3200,7 @@ bpf_core_reloc_fields(struct bpf_object *obj, const char *targ_btf_path)
} }
prog = bpf_object__find_program_by_title(obj, sec_name); prog = bpf_object__find_program_by_title(obj, sec_name);
if (!prog) { if (!prog) {
pr_warning("failed to find program '%s' for CO-RE offset relocation\n", pr_warn("failed to find program '%s' for CO-RE offset relocation\n",
sec_name); sec_name);
err = -EINVAL; err = -EINVAL;
goto out; goto out;
...@@ -3216,7 +3213,7 @@ bpf_core_reloc_fields(struct bpf_object *obj, const char *targ_btf_path) ...@@ -3216,7 +3213,7 @@ bpf_core_reloc_fields(struct bpf_object *obj, const char *targ_btf_path)
err = bpf_core_reloc_field(prog, rec, i, obj->btf, err = bpf_core_reloc_field(prog, rec, i, obj->btf,
targ_btf, cand_cache); targ_btf, cand_cache);
if (err) { if (err) {
pr_warning("prog '%s': relo #%d: failed to relocate: %d\n", pr_warn("prog '%s': relo #%d: failed to relocate: %d\n",
sec_name, i, err); sec_name, i, err);
goto out; goto out;
} }
...@@ -3258,7 +3255,7 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj, ...@@ -3258,7 +3255,7 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj,
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
if (prog->idx == obj->efile.text_shndx) { if (prog->idx == obj->efile.text_shndx) {
pr_warning("relo in .text insn %d into off %d\n", pr_warn("relo in .text insn %d into off %d\n",
relo->insn_idx, relo->text_off); relo->insn_idx, relo->text_off);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
...@@ -3266,13 +3263,13 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj, ...@@ -3266,13 +3263,13 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj,
if (prog->main_prog_cnt == 0) { if (prog->main_prog_cnt == 0) {
text = bpf_object__find_prog_by_idx(obj, obj->efile.text_shndx); text = bpf_object__find_prog_by_idx(obj, obj->efile.text_shndx);
if (!text) { if (!text) {
pr_warning("no .text section found yet relo into text exist\n"); pr_warn("no .text section found yet relo into text exist\n");
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
new_cnt = prog->insns_cnt + text->insns_cnt; new_cnt = prog->insns_cnt + text->insns_cnt;
new_insn = reallocarray(prog->insns, new_cnt, sizeof(*insn)); new_insn = reallocarray(prog->insns, new_cnt, sizeof(*insn));
if (!new_insn) { if (!new_insn) {
pr_warning("oom in prog realloc\n"); pr_warn("oom in prog realloc\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -3327,7 +3324,7 @@ bpf_program__relocate(struct bpf_program *prog, struct bpf_object *obj) ...@@ -3327,7 +3324,7 @@ bpf_program__relocate(struct bpf_program *prog, struct bpf_object *obj)
map_idx = prog->reloc_desc[i].map_idx; map_idx = prog->reloc_desc[i].map_idx;
if (insn_idx + 1 >= (int)prog->insns_cnt) { if (insn_idx + 1 >= (int)prog->insns_cnt) {
pr_warning("relocation out of range: '%s'\n", pr_warn("relocation out of range: '%s'\n",
prog->section_name); prog->section_name);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
...@@ -3362,7 +3359,7 @@ bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_path) ...@@ -3362,7 +3359,7 @@ bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_path)
if (obj->btf_ext) { if (obj->btf_ext) {
err = bpf_object__relocate_core(obj, targ_btf_path); err = bpf_object__relocate_core(obj, targ_btf_path);
if (err) { if (err) {
pr_warning("failed to perform CO-RE relocations: %d\n", pr_warn("failed to perform CO-RE relocations: %d\n",
err); err);
return err; return err;
} }
...@@ -3372,8 +3369,7 @@ bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_path) ...@@ -3372,8 +3369,7 @@ bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_path)
err = bpf_program__relocate(prog, obj); err = bpf_program__relocate(prog, obj);
if (err) { if (err) {
pr_warning("failed to relocate '%s'\n", pr_warn("failed to relocate '%s'\n", prog->section_name);
prog->section_name);
return err; return err;
} }
} }
...@@ -3385,7 +3381,7 @@ static int bpf_object__collect_reloc(struct bpf_object *obj) ...@@ -3385,7 +3381,7 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
int i, err; int i, err;
if (!obj_elf_valid(obj)) { if (!obj_elf_valid(obj)) {
pr_warning("Internal error: elf object is closed\n"); pr_warn("Internal error: elf object is closed\n");
return -LIBBPF_ERRNO__INTERNAL; return -LIBBPF_ERRNO__INTERNAL;
} }
...@@ -3396,13 +3392,13 @@ static int bpf_object__collect_reloc(struct bpf_object *obj) ...@@ -3396,13 +3392,13 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
struct bpf_program *prog; struct bpf_program *prog;
if (shdr->sh_type != SHT_REL) { if (shdr->sh_type != SHT_REL) {
pr_warning("internal error at %d\n", __LINE__); pr_warn("internal error at %d\n", __LINE__);
return -LIBBPF_ERRNO__INTERNAL; return -LIBBPF_ERRNO__INTERNAL;
} }
prog = bpf_object__find_prog_by_idx(obj, idx); prog = bpf_object__find_prog_by_idx(obj, idx);
if (!prog) { if (!prog) {
pr_warning("relocation failed: no section(%d)\n", idx); pr_warn("relocation failed: no section(%d)\n", idx);
return -LIBBPF_ERRNO__RELOC; return -LIBBPF_ERRNO__RELOC;
} }
...@@ -3454,7 +3450,7 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt, ...@@ -3454,7 +3450,7 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt,
retry_load: retry_load:
log_buf = malloc(log_buf_size); log_buf = malloc(log_buf_size);
if (!log_buf) if (!log_buf)
pr_warning("Alloc log buffer for bpf loader error, continue without log\n"); pr_warn("Alloc log buffer for bpf loader error, continue without log\n");
ret = bpf_load_program_xattr(&load_attr, log_buf, log_buf_size); ret = bpf_load_program_xattr(&load_attr, log_buf, log_buf_size);
...@@ -3473,15 +3469,15 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt, ...@@ -3473,15 +3469,15 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt,
} }
ret = -LIBBPF_ERRNO__LOAD; ret = -LIBBPF_ERRNO__LOAD;
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warning("load bpf program failed: %s\n", cp); pr_warn("load bpf program failed: %s\n", cp);
if (log_buf && log_buf[0] != '\0') { if (log_buf && log_buf[0] != '\0') {
ret = -LIBBPF_ERRNO__VERIFY; ret = -LIBBPF_ERRNO__VERIFY;
pr_warning("-- BEGIN DUMP LOG ---\n"); pr_warn("-- BEGIN DUMP LOG ---\n");
pr_warning("\n%s\n", log_buf); pr_warn("\n%s\n", log_buf);
pr_warning("-- END LOG --\n"); pr_warn("-- END LOG --\n");
} else if (load_attr.insns_cnt >= BPF_MAXINSNS) { } else if (load_attr.insns_cnt >= BPF_MAXINSNS) {
pr_warning("Program too large (%zu insns), at most %d insns\n", pr_warn("Program too large (%zu insns), at most %d insns\n",
load_attr.insns_cnt, BPF_MAXINSNS); load_attr.insns_cnt, BPF_MAXINSNS);
ret = -LIBBPF_ERRNO__PROG2BIG; ret = -LIBBPF_ERRNO__PROG2BIG;
} else { } else {
...@@ -3516,14 +3512,14 @@ bpf_program__load(struct bpf_program *prog, ...@@ -3516,14 +3512,14 @@ bpf_program__load(struct bpf_program *prog,
if (prog->instances.nr < 0 || !prog->instances.fds) { if (prog->instances.nr < 0 || !prog->instances.fds) {
if (prog->preprocessor) { if (prog->preprocessor) {
pr_warning("Internal error: can't load program '%s'\n", pr_warn("Internal error: can't load program '%s'\n",
prog->section_name); prog->section_name);
return -LIBBPF_ERRNO__INTERNAL; return -LIBBPF_ERRNO__INTERNAL;
} }
prog->instances.fds = malloc(sizeof(int)); prog->instances.fds = malloc(sizeof(int));
if (!prog->instances.fds) { if (!prog->instances.fds) {
pr_warning("Not enough memory for BPF fds\n"); pr_warn("Not enough memory for BPF fds\n");
return -ENOMEM; return -ENOMEM;
} }
prog->instances.nr = 1; prog->instances.nr = 1;
...@@ -3532,7 +3528,7 @@ bpf_program__load(struct bpf_program *prog, ...@@ -3532,7 +3528,7 @@ bpf_program__load(struct bpf_program *prog,
if (!prog->preprocessor) { if (!prog->preprocessor) {
if (prog->instances.nr != 1) { if (prog->instances.nr != 1) {
pr_warning("Program '%s' is inconsistent: nr(%d) != 1\n", pr_warn("Program '%s' is inconsistent: nr(%d) != 1\n",
prog->section_name, prog->instances.nr); prog->section_name, prog->instances.nr);
} }
err = load_program(prog, prog->insns, prog->insns_cnt, err = load_program(prog, prog->insns, prog->insns_cnt,
...@@ -3550,7 +3546,7 @@ bpf_program__load(struct bpf_program *prog, ...@@ -3550,7 +3546,7 @@ bpf_program__load(struct bpf_program *prog,
err = preprocessor(prog, i, prog->insns, err = preprocessor(prog, i, prog->insns,
prog->insns_cnt, &result); prog->insns_cnt, &result);
if (err) { if (err) {
pr_warning("Preprocessing the %dth instance of program '%s' failed\n", pr_warn("Preprocessing the %dth instance of program '%s' failed\n",
i, prog->section_name); i, prog->section_name);
goto out; goto out;
} }
...@@ -3569,7 +3565,7 @@ bpf_program__load(struct bpf_program *prog, ...@@ -3569,7 +3565,7 @@ bpf_program__load(struct bpf_program *prog,
license, kern_version, &fd); license, kern_version, &fd);
if (err) { if (err) {
pr_warning("Loading the %dth instance of program '%s' failed\n", pr_warn("Loading the %dth instance of program '%s' failed\n",
i, prog->section_name); i, prog->section_name);
goto out; goto out;
} }
...@@ -3580,8 +3576,7 @@ bpf_program__load(struct bpf_program *prog, ...@@ -3580,8 +3576,7 @@ bpf_program__load(struct bpf_program *prog,
} }
out: out:
if (err) if (err)
pr_warning("failed to load program '%s'\n", pr_warn("failed to load program '%s'\n", prog->section_name);
prog->section_name);
zfree(&prog->insns); zfree(&prog->insns);
prog->insns_cnt = 0; prog->insns_cnt = 0;
return err; return err;
...@@ -3623,7 +3618,7 @@ __bpf_object__open(const char *path, const void *obj_buf, size_t obj_buf_sz, ...@@ -3623,7 +3618,7 @@ __bpf_object__open(const char *path, const void *obj_buf, size_t obj_buf_sz,
int err; int err;
if (elf_version(EV_CURRENT) == EV_NONE) { if (elf_version(EV_CURRENT) == EV_NONE) {
pr_warning("failed to init libelf for %s\n", pr_warn("failed to init libelf for %s\n",
path ? : "(mem buf)"); path ? : "(mem buf)");
return ERR_PTR(-LIBBPF_ERRNO__LIBELF); return ERR_PTR(-LIBBPF_ERRNO__LIBELF);
} }
...@@ -3759,7 +3754,7 @@ int bpf_object__load_xattr(struct bpf_object_load_attr *attr) ...@@ -3759,7 +3754,7 @@ int bpf_object__load_xattr(struct bpf_object_load_attr *attr)
return -EINVAL; return -EINVAL;
if (obj->loaded) { if (obj->loaded) {
pr_warning("object should not be loaded twice\n"); pr_warn("object should not be loaded twice\n");
return -EINVAL; return -EINVAL;
} }
...@@ -3772,7 +3767,7 @@ int bpf_object__load_xattr(struct bpf_object_load_attr *attr) ...@@ -3772,7 +3767,7 @@ int bpf_object__load_xattr(struct bpf_object_load_attr *attr)
return 0; return 0;
out: out:
bpf_object__unload(obj); bpf_object__unload(obj);
pr_warning("failed to load object '%s'\n", obj->path); pr_warn("failed to load object '%s'\n", obj->path);
return err; return err;
} }
...@@ -3802,13 +3797,13 @@ static int check_path(const char *path) ...@@ -3802,13 +3797,13 @@ static int check_path(const char *path)
dir = dirname(dname); dir = dirname(dname);
if (statfs(dir, &st_fs)) { if (statfs(dir, &st_fs)) {
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warning("failed to statfs %s: %s\n", dir, cp); pr_warn("failed to statfs %s: %s\n", dir, cp);
err = -errno; err = -errno;
} }
free(dname); free(dname);
if (!err && st_fs.f_type != BPF_FS_MAGIC) { if (!err && st_fs.f_type != BPF_FS_MAGIC) {
pr_warning("specified path %s is not on BPF FS\n", path); pr_warn("specified path %s is not on BPF FS\n", path);
err = -EINVAL; err = -EINVAL;
} }
...@@ -3826,19 +3821,19 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path, ...@@ -3826,19 +3821,19 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path,
return err; return err;
if (prog == NULL) { if (prog == NULL) {
pr_warning("invalid program pointer\n"); pr_warn("invalid program pointer\n");
return -EINVAL; return -EINVAL;
} }
if (instance < 0 || instance >= prog->instances.nr) { if (instance < 0 || instance >= prog->instances.nr) {
pr_warning("invalid prog instance %d of prog %s (max %d)\n", pr_warn("invalid prog instance %d of prog %s (max %d)\n",
instance, prog->section_name, prog->instances.nr); instance, prog->section_name, prog->instances.nr);
return -EINVAL; return -EINVAL;
} }
if (bpf_obj_pin(prog->instances.fds[instance], path)) { if (bpf_obj_pin(prog->instances.fds[instance], path)) {
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warning("failed to pin program: %s\n", cp); pr_warn("failed to pin program: %s\n", cp);
return -errno; return -errno;
} }
pr_debug("pinned program '%s'\n", path); pr_debug("pinned program '%s'\n", path);
...@@ -3856,12 +3851,12 @@ int bpf_program__unpin_instance(struct bpf_program *prog, const char *path, ...@@ -3856,12 +3851,12 @@ int bpf_program__unpin_instance(struct bpf_program *prog, const char *path,
return err; return err;
if (prog == NULL) { if (prog == NULL) {
pr_warning("invalid program pointer\n"); pr_warn("invalid program pointer\n");
return -EINVAL; return -EINVAL;
} }
if (instance < 0 || instance >= prog->instances.nr) { if (instance < 0 || instance >= prog->instances.nr) {
pr_warning("invalid prog instance %d of prog %s (max %d)\n", pr_warn("invalid prog instance %d of prog %s (max %d)\n",
instance, prog->section_name, prog->instances.nr); instance, prog->section_name, prog->instances.nr);
return -EINVAL; return -EINVAL;
} }
...@@ -3884,7 +3879,7 @@ static int make_dir(const char *path) ...@@ -3884,7 +3879,7 @@ static int make_dir(const char *path)
if (err) { if (err) {
cp = libbpf_strerror_r(-err, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(-err, errmsg, sizeof(errmsg));
pr_warning("failed to mkdir %s: %s\n", path, cp); pr_warn("failed to mkdir %s: %s\n", path, cp);
} }
return err; return err;
} }
...@@ -3898,12 +3893,12 @@ int bpf_program__pin(struct bpf_program *prog, const char *path) ...@@ -3898,12 +3893,12 @@ int bpf_program__pin(struct bpf_program *prog, const char *path)
return err; return err;
if (prog == NULL) { if (prog == NULL) {
pr_warning("invalid program pointer\n"); pr_warn("invalid program pointer\n");
return -EINVAL; return -EINVAL;
} }
if (prog->instances.nr <= 0) { if (prog->instances.nr <= 0) {
pr_warning("no instances of prog %s to pin\n", pr_warn("no instances of prog %s to pin\n",
prog->section_name); prog->section_name);
return -EINVAL; return -EINVAL;
} }
...@@ -3965,12 +3960,12 @@ int bpf_program__unpin(struct bpf_program *prog, const char *path) ...@@ -3965,12 +3960,12 @@ int bpf_program__unpin(struct bpf_program *prog, const char *path)
return err; return err;
if (prog == NULL) { if (prog == NULL) {
pr_warning("invalid program pointer\n"); pr_warn("invalid program pointer\n");
return -EINVAL; return -EINVAL;
} }
if (prog->instances.nr <= 0) { if (prog->instances.nr <= 0) {
pr_warning("no instances of prog %s to pin\n", pr_warn("no instances of prog %s to pin\n",
prog->section_name); prog->section_name);
return -EINVAL; return -EINVAL;
} }
...@@ -4012,13 +4007,13 @@ int bpf_map__pin(struct bpf_map *map, const char *path) ...@@ -4012,13 +4007,13 @@ int bpf_map__pin(struct bpf_map *map, const char *path)
return err; return err;
if (map == NULL) { if (map == NULL) {
pr_warning("invalid map pointer\n"); pr_warn("invalid map pointer\n");
return -EINVAL; return -EINVAL;
} }
if (bpf_obj_pin(map->fd, path)) { if (bpf_obj_pin(map->fd, path)) {
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warning("failed to pin map: %s\n", cp); pr_warn("failed to pin map: %s\n", cp);
return -errno; return -errno;
} }
...@@ -4036,7 +4031,7 @@ int bpf_map__unpin(struct bpf_map *map, const char *path) ...@@ -4036,7 +4031,7 @@ int bpf_map__unpin(struct bpf_map *map, const char *path)
return err; return err;
if (map == NULL) { if (map == NULL) {
pr_warning("invalid map pointer\n"); pr_warn("invalid map pointer\n");
return -EINVAL; return -EINVAL;
} }
...@@ -4057,7 +4052,7 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path) ...@@ -4057,7 +4052,7 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)
return -ENOENT; return -ENOENT;
if (!obj->loaded) { if (!obj->loaded) {
pr_warning("object not yet loaded; load it first\n"); pr_warn("object not yet loaded; load it first\n");
return -ENOENT; return -ENOENT;
} }
...@@ -4140,7 +4135,7 @@ int bpf_object__pin_programs(struct bpf_object *obj, const char *path) ...@@ -4140,7 +4135,7 @@ int bpf_object__pin_programs(struct bpf_object *obj, const char *path)
return -ENOENT; return -ENOENT;
if (!obj->loaded) { if (!obj->loaded) {
pr_warning("object not yet loaded; load it first\n"); pr_warn("object not yet loaded; load it first\n");
return -ENOENT; return -ENOENT;
} }
...@@ -4341,7 +4336,7 @@ __bpf_program__iter(const struct bpf_program *p, const struct bpf_object *obj, ...@@ -4341,7 +4336,7 @@ __bpf_program__iter(const struct bpf_program *p, const struct bpf_object *obj,
&obj->programs[nr_programs - 1]; &obj->programs[nr_programs - 1];
if (p->obj != obj) { if (p->obj != obj) {
pr_warning("error: program handler doesn't match object\n"); pr_warn("error: program handler doesn't match object\n");
return NULL; return NULL;
} }
...@@ -4404,7 +4399,7 @@ const char *bpf_program__title(const struct bpf_program *prog, bool needs_copy) ...@@ -4404,7 +4399,7 @@ const char *bpf_program__title(const struct bpf_program *prog, bool needs_copy)
if (needs_copy) { if (needs_copy) {
title = strdup(title); title = strdup(title);
if (!title) { if (!title) {
pr_warning("failed to strdup program title\n"); pr_warn("failed to strdup program title\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
} }
...@@ -4426,13 +4421,13 @@ int bpf_program__set_prep(struct bpf_program *prog, int nr_instances, ...@@ -4426,13 +4421,13 @@ int bpf_program__set_prep(struct bpf_program *prog, int nr_instances,
return -EINVAL; return -EINVAL;
if (prog->instances.nr > 0 || prog->instances.fds) { if (prog->instances.nr > 0 || prog->instances.fds) {
pr_warning("Can't set pre-processor after loading\n"); pr_warn("Can't set pre-processor after loading\n");
return -EINVAL; return -EINVAL;
} }
instances_fds = malloc(sizeof(int) * nr_instances); instances_fds = malloc(sizeof(int) * nr_instances);
if (!instances_fds) { if (!instances_fds) {
pr_warning("alloc memory failed for fds\n"); pr_warn("alloc memory failed for fds\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -4453,14 +4448,14 @@ int bpf_program__nth_fd(const struct bpf_program *prog, int n) ...@@ -4453,14 +4448,14 @@ int bpf_program__nth_fd(const struct bpf_program *prog, int n)
return -EINVAL; return -EINVAL;
if (n >= prog->instances.nr || n < 0) { if (n >= prog->instances.nr || n < 0) {
pr_warning("Can't get the %dth fd from program %s: only %d instances\n", pr_warn("Can't get the %dth fd from program %s: only %d instances\n",
n, prog->section_name, prog->instances.nr); n, prog->section_name, prog->instances.nr);
return -EINVAL; return -EINVAL;
} }
fd = prog->instances.fds[n]; fd = prog->instances.fds[n];
if (fd < 0) { if (fd < 0) {
pr_warning("%dth instance of program '%s' is invalid\n", pr_warn("%dth instance of program '%s' is invalid\n",
n, prog->section_name); n, prog->section_name);
return -ENOENT; return -ENOENT;
} }
...@@ -4658,7 +4653,7 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, ...@@ -4658,7 +4653,7 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
int ret; int ret;
if (IS_ERR(btf)) { if (IS_ERR(btf)) {
pr_warning("vmlinux BTF is not found\n"); pr_warn("vmlinux BTF is not found\n");
return -EINVAL; return -EINVAL;
} }
/* prepend "btf_trace_" prefix per kernel convention */ /* prepend "btf_trace_" prefix per kernel convention */
...@@ -4667,14 +4662,14 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, ...@@ -4667,14 +4662,14 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
ret = btf__find_by_name(btf, raw_tp_btf_name); ret = btf__find_by_name(btf, raw_tp_btf_name);
btf__free(btf); btf__free(btf);
if (ret <= 0) { if (ret <= 0) {
pr_warning("%s is not found in vmlinux BTF\n", dst); pr_warn("%s is not found in vmlinux BTF\n", dst);
return -EINVAL; return -EINVAL;
} }
*expected_attach_type = ret; *expected_attach_type = ret;
} }
return 0; return 0;
} }
pr_warning("failed to guess program type based on ELF section name '%s'\n", name); pr_warn("failed to guess program type based on ELF section name '%s'\n", name);
type_names = libbpf_get_type_names(false); type_names = libbpf_get_type_names(false);
if (type_names != NULL) { if (type_names != NULL) {
pr_info("supported section(type) names are:%s\n", type_names); pr_info("supported section(type) names are:%s\n", type_names);
...@@ -4701,7 +4696,7 @@ int libbpf_attach_type_by_name(const char *name, ...@@ -4701,7 +4696,7 @@ int libbpf_attach_type_by_name(const char *name,
*attach_type = section_names[i].attach_type; *attach_type = section_names[i].attach_type;
return 0; return 0;
} }
pr_warning("failed to guess attach type based on ELF section name '%s'\n", name); pr_warn("failed to guess attach type based on ELF section name '%s'\n", name);
type_names = libbpf_get_type_names(true); type_names = libbpf_get_type_names(true);
if (type_names != NULL) { if (type_names != NULL) {
pr_info("attachable section(type) names are:%s\n", type_names); pr_info("attachable section(type) names are:%s\n", type_names);
...@@ -4784,11 +4779,11 @@ void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex) ...@@ -4784,11 +4779,11 @@ void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex)
int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd) int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd)
{ {
if (!bpf_map_type__is_map_in_map(map->def.type)) { if (!bpf_map_type__is_map_in_map(map->def.type)) {
pr_warning("error: unsupported map type\n"); pr_warn("error: unsupported map type\n");
return -EINVAL; return -EINVAL;
} }
if (map->inner_map_fd != -1) { if (map->inner_map_fd != -1) {
pr_warning("error: inner_map_fd already specified\n"); pr_warn("error: inner_map_fd already specified\n");
return -EINVAL; return -EINVAL;
} }
map->inner_map_fd = fd; map->inner_map_fd = fd;
...@@ -4808,7 +4803,7 @@ __bpf_map__iter(const struct bpf_map *m, const struct bpf_object *obj, int i) ...@@ -4808,7 +4803,7 @@ __bpf_map__iter(const struct bpf_map *m, const struct bpf_object *obj, int i)
e = obj->maps + obj->nr_maps; e = obj->maps + obj->nr_maps;
if ((m < s) || (m >= e)) { if ((m < s) || (m >= e)) {
pr_warning("error in %s: map handler doesn't belong to object\n", pr_warn("error in %s: map handler doesn't belong to object\n",
__func__); __func__);
return NULL; return NULL;
} }
...@@ -4938,7 +4933,7 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, ...@@ -4938,7 +4933,7 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
} }
if (!first_prog) { if (!first_prog) {
pr_warning("object file doesn't contain bpf program\n"); pr_warn("object file doesn't contain bpf program\n");
bpf_object__close(obj); bpf_object__close(obj);
return -ENOENT; return -ENOENT;
} }
...@@ -4997,13 +4992,13 @@ struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog, ...@@ -4997,13 +4992,13 @@ struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog,
int prog_fd, err; int prog_fd, err;
if (pfd < 0) { if (pfd < 0) {
pr_warning("program '%s': invalid perf event FD %d\n", pr_warn("program '%s': invalid perf event FD %d\n",
bpf_program__title(prog, false), pfd); bpf_program__title(prog, false), pfd);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
prog_fd = bpf_program__fd(prog); prog_fd = bpf_program__fd(prog);
if (prog_fd < 0) { if (prog_fd < 0) {
pr_warning("program '%s': can't attach BPF program w/o FD (did you load it?)\n", pr_warn("program '%s': can't attach BPF program w/o FD (did you load it?)\n",
bpf_program__title(prog, false)); bpf_program__title(prog, false));
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -5017,7 +5012,7 @@ struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog, ...@@ -5017,7 +5012,7 @@ struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog,
if (ioctl(pfd, PERF_EVENT_IOC_SET_BPF, prog_fd) < 0) { if (ioctl(pfd, PERF_EVENT_IOC_SET_BPF, prog_fd) < 0) {
err = -errno; err = -errno;
free(link); free(link);
pr_warning("program '%s': failed to attach to pfd %d: %s\n", pr_warn("program '%s': failed to attach to pfd %d: %s\n",
bpf_program__title(prog, false), pfd, bpf_program__title(prog, false), pfd,
libbpf_strerror_r(err, errmsg, sizeof(errmsg))); libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
return ERR_PTR(err); return ERR_PTR(err);
...@@ -5025,7 +5020,7 @@ struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog, ...@@ -5025,7 +5020,7 @@ struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog,
if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) { if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) {
err = -errno; err = -errno;
free(link); free(link);
pr_warning("program '%s': failed to enable pfd %d: %s\n", pr_warn("program '%s': failed to enable pfd %d: %s\n",
bpf_program__title(prog, false), pfd, bpf_program__title(prog, false), pfd,
libbpf_strerror_r(err, errmsg, sizeof(errmsg))); libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
return ERR_PTR(err); return ERR_PTR(err);
...@@ -5101,7 +5096,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name, ...@@ -5101,7 +5096,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
type = uprobe ? determine_uprobe_perf_type() type = uprobe ? determine_uprobe_perf_type()
: determine_kprobe_perf_type(); : determine_kprobe_perf_type();
if (type < 0) { if (type < 0) {
pr_warning("failed to determine %s perf type: %s\n", pr_warn("failed to determine %s perf type: %s\n",
uprobe ? "uprobe" : "kprobe", uprobe ? "uprobe" : "kprobe",
libbpf_strerror_r(type, errmsg, sizeof(errmsg))); libbpf_strerror_r(type, errmsg, sizeof(errmsg)));
return type; return type;
...@@ -5111,10 +5106,9 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name, ...@@ -5111,10 +5106,9 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
: determine_kprobe_retprobe_bit(); : determine_kprobe_retprobe_bit();
if (bit < 0) { if (bit < 0) {
pr_warning("failed to determine %s retprobe bit: %s\n", pr_warn("failed to determine %s retprobe bit: %s\n",
uprobe ? "uprobe" : "kprobe", uprobe ? "uprobe" : "kprobe",
libbpf_strerror_r(bit, errmsg, libbpf_strerror_r(bit, errmsg, sizeof(errmsg)));
sizeof(errmsg)));
return bit; return bit;
} }
attr.config |= 1 << bit; attr.config |= 1 << bit;
...@@ -5131,7 +5125,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name, ...@@ -5131,7 +5125,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
-1 /* group_fd */, PERF_FLAG_FD_CLOEXEC); -1 /* group_fd */, PERF_FLAG_FD_CLOEXEC);
if (pfd < 0) { if (pfd < 0) {
err = -errno; err = -errno;
pr_warning("%s perf_event_open() failed: %s\n", pr_warn("%s perf_event_open() failed: %s\n",
uprobe ? "uprobe" : "kprobe", uprobe ? "uprobe" : "kprobe",
libbpf_strerror_r(err, errmsg, sizeof(errmsg))); libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
return err; return err;
...@@ -5150,7 +5144,7 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog, ...@@ -5150,7 +5144,7 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog,
pfd = perf_event_open_probe(false /* uprobe */, retprobe, func_name, pfd = perf_event_open_probe(false /* uprobe */, retprobe, func_name,
0 /* offset */, -1 /* pid */); 0 /* offset */, -1 /* pid */);
if (pfd < 0) { if (pfd < 0) {
pr_warning("program '%s': failed to create %s '%s' perf event: %s\n", pr_warn("program '%s': failed to create %s '%s' perf event: %s\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
retprobe ? "kretprobe" : "kprobe", func_name, retprobe ? "kretprobe" : "kprobe", func_name,
libbpf_strerror_r(pfd, errmsg, sizeof(errmsg))); libbpf_strerror_r(pfd, errmsg, sizeof(errmsg)));
...@@ -5160,7 +5154,7 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog, ...@@ -5160,7 +5154,7 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog,
if (IS_ERR(link)) { if (IS_ERR(link)) {
close(pfd); close(pfd);
err = PTR_ERR(link); err = PTR_ERR(link);
pr_warning("program '%s': failed to attach to %s '%s': %s\n", pr_warn("program '%s': failed to attach to %s '%s': %s\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
retprobe ? "kretprobe" : "kprobe", func_name, retprobe ? "kretprobe" : "kprobe", func_name,
libbpf_strerror_r(err, errmsg, sizeof(errmsg))); libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
...@@ -5181,7 +5175,7 @@ struct bpf_link *bpf_program__attach_uprobe(struct bpf_program *prog, ...@@ -5181,7 +5175,7 @@ struct bpf_link *bpf_program__attach_uprobe(struct bpf_program *prog,
pfd = perf_event_open_probe(true /* uprobe */, retprobe, pfd = perf_event_open_probe(true /* uprobe */, retprobe,
binary_path, func_offset, pid); binary_path, func_offset, pid);
if (pfd < 0) { if (pfd < 0) {
pr_warning("program '%s': failed to create %s '%s:0x%zx' perf event: %s\n", pr_warn("program '%s': failed to create %s '%s:0x%zx' perf event: %s\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
retprobe ? "uretprobe" : "uprobe", retprobe ? "uretprobe" : "uprobe",
binary_path, func_offset, binary_path, func_offset,
...@@ -5192,7 +5186,7 @@ struct bpf_link *bpf_program__attach_uprobe(struct bpf_program *prog, ...@@ -5192,7 +5186,7 @@ struct bpf_link *bpf_program__attach_uprobe(struct bpf_program *prog,
if (IS_ERR(link)) { if (IS_ERR(link)) {
close(pfd); close(pfd);
err = PTR_ERR(link); err = PTR_ERR(link);
pr_warning("program '%s': failed to attach to %s '%s:0x%zx': %s\n", pr_warn("program '%s': failed to attach to %s '%s:0x%zx': %s\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
retprobe ? "uretprobe" : "uprobe", retprobe ? "uretprobe" : "uprobe",
binary_path, func_offset, binary_path, func_offset,
...@@ -5230,7 +5224,7 @@ static int perf_event_open_tracepoint(const char *tp_category, ...@@ -5230,7 +5224,7 @@ static int perf_event_open_tracepoint(const char *tp_category,
tp_id = determine_tracepoint_id(tp_category, tp_name); tp_id = determine_tracepoint_id(tp_category, tp_name);
if (tp_id < 0) { if (tp_id < 0) {
pr_warning("failed to determine tracepoint '%s/%s' perf event ID: %s\n", pr_warn("failed to determine tracepoint '%s/%s' perf event ID: %s\n",
tp_category, tp_name, tp_category, tp_name,
libbpf_strerror_r(tp_id, errmsg, sizeof(errmsg))); libbpf_strerror_r(tp_id, errmsg, sizeof(errmsg)));
return tp_id; return tp_id;
...@@ -5244,7 +5238,7 @@ static int perf_event_open_tracepoint(const char *tp_category, ...@@ -5244,7 +5238,7 @@ static int perf_event_open_tracepoint(const char *tp_category,
-1 /* group_fd */, PERF_FLAG_FD_CLOEXEC); -1 /* group_fd */, PERF_FLAG_FD_CLOEXEC);
if (pfd < 0) { if (pfd < 0) {
err = -errno; err = -errno;
pr_warning("tracepoint '%s/%s' perf_event_open() failed: %s\n", pr_warn("tracepoint '%s/%s' perf_event_open() failed: %s\n",
tp_category, tp_name, tp_category, tp_name,
libbpf_strerror_r(err, errmsg, sizeof(errmsg))); libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
return err; return err;
...@@ -5262,7 +5256,7 @@ struct bpf_link *bpf_program__attach_tracepoint(struct bpf_program *prog, ...@@ -5262,7 +5256,7 @@ struct bpf_link *bpf_program__attach_tracepoint(struct bpf_program *prog,
pfd = perf_event_open_tracepoint(tp_category, tp_name); pfd = perf_event_open_tracepoint(tp_category, tp_name);
if (pfd < 0) { if (pfd < 0) {
pr_warning("program '%s': failed to create tracepoint '%s/%s' perf event: %s\n", pr_warn("program '%s': failed to create tracepoint '%s/%s' perf event: %s\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
tp_category, tp_name, tp_category, tp_name,
libbpf_strerror_r(pfd, errmsg, sizeof(errmsg))); libbpf_strerror_r(pfd, errmsg, sizeof(errmsg)));
...@@ -5272,7 +5266,7 @@ struct bpf_link *bpf_program__attach_tracepoint(struct bpf_program *prog, ...@@ -5272,7 +5266,7 @@ struct bpf_link *bpf_program__attach_tracepoint(struct bpf_program *prog,
if (IS_ERR(link)) { if (IS_ERR(link)) {
close(pfd); close(pfd);
err = PTR_ERR(link); err = PTR_ERR(link);
pr_warning("program '%s': failed to attach to tracepoint '%s/%s': %s\n", pr_warn("program '%s': failed to attach to tracepoint '%s/%s': %s\n",
bpf_program__title(prog, false), bpf_program__title(prog, false),
tp_category, tp_name, tp_category, tp_name,
libbpf_strerror_r(err, errmsg, sizeof(errmsg))); libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
...@@ -5297,7 +5291,7 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(struct bpf_program *prog, ...@@ -5297,7 +5291,7 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(struct bpf_program *prog,
prog_fd = bpf_program__fd(prog); prog_fd = bpf_program__fd(prog);
if (prog_fd < 0) { if (prog_fd < 0) {
pr_warning("program '%s': can't attach before loaded\n", pr_warn("program '%s': can't attach before loaded\n",
bpf_program__title(prog, false)); bpf_program__title(prog, false));
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -5311,7 +5305,7 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(struct bpf_program *prog, ...@@ -5311,7 +5305,7 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(struct bpf_program *prog,
if (pfd < 0) { if (pfd < 0) {
pfd = -errno; pfd = -errno;
free(link); free(link);
pr_warning("program '%s': failed to attach to raw tracepoint '%s': %s\n", pr_warn("program '%s': failed to attach to raw tracepoint '%s': %s\n",
bpf_program__title(prog, false), tp_name, bpf_program__title(prog, false), tp_name,
libbpf_strerror_r(pfd, errmsg, sizeof(errmsg))); libbpf_strerror_r(pfd, errmsg, sizeof(errmsg)));
return ERR_PTR(pfd); return ERR_PTR(pfd);
...@@ -5415,7 +5409,7 @@ static void perf_buffer__free_cpu_buf(struct perf_buffer *pb, ...@@ -5415,7 +5409,7 @@ static void perf_buffer__free_cpu_buf(struct perf_buffer *pb,
return; return;
if (cpu_buf->base && if (cpu_buf->base &&
munmap(cpu_buf->base, pb->mmap_size + pb->page_size)) munmap(cpu_buf->base, pb->mmap_size + pb->page_size))
pr_warning("failed to munmap cpu_buf #%d\n", cpu_buf->cpu); pr_warn("failed to munmap cpu_buf #%d\n", cpu_buf->cpu);
if (cpu_buf->fd >= 0) { if (cpu_buf->fd >= 0) {
ioctl(cpu_buf->fd, PERF_EVENT_IOC_DISABLE, 0); ioctl(cpu_buf->fd, PERF_EVENT_IOC_DISABLE, 0);
close(cpu_buf->fd); close(cpu_buf->fd);
...@@ -5465,7 +5459,7 @@ perf_buffer__open_cpu_buf(struct perf_buffer *pb, struct perf_event_attr *attr, ...@@ -5465,7 +5459,7 @@ perf_buffer__open_cpu_buf(struct perf_buffer *pb, struct perf_event_attr *attr,
-1, PERF_FLAG_FD_CLOEXEC); -1, PERF_FLAG_FD_CLOEXEC);
if (cpu_buf->fd < 0) { if (cpu_buf->fd < 0) {
err = -errno; err = -errno;
pr_warning("failed to open perf buffer event on cpu #%d: %s\n", pr_warn("failed to open perf buffer event on cpu #%d: %s\n",
cpu, libbpf_strerror_r(err, msg, sizeof(msg))); cpu, libbpf_strerror_r(err, msg, sizeof(msg)));
goto error; goto error;
} }
...@@ -5476,14 +5470,14 @@ perf_buffer__open_cpu_buf(struct perf_buffer *pb, struct perf_event_attr *attr, ...@@ -5476,14 +5470,14 @@ perf_buffer__open_cpu_buf(struct perf_buffer *pb, struct perf_event_attr *attr,
if (cpu_buf->base == MAP_FAILED) { if (cpu_buf->base == MAP_FAILED) {
cpu_buf->base = NULL; cpu_buf->base = NULL;
err = -errno; err = -errno;
pr_warning("failed to mmap perf buffer on cpu #%d: %s\n", pr_warn("failed to mmap perf buffer on cpu #%d: %s\n",
cpu, libbpf_strerror_r(err, msg, sizeof(msg))); cpu, libbpf_strerror_r(err, msg, sizeof(msg)));
goto error; goto error;
} }
if (ioctl(cpu_buf->fd, PERF_EVENT_IOC_ENABLE, 0) < 0) { if (ioctl(cpu_buf->fd, PERF_EVENT_IOC_ENABLE, 0) < 0) {
err = -errno; err = -errno;
pr_warning("failed to enable perf buffer event on cpu #%d: %s\n", pr_warn("failed to enable perf buffer event on cpu #%d: %s\n",
cpu, libbpf_strerror_r(err, msg, sizeof(msg))); cpu, libbpf_strerror_r(err, msg, sizeof(msg)));
goto error; goto error;
} }
...@@ -5544,7 +5538,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt, ...@@ -5544,7 +5538,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
int err, i; int err, i;
if (page_cnt & (page_cnt - 1)) { if (page_cnt & (page_cnt - 1)) {
pr_warning("page count should be power of two, but is %zu\n", pr_warn("page count should be power of two, but is %zu\n",
page_cnt); page_cnt);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -5553,13 +5547,13 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt, ...@@ -5553,13 +5547,13 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
err = bpf_obj_get_info_by_fd(map_fd, &map, &map_info_len); err = bpf_obj_get_info_by_fd(map_fd, &map, &map_info_len);
if (err) { if (err) {
err = -errno; err = -errno;
pr_warning("failed to get map info for map FD %d: %s\n", pr_warn("failed to get map info for map FD %d: %s\n",
map_fd, libbpf_strerror_r(err, msg, sizeof(msg))); map_fd, libbpf_strerror_r(err, msg, sizeof(msg)));
return ERR_PTR(err); return ERR_PTR(err);
} }
if (map.type != BPF_MAP_TYPE_PERF_EVENT_ARRAY) { if (map.type != BPF_MAP_TYPE_PERF_EVENT_ARRAY) {
pr_warning("map '%s' should be BPF_MAP_TYPE_PERF_EVENT_ARRAY\n", pr_warn("map '%s' should be BPF_MAP_TYPE_PERF_EVENT_ARRAY\n",
map.name); map.name);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -5580,7 +5574,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt, ...@@ -5580,7 +5574,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
pb->epoll_fd = epoll_create1(EPOLL_CLOEXEC); pb->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (pb->epoll_fd < 0) { if (pb->epoll_fd < 0) {
err = -errno; err = -errno;
pr_warning("failed to create epoll instance: %s\n", pr_warn("failed to create epoll instance: %s\n",
libbpf_strerror_r(err, msg, sizeof(msg))); libbpf_strerror_r(err, msg, sizeof(msg)));
goto error; goto error;
} }
...@@ -5600,13 +5594,13 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt, ...@@ -5600,13 +5594,13 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
pb->events = calloc(pb->cpu_cnt, sizeof(*pb->events)); pb->events = calloc(pb->cpu_cnt, sizeof(*pb->events));
if (!pb->events) { if (!pb->events) {
err = -ENOMEM; err = -ENOMEM;
pr_warning("failed to allocate events: out of memory\n"); pr_warn("failed to allocate events: out of memory\n");
goto error; goto error;
} }
pb->cpu_bufs = calloc(pb->cpu_cnt, sizeof(*pb->cpu_bufs)); pb->cpu_bufs = calloc(pb->cpu_cnt, sizeof(*pb->cpu_bufs));
if (!pb->cpu_bufs) { if (!pb->cpu_bufs) {
err = -ENOMEM; err = -ENOMEM;
pr_warning("failed to allocate buffers: out of memory\n"); pr_warn("failed to allocate buffers: out of memory\n");
goto error; goto error;
} }
...@@ -5629,7 +5623,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt, ...@@ -5629,7 +5623,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
&cpu_buf->fd, 0); &cpu_buf->fd, 0);
if (err) { if (err) {
err = -errno; err = -errno;
pr_warning("failed to set cpu #%d, key %d -> perf FD %d: %s\n", pr_warn("failed to set cpu #%d, key %d -> perf FD %d: %s\n",
cpu, map_key, cpu_buf->fd, cpu, map_key, cpu_buf->fd,
libbpf_strerror_r(err, msg, sizeof(msg))); libbpf_strerror_r(err, msg, sizeof(msg)));
goto error; goto error;
...@@ -5640,7 +5634,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt, ...@@ -5640,7 +5634,7 @@ static struct perf_buffer *__perf_buffer__new(int map_fd, size_t page_cnt,
if (epoll_ctl(pb->epoll_fd, EPOLL_CTL_ADD, cpu_buf->fd, if (epoll_ctl(pb->epoll_fd, EPOLL_CTL_ADD, cpu_buf->fd,
&pb->events[i]) < 0) { &pb->events[i]) < 0) {
err = -errno; err = -errno;
pr_warning("failed to epoll_ctl cpu #%d perf FD %d: %s\n", pr_warn("failed to epoll_ctl cpu #%d perf FD %d: %s\n",
cpu, cpu_buf->fd, cpu, cpu_buf->fd,
libbpf_strerror_r(err, msg, sizeof(msg))); libbpf_strerror_r(err, msg, sizeof(msg)));
goto error; goto error;
...@@ -5695,7 +5689,7 @@ perf_buffer__process_record(struct perf_event_header *e, void *ctx) ...@@ -5695,7 +5689,7 @@ perf_buffer__process_record(struct perf_event_header *e, void *ctx)
break; break;
} }
default: default:
pr_warning("unknown perf sample type %d\n", e->type); pr_warn("unknown perf sample type %d\n", e->type);
return LIBBPF_PERF_EVENT_ERROR; return LIBBPF_PERF_EVENT_ERROR;
} }
return LIBBPF_PERF_EVENT_CONT; return LIBBPF_PERF_EVENT_CONT;
...@@ -5725,7 +5719,7 @@ int perf_buffer__poll(struct perf_buffer *pb, int timeout_ms) ...@@ -5725,7 +5719,7 @@ int perf_buffer__poll(struct perf_buffer *pb, int timeout_ms)
err = perf_buffer__process_records(pb, cpu_buf); err = perf_buffer__process_records(pb, cpu_buf);
if (err) { if (err) {
pr_warning("error while processing records: %d\n", err); pr_warn("error while processing records: %d\n", err);
return err; return err;
} }
} }
...@@ -5922,13 +5916,13 @@ bpf_program__get_prog_info_linear(int fd, __u64 arrays) ...@@ -5922,13 +5916,13 @@ bpf_program__get_prog_info_linear(int fd, __u64 arrays)
v2 = bpf_prog_info_read_offset_u32(&info_linear->info, v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
desc->count_offset); desc->count_offset);
if (v1 != v2) if (v1 != v2)
pr_warning("%s: mismatch in element count\n", __func__); pr_warn("%s: mismatch in element count\n", __func__);
v1 = bpf_prog_info_read_offset_u32(&info, desc->size_offset); v1 = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
v2 = bpf_prog_info_read_offset_u32(&info_linear->info, v2 = bpf_prog_info_read_offset_u32(&info_linear->info,
desc->size_offset); desc->size_offset);
if (v1 != v2) if (v1 != v2)
pr_warning("%s: mismatch in rec size\n", __func__); pr_warn("%s: mismatch in rec size\n", __func__);
} }
/* step 7: update info_len and data_len */ /* step 7: update info_len and data_len */
...@@ -5996,20 +5990,19 @@ int libbpf_num_possible_cpus(void) ...@@ -5996,20 +5990,19 @@ int libbpf_num_possible_cpus(void)
fd = open(fcpu, O_RDONLY); fd = open(fcpu, O_RDONLY);
if (fd < 0) { if (fd < 0) {
error = errno; error = errno;
pr_warning("Failed to open file %s: %s\n", pr_warn("Failed to open file %s: %s\n", fcpu, strerror(error));
fcpu, strerror(error));
return -error; return -error;
} }
len = read(fd, buf, sizeof(buf)); len = read(fd, buf, sizeof(buf));
close(fd); close(fd);
if (len <= 0) { if (len <= 0) {
error = len ? errno : EINVAL; error = len ? errno : EINVAL;
pr_warning("Failed to read # of possible cpus from %s: %s\n", pr_warn("Failed to read # of possible cpus from %s: %s\n",
fcpu, strerror(error)); fcpu, strerror(error));
return -error; return -error;
} }
if (len == sizeof(buf)) { if (len == sizeof(buf)) {
pr_warning("File %s size overflow\n", fcpu); pr_warn("File %s size overflow\n", fcpu);
return -EOVERFLOW; return -EOVERFLOW;
} }
buf[len] = '\0'; buf[len] = '\0';
...@@ -6020,7 +6013,7 @@ int libbpf_num_possible_cpus(void) ...@@ -6020,7 +6013,7 @@ int libbpf_num_possible_cpus(void)
buf[ir] = '\0'; buf[ir] = '\0';
n = sscanf(&buf[il], "%u-%u", &start, &end); n = sscanf(&buf[il], "%u-%u", &start, &end);
if (n <= 0) { if (n <= 0) {
pr_warning("Failed to get # CPUs from %s\n", pr_warn("Failed to get # CPUs from %s\n",
&buf[il]); &buf[il]);
return -EINVAL; return -EINVAL;
} else if (n == 1) { } else if (n == 1) {
...@@ -6031,7 +6024,7 @@ int libbpf_num_possible_cpus(void) ...@@ -6031,7 +6024,7 @@ int libbpf_num_possible_cpus(void)
} }
} }
if (tmp_cpus <= 0) { if (tmp_cpus <= 0) {
pr_warning("Invalid #CPUs %d from %s\n", tmp_cpus, fcpu); pr_warn("Invalid #CPUs %d from %s\n", tmp_cpus, fcpu);
return -EINVAL; return -EINVAL;
} }
......
...@@ -43,7 +43,7 @@ do { \ ...@@ -43,7 +43,7 @@ do { \
libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \ libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \
} while (0) } while (0)
#define pr_warning(fmt, ...) __pr(LIBBPF_WARN, fmt, ##__VA_ARGS__) #define pr_warn(fmt, ...) __pr(LIBBPF_WARN, fmt, ##__VA_ARGS__)
#define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__) #define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__) #define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
...@@ -52,7 +52,7 @@ static inline bool libbpf_validate_opts(const char *opts, ...@@ -52,7 +52,7 @@ static inline bool libbpf_validate_opts(const char *opts,
const char *type_name) const char *type_name)
{ {
if (user_sz < sizeof(size_t)) { if (user_sz < sizeof(size_t)) {
pr_warning("%s size (%zu) is too small\n", type_name, user_sz); pr_warn("%s size (%zu) is too small\n", type_name, user_sz);
return false; return false;
} }
if (user_sz > opts_sz) { if (user_sz > opts_sz) {
...@@ -60,7 +60,7 @@ static inline bool libbpf_validate_opts(const char *opts, ...@@ -60,7 +60,7 @@ static inline bool libbpf_validate_opts(const char *opts,
for (i = opts_sz; i < user_sz; i++) { for (i = opts_sz; i < user_sz; i++) {
if (opts[i]) { if (opts[i]) {
pr_warning("%s has non-zero extra bytes", pr_warn("%s has non-zero extra bytes",
type_name); type_name);
return false; return false;
} }
......
...@@ -311,7 +311,7 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk) ...@@ -311,7 +311,7 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
"LGPL-2.1 or BSD-2-Clause", 0, log_buf, "LGPL-2.1 or BSD-2-Clause", 0, log_buf,
log_buf_size); log_buf_size);
if (prog_fd < 0) { if (prog_fd < 0) {
pr_warning("BPF log buffer:\n%s", log_buf); pr_warn("BPF log buffer:\n%s", log_buf);
return prog_fd; return prog_fd;
} }
...@@ -499,7 +499,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, ...@@ -499,7 +499,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
return -EFAULT; return -EFAULT;
if (umem->refcount) { if (umem->refcount) {
pr_warning("Error: shared umems not supported by libbpf.\n"); pr_warn("Error: shared umems not supported by libbpf.\n");
return -EBUSY; return -EBUSY;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment