Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs/bpf: Fix sphinx warnings for cpumap

Sphinx version >=3.1 warns about duplicate function declarations in the
CPUMAP documentation. This is because the function name is the same for
kernel and user space BPF progs but the parameters and return types
they take is what differs. This patch moves from using the ``c:function::``
directive to using the ``code-block:: c`` directive. The patches also fix
the indentation for the text associated with the "new" code block delcarations.
The missing support of c:namespace-push:: and c:namespace-pop:: directives by
helper scripts for kernel documentation prevents using the ``c:function::``
directive with proper namespacing.

Signed-off-by: Maryam Tahhan <mtahhan@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20221123092321.88558-2-mtahhan@redhat.com

authored by

Maryam Tahhan and committed by
Daniel Borkmann
3685b0dc c742cb7c

+34 -22
+34 -22
Documentation/bpf/map_cpumap.rst
··· 30 30 31 31 Kernel BPF 32 32 ---------- 33 - .. c:function:: 33 + bpf_redirect_map() 34 + ^^^^^^^^^^^^^^^^^^ 35 + .. code-block:: c 36 + 34 37 long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags) 35 38 36 - Redirect the packet to the endpoint referenced by ``map`` at index ``key``. 37 - For ``BPF_MAP_TYPE_CPUMAP`` this map contains references to CPUs. 39 + Redirect the packet to the endpoint referenced by ``map`` at index ``key``. 40 + For ``BPF_MAP_TYPE_CPUMAP`` this map contains references to CPUs. 38 41 39 - The lower two bits of ``flags`` are used as the return code if the map lookup 40 - fails. This is so that the return value can be one of the XDP program return 41 - codes up to ``XDP_TX``, as chosen by the caller. 42 + The lower two bits of ``flags`` are used as the return code if the map lookup 43 + fails. This is so that the return value can be one of the XDP program return 44 + codes up to ``XDP_TX``, as chosen by the caller. 42 45 43 - Userspace 44 - --------- 46 + User space 47 + ---------- 45 48 .. note:: 46 49 CPUMAP entries can only be updated/looked up/deleted from user space and not 47 50 from an eBPF program. Trying to call these functions from a kernel eBPF 48 51 program will result in the program failing to load and a verifier warning. 49 52 50 - .. c:function:: 53 + bpf_map_update_elem() 54 + ^^^^^^^^^^^^^^^^^^^^^ 55 + .. code-block:: c 56 + 51 57 int bpf_map_update_elem(int fd, const void *key, const void *value, __u64 flags); 52 58 53 - CPU entries can be added or updated using the ``bpf_map_update_elem()`` 54 - helper. This helper replaces existing elements atomically. The ``value`` parameter 55 - can be ``struct bpf_cpumap_val``. 59 + CPU entries can be added or updated using the ``bpf_map_update_elem()`` 60 + helper. This helper replaces existing elements atomically. The ``value`` parameter 61 + can be ``struct bpf_cpumap_val``. 56 62 57 63 .. code-block:: c 58 64 ··· 70 64 } bpf_prog; 71 65 }; 72 66 73 - The flags argument can be one of the following: 67 + The flags argument can be one of the following: 74 68 - BPF_ANY: Create a new element or update an existing element. 75 69 - BPF_NOEXIST: Create a new element only if it did not exist. 76 70 - BPF_EXIST: Update an existing element. 77 71 78 - .. c:function:: 72 + bpf_map_lookup_elem() 73 + ^^^^^^^^^^^^^^^^^^^^^ 74 + .. code-block:: c 75 + 79 76 int bpf_map_lookup_elem(int fd, const void *key, void *value); 80 77 81 - CPU entries can be retrieved using the ``bpf_map_lookup_elem()`` 82 - helper. 78 + CPU entries can be retrieved using the ``bpf_map_lookup_elem()`` 79 + helper. 83 80 84 - .. c:function:: 81 + bpf_map_delete_elem() 82 + ^^^^^^^^^^^^^^^^^^^^^ 83 + .. code-block:: c 84 + 85 85 int bpf_map_delete_elem(int fd, const void *key); 86 86 87 - CPU entries can be deleted using the ``bpf_map_delete_elem()`` 88 - helper. This helper will return 0 on success, or negative error in case of 89 - failure. 87 + CPU entries can be deleted using the ``bpf_map_delete_elem()`` 88 + helper. This helper will return 0 on success, or negative error in case of 89 + failure. 90 90 91 91 Examples 92 92 ======== ··· 153 141 return bpf_redirect_map(&cpu_map, cpu_dest, 0); 154 142 } 155 143 156 - Userspace 157 - --------- 144 + User space 145 + ---------- 158 146 159 147 The following code snippet shows how to dynamically set the max_entries for a 160 148 CPUMAP to the max number of cpus available on the system.