diff options
author | David S. Miller <davem@davemloft.net> | 2018-05-24 22:20:51 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-05-24 22:20:51 -0400 |
commit | 90fed9c94625718a3a10db7d1e8e4efe093bbf5f (patch) | |
tree | 09b3bc9ea679316372b139338179a230105306dc /tools/lib/bpf | |
parent | 49a473f5b5f54f33e0bd8618158d33f83153c921 (diff) | |
parent | 10f678683e4026e43524b0492068a371d00fdeed (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Alexei Starovoitov says:
====================
pull-request: bpf-next 2018-05-24
The following pull-request contains BPF updates for your *net-next* tree.
The main changes are:
1) Björn Töpel cleans up AF_XDP (removes rebind, explicit cache alignment from uapi, etc).
2) David Ahern adds mtu checks to bpf_ipv{4,6}_fib_lookup() helpers.
3) Jesper Dangaard Brouer adds bulking support to ndo_xdp_xmit.
4) Jiong Wang adds support for indirect and arithmetic shifts to NFP
5) Martin KaFai Lau cleans up BTF uapi and makes the btf_header extensible.
6) Mathieu Xhonneux adds an End.BPF action to seg6local with BPF helpers allowing
to edit/grow/shrink a SRH and apply on a packet generic SRv6 actions.
7) Sandipan Das adds support for bpf2bpf function calls in ppc64 JIT.
8) Yonghong Song adds BPF_TASK_FD_QUERY command for introspection of tracing events.
9) other misc fixes from Gustavo A. R. Silva, Sirio Balmelli, John Fastabend, and Magnus Karlsson
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r-- | tools/lib/bpf/bpf.c | 27 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.h | 7 | ||||
-rw-r--r-- | tools/lib/bpf/btf.c | 5 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.c | 43 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 4 |
5 files changed, 56 insertions, 30 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 6a8a00097fd8..9ddc89dae962 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -89,8 +89,8 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr) | |||
89 | min(name_len, BPF_OBJ_NAME_LEN - 1)); | 89 | min(name_len, BPF_OBJ_NAME_LEN - 1)); |
90 | attr.numa_node = create_attr->numa_node; | 90 | attr.numa_node = create_attr->numa_node; |
91 | attr.btf_fd = create_attr->btf_fd; | 91 | attr.btf_fd = create_attr->btf_fd; |
92 | attr.btf_key_id = create_attr->btf_key_id; | 92 | attr.btf_key_type_id = create_attr->btf_key_type_id; |
93 | attr.btf_value_id = create_attr->btf_value_id; | 93 | attr.btf_value_type_id = create_attr->btf_value_type_id; |
94 | attr.map_ifindex = create_attr->map_ifindex; | 94 | attr.map_ifindex = create_attr->map_ifindex; |
95 | 95 | ||
96 | return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); | 96 | return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); |
@@ -643,3 +643,26 @@ retry: | |||
643 | 643 | ||
644 | return fd; | 644 | return fd; |
645 | } | 645 | } |
646 | |||
647 | int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, | ||
648 | __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset, | ||
649 | __u64 *probe_addr) | ||
650 | { | ||
651 | union bpf_attr attr = {}; | ||
652 | int err; | ||
653 | |||
654 | attr.task_fd_query.pid = pid; | ||
655 | attr.task_fd_query.fd = fd; | ||
656 | attr.task_fd_query.flags = flags; | ||
657 | attr.task_fd_query.buf = ptr_to_u64(buf); | ||
658 | attr.task_fd_query.buf_len = *buf_len; | ||
659 | |||
660 | err = sys_bpf(BPF_TASK_FD_QUERY, &attr, sizeof(attr)); | ||
661 | *buf_len = attr.task_fd_query.buf_len; | ||
662 | *prog_id = attr.task_fd_query.prog_id; | ||
663 | *fd_type = attr.task_fd_query.fd_type; | ||
664 | *probe_offset = attr.task_fd_query.probe_offset; | ||
665 | *probe_addr = attr.task_fd_query.probe_addr; | ||
666 | |||
667 | return err; | ||
668 | } | ||
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 15bff7728cf1..0639a30a457d 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
@@ -36,8 +36,8 @@ struct bpf_create_map_attr { | |||
36 | __u32 max_entries; | 36 | __u32 max_entries; |
37 | __u32 numa_node; | 37 | __u32 numa_node; |
38 | __u32 btf_fd; | 38 | __u32 btf_fd; |
39 | __u32 btf_key_id; | 39 | __u32 btf_key_type_id; |
40 | __u32 btf_value_id; | 40 | __u32 btf_value_type_id; |
41 | __u32 map_ifindex; | 41 | __u32 map_ifindex; |
42 | }; | 42 | }; |
43 | 43 | ||
@@ -107,4 +107,7 @@ int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags, | |||
107 | int bpf_raw_tracepoint_open(const char *name, int prog_fd); | 107 | int bpf_raw_tracepoint_open(const char *name, int prog_fd); |
108 | int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size, | 108 | int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size, |
109 | bool do_log); | 109 | bool do_log); |
110 | int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, | ||
111 | __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset, | ||
112 | __u64 *probe_addr); | ||
110 | #endif | 113 | #endif |
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 2bac710e3194..8c54a4b6f187 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c | |||
@@ -35,9 +35,8 @@ struct btf { | |||
35 | 35 | ||
36 | static const char *btf_name_by_offset(const struct btf *btf, uint32_t offset) | 36 | static const char *btf_name_by_offset(const struct btf *btf, uint32_t offset) |
37 | { | 37 | { |
38 | if (!BTF_STR_TBL_ELF_ID(offset) && | 38 | if (offset < btf->hdr->str_len) |
39 | BTF_STR_OFFSET(offset) < btf->hdr->str_len) | 39 | return &btf->strings[offset]; |
40 | return &btf->strings[BTF_STR_OFFSET(offset)]; | ||
41 | else | 40 | else |
42 | return NULL; | 41 | return NULL; |
43 | } | 42 | } |
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index cbdf34a6fb93..d20411ebfa2f 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -216,8 +216,8 @@ struct bpf_map { | |||
216 | size_t offset; | 216 | size_t offset; |
217 | int map_ifindex; | 217 | int map_ifindex; |
218 | struct bpf_map_def def; | 218 | struct bpf_map_def def; |
219 | uint32_t btf_key_id; | 219 | uint32_t btf_key_type_id; |
220 | uint32_t btf_value_id; | 220 | uint32_t btf_value_type_id; |
221 | void *priv; | 221 | void *priv; |
222 | bpf_map_clear_priv_t clear_priv; | 222 | bpf_map_clear_priv_t clear_priv; |
223 | }; | 223 | }; |
@@ -1042,8 +1042,8 @@ static int bpf_map_find_btf_info(struct bpf_map *map, const struct btf *btf) | |||
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | if (def->key_size != key_size) { | 1044 | if (def->key_size != key_size) { |
1045 | pr_warning("map:%s key_type:%s has BTF type_size:%ld != key_size:%u\n", | 1045 | pr_warning("map:%s key_type:%s has BTF type_size:%u != key_size:%u\n", |
1046 | map->name, name, key_size, def->key_size); | 1046 | map->name, name, (unsigned int)key_size, def->key_size); |
1047 | return -EINVAL; | 1047 | return -EINVAL; |
1048 | } | 1048 | } |
1049 | 1049 | ||
@@ -1069,13 +1069,13 @@ static int bpf_map_find_btf_info(struct bpf_map *map, const struct btf *btf) | |||
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | if (def->value_size != value_size) { | 1071 | if (def->value_size != value_size) { |
1072 | pr_warning("map:%s value_type:%s has BTF type_size:%ld != value_size:%u\n", | 1072 | pr_warning("map:%s value_type:%s has BTF type_size:%u != value_size:%u\n", |
1073 | map->name, name, value_size, def->value_size); | 1073 | map->name, name, (unsigned int)value_size, def->value_size); |
1074 | return -EINVAL; | 1074 | return -EINVAL; |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | map->btf_key_id = key_id; | 1077 | map->btf_key_type_id = key_id; |
1078 | map->btf_value_id = value_id; | 1078 | map->btf_value_type_id = value_id; |
1079 | 1079 | ||
1080 | return 0; | 1080 | return 0; |
1081 | } | 1081 | } |
@@ -1100,24 +1100,24 @@ bpf_object__create_maps(struct bpf_object *obj) | |||
1100 | create_attr.value_size = def->value_size; | 1100 | create_attr.value_size = def->value_size; |
1101 | create_attr.max_entries = def->max_entries; | 1101 | create_attr.max_entries = def->max_entries; |
1102 | create_attr.btf_fd = 0; | 1102 | create_attr.btf_fd = 0; |
1103 | create_attr.btf_key_id = 0; | 1103 | create_attr.btf_key_type_id = 0; |
1104 | create_attr.btf_value_id = 0; | 1104 | create_attr.btf_value_type_id = 0; |
1105 | 1105 | ||
1106 | if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) { | 1106 | if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) { |
1107 | create_attr.btf_fd = btf__fd(obj->btf); | 1107 | create_attr.btf_fd = btf__fd(obj->btf); |
1108 | create_attr.btf_key_id = map->btf_key_id; | 1108 | create_attr.btf_key_type_id = map->btf_key_type_id; |
1109 | create_attr.btf_value_id = map->btf_value_id; | 1109 | create_attr.btf_value_type_id = map->btf_value_type_id; |
1110 | } | 1110 | } |
1111 | 1111 | ||
1112 | *pfd = bpf_create_map_xattr(&create_attr); | 1112 | *pfd = bpf_create_map_xattr(&create_attr); |
1113 | if (*pfd < 0 && create_attr.btf_key_id) { | 1113 | if (*pfd < 0 && create_attr.btf_key_type_id) { |
1114 | pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n", | 1114 | pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n", |
1115 | map->name, strerror(errno), errno); | 1115 | map->name, strerror(errno), errno); |
1116 | create_attr.btf_fd = 0; | 1116 | create_attr.btf_fd = 0; |
1117 | create_attr.btf_key_id = 0; | 1117 | create_attr.btf_key_type_id = 0; |
1118 | create_attr.btf_value_id = 0; | 1118 | create_attr.btf_value_type_id = 0; |
1119 | map->btf_key_id = 0; | 1119 | map->btf_key_type_id = 0; |
1120 | map->btf_value_id = 0; | 1120 | map->btf_value_type_id = 0; |
1121 | *pfd = bpf_create_map_xattr(&create_attr); | 1121 | *pfd = bpf_create_map_xattr(&create_attr); |
1122 | } | 1122 | } |
1123 | 1123 | ||
@@ -1456,6 +1456,7 @@ static bool bpf_prog_type__needs_kver(enum bpf_prog_type type) | |||
1456 | case BPF_PROG_TYPE_LWT_IN: | 1456 | case BPF_PROG_TYPE_LWT_IN: |
1457 | case BPF_PROG_TYPE_LWT_OUT: | 1457 | case BPF_PROG_TYPE_LWT_OUT: |
1458 | case BPF_PROG_TYPE_LWT_XMIT: | 1458 | case BPF_PROG_TYPE_LWT_XMIT: |
1459 | case BPF_PROG_TYPE_LWT_SEG6LOCAL: | ||
1459 | case BPF_PROG_TYPE_SOCK_OPS: | 1460 | case BPF_PROG_TYPE_SOCK_OPS: |
1460 | case BPF_PROG_TYPE_SK_SKB: | 1461 | case BPF_PROG_TYPE_SK_SKB: |
1461 | case BPF_PROG_TYPE_CGROUP_DEVICE: | 1462 | case BPF_PROG_TYPE_CGROUP_DEVICE: |
@@ -2085,14 +2086,14 @@ const char *bpf_map__name(struct bpf_map *map) | |||
2085 | return map ? map->name : NULL; | 2086 | return map ? map->name : NULL; |
2086 | } | 2087 | } |
2087 | 2088 | ||
2088 | uint32_t bpf_map__btf_key_id(const struct bpf_map *map) | 2089 | uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map) |
2089 | { | 2090 | { |
2090 | return map ? map->btf_key_id : 0; | 2091 | return map ? map->btf_key_type_id : 0; |
2091 | } | 2092 | } |
2092 | 2093 | ||
2093 | uint32_t bpf_map__btf_value_id(const struct bpf_map *map) | 2094 | uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map) |
2094 | { | 2095 | { |
2095 | return map ? map->btf_value_id : 0; | 2096 | return map ? map->btf_value_type_id : 0; |
2096 | } | 2097 | } |
2097 | 2098 | ||
2098 | int bpf_map__set_priv(struct bpf_map *map, void *priv, | 2099 | int bpf_map__set_priv(struct bpf_map *map, void *priv, |
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index cd3fd8d782c7..09976531aa74 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h | |||
@@ -244,8 +244,8 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj); | |||
244 | int bpf_map__fd(struct bpf_map *map); | 244 | int bpf_map__fd(struct bpf_map *map); |
245 | const struct bpf_map_def *bpf_map__def(struct bpf_map *map); | 245 | const struct bpf_map_def *bpf_map__def(struct bpf_map *map); |
246 | const char *bpf_map__name(struct bpf_map *map); | 246 | const char *bpf_map__name(struct bpf_map *map); |
247 | uint32_t bpf_map__btf_key_id(const struct bpf_map *map); | 247 | uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map); |
248 | uint32_t bpf_map__btf_value_id(const struct bpf_map *map); | 248 | uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map); |
249 | 249 | ||
250 | typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); | 250 | typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); |
251 | int bpf_map__set_priv(struct bpf_map *map, void *priv, | 251 | int bpf_map__set_priv(struct bpf_map *map, void *priv, |