Skip to content

Commit ef57dc6

Browse files
yoongsiang2Martin KaFai Lau
authored andcommitted
doc: xdp: Clarify driver implementation for XDP Rx metadata
Clarify that drivers must remove device-reserved metadata from the data_meta area before passing frames to XDP programs. Additionally, expand the explanation of how userspace and BPF programs should coordinate the use of METADATA_SIZE, and add a detailed diagram to illustrate pointer adjustments and metadata layout. Also describe the requirements and constraints enforced by bpf_xdp_adjust_meta(). Signed-off-by: Song Yoong Siang <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6e375b2 commit ef57dc6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Documentation/networking/xdp-rx-metadata.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,39 @@ It is possible to query which kfunc the particular netdev implements via
120120
netlink. See ``xdp-rx-metadata-features`` attribute set in
121121
``Documentation/netlink/specs/netdev.yaml``.
122122

123+
Driver Implementation
124+
=====================
125+
126+
Certain devices may prepend metadata to received packets. However, as of now,
127+
``AF_XDP`` lacks the ability to communicate the size of the ``data_meta`` area
128+
to the consumer. Therefore, it is the responsibility of the driver to copy any
129+
device-reserved metadata out from the metadata area and ensure that
130+
``xdp_buff->data_meta`` is pointing to ``xdp_buff->data`` before presenting the
131+
frame to the XDP program. This is necessary so that, after the XDP program
132+
adjusts the metadata area, the consumer can reliably retrieve the metadata
133+
address using ``METADATA_SIZE`` offset.
134+
135+
The following diagram shows how custom metadata is positioned relative to the
136+
packet data and how pointers are adjusted for metadata access::
137+
138+
|<-- bpf_xdp_adjust_meta(xdp_buff, -METADATA_SIZE) --|
139+
new xdp_buff->data_meta old xdp_buff->data_meta
140+
| |
141+
| xdp_buff->data
142+
| |
143+
+----------+----------------------------------------------------+------+
144+
| headroom | custom metadata | data |
145+
+----------+----------------------------------------------------+------+
146+
| |
147+
| xdp_desc->addr
148+
|<------ xsk_umem__get_data() - METADATA_SIZE -------|
149+
150+
``bpf_xdp_adjust_meta`` ensures that ``METADATA_SIZE`` is aligned to 4 bytes,
151+
does not exceed 252 bytes, and leaves sufficient space for building the
152+
xdp_frame. If these conditions are not met, it returns a negative error. In this
153+
case, the BPF program should not proceed to populate data into the ``data_meta``
154+
area.
155+
123156
Example
124157
=======
125158

0 commit comments

Comments
 (0)