* [PATCH bpf-next 0/3] Auto-generate list of BPF helpers
@ 2019-10-05 7:59 Andrii Nakryiko
2019-10-05 7:59 ` [PATCH bpf-next 1/3] uapi/bpf: fix helper docs Andrii Nakryiko
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-10-05 7:59 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
This patch set adds ability to auto-generate list of BPF helper definitions.
It relies on existing scripts/bpf_helpers_doc.py and include/uapi/linux/bpf.h
having a well-defined set of comments. All this is integrated with libbpf's
Makefile to ensure that bpf_helpers_defs.h stays in sync with latest kernel
UAPI. By checking bpf_helpers_defs.h, we also make sure that Github projection
doesn't rely on latest kernel headers for successful build.
Andrii Nakryiko (3):
uapi/bpf: fix helper docs
scripts/bpf: teach bpf_helpers_doc.py to dump BPF helper definitions
libbpf: auto-generate list of BPF helper definitions
include/uapi/linux/bpf.h | 32 +-
scripts/bpf_helpers_doc.py | 156 +-
tools/include/uapi/linux/bpf.h | 32 +-
tools/lib/bpf/Makefile | 8 +-
tools/lib/bpf/bpf_helpers.h | 264 +--
tools/lib/bpf/bpf_helpers_defs.h | 2677 ++++++++++++++++++++++++++++++
6 files changed, 2872 insertions(+), 297 deletions(-)
create mode 100644 tools/lib/bpf/bpf_helpers_defs.h
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf-next 1/3] uapi/bpf: fix helper docs
2019-10-05 7:59 [PATCH bpf-next 0/3] Auto-generate list of BPF helpers Andrii Nakryiko
@ 2019-10-05 7:59 ` Andrii Nakryiko
2019-10-05 7:59 ` [PATCH bpf-next 2/3] scripts/bpf: teach bpf_helpers_doc.py to dump BPF helper definitions Andrii Nakryiko
[not found] ` <20191005075921.3310139-4-andriin@fb.com>
2 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-10-05 7:59 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
Various small fixes to BPF helper documentation comments, enabling
automatic header generation with a list of BPF helpers.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
include/uapi/linux/bpf.h | 32 ++++++++++++++++----------------
tools/include/uapi/linux/bpf.h | 32 ++++++++++++++++----------------
2 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 77c6be96d676..a65c3b0c6935 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -794,7 +794,7 @@ union bpf_attr {
* A 64-bit integer containing the current GID and UID, and
* created as such: *current_gid* **<< 32 \|** *current_uid*.
*
- * int bpf_get_current_comm(char *buf, u32 size_of_buf)
+ * int bpf_get_current_comm(void *buf, u32 size_of_buf)
* Description
* Copy the **comm** attribute of the current task into *buf* of
* *size_of_buf*. The **comm** attribute contains the name of
@@ -1023,7 +1023,7 @@ union bpf_attr {
* The realm of the route for the packet associated to *skb*, or 0
* if none was found.
*
- * int bpf_perf_event_output(struct pt_regs *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
+ * int bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
* Description
* Write raw *data* blob into a special BPF perf event held by
* *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
@@ -1068,7 +1068,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset, void *to, u32 len)
+ * int bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)
* Description
* This helper was provided as an easy way to load data from a
* packet. It can be used to load *len* bytes from *offset* from
@@ -1085,7 +1085,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_get_stackid(struct pt_regs *ctx, struct bpf_map *map, u64 flags)
+ * int bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)
* Description
* Walk a user or a kernel stack and return its id. To achieve
* this, the helper needs *ctx*, which is a pointer to the context
@@ -1154,7 +1154,7 @@ union bpf_attr {
* The checksum result, or a negative error code in case of
* failure.
*
- * int bpf_skb_get_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
+ * int bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
* Description
* Retrieve tunnel options metadata for the packet associated to
* *skb*, and store the raw tunnel option data to the buffer *opt*
@@ -1172,7 +1172,7 @@ union bpf_attr {
* Return
* The size of the option data retrieved.
*
- * int bpf_skb_set_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
+ * int bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
* Description
* Set tunnel options metadata for the packet associated to *skb*
* to the option data contained in the raw buffer *opt* of *size*.
@@ -1511,7 +1511,7 @@ union bpf_attr {
* Return
* 0
*
- * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
+ * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, void *optval, int optlen)
* Description
* Emulate a call to **setsockopt()** on the socket associated to
* *bpf_socket*, which must be a full socket. The *level* at
@@ -1595,7 +1595,7 @@ union bpf_attr {
* Return
* **XDP_REDIRECT** on success, or **XDP_ABORTED** on error.
*
- * int bpf_sk_redirect_map(struct bpf_map *map, u32 key, u64 flags)
+ * int bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
* Description
* Redirect the packet to the socket referenced by *map* (of type
* **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
@@ -1715,7 +1715,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
+ * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, void *optval, int optlen)
* Description
* Emulate a call to **getsockopt()** on the socket associated to
* *bpf_socket*, which must be a full socket. The *level* at
@@ -1947,7 +1947,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_get_stack(struct pt_regs *regs, void *buf, u32 size, u64 flags)
+ * int bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)
* Description
* Return a user or a kernel stack in bpf program provided buffer.
* To achieve this, the helper needs *ctx*, which is a pointer
@@ -1980,7 +1980,7 @@ union bpf_attr {
* A non-negative value equal to or less than *size* on success,
* or a negative error in case of failure.
*
- * int bpf_skb_load_bytes_relative(const struct sk_buff *skb, u32 offset, void *to, u32 len, u32 start_header)
+ * int bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
* Description
* This helper is similar to **bpf_skb_load_bytes**\ () in that
* it provides an easy way to load *len* bytes from *offset*
@@ -2033,7 +2033,7 @@ union bpf_attr {
* * > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
* packet is not forwarded or needs assist from full stack
*
- * int bpf_sock_hash_update(struct bpf_sock_ops_kern *skops, struct bpf_map *map, void *key, u64 flags)
+ * int bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
* Description
* Add an entry to, or update a sockhash *map* referencing sockets.
* The *skops* is used as a new value for the entry associated to
@@ -2392,7 +2392,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_msg_push_data(struct sk_buff *skb, u32 start, u32 len, u64 flags)
+ * int bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
* Description
* For socket policies, insert *len* bytes into *msg* at offset
* *start*.
@@ -2408,9 +2408,9 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 pop, u64 flags)
+ * int bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
* Description
- * Will remove *pop* bytes from a *msg* starting at byte *start*.
+ * Will remove *len* bytes from a *msg* starting at byte *start*.
* This may result in **ENOMEM** errors under certain situations if
* an allocation and copy are required due to a full ring buffer.
* However, the helper will try to avoid doing the allocation
@@ -2505,7 +2505,7 @@ union bpf_attr {
* A **struct bpf_tcp_sock** pointer on success, or **NULL** in
* case of failure.
*
- * int bpf_skb_ecn_set_ce(struct sk_buf *skb)
+ * int bpf_skb_ecn_set_ce(struct sk_buff *skb)
* Description
* Set ECN (Explicit Congestion Notification) field of IP header
* to **CE** (Congestion Encountered) if current value is **ECT**
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 77c6be96d676..a65c3b0c6935 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -794,7 +794,7 @@ union bpf_attr {
* A 64-bit integer containing the current GID and UID, and
* created as such: *current_gid* **<< 32 \|** *current_uid*.
*
- * int bpf_get_current_comm(char *buf, u32 size_of_buf)
+ * int bpf_get_current_comm(void *buf, u32 size_of_buf)
* Description
* Copy the **comm** attribute of the current task into *buf* of
* *size_of_buf*. The **comm** attribute contains the name of
@@ -1023,7 +1023,7 @@ union bpf_attr {
* The realm of the route for the packet associated to *skb*, or 0
* if none was found.
*
- * int bpf_perf_event_output(struct pt_regs *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
+ * int bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
* Description
* Write raw *data* blob into a special BPF perf event held by
* *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
@@ -1068,7 +1068,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset, void *to, u32 len)
+ * int bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)
* Description
* This helper was provided as an easy way to load data from a
* packet. It can be used to load *len* bytes from *offset* from
@@ -1085,7 +1085,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_get_stackid(struct pt_regs *ctx, struct bpf_map *map, u64 flags)
+ * int bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)
* Description
* Walk a user or a kernel stack and return its id. To achieve
* this, the helper needs *ctx*, which is a pointer to the context
@@ -1154,7 +1154,7 @@ union bpf_attr {
* The checksum result, or a negative error code in case of
* failure.
*
- * int bpf_skb_get_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
+ * int bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
* Description
* Retrieve tunnel options metadata for the packet associated to
* *skb*, and store the raw tunnel option data to the buffer *opt*
@@ -1172,7 +1172,7 @@ union bpf_attr {
* Return
* The size of the option data retrieved.
*
- * int bpf_skb_set_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
+ * int bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
* Description
* Set tunnel options metadata for the packet associated to *skb*
* to the option data contained in the raw buffer *opt* of *size*.
@@ -1511,7 +1511,7 @@ union bpf_attr {
* Return
* 0
*
- * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
+ * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, void *optval, int optlen)
* Description
* Emulate a call to **setsockopt()** on the socket associated to
* *bpf_socket*, which must be a full socket. The *level* at
@@ -1595,7 +1595,7 @@ union bpf_attr {
* Return
* **XDP_REDIRECT** on success, or **XDP_ABORTED** on error.
*
- * int bpf_sk_redirect_map(struct bpf_map *map, u32 key, u64 flags)
+ * int bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
* Description
* Redirect the packet to the socket referenced by *map* (of type
* **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
@@ -1715,7 +1715,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
+ * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, void *optval, int optlen)
* Description
* Emulate a call to **getsockopt()** on the socket associated to
* *bpf_socket*, which must be a full socket. The *level* at
@@ -1947,7 +1947,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_get_stack(struct pt_regs *regs, void *buf, u32 size, u64 flags)
+ * int bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)
* Description
* Return a user or a kernel stack in bpf program provided buffer.
* To achieve this, the helper needs *ctx*, which is a pointer
@@ -1980,7 +1980,7 @@ union bpf_attr {
* A non-negative value equal to or less than *size* on success,
* or a negative error in case of failure.
*
- * int bpf_skb_load_bytes_relative(const struct sk_buff *skb, u32 offset, void *to, u32 len, u32 start_header)
+ * int bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
* Description
* This helper is similar to **bpf_skb_load_bytes**\ () in that
* it provides an easy way to load *len* bytes from *offset*
@@ -2033,7 +2033,7 @@ union bpf_attr {
* * > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
* packet is not forwarded or needs assist from full stack
*
- * int bpf_sock_hash_update(struct bpf_sock_ops_kern *skops, struct bpf_map *map, void *key, u64 flags)
+ * int bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
* Description
* Add an entry to, or update a sockhash *map* referencing sockets.
* The *skops* is used as a new value for the entry associated to
@@ -2392,7 +2392,7 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_msg_push_data(struct sk_buff *skb, u32 start, u32 len, u64 flags)
+ * int bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
* Description
* For socket policies, insert *len* bytes into *msg* at offset
* *start*.
@@ -2408,9 +2408,9 @@ union bpf_attr {
* Return
* 0 on success, or a negative error in case of failure.
*
- * int bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 pop, u64 flags)
+ * int bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
* Description
- * Will remove *pop* bytes from a *msg* starting at byte *start*.
+ * Will remove *len* bytes from a *msg* starting at byte *start*.
* This may result in **ENOMEM** errors under certain situations if
* an allocation and copy are required due to a full ring buffer.
* However, the helper will try to avoid doing the allocation
@@ -2505,7 +2505,7 @@ union bpf_attr {
* A **struct bpf_tcp_sock** pointer on success, or **NULL** in
* case of failure.
*
- * int bpf_skb_ecn_set_ce(struct sk_buf *skb)
+ * int bpf_skb_ecn_set_ce(struct sk_buff *skb)
* Description
* Set ECN (Explicit Congestion Notification) field of IP header
* to **CE** (Congestion Encountered) if current value is **ECT**
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf-next 2/3] scripts/bpf: teach bpf_helpers_doc.py to dump BPF helper definitions
2019-10-05 7:59 [PATCH bpf-next 0/3] Auto-generate list of BPF helpers Andrii Nakryiko
2019-10-05 7:59 ` [PATCH bpf-next 1/3] uapi/bpf: fix helper docs Andrii Nakryiko
@ 2019-10-05 7:59 ` Andrii Nakryiko
[not found] ` <20191005075921.3310139-4-andriin@fb.com>
2 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-10-05 7:59 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
Enhance scripts/bpf_helpers_doc.py to emit C header with BPF helper
definitions (to be included from libbpf's bpf_helpers.h).
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
scripts/bpf_helpers_doc.py | 156 ++++++++++++++++++++++++++++++++++++-
1 file changed, 155 insertions(+), 1 deletion(-)
diff --git a/scripts/bpf_helpers_doc.py b/scripts/bpf_helpers_doc.py
index 894cc58c1a03..410a994e2b36 100755
--- a/scripts/bpf_helpers_doc.py
+++ b/scripts/bpf_helpers_doc.py
@@ -391,6 +391,155 @@ SEE ALSO
print('')
+class PrinterHelpers(Printer):
+ """
+ A printer for dumping collected information about helpers as C header to
+ be included from BPF program.
+ @helpers: array of Helper objects to print to standard output
+ """
+
+ type_fwds = [
+ 'struct bpf_fib_lookup',
+ 'struct bpf_perf_event_data',
+ 'struct bpf_perf_event_value',
+ 'struct bpf_sock',
+ 'struct bpf_sock_addr',
+ 'struct bpf_sock_ops',
+ 'struct bpf_sock_tuple',
+ 'struct bpf_spin_lock',
+ 'struct bpf_sysctl',
+ 'struct bpf_tcp_sock',
+ 'struct bpf_tunnel_key',
+ 'struct bpf_xfrm_state',
+ 'struct pt_regs',
+ 'struct sk_reuseport_md',
+ 'struct sockaddr',
+ 'struct tcphdr',
+
+ 'struct __sk_buff',
+ 'struct sk_msg_md',
+ 'struct xpd_md',
+ ]
+ known_types = {
+ '...',
+ 'void',
+ 'const void',
+ 'char',
+ 'const char',
+ 'int',
+ 'long',
+ 'unsigned long',
+
+ '__be16',
+ '__be32',
+ '__wsum',
+
+ 'struct bpf_fib_lookup',
+ 'struct bpf_perf_event_data',
+ 'struct bpf_perf_event_value',
+ 'struct bpf_sock',
+ 'struct bpf_sock_addr',
+ 'struct bpf_sock_ops',
+ 'struct bpf_sock_tuple',
+ 'struct bpf_spin_lock',
+ 'struct bpf_sysctl',
+ 'struct bpf_tcp_sock',
+ 'struct bpf_tunnel_key',
+ 'struct bpf_xfrm_state',
+ 'struct pt_regs',
+ 'struct sk_reuseport_md',
+ 'struct sockaddr',
+ 'struct tcphdr',
+ }
+ mapped_types = {
+ 'u8': '__u8',
+ 'u16': '__u16',
+ 'u32': '__u32',
+ 'u64': '__u64',
+ 's8': '__s8',
+ 's16': '__s16',
+ 's32': '__s32',
+ 's64': '__s64',
+ 'size_t': 'unsigned long',
+ 'struct bpf_map': 'void',
+ 'struct sk_buff': 'struct __sk_buff',
+ 'const struct sk_buff': 'const struct __sk_buff',
+ 'struct sk_msg_buff': 'struct sk_msg_md',
+ 'struct xdp_buff': 'struct xdp_md',
+ }
+
+ def print_header(self):
+ header = '''\
+/* This is auto-generated file. See bpf_helpers_doc.py for details. */
+
+/* Forward declarations of BPF structs */ '''
+
+ print(header)
+ for fwd in self.type_fwds:
+ print('%s;' % fwd)
+ print('')
+
+ def print_footer(self):
+ footer = ''
+ print(footer)
+
+ def map_type(self, t):
+ if t in self.known_types:
+ return t
+ if t in self.mapped_types:
+ return self.mapped_types[t]
+ print("")
+ print("Unrecognized type '%s', please add it to known types!" % t)
+ sys.exit(1)
+
+ seen_helpers = set()
+
+ def print_one(self, helper):
+ proto = helper.proto_break_down()
+
+ if proto['name'] in self.seen_helpers:
+ return
+ self.seen_helpers.add(proto['name'])
+
+ print('/*')
+ print(" * %s" % proto['name'])
+ print(" *")
+ if (helper.desc):
+ # print(' * Description')
+ # Do not strip all newline characters: formatted code at the end of
+ # a section must be followed by a blank line.
+ for line in re.sub('\n$', '', helper.desc, count=1).split('\n'):
+ print(' *{}{}'.format(' \t' if line else '', line))
+
+ if (helper.ret):
+ print(' *')
+ print(' * Returns')
+ for line in helper.ret.rstrip().split('\n'):
+ print(' *{}{}'.format(' \t' if line else '', line))
+
+ print(' */')
+ print('static %s %s(*%s)(' % (self.map_type(proto['ret_type']),
+ proto['ret_star'], proto['name']), end='')
+ comma = ''
+ for i, a in enumerate(proto['args']):
+ t = a['type']
+ n = a['name']
+ if proto['name'] == 'bpf_get_socket_cookie' and i == 0:
+ t = 'void'
+ n = 'ctx'
+ one_arg = '{}{}'.format(comma, self.map_type(t))
+ if n:
+ if a['star']:
+ one_arg += ' {}'.format(a['star'])
+ else:
+ one_arg += ' '
+ one_arg += '{}'.format(n)
+ comma = ', '
+ print(one_arg, end='')
+
+ print(') = (void *) %d;' % len(self.seen_helpers))
+ print('')
+
###############################################################################
# If script is launched from scripts/ from kernel tree and can access
@@ -405,6 +554,8 @@ Parse eBPF header file and generate documentation for eBPF helper functions.
The RST-formatted output produced can be turned into a manual page with the
rst2man utility.
""")
+argParser.add_argument('--header', action='store_true',
+ help='generate C header file')
if (os.path.isfile(bpfh)):
argParser.add_argument('--filename', help='path to include/uapi/linux/bpf.h',
default=bpfh)
@@ -417,5 +568,8 @@ headerParser = HeaderParser(args.filename)
headerParser.run()
# Print formatted output to standard output.
-printer = PrinterRST(headerParser.helpers)
+if args.header:
+ printer = PrinterHelpers(headerParser.helpers)
+else:
+ printer = PrinterRST(headerParser.helpers)
printer.print_all()
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 3/3] libbpf: auto-generate list of BPF helper definitions
[not found] ` <20191005075921.3310139-4-andriin@fb.com>
@ 2019-10-05 17:10 ` Alexei Starovoitov
2019-10-05 18:24 ` Andrii Nakryiko
0 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2019-10-05 17:10 UTC (permalink / raw)
To: Andrii Nakryiko, bpf, netdev, daniel; +Cc: andrii.nakryiko, Kernel Team
On 10/5/19 12:59 AM, Andrii Nakryiko wrote:
> Get rid of list of BPF helpers in bpf_helpers.h (irony...) and
> auto-generate it into bpf_helpers_defs.h, which is now included from
> bpf_helpers.h.
>
> Suggested-by: Alexei Starovoitov<ast@fb.com>
> Signed-off-by: Andrii Nakryiko<andriin@fb.com>
> ---
> tools/lib/bpf/Makefile | 8 +-
> tools/lib/bpf/bpf_helpers.h | 264 +--
> tools/lib/bpf/bpf_helpers_defs.h | 2677 ++++++++++++++++++++++++++++++
> 3 files changed, 2685 insertions(+), 264 deletions(-)
> create mode 100644 tools/lib/bpf/bpf_helpers_defs.h
Approach looks good to me.
imo that's better than messing with macros.
Using bpf_helpers_doc.py as part of build will help man pages too.
I think we were sloppy documenting helpers, since only Quentin
was running that script regularly.
Only question is what is the reason to commit generated .h into git?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 3/3] libbpf: auto-generate list of BPF helper definitions
2019-10-05 17:10 ` [PATCH bpf-next 3/3] libbpf: auto-generate list of " Alexei Starovoitov
@ 2019-10-05 18:24 ` Andrii Nakryiko
2019-10-06 1:01 ` Alexei Starovoitov
0 siblings, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2019-10-05 18:24 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Andrii Nakryiko, bpf, netdev, daniel, Kernel Team, Quentin Monnet
On Sat, Oct 5, 2019 at 10:10 AM Alexei Starovoitov <ast@fb.com> wrote:
>
> On 10/5/19 12:59 AM, Andrii Nakryiko wrote:
> > Get rid of list of BPF helpers in bpf_helpers.h (irony...) and
> > auto-generate it into bpf_helpers_defs.h, which is now included from
> > bpf_helpers.h.
> >
> > Suggested-by: Alexei Starovoitov<ast@fb.com>
> > Signed-off-by: Andrii Nakryiko<andriin@fb.com>
> > ---
> > tools/lib/bpf/Makefile | 8 +-
> > tools/lib/bpf/bpf_helpers.h | 264 +--
> > tools/lib/bpf/bpf_helpers_defs.h | 2677 ++++++++++++++++++++++++++++++
> > 3 files changed, 2685 insertions(+), 264 deletions(-)
> > create mode 100644 tools/lib/bpf/bpf_helpers_defs.h
>
> Approach looks good to me.
> imo that's better than messing with macros.
>
> Using bpf_helpers_doc.py as part of build will help man pages too.
> I think we were sloppy documenting helpers, since only Quentin
> was running that script regularly.
Yep, I agree, I had to fix few things, as well as (char *) vs (void *)
vs (__u8 *) differences were causing some extra warnings.
Please check the list of type translations whether they make sense.
>
> Only question is what is the reason to commit generated .h into git?
So originally I didn't want to depend on system UAPI headers during
Github build. But now I recalled that we do have latest UAPI synced
into Github's include/ subdir, so that's not an obstacle really. We'll
just need to re-license bpf_helpers_doc.py (I don't think Quentin will
mind) and start syncing it to Github (not a big deal at all).
There is still a benefit in having it checked in: easy to spot if
script does something wrong and double-check the changes (after
initial big commit, of course).
If you think that's not reason enough, let me know and I can drop it in v2.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 3/3] libbpf: auto-generate list of BPF helper definitions
2019-10-05 18:24 ` Andrii Nakryiko
@ 2019-10-06 1:01 ` Alexei Starovoitov
2019-10-06 2:29 ` Andrii Nakryiko
0 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2019-10-06 1:01 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: Andrii Nakryiko, bpf, netdev, daniel, Kernel Team, Quentin Monnet
On 10/5/19 11:24 AM, Andrii Nakryiko wrote:
> On Sat, Oct 5, 2019 at 10:10 AM Alexei Starovoitov <ast@fb.com> wrote:
>>
>> On 10/5/19 12:59 AM, Andrii Nakryiko wrote:
>>> Get rid of list of BPF helpers in bpf_helpers.h (irony...) and
>>> auto-generate it into bpf_helpers_defs.h, which is now included from
>>> bpf_helpers.h.
>>>
>>> Suggested-by: Alexei Starovoitov<ast@fb.com>
>>> Signed-off-by: Andrii Nakryiko<andriin@fb.com>
>>> ---
>>> tools/lib/bpf/Makefile | 8 +-
>>> tools/lib/bpf/bpf_helpers.h | 264 +--
>>> tools/lib/bpf/bpf_helpers_defs.h | 2677 ++++++++++++++++++++++++++++++
>>> 3 files changed, 2685 insertions(+), 264 deletions(-)
>>> create mode 100644 tools/lib/bpf/bpf_helpers_defs.h
>>
>> Approach looks good to me.
>> imo that's better than messing with macros.
>>
>> Using bpf_helpers_doc.py as part of build will help man pages too.
>> I think we were sloppy documenting helpers, since only Quentin
>> was running that script regularly.
>
> Yep, I agree, I had to fix few things, as well as (char *) vs (void *)
> vs (__u8 *) differences were causing some extra warnings.
> Please check the list of type translations whether they make sense.
yes. These conversions make sense.
Only one sk_buff->__sk_buff won't work for too long.
Once my btf vmlinux stuff lands both structs will be possible.
>>
>> Only question is what is the reason to commit generated .h into git?
>
> So originally I didn't want to depend on system UAPI headers during
> Github build. But now I recalled that we do have latest UAPI synced
> into Github's include/ subdir, so that's not an obstacle really. We'll
> just need to re-license bpf_helpers_doc.py (I don't think Quentin will
> mind) and start syncing it to Github (not a big deal at all).
github sync script can run make, grab generated .h,
and check it in into github.
>
> There is still a benefit in having it checked in: easy to spot if
> script does something wrong and double-check the changes (after
> initial big commit, of course).
>
> If you think that's not reason enough, let me know and I can drop it in v2.
I don't remember too many cases when generated files were committed.
My preference to keep it out of kernel git.
github/libbpf is a pure mirror. That .h can be committed there.
The whole thing is automatic, so we don't need to move .py
into github too.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 3/3] libbpf: auto-generate list of BPF helper definitions
2019-10-06 1:01 ` Alexei Starovoitov
@ 2019-10-06 2:29 ` Andrii Nakryiko
0 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-10-06 2:29 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Andrii Nakryiko, bpf, netdev, daniel, Kernel Team, Quentin Monnet
On Sat, Oct 5, 2019 at 6:01 PM Alexei Starovoitov <ast@fb.com> wrote:
>
> On 10/5/19 11:24 AM, Andrii Nakryiko wrote:
> > On Sat, Oct 5, 2019 at 10:10 AM Alexei Starovoitov <ast@fb.com> wrote:
> >>
> >> On 10/5/19 12:59 AM, Andrii Nakryiko wrote:
> >>> Get rid of list of BPF helpers in bpf_helpers.h (irony...) and
> >>> auto-generate it into bpf_helpers_defs.h, which is now included from
> >>> bpf_helpers.h.
> >>>
> >>> Suggested-by: Alexei Starovoitov<ast@fb.com>
> >>> Signed-off-by: Andrii Nakryiko<andriin@fb.com>
> >>> ---
> >>> tools/lib/bpf/Makefile | 8 +-
> >>> tools/lib/bpf/bpf_helpers.h | 264 +--
> >>> tools/lib/bpf/bpf_helpers_defs.h | 2677 ++++++++++++++++++++++++++++++
> >>> 3 files changed, 2685 insertions(+), 264 deletions(-)
> >>> create mode 100644 tools/lib/bpf/bpf_helpers_defs.h
> >>
> >> Approach looks good to me.
> >> imo that's better than messing with macros.
> >>
> >> Using bpf_helpers_doc.py as part of build will help man pages too.
> >> I think we were sloppy documenting helpers, since only Quentin
> >> was running that script regularly.
> >
> > Yep, I agree, I had to fix few things, as well as (char *) vs (void *)
> > vs (__u8 *) differences were causing some extra warnings.
> > Please check the list of type translations whether they make sense.
>
> yes. These conversions make sense.
cool, thanks for checking!
> Only one sk_buff->__sk_buff won't work for too long.
> Once my btf vmlinux stuff lands both structs will be possible.
I guess it will have to be sk_buff -> void conversion then, but we'll
do it later.
>
> >>
> >> Only question is what is the reason to commit generated .h into git?
> >
> > So originally I didn't want to depend on system UAPI headers during
> > Github build. But now I recalled that we do have latest UAPI synced
> > into Github's include/ subdir, so that's not an obstacle really. We'll
> > just need to re-license bpf_helpers_doc.py (I don't think Quentin will
> > mind) and start syncing it to Github (not a big deal at all).
>
> github sync script can run make, grab generated .h,
> and check it in into github.
Haven't considered that. That will work as well, a bit more work for
me on sync script side, but that's ok.
>
> >
> > There is still a benefit in having it checked in: easy to spot if
> > script does something wrong and double-check the changes (after
> > initial big commit, of course).
> >
> > If you think that's not reason enough, let me know and I can drop it in v2.
>
> I don't remember too many cases when generated files were committed.
> My preference to keep it out of kernel git.
> github/libbpf is a pure mirror. That .h can be committed there.
> The whole thing is automatic, so we don't need to move .py
> into github too.
>
Yeah, makes sense, will submit v2 w/ bpf_helpers_defs.h added to .gitignore
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-10-06 2:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-05 7:59 [PATCH bpf-next 0/3] Auto-generate list of BPF helpers Andrii Nakryiko
2019-10-05 7:59 ` [PATCH bpf-next 1/3] uapi/bpf: fix helper docs Andrii Nakryiko
2019-10-05 7:59 ` [PATCH bpf-next 2/3] scripts/bpf: teach bpf_helpers_doc.py to dump BPF helper definitions Andrii Nakryiko
[not found] ` <20191005075921.3310139-4-andriin@fb.com>
2019-10-05 17:10 ` [PATCH bpf-next 3/3] libbpf: auto-generate list of " Alexei Starovoitov
2019-10-05 18:24 ` Andrii Nakryiko
2019-10-06 1:01 ` Alexei Starovoitov
2019-10-06 2:29 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).