* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page [not found] <20180406111122.11038-1-quentin.monnet@netronome.com> @ 2018-04-09 3:48 ` Alexei Starovoitov 2018-04-09 9:01 ` Daniel Borkmann 1 sibling, 0 replies; 11+ messages in thread From: Alexei Starovoitov @ 2018-04-09 3:48 UTC (permalink / raw) To: Quentin Monnet; +Cc: daniel, ast, netdev, oss-drivers, linux-doc, linux-man On Fri, Apr 06, 2018 at 12:11:22PM +0100, Quentin Monnet wrote: > eBPF helper functions can be called from within eBPF programs to perform > a variety of tasks that would be otherwise hard or impossible to do with > eBPF itself. There is a growing number of such helper functions in the > kernel, but documentation is scarce. The main user space header file > does contain a short commented description of most helpers, but it is > somewhat outdated and not complete. It is more a "cheat sheet" than a > real documentation accessible to new eBPF developers. > > This commit attempts to improve the situation by replacing the existing > overview for the helpers with a more developed description. Furthermore, > a Python script is added to generate a manual page for eBPF helpers. The > workflow is the following, and requires the rst2man utility: > > $ ./scripts/bpf_helpers_doc.py \ > --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst > $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7 > $ man /tmp/bpf-helpers.7 > > The objective is to keep all documentation related to the helpers in a > single place, and to be able to generate from here a manual page that > could be packaged in the man-pages repository and shipped with most > distributions [1]. > > Additionally, parsing the prototypes of the helper functions could > hopefully be reused, with a different Printer object, to generate > header files needed in some eBPF-related projects. > > Regarding the description of each helper, it comprises several items: > > - The function prototype. > - A description of the function and of its arguments (except for a > couple of cases, when there are no arguments and the return value > makes the function usage really obvious). > - A description of return values (if not void). > - A listing of eBPF program types (if relevant, map types) compatible > with the helper. > - Information about the helper being restricted to GPL programs, or not. > - The kernel version in which the helper was introduced. > - The commit that introduced the helper (this is mostly to have it in > the source of the man page, as it can be used to track changes and > update the page). > > For several helpers, descriptions are inspired (at times, nearly copied) > from the commit logs introducing them in the kernel--Many thanks to > their respective authors! They were completed as much as possible, the > objective being to have something easily accessible even for people just > starting with eBPF. There is probably a bit more work to do in this > direction for some helpers. > > Some RST formatting is used in the descriptions (not in function > prototypes, to keep them readable, but the Python script provided in > order to generate the RST for the manual page does add formatting to > prototypes, to produce something pretty) to get "bold" and "italics" in > manual pages. Hopefully, the descriptions in bpf.h file remains > perfectly readable. Note that the few trailing white spaces are > intentional, removing them would break paragraphs for rst2man. > > The descriptions should ideally be updated each time someone adds a new > helper, or updates the behaviour (compatibility extended to new program > types, new socket option supported...) or the interface (new flags > available, ...) of existing ones. > > [1] I have not contacted people from the man-pages project prior to > sending this RFC, so I can offer no guaranty at this time that they > would accept to take the generated man page. > > Cc: linux-doc@vger.kernel.org > Cc: linux-man@vger.kernel.org > Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> > --- > include/uapi/linux/bpf.h | 2237 ++++++++++++++++++++++++++++++++++++-------- > scripts/bpf_helpers_doc.py | 568 +++++++++++ > 2 files changed, 2429 insertions(+), 376 deletions(-) > create mode 100755 scripts/bpf_helpers_doc.py > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index c5ec89732a8d..f47aeddbbe0a 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -367,394 +367,1879 @@ union bpf_attr { > > /* BPF helper function descriptions: > * > - * void *bpf_map_lookup_elem(&map, &key) > - * Return: Map value or NULL > - * > - * int bpf_map_update_elem(&map, &key, &value, flags) > - * Return: 0 on success or negative error > - * > - * int bpf_map_delete_elem(&map, &key) > - * Return: 0 on success or negative error > - * > - * int bpf_probe_read(void *dst, int size, void *src) > - * Return: 0 on success or negative error > + * void *bpf_map_lookup_elem(struct bpf_map *map, void *key) > + * Description > + * Perform a lookup in *map* for an entry associated to *key*. > + * Return > + * Map value associated to *key*, or **NULL** if no entry was > + * found. > + * For > + * All types of programs. Limited to maps of types > + * **BPF_MAP_TYPE_HASH**, > + * **BPF_MAP_TYPE_ARRAY**, > + * **BPF_MAP_TYPE_PERCPU_HASH**, > + * **BPF_MAP_TYPE_PERCPU_ARRAY**, > + * **BPF_MAP_TYPE_LRU_HASH**, > + * **BPF_MAP_TYPE_LRU_PERCPU_HASH**, > + * **BPF_MAP_TYPE_LPM_TRIE**, > + * **BPF_MAP_TYPE_ARRAY_OF_MAPS**, > + * and **BPF_MAP_TYPE_HASH_OF_MAPS**. > + * GPL only > + * No > + * Since > + * Linux 3.19 I think we should give it a try. There is a risk that it will become stale and to reduce that I'd propose to remove 'For', 'GPL only' and 'Since', since for new helpers 'Since' is kinda hard to fill in before it lands all the way, and 'For' keeps changing as new types are added. 'Description' is the most useful and it needs separate thorough review for every helper. -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page [not found] <20180406111122.11038-1-quentin.monnet@netronome.com> 2018-04-09 3:48 ` [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page Alexei Starovoitov @ 2018-04-09 9:01 ` Daniel Borkmann [not found] ` <AB89F6E2-DE8A-4259-B361-BE96AD32E84E@darmarit.de> ` (2 more replies) 1 sibling, 3 replies; 11+ messages in thread From: Daniel Borkmann @ 2018-04-09 9:01 UTC (permalink / raw) To: Quentin Monnet, ast; +Cc: netdev, oss-drivers, linux-doc, linux-man On 04/06/2018 01:11 PM, Quentin Monnet wrote: > eBPF helper functions can be called from within eBPF programs to perform > a variety of tasks that would be otherwise hard or impossible to do with > eBPF itself. There is a growing number of such helper functions in the > kernel, but documentation is scarce. The main user space header file > does contain a short commented description of most helpers, but it is > somewhat outdated and not complete. It is more a "cheat sheet" than a > real documentation accessible to new eBPF developers. > > This commit attempts to improve the situation by replacing the existing > overview for the helpers with a more developed description. Furthermore, > a Python script is added to generate a manual page for eBPF helpers. The > workflow is the following, and requires the rst2man utility: > > $ ./scripts/bpf_helpers_doc.py \ > --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst > $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7 > $ man /tmp/bpf-helpers.7 > > The objective is to keep all documentation related to the helpers in a > single place, and to be able to generate from here a manual page that > could be packaged in the man-pages repository and shipped with most > distributions [1]. > > Additionally, parsing the prototypes of the helper functions could > hopefully be reused, with a different Printer object, to generate > header files needed in some eBPF-related projects. > > Regarding the description of each helper, it comprises several items: > > - The function prototype. > - A description of the function and of its arguments (except for a > couple of cases, when there are no arguments and the return value > makes the function usage really obvious). > - A description of return values (if not void). > - A listing of eBPF program types (if relevant, map types) compatible > with the helper. > - Information about the helper being restricted to GPL programs, or not. > - The kernel version in which the helper was introduced. > - The commit that introduced the helper (this is mostly to have it in > the source of the man page, as it can be used to track changes and > update the page). > > For several helpers, descriptions are inspired (at times, nearly copied) > from the commit logs introducing them in the kernel--Many thanks to > their respective authors! They were completed as much as possible, the > objective being to have something easily accessible even for people just > starting with eBPF. There is probably a bit more work to do in this > direction for some helpers. > > Some RST formatting is used in the descriptions (not in function > prototypes, to keep them readable, but the Python script provided in > order to generate the RST for the manual page does add formatting to > prototypes, to produce something pretty) to get "bold" and "italics" in > manual pages. Hopefully, the descriptions in bpf.h file remains > perfectly readable. Note that the few trailing white spaces are > intentional, removing them would break paragraphs for rst2man. > > The descriptions should ideally be updated each time someone adds a new > helper, or updates the behaviour (compatibility extended to new program > types, new socket option supported...) or the interface (new flags > available, ...) of existing ones. > > [1] I have not contacted people from the man-pages project prior to > sending this RFC, so I can offer no guaranty at this time that they > would accept to take the generated man page. > > Cc: linux-doc@vger.kernel.org > Cc: linux-man@vger.kernel.org > Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Great work, thanks a lot for doing this! [...] > + * int bpf_probe_read(void *dst, u32 size, const void *src) > + * Description > + * For tracing programs, safely attempt to read *size* bytes from > + * address *src* and store the data in *dst*. > + * Return > + * 0 on success, or a negative error in case of failure. > + * For > + * *Tracing programs*. > + * GPL only > + * Yes > + * Since > + * Linux 4.1 > + * > + * .. commit 2541517c32be > * > * u64 bpf_ktime_get_ns(void) > - * Return: current ktime > - * > - * int bpf_trace_printk(const char *fmt, int fmt_size, ...) > - * Return: length of buffer written or negative error > + * Description > + * Return the time elapsed since system boot, in nanoseconds. > + * Return > + * Current *ktime*. > + * For > + * All program types, except > + * **BPF_PROG_TYPE_CGROUP_DEVICE**. I think we should probably always just list the actual program types instead, since when new types get added to the kernel not supporting bpf_ktime_get_ns() helper in this example, the above statement would be misleading (potentially more misleading than the other way around when it's not yet mentioned to be supported). > + * GPL only > + * Yes > + * Since > + * Linux 4.1 > + * > + * .. commit d9847d310ab4 > + * > + * int bpf_trace_printk(const char *fmt, u32 fmt_size, ...) > + * Description > + * This helper is a "printk()-like" facility for debugging. It > + * prints a message defined by format *fmt* (of size *fmt_size*) > + * to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if > + * available. It can take up to three additional **u64** > + * arguments (as an eBPF helpers, the total number of arguments is > + * limited to five). Each time the helper is called, it appends a > + * line that looks like the following: > + * > + * :: > + * > + * telnet-470 [001] .N.. 419421.045894: 0x00000001: BPF command: 2 > + * > + * In the above: > + * > + * * ``telnet`` is the name of the current task. > + * * ``470`` is the PID of the current task. > + * * ``001`` is the CPU number on which the task is > + * running. > + * * In ``.N..``, each character refers to a set of > + * options (whether irqs are enabled, scheduling > + * options, whether hard/softirqs are running, level of > + * preempt_disabled respectively). **N** means that > + * **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED** > + * are set. > + * * ``419421.045894`` is a timestamp. > + * * ``0x00000001`` is a fake value used by BPF for the > + * instruction pointer register. > + * * ``BPF command: 2`` is the message formatted with > + * *fmt*. > + * > + * The conversion specifiers supported by *fmt* are similar, but > + * more limited than for printk(). They are **%d**, **%i**, > + * **%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**, > + * **%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size > + * of field, padding with zeroes, etc.) is available, and the > + * helper will silently fail if it encounters an unknown > + * specifier. > + * > + * Also, note that **bpf_trace_printk**\ () is slow, and should > + * only be used for debugging purposes. For passing values to user > + * space, perf events should be preferred. > + * Return > + * The number of bytes written to the buffer, or a negative error > + * in case of failure. > + * For > + * All types of programs. Ditto, and various other places. > + * GPL only > + * Yes > + * Since > + * Linux 4.1 > + * > + * .. commit 9c959c863f82 > * > * u32 bpf_prandom_u32(void) > - * Return: random value > - * > - * u32 bpf_raw_smp_processor_id(void) > - * Return: SMP processor ID > - * [...] > + * u32 bpf_get_smp_processor_id(void) > + * Return > + * The SMP (Symmetric multiprocessing) processor id. > + * For > + * *Networking programs*. Ditto plus above is actually not correct. See tracing_func_proto(): [...] case BPF_FUNC_get_smp_processor_id: return &bpf_get_smp_processor_id_proto; [...] > + * GPL only > + * No > + * Since > + * Linux 4.1 > + * > + * .. commit c04167ce2ca0 > + * > + * int bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags) > + * Description > + * Store *len* bytes from address *from* into the packet > + * associated to *skb*, at *offset*. *flags* are a combination of > + * **BPF_F_RECOMPUTE_CSUM** (automatically recompute the > + * checksum for the packet after storing the bytes) and > + * **BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\ > + * **->swhash** and *skb*\ **->l4hash** to 0). > + * > + * A call to this helper is susceptible to change data from the > + * packet. Therefore, at load time, all checks on pointers > + * previously done by the verifier are invalidated and must be > + * performed again. > + * Return [...] Agree with Alexei that 'Description' but also 'Return' is the most useful (the latter we can still improve a bit wrt errors). 'For' gets indeed quickly out of hand but I do think that for BPF program developers 'Since' has good value to quickly check when a helper could be available, but then again this is actually tied to an individual kconfig and/or program type, and could potentially require to add or (worst case) remove the info in a second commit e.g. after the merge window similar with the commit sha. Probably best indeed to stick to the signature, 'Description' and 'Return' initially. We should probably also have the bpf_helpers_doc.py workflow in a separate comment above this one such that developers don't have to look up the original commit message, but have the required steps to render the rst/man page available right where they need it. Thanks, Daniel -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <AB89F6E2-DE8A-4259-B361-BE96AD32E84E@darmarit.de>]
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page [not found] ` <AB89F6E2-DE8A-4259-B361-BE96AD32E84E@darmarit.de> @ 2018-04-09 9:25 ` Daniel Borkmann 2018-04-09 9:35 ` Markus Heiser 0 siblings, 1 reply; 11+ messages in thread From: Daniel Borkmann @ 2018-04-09 9:25 UTC (permalink / raw) To: Markus Heiser, Jonathan Corbet Cc: Quentin Monnet, ast, netdev, oss-drivers, Linux Doc Mailing List, linux-man On 04/09/2018 11:21 AM, Markus Heiser wrote: [...] > Do we really need another kernel-doc parser? > > ./scripts/kernel-doc include/uapi/linux/bpf.h > > should already do the job (producing .rst). For more infos, take a look at This has absolutely zero to do with kernel-doc, but rather producing a description of BPF helper function that are later assembled into an actual man-page that BPF program developers (user space) can use. -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-09 9:25 ` Daniel Borkmann @ 2018-04-09 9:35 ` Markus Heiser 2018-04-09 10:08 ` Daniel Borkmann 0 siblings, 1 reply; 11+ messages in thread From: Markus Heiser @ 2018-04-09 9:35 UTC (permalink / raw) To: Daniel Borkmann Cc: Jonathan Corbet, Quentin Monnet, ast, netdev, oss-drivers, Linux Doc Mailing List, linux-man > Am 09.04.2018 um 11:25 schrieb Daniel Borkmann <daniel@iogearbox.net>: > > On 04/09/2018 11:21 AM, Markus Heiser wrote: > [...] >> Do we really need another kernel-doc parser? >> >> ./scripts/kernel-doc include/uapi/linux/bpf.h >> >> should already do the job (producing .rst). For more infos, take a look at > > This has absolutely zero to do with kernel-doc, but rather producing > a description of BPF helper function that are later assembled into an > actual man-page that BPF program developers (user space) can use. May I completely misunderstood you, so correct my if I'am wrong: - ./scripts/bpf_helpers_doc.py : produces reST markup from C-comments - ./scripts/kerne-doc : produces reST markup from C-comments IMO: both are doing the same job, so why not using kernel-doc? -- Markus -- -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-09 9:35 ` Markus Heiser @ 2018-04-09 10:08 ` Daniel Borkmann 2018-04-09 10:52 ` Markus Heiser 0 siblings, 1 reply; 11+ messages in thread From: Daniel Borkmann @ 2018-04-09 10:08 UTC (permalink / raw) To: Markus Heiser Cc: Jonathan Corbet, Quentin Monnet, ast, netdev, oss-drivers, Linux Doc Mailing List, linux-man On 04/09/2018 11:35 AM, Markus Heiser wrote: > >> Am 09.04.2018 um 11:25 schrieb Daniel Borkmann <daniel@iogearbox.net>: >> >> On 04/09/2018 11:21 AM, Markus Heiser wrote: >> [...] >>> Do we really need another kernel-doc parser? >>> >>> ./scripts/kernel-doc include/uapi/linux/bpf.h >>> >>> should already do the job (producing .rst). For more infos, take a look at >> >> This has absolutely zero to do with kernel-doc, but rather producing >> a description of BPF helper function that are later assembled into an >> actual man-page that BPF program developers (user space) can use. > > May I completely misunderstood you, so correct my if I'am wrong: > > - ./scripts/bpf_helpers_doc.py : produces reST markup from C-comments > - ./scripts/kerne-doc : produces reST markup from C-comments > > IMO: both are doing the same job, so why not using kernel-doc? They are not really doing the same job, in bpf_helpers_doc.py case you don't want the whole header rendered, but just a fraction of it, that is, the single big comment which describes all BPF helper functions that a BPF program developer has available to use in user space - aka the entries in the __BPF_FUNC_MAPPER() macro; I also doubt the latter would actually qualify in kdoc context as some sort of a function description. -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-09 10:08 ` Daniel Borkmann @ 2018-04-09 10:52 ` Markus Heiser 2018-04-09 13:33 ` Quentin Monnet 0 siblings, 1 reply; 11+ messages in thread From: Markus Heiser @ 2018-04-09 10:52 UTC (permalink / raw) To: Daniel Borkmann Cc: Jonathan Corbet, Quentin Monnet, ast, netdev, oss-drivers, Linux Doc Mailing List, linux-man > Am 09.04.2018 um 12:08 schrieb Daniel Borkmann <daniel@iogearbox.net>: [...] >> May I completely misunderstood you, so correct my if I'am wrong: >> >> - ./scripts/bpf_helpers_doc.py : produces reST markup from C-comments >> - ./scripts/kerne-doc : produces reST markup from C-comments >> >> IMO: both are doing the same job, so why not using kernel-doc? > > They are not really doing the same job, in bpf_helpers_doc.py case you don't > want the whole header rendered, but just a fraction of it, that is, the > single big comment which describes all BPF helper functions that a BPF > program developer has available to use in user space - aka the entries in > the __BPF_FUNC_MAPPER() macro; > I also doubt the latter would actually qualify > in kdoc context as some sort of a function description. latter .. ah, OK .. thanks for clarifying. -- Markus -- -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-09 10:52 ` Markus Heiser @ 2018-04-09 13:33 ` Quentin Monnet 0 siblings, 0 replies; 11+ messages in thread From: Quentin Monnet @ 2018-04-09 13:33 UTC (permalink / raw) To: Markus Heiser, Daniel Borkmann Cc: Jonathan Corbet, ast, netdev, oss-drivers, Linux Doc Mailing List, linux-man 2018-04-09 12:52 UTC+0200 ~ Markus Heiser <markus.heiser@darmarit.de> > >> Am 09.04.2018 um 12:08 schrieb Daniel Borkmann <daniel@iogearbox.net>: > [...] > >>> May I completely misunderstood you, so correct my if I'am wrong: >>> >>> - ./scripts/bpf_helpers_doc.py : produces reST markup from C-comments >>> - ./scripts/kerne-doc : produces reST markup from C-comments >>> >>> IMO: both are doing the same job, so why not using kernel-doc? >> >> They are not really doing the same job, in bpf_helpers_doc.py case you don't >> want the whole header rendered, but just a fraction of it, that is, the >> single big comment which describes all BPF helper functions that a BPF >> program developer has available to use in user space - aka the entries in >> the __BPF_FUNC_MAPPER() macro; > > >> I also doubt the latter would actually qualify >> in kdoc context as some sort of a function description. > > latter .. ah, OK .. thanks for clarifying. > > -- Markus -- As Daniel explained, kernel-doc does not apply in this case, we do not have the full function prototype for eBPF helpers in the header file. But to be honest, I didn't even realise kernel-doc was available and could do something close to what I was looking for, so thanks for your feedback! :) Quentin -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-09 9:01 ` Daniel Borkmann [not found] ` <AB89F6E2-DE8A-4259-B361-BE96AD32E84E@darmarit.de> @ 2018-04-09 9:26 ` Markus Heiser 2018-04-09 13:25 ` Quentin Monnet 2 siblings, 0 replies; 11+ messages in thread From: Markus Heiser @ 2018-04-09 9:26 UTC (permalink / raw) To: Daniel Borkmann, Jonathan Corbet Cc: Quentin Monnet, ast, netdev, oss-drivers, Linux Doc Mailing List, linux-man On 04/06/2018 01:11 PM, Quentin Monnet wrote: >> eBPF helper functions can be called from within eBPF programs to perform >> a variety of tasks that would be otherwise hard or impossible to do with >> eBPF itself. There is a growing number of such helper functions in the >> kernel, but documentation is scarce. The main user space header file >> does contain a short commented description of most helpers, but it is >> somewhat outdated and not complete. It is more a "cheat sheet" than a >> real documentation accessible to new eBPF developers. >> >> This commit attempts to improve the situation by replacing the existing >> overview for the helpers with a more developed description. Furthermore, >> a Python script is added to generate a manual page for eBPF helpers. The >> workflow is the following, and requires the rst2man utility: >> >> $ ./scripts/bpf_helpers_doc.py \ >> --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst >> $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7 >> $ man /tmp/bpf-helpers.7 >> >> The objective is to keep all documentation related to the helpers in a >> single place, Do we really need another kernel-doc parser? ./scripts/kernel-doc include/uapi/linux/bpf.h should already do the job (producing .rst). For more infos, take a look at https://www.kernel.org/doc/html/latest/doc-guide/index.html -- Markus -- PS: sorry for re-post, first post was HTML which is not accepted by ML :o -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-09 9:01 ` Daniel Borkmann [not found] ` <AB89F6E2-DE8A-4259-B361-BE96AD32E84E@darmarit.de> 2018-04-09 9:26 ` Markus Heiser @ 2018-04-09 13:25 ` Quentin Monnet 2018-04-10 1:47 ` Alexei Starovoitov 2 siblings, 1 reply; 11+ messages in thread From: Quentin Monnet @ 2018-04-09 13:25 UTC (permalink / raw) To: Daniel Borkmann, ast; +Cc: netdev, oss-drivers, linux-doc, linux-man 2018-04-09 11:01 UTC+0200 ~ Daniel Borkmann <daniel@iogearbox.net> > On 04/06/2018 01:11 PM, Quentin Monnet wrote: >> eBPF helper functions can be called from within eBPF programs to perform >> a variety of tasks that would be otherwise hard or impossible to do with >> eBPF itself. There is a growing number of such helper functions in the >> kernel, but documentation is scarce. The main user space header file >> does contain a short commented description of most helpers, but it is >> somewhat outdated and not complete. It is more a "cheat sheet" than a >> real documentation accessible to new eBPF developers. >> >> This commit attempts to improve the situation by replacing the existing >> overview for the helpers with a more developed description. Furthermore, >> a Python script is added to generate a manual page for eBPF helpers. The >> workflow is the following, and requires the rst2man utility: >> >> $ ./scripts/bpf_helpers_doc.py \ >> --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst >> $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7 >> $ man /tmp/bpf-helpers.7 >> >> The objective is to keep all documentation related to the helpers in a >> single place, and to be able to generate from here a manual page that >> could be packaged in the man-pages repository and shipped with most >> distributions [1]. >> >> Additionally, parsing the prototypes of the helper functions could >> hopefully be reused, with a different Printer object, to generate >> header files needed in some eBPF-related projects. >> >> Regarding the description of each helper, it comprises several items: >> >> - The function prototype. >> - A description of the function and of its arguments (except for a >> couple of cases, when there are no arguments and the return value >> makes the function usage really obvious). >> - A description of return values (if not void). >> - A listing of eBPF program types (if relevant, map types) compatible >> with the helper. >> - Information about the helper being restricted to GPL programs, or not. >> - The kernel version in which the helper was introduced. >> - The commit that introduced the helper (this is mostly to have it in >> the source of the man page, as it can be used to track changes and >> update the page). >> >> For several helpers, descriptions are inspired (at times, nearly copied) >> from the commit logs introducing them in the kernel--Many thanks to >> their respective authors! They were completed as much as possible, the >> objective being to have something easily accessible even for people just >> starting with eBPF. There is probably a bit more work to do in this >> direction for some helpers. >> >> Some RST formatting is used in the descriptions (not in function >> prototypes, to keep them readable, but the Python script provided in >> order to generate the RST for the manual page does add formatting to >> prototypes, to produce something pretty) to get "bold" and "italics" in >> manual pages. Hopefully, the descriptions in bpf.h file remains >> perfectly readable. Note that the few trailing white spaces are >> intentional, removing them would break paragraphs for rst2man. >> >> The descriptions should ideally be updated each time someone adds a new >> helper, or updates the behaviour (compatibility extended to new program >> types, new socket option supported...) or the interface (new flags >> available, ...) of existing ones. >> >> [1] I have not contacted people from the man-pages project prior to >> sending this RFC, so I can offer no guaranty at this time that they >> would accept to take the generated man page. >> >> Cc: linux-doc@vger.kernel.org >> Cc: linux-man@vger.kernel.org >> Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> > > Great work, thanks a lot for doing this! > > [...] >> + * int bpf_probe_read(void *dst, u32 size, const void *src) >> + * Description >> + * For tracing programs, safely attempt to read *size* bytes from >> + * address *src* and store the data in *dst*. >> + * Return >> + * 0 on success, or a negative error in case of failure. >> + * For >> + * *Tracing programs*. >> + * GPL only >> + * Yes >> + * Since >> + * Linux 4.1 >> + * >> + * .. commit 2541517c32be >> * >> * u64 bpf_ktime_get_ns(void) >> - * Return: current ktime >> - * >> - * int bpf_trace_printk(const char *fmt, int fmt_size, ...) >> - * Return: length of buffer written or negative error >> + * Description >> + * Return the time elapsed since system boot, in nanoseconds. >> + * Return >> + * Current *ktime*. >> + * For >> + * All program types, except >> + * **BPF_PROG_TYPE_CGROUP_DEVICE**. > > I think we should probably always just list the actual program types instead, > since when new types get added to the kernel not supporting bpf_ktime_get_ns() > helper in this example, the above statement would be misleading (potentially > more misleading than the other way around when it's not yet mentioned to be > supported). Agreed. I realise “All program types” is really awkward here. >> + * GPL only >> + * Yes >> + * Since >> + * Linux 4.1 >> + * >> + * .. commit d9847d310ab4 >> + * [...] >> + * u32 bpf_get_smp_processor_id(void) >> + * Return >> + * The SMP (Symmetric multiprocessing) processor id. >> + * For >> + * *Networking programs*. > > Ditto plus above is actually not correct. See tracing_func_proto(): > > [...] > case BPF_FUNC_get_smp_processor_id: > return &bpf_get_smp_processor_id_proto; > [...] Thanks for the catch! I will fix on my side, even if we drop the "For" section for now. >> + * GPL only >> + * No >> + * Since >> + * Linux 4.1 >> + * >> + * .. commit c04167ce2ca0 >> + * >> + * int bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags) >> + * Description >> + * Store *len* bytes from address *from* into the packet >> + * associated to *skb*, at *offset*. *flags* are a combination of >> + * **BPF_F_RECOMPUTE_CSUM** (automatically recompute the >> + * checksum for the packet after storing the bytes) and >> + * **BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\ >> + * **->swhash** and *skb*\ **->l4hash** to 0). >> + * >> + * A call to this helper is susceptible to change data from the >> + * packet. Therefore, at load time, all checks on pointers >> + * previously done by the verifier are invalidated and must be >> + * performed again. >> + * Return > [...] > > Agree with Alexei that 'Description' but also 'Return' is the most useful > (the latter we can still improve a bit wrt errors). 'For' gets indeed quickly > out of hand but I do think that for BPF program developers 'Since' has good > value to quickly check when a helper could be available, but then again > this is actually tied to an individual kconfig and/or program type, and could > potentially require to add or (worst case) remove the info in a second commit > e.g. after the merge window similar with the commit sha. Probably best indeed > to stick to the signature, 'Description' and 'Return' initially. I understand that the "For" section will be the hardest to maintain up-to-date, however, I believe that--along with minimal kernel version and GPL information--it would be useful for readers (Alexei, what is your case against the "GPL only" section?). Daniel, your proposal for the "Since" information in a second time sounds good! But I do not have a solution right now for maintaining the "For" section on the long term. Anyway, I am fine with keeping just signatures, descriptions and return values for now. I will submit a new version with only those items. > We should probably also have the bpf_helpers_doc.py workflow in a separate > comment above this one such that developers don't have to look up the original > commit message, but have the required steps to render the rst/man page available > right where they need it. Sure! I was considering adding some comments on top of the description, but haven't done it for the RFC. I will do for the next version. Thanks for the reviews! Quentin -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-09 13:25 ` Quentin Monnet @ 2018-04-10 1:47 ` Alexei Starovoitov 2018-04-10 10:21 ` Quentin Monnet 0 siblings, 1 reply; 11+ messages in thread From: Alexei Starovoitov @ 2018-04-10 1:47 UTC (permalink / raw) To: Quentin Monnet Cc: Daniel Borkmann, ast, netdev, oss-drivers, linux-doc, linux-man On Mon, Apr 09, 2018 at 02:25:26PM +0100, Quentin Monnet wrote: > > Anyway, I am fine with keeping just signatures, descriptions and return > values for now. I will submit a new version with only those items. Thank you. Could you also split it into few patches? include/uapi/linux/bpf.h | 2237 ++++++++++++++++++++++++++++++++++++-------- scripts/bpf_helpers_doc.py | 568 +++++++++++ 2 files changed, 2429 insertions(+), 376 deletions(-) replying back and forth on a single patch of such size will be tedious for others to follow. May be document ~10 helpers at a time ? Total of ~7 patches and extra patch for .py ? -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page 2018-04-10 1:47 ` Alexei Starovoitov @ 2018-04-10 10:21 ` Quentin Monnet 0 siblings, 0 replies; 11+ messages in thread From: Quentin Monnet @ 2018-04-10 10:21 UTC (permalink / raw) To: Alexei Starovoitov Cc: Daniel Borkmann, ast, netdev, oss-drivers, linux-doc, linux-man 2018-04-09 18:47 UTC-0700 ~ Alexei Starovoitov <alexei.starovoitov@gmail.com> > On Mon, Apr 09, 2018 at 02:25:26PM +0100, Quentin Monnet wrote: >> >> Anyway, I am fine with keeping just signatures, descriptions and return >> values for now. I will submit a new version with only those items. > > Thank you. > > Could you also split it into few patches? > include/uapi/linux/bpf.h | 2237 ++++++++++++++++++++++++++++++++++++-------- > scripts/bpf_helpers_doc.py | 568 +++++++++++ > 2 files changed, 2429 insertions(+), 376 deletions(-) > > replying back and forth on a single patch of such size will be tedious > for others to follow. > May be document ~10 helpers at a time ? Total of ~7 patches and extra > patch for .py ? > Sure, I'll do that. And I'll try to group helpers in a patch by author, it should also help for reviewing the descriptions. Quentin -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-04-10 10:21 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20180406111122.11038-1-quentin.monnet@netronome.com>
2018-04-09 3:48 ` [RFC bpf-next] bpf: document eBPF helpers and add a script to generate man page Alexei Starovoitov
2018-04-09 9:01 ` Daniel Borkmann
[not found] ` <AB89F6E2-DE8A-4259-B361-BE96AD32E84E@darmarit.de>
2018-04-09 9:25 ` Daniel Borkmann
2018-04-09 9:35 ` Markus Heiser
2018-04-09 10:08 ` Daniel Borkmann
2018-04-09 10:52 ` Markus Heiser
2018-04-09 13:33 ` Quentin Monnet
2018-04-09 9:26 ` Markus Heiser
2018-04-09 13:25 ` Quentin Monnet
2018-04-10 1:47 ` Alexei Starovoitov
2018-04-10 10:21 ` Quentin Monnet
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox