aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-08-07 14:02:05 -0400
committerDavid S. Miller <davem@davemloft.net>2018-08-07 14:02:05 -0400
commit1ba982806ce58baac44c52e6c7812245afad27c8 (patch)
treeb0a8061a496c3d01eed36eadf22cea845a2a995b /tools/lib
parentc5d99d2b35dadebab2408bb10dcd50364eaaf9f4 (diff)
parent85fc4b16aaf05fc8978d242c556a1711dce15cf8 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2018-08-07 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add cgroup local storage for BPF programs, which provides a fast accessible memory for storing various per-cgroup data like number of transmitted packets, etc, from Roman. 2) Support bpf_get_socket_cookie() BPF helper in several more program types that have a full socket available, from Andrey. 3) Significantly improve the performance of perf events which are reported from BPF offload. Also convert a couple of BPF AF_XDP samples overto use libbpf, both from Jakub. 4) seg6local LWT provides the End.DT6 action, which allows to decapsulate an outer IPv6 header containing a Segment Routing Header. Adds this action now to the seg6local BPF interface, from Mathieu. 5) Do not mark dst register as unbounded in MOV64 instruction when both src and dst register are the same, from Arthur. 6) Define u_smp_rmb() and u_smp_wmb() to their respective barrier instructions on arm64 for the AF_XDP sample code, from Brian. 7) Convert the tcp_client.py and tcp_server.py BPF selftest scripts over from Python 2 to Python 3, from Jeremy. 8) Enable BTF build flags to the BPF sample code Makefile, from Taeung. 9) Remove an unnecessary rcu_read_lock() in run_lwt_bpf(), from Taehee. 10) Several improvements to the README.rst from the BPF documentation to make it more consistent with RST format, from Tobin. 11) Replace all occurrences of strerror() by calls to strerror_r() in libbpf and fix a FORTIFY_SOURCE build error along with it, from Thomas. 12) Fix a bug in bpftool's get_btf() function to correctly propagate an error via PTR_ERR(), from Yue. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/libbpf.c57
-rw-r--r--tools/lib/bpf/libbpf.h3
2 files changed, 47 insertions, 13 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 26e9527ee464..40211b51427a 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -468,8 +468,10 @@ static int bpf_object__elf_init(struct bpf_object *obj)
468 } else { 468 } else {
469 obj->efile.fd = open(obj->path, O_RDONLY); 469 obj->efile.fd = open(obj->path, O_RDONLY);
470 if (obj->efile.fd < 0) { 470 if (obj->efile.fd < 0) {
471 pr_warning("failed to open %s: %s\n", obj->path, 471 char errmsg[STRERR_BUFSIZE];
472 strerror(errno)); 472 char *cp = strerror_r(errno, errmsg, sizeof(errmsg));
473
474 pr_warning("failed to open %s: %s\n", obj->path, cp);
473 return -errno; 475 return -errno;
474 } 476 }
475 477
@@ -808,10 +810,11 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
808 data->d_size, name, idx); 810 data->d_size, name, idx);
809 if (err) { 811 if (err) {
810 char errmsg[STRERR_BUFSIZE]; 812 char errmsg[STRERR_BUFSIZE];
813 char *cp = strerror_r(-err, errmsg,
814 sizeof(errmsg));
811 815
812 strerror_r(-err, errmsg, sizeof(errmsg));
813 pr_warning("failed to alloc program %s (%s): %s", 816 pr_warning("failed to alloc program %s (%s): %s",
814 name, obj->path, errmsg); 817 name, obj->path, cp);
815 } 818 }
816 } else if (sh.sh_type == SHT_REL) { 819 } else if (sh.sh_type == SHT_REL) {
817 void *reloc = obj->efile.reloc; 820 void *reloc = obj->efile.reloc;
@@ -874,6 +877,18 @@ bpf_object__find_prog_by_idx(struct bpf_object *obj, int idx)
874 return NULL; 877 return NULL;
875} 878}
876 879
880struct bpf_program *
881bpf_object__find_program_by_title(struct bpf_object *obj, const char *title)
882{
883 struct bpf_program *pos;
884
885 bpf_object__for_each_program(pos, obj) {
886 if (pos->section_name && !strcmp(pos->section_name, title))
887 return pos;
888 }
889 return NULL;
890}
891
877static int 892static int
878bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, 893bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
879 Elf_Data *data, struct bpf_object *obj) 894 Elf_Data *data, struct bpf_object *obj)
@@ -1097,6 +1112,7 @@ bpf_object__create_maps(struct bpf_object *obj)
1097 for (i = 0; i < obj->nr_maps; i++) { 1112 for (i = 0; i < obj->nr_maps; i++) {
1098 struct bpf_map *map = &obj->maps[i]; 1113 struct bpf_map *map = &obj->maps[i];
1099 struct bpf_map_def *def = &map->def; 1114 struct bpf_map_def *def = &map->def;
1115 char *cp, errmsg[STRERR_BUFSIZE];
1100 int *pfd = &map->fd; 1116 int *pfd = &map->fd;
1101 1117
1102 if (map->fd >= 0) { 1118 if (map->fd >= 0) {
@@ -1124,8 +1140,9 @@ bpf_object__create_maps(struct bpf_object *obj)
1124 1140
1125 *pfd = bpf_create_map_xattr(&create_attr); 1141 *pfd = bpf_create_map_xattr(&create_attr);
1126 if (*pfd < 0 && create_attr.btf_key_type_id) { 1142 if (*pfd < 0 && create_attr.btf_key_type_id) {
1143 cp = strerror_r(errno, errmsg, sizeof(errmsg));
1127 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n", 1144 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
1128 map->name, strerror(errno), errno); 1145 map->name, cp, errno);
1129 create_attr.btf_fd = 0; 1146 create_attr.btf_fd = 0;
1130 create_attr.btf_key_type_id = 0; 1147 create_attr.btf_key_type_id = 0;
1131 create_attr.btf_value_type_id = 0; 1148 create_attr.btf_value_type_id = 0;
@@ -1138,9 +1155,9 @@ bpf_object__create_maps(struct bpf_object *obj)
1138 size_t j; 1155 size_t j;
1139 1156
1140 err = *pfd; 1157 err = *pfd;
1158 cp = strerror_r(errno, errmsg, sizeof(errmsg));
1141 pr_warning("failed to create map (name: '%s'): %s\n", 1159 pr_warning("failed to create map (name: '%s'): %s\n",
1142 map->name, 1160 map->name, cp);
1143 strerror(errno));
1144 for (j = 0; j < i; j++) 1161 for (j = 0; j < i; j++)
1145 zclose(obj->maps[j].fd); 1162 zclose(obj->maps[j].fd);
1146 return err; 1163 return err;
@@ -1292,6 +1309,7 @@ load_program(enum bpf_prog_type type, enum bpf_attach_type expected_attach_type,
1292 char *license, u32 kern_version, int *pfd, int prog_ifindex) 1309 char *license, u32 kern_version, int *pfd, int prog_ifindex)
1293{ 1310{
1294 struct bpf_load_program_attr load_attr; 1311 struct bpf_load_program_attr load_attr;
1312 char *cp, errmsg[STRERR_BUFSIZE];
1295 char *log_buf; 1313 char *log_buf;
1296 int ret; 1314 int ret;
1297 1315
@@ -1321,7 +1339,8 @@ load_program(enum bpf_prog_type type, enum bpf_attach_type expected_attach_type,
1321 } 1339 }
1322 1340
1323 ret = -LIBBPF_ERRNO__LOAD; 1341 ret = -LIBBPF_ERRNO__LOAD;
1324 pr_warning("load bpf program failed: %s\n", strerror(errno)); 1342 cp = strerror_r(errno, errmsg, sizeof(errmsg));
1343 pr_warning("load bpf program failed: %s\n", cp);
1325 1344
1326 if (log_buf && log_buf[0] != '\0') { 1345 if (log_buf && log_buf[0] != '\0') {
1327 ret = -LIBBPF_ERRNO__VERIFY; 1346 ret = -LIBBPF_ERRNO__VERIFY;
@@ -1620,6 +1639,7 @@ out:
1620 1639
1621static int check_path(const char *path) 1640static int check_path(const char *path)
1622{ 1641{
1642 char *cp, errmsg[STRERR_BUFSIZE];
1623 struct statfs st_fs; 1643 struct statfs st_fs;
1624 char *dname, *dir; 1644 char *dname, *dir;
1625 int err = 0; 1645 int err = 0;
@@ -1633,7 +1653,8 @@ static int check_path(const char *path)
1633 1653
1634 dir = dirname(dname); 1654 dir = dirname(dname);
1635 if (statfs(dir, &st_fs)) { 1655 if (statfs(dir, &st_fs)) {
1636 pr_warning("failed to statfs %s: %s\n", dir, strerror(errno)); 1656 cp = strerror_r(errno, errmsg, sizeof(errmsg));
1657 pr_warning("failed to statfs %s: %s\n", dir, cp);
1637 err = -errno; 1658 err = -errno;
1638 } 1659 }
1639 free(dname); 1660 free(dname);
@@ -1649,6 +1670,7 @@ static int check_path(const char *path)
1649int bpf_program__pin_instance(struct bpf_program *prog, const char *path, 1670int bpf_program__pin_instance(struct bpf_program *prog, const char *path,
1650 int instance) 1671 int instance)
1651{ 1672{
1673 char *cp, errmsg[STRERR_BUFSIZE];
1652 int err; 1674 int err;
1653 1675
1654 err = check_path(path); 1676 err = check_path(path);
@@ -1667,7 +1689,8 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path,
1667 } 1689 }
1668 1690
1669 if (bpf_obj_pin(prog->instances.fds[instance], path)) { 1691 if (bpf_obj_pin(prog->instances.fds[instance], path)) {
1670 pr_warning("failed to pin program: %s\n", strerror(errno)); 1692 cp = strerror_r(errno, errmsg, sizeof(errmsg));
1693 pr_warning("failed to pin program: %s\n", cp);
1671 return -errno; 1694 return -errno;
1672 } 1695 }
1673 pr_debug("pinned program '%s'\n", path); 1696 pr_debug("pinned program '%s'\n", path);
@@ -1677,13 +1700,16 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path,
1677 1700
1678static int make_dir(const char *path) 1701static int make_dir(const char *path)
1679{ 1702{
1703 char *cp, errmsg[STRERR_BUFSIZE];
1680 int err = 0; 1704 int err = 0;
1681 1705
1682 if (mkdir(path, 0700) && errno != EEXIST) 1706 if (mkdir(path, 0700) && errno != EEXIST)
1683 err = -errno; 1707 err = -errno;
1684 1708
1685 if (err) 1709 if (err) {
1686 pr_warning("failed to mkdir %s: %s\n", path, strerror(-err)); 1710 cp = strerror_r(-err, errmsg, sizeof(errmsg));
1711 pr_warning("failed to mkdir %s: %s\n", path, cp);
1712 }
1687 return err; 1713 return err;
1688} 1714}
1689 1715
@@ -1730,6 +1756,7 @@ int bpf_program__pin(struct bpf_program *prog, const char *path)
1730 1756
1731int bpf_map__pin(struct bpf_map *map, const char *path) 1757int bpf_map__pin(struct bpf_map *map, const char *path)
1732{ 1758{
1759 char *cp, errmsg[STRERR_BUFSIZE];
1733 int err; 1760 int err;
1734 1761
1735 err = check_path(path); 1762 err = check_path(path);
@@ -1742,7 +1769,8 @@ int bpf_map__pin(struct bpf_map *map, const char *path)
1742 } 1769 }
1743 1770
1744 if (bpf_obj_pin(map->fd, path)) { 1771 if (bpf_obj_pin(map->fd, path)) {
1745 pr_warning("failed to pin map: %s\n", strerror(errno)); 1772 cp = strerror_r(errno, errmsg, sizeof(errmsg));
1773 pr_warning("failed to pin map: %s\n", cp);
1746 return -errno; 1774 return -errno;
1747 } 1775 }
1748 1776
@@ -1996,6 +2024,9 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)
1996{ 2024{
1997 int fd; 2025 int fd;
1998 2026
2027 if (!prog)
2028 return -EINVAL;
2029
1999 if (n >= prog->instances.nr || n < 0) { 2030 if (n >= prog->instances.nr || n < 0) {
2000 pr_warning("Can't get the %dth fd from program %s: only %d instances\n", 2031 pr_warning("Can't get the %dth fd from program %s: only %d instances\n",
2001 n, prog->section_name, prog->instances.nr); 2032 n, prog->section_name, prog->instances.nr);
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 413778a93499..96c55fac54c3 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -86,6 +86,9 @@ const char *bpf_object__name(struct bpf_object *obj);
86unsigned int bpf_object__kversion(struct bpf_object *obj); 86unsigned int bpf_object__kversion(struct bpf_object *obj);
87int bpf_object__btf_fd(const struct bpf_object *obj); 87int bpf_object__btf_fd(const struct bpf_object *obj);
88 88
89struct bpf_program *
90bpf_object__find_program_by_title(struct bpf_object *obj, const char *title);
91
89struct bpf_object *bpf_object__next(struct bpf_object *prev); 92struct bpf_object *bpf_object__next(struct bpf_object *prev);
90#define bpf_object__for_each_safe(pos, tmp) \ 93#define bpf_object__for_each_safe(pos, tmp) \
91 for ((pos) = bpf_object__next(NULL), \ 94 for ((pos) = bpf_object__next(NULL), \