From: Bagas Sanjaya <bagasdotme@gmail.com>
To: mtahhan@redhat.com
Cc: bpf@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 1/1] doc: DEVMAPs and XDP_REDIRECT
Date: Sat, 15 Oct 2022 11:19:59 +0700 [thread overview]
Message-ID: <Y0o07w0OguaTIH1e@debian.me> (raw)
In-Reply-To: <20221013111129.401325-2-mtahhan@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4553 bytes --]
On Thu, Oct 13, 2022 at 07:11:29AM -0400, mtahhan@redhat.com wrote:
> diff --git a/Documentation/bpf/map_devmap.rst b/Documentation/bpf/map_devmap.rst
> new file mode 100644
> index 000000000000..bdba55640f4c
> --- /dev/null
> +++ b/Documentation/bpf/map_devmap.rst
> @@ -0,0 +1,192 @@
> +.. SPDX-License-Identifier: GPL-2.0-only
> +.. Copyright (C) 2022 Red Hat, Inc.
> +
> +=================================================
> +BPF_MAP_TYPE_DEVMAP and BPF_MAP_TYPE_DEVMAP_HASH
> +=================================================
> +
> +.. note::
> + - ``BPF_MAP_TYPE_DEVMAP`` was introduced in kernel version 4.14
> + - ``BPF_MAP_TYPE_DEVMAP_HASH`` was introduced in kernel version 5.4
> +
> +``BPF_MAP_TYPE_DEVMAP`` and ``BPF_MAP_TYPE_DEVMAP_HASH`` are BPF maps primarily
> +used as backend maps for the XDP BPF helper call ``bpf_redirect_map()``.
> +``BPF_MAP_TYPE_DEVMAP`` is backed by an array that uses the key as
> +the index to lookup a reference to a net device. While ``BPF_MAP_TYPE_DEVMAP_HASH``
> +is backed by a hash table that uses the ``ifindex`` as the key to lookup a reference
> +to a net device. The user provides either <``key``/ ``ifindex``> or
> +<``key``/ ``struct bpf_devmap_val``> pairs to update the maps with new net devices.
> +
> +.. note::
> + While ``BPF_MAP_TYPE_DEVMAP_HASH`` allows for densely packing the net devices
> + it comes at the cost of a hash of the key when performing a look up.
> +
> +The setup and packet enqueue/send code is shared between the two types of
> +devmap; only the lookup and insertion is different.
> +
> +Usage
> +=====
> +
> +.. c:function::
> + long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
> +
> + Net device entries can be added or updated using the ``bpf_map_update_elem()``
> + helper. This helper replaces existing elements atomically. The ``value`` parameter
> + can be ``struct bpf_devmap_val`` or a simple ``int ifindex`` for backwards
> + compatibility.
> +
> +.. note::
> + The maps can only be updated from user space and not from a BPF program.
> +
Only the sentence above should be in the note directive, so align the
directive to the surrounding text:
---- >8 ----
diff --git a/Documentation/bpf/map_devmap.rst b/Documentation/bpf/map_devmap.rst
index bdba55640f4c7d..b4f2b1a9ef9b09 100644
--- a/Documentation/bpf/map_devmap.rst
+++ b/Documentation/bpf/map_devmap.rst
@@ -35,7 +35,7 @@ Usage
can be ``struct bpf_devmap_val`` or a simple ``int ifindex`` for backwards
compatibility.
-.. note::
+ .. note::
The maps can only be updated from user space and not from a BPF program.
.. code-block:: c
> + When a program is associated with a device index, the program is run on an
> + ``XDP_REDIRECT`` and before the buffer is added to the per-cpu queue. Examples
> + of how to attach/use xdp_devmap progs can be found in the kernel selftests:
> +
> + - test_xdp_with_devmap_helpers_
> + - xdp_devmap_attach_
> +
> +.. _xdp_devmap_attach: https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
> +.. _test_xdp_with_devmap_helpers: https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c
> +
Instead of external link to the Linus's tree, just specify the file location
of these selftests:
---- >8 ----
diff --git a/Documentation/bpf/map_devmap.rst b/Documentation/bpf/map_devmap.rst
index b4f2b1a9ef9b09..55ad36d4a8dbd5 100644
--- a/Documentation/bpf/map_devmap.rst
+++ b/Documentation/bpf/map_devmap.rst
@@ -56,11 +56,8 @@ Usage
``XDP_REDIRECT`` and before the buffer is added to the per-cpu queue. Examples
of how to attach/use xdp_devmap progs can be found in the kernel selftests:
- - test_xdp_with_devmap_helpers_
- - xdp_devmap_attach_
-
-.. _xdp_devmap_attach: https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
-.. _test_xdp_with_devmap_helpers: https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c
+ - ``test_xdp_with_devmap_helpers`` (in ``tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c``)
+ - ``xdp_devmap_attach`` (in ``tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c``)
.. c:function::
void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
Thanks.
--
An old man doll... just what I always wanted! - Clara
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2022-10-15 4:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 11:11 [PATCH bpf-next v2 0/1] doc: DEVMAPs and XDP_REDIRECT mtahhan
2022-10-13 11:11 ` [PATCH bpf-next v2 1/1] " mtahhan
2022-10-15 4:19 ` Bagas Sanjaya [this message]
2022-10-20 16:39 ` Toke Høiland-Jørgensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y0o07w0OguaTIH1e@debian.me \
--to=bagasdotme@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=mtahhan@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.