Skip to contentSkip to conversation

doc: DEVMAPs and XDP_REDIRECT

PATCH Superseded [email protected] 2 participants 3 messages Nov 8, 2022 – Nov 9, 2022

Subsystems (4)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover doc: DEVMAPs and XDP_REDIRECT

From: Maryam Tahhan <[email protected]>

Add documentation for BPF_MAP_TYPE_DEVMAP and
BPF_MAP_TYPE_DEVMAP_HASH including kernel version
introduced, usage and examples.

Add documentation that describes XDP_REDIRECT.

v5->v6:
- Separate Kernel BPF and userspace functions for devmaps.
- Include some packet/tracepoint debug info in the redirect documentation.

v4->v5:
- Remove unused 'index' variable in example.

v3->v4:
- Prepend supported map section for XDP_REDIRECT documentation.

v2->v3:
- Fixed indentations in usage section to exclude non note text.
- Replace links to selftest with actual paths.

v1->v2:
- Separate xdp_redirect documentation to its own file.
- Clean up and simplify examples and usage function descriptions.

Maryam Tahhan (1):
doc: DEVMAPs and XDP_REDIRECT

 Documentation/bpf/index.rst      |   1 +
 Documentation/bpf/map_devmap.rst | 221 +++++++++++++++++++++++++++++++
 Documentation/bpf/redirect.rst   |  82 ++++++++++++
 net/core/filter.c                |   8 +-
 4 files changed, 310 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/bpf/map_devmap.rst
 create mode 100644 Documentation/bpf/redirect.rst
Signature · 1 line
2.35.3
#1 lore raw

PATCH v6 1/1 doc: DEVMAPs and XDP_REDIRECT

From: Maryam Tahhan <[email protected]>

Add documentation for BPF_MAP_TYPE_DEVMAP and
BPF_MAP_TYPE_DEVMAP_HASH including kernel version
introduced, usage and examples.

Add documentation that describes XDP_REDIRECT.

---
 Documentation/bpf/index.rst      |   1 +
 Documentation/bpf/map_devmap.rst | 221 +++++++++++++++++++++++++++++++
 Documentation/bpf/redirect.rst   |  81 +++++++++++
 net/core/filter.c                |   8 +-
 4 files changed, 309 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/bpf/map_devmap.rst
 create mode 100644 Documentation/bpf/redirect.rst
Documentation/bpf/index.rst +1 -0
index 1b50de1983ee..1088d44634d6 100644
@@ -29,6 +29,7 @@ that goes into great technical depth about the BPF Architecture.
    clang-notes
    linux-notes
    other
+   redirect
 
 .. only::  subproject and html
 
Documentation/bpf/map_devmap.rst new file +221 -0

221 lines not on this page · raw message

Documentation/bpf/redirect.rst new file +81 -0

81 lines not on this page · raw message

net/core/filter.c +6 -2
index bb0136e7a8e4..d582cb025f4c 100644
@@ -4104,7 +4104,10 @@ static const struct bpf_func_proto bpf_xdp_adjust_meta_proto = {
 	.arg2_type	= ARG_ANYTHING,
 };
 
-/* XDP_REDIRECT works by a three-step process, implemented in the functions
+/**
+ * DOC: xdp redirect
+ *
+ * XDP_REDIRECT works by a three-step process, implemented in the functions
  * below:
  *
  * 1. The bpf_redirect() and bpf_redirect_map() helpers will lookup the target
@@ -4119,7 +4122,8 @@ static const struct bpf_func_proto bpf_xdp_adjust_meta_proto = {
  * 3. Before exiting its NAPI poll loop, the driver will call xdp_do_flush(),
  *    which will flush all the different bulk queues, thus completing the
  *    redirect.
- *
+ */
+/*
  * Pointers to the map entries will be kept around for this whole sequence of
  * steps, protected by RCU. However, there is no top-level rcu_read_lock() in
  * the core code; instead, the RCU protection relies on everything happening
Signature · 1 line
2.35.3
Acked-by on v6 1/1
#2 lore raw
Quoted 9 lines · On 11/8/22 9:48 AM, [email protected] wrote:

From: Maryam Tahhan <[email protected]>

Add documentation for BPF_MAP_TYPE_DEVMAP and
BPF_MAP_TYPE_DEVMAP_HASH including kernel version
introduced, usage and examples.

Add documentation that describes XDP_REDIRECT.

LGTM with a couple of nits below.

Quoted 21 lines
---
  Documentation/bpf/index.rst      |   1 +
  Documentation/bpf/map_devmap.rst | 221 +++++++++++++++++++++++++++++++
  Documentation/bpf/redirect.rst   |  81 +++++++++++
  net/core/filter.c                |   8 +-
  4 files changed, 309 insertions(+), 2 deletions(-)

create mode 100644 Documentation/bpf/map_devmap.rst create mode 100644 Documentation/bpf/redirect.rst

Documentation/bpf/index.rst +1 -0
index 1b50de1983ee..1088d44634d6 100644
@@ -29,6 +29,7 @@ that goes into great technical depth about the BPF Architecture.
     clang-notes
     linux-notes
     other
+   redirect
 
  .. only::  subproject and html
 

[...]

Documentation/bpf/index.rst

Quoted 11 lines
Documentation/bpf/index.rst +11 -0
+
+User space
+----------
+
+The following code snippet shows how to update a devmap called ``tx_port``.
+
+.. code-block:: c
+
+    int update_devmap(int ifindex, int redirect_ifindex)
+    {
+        int ret = -1;

There is no need to initialize the value to -1, the below is 'ret = ...'.

Quoted 8 lines
Documentation/bpf/index.rst +8 -0
+
+        ret = bpf_map_update_elem(bpf_map__fd(tx_port), &ifindex, &redirect_ifindex, 0);
+        if (ret < 0) {
+            fprintf(stderr, "Failed to update devmap_ value: %s\n",
+                strerror(errno));
+        }
+
+        return ret;

Documentation/bpf/index.rst

Quoted 10 lines
Documentation/bpf/index.rst +10 -0
+    }
+
+The following code snippet shows how to update a hash_devmap called ``forward_map``.
+
+.. code-block:: c
+
+    int update_devmap(int ifindex, int redirect_ifindex)
+    {
+        struct bpf_devmap_val devmap_val = { .ifindex = redirect_ifindex };
+        int ret = -1;

same here, no need to have '-1'.

Quoted 9 lines
Documentation/bpf/index.rst +9 -0
+
+        ret = bpf_map_update_elem(bpf_map__fd(forward_map), &ifindex, &devmap_val, 0);
+        if (ret < 0) {
+            fprintf(stderr, "Failed to update devmap_ value: %s\n",
+                strerror(errno));
+        }
+        return ret;
+    }
+

[...]