mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:04:41 +01:00
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 <yoong.siang.song@intel.com> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Link: https://lore.kernel.org/r/20250716154846.3513575-1-yoong.siang.song@intel.com
This commit is contained in:
parent
6e375b2363
commit
ef57dc6f52
1 changed files with 33 additions and 0 deletions
|
|
@ -120,6 +120,39 @@ It is possible to query which kfunc the particular netdev implements via
|
|||
netlink. See ``xdp-rx-metadata-features`` attribute set in
|
||||
``Documentation/netlink/specs/netdev.yaml``.
|
||||
|
||||
Driver Implementation
|
||||
=====================
|
||||
|
||||
Certain devices may prepend metadata to received packets. However, as of now,
|
||||
``AF_XDP`` lacks the ability to communicate the size of the ``data_meta`` area
|
||||
to the consumer. Therefore, it is the responsibility of the driver to copy any
|
||||
device-reserved metadata out from the metadata area and ensure that
|
||||
``xdp_buff->data_meta`` is pointing to ``xdp_buff->data`` before presenting the
|
||||
frame to the XDP program. This is necessary so that, after the XDP program
|
||||
adjusts the metadata area, the consumer can reliably retrieve the metadata
|
||||
address using ``METADATA_SIZE`` offset.
|
||||
|
||||
The following diagram shows how custom metadata is positioned relative to the
|
||||
packet data and how pointers are adjusted for metadata access::
|
||||
|
||||
|<-- bpf_xdp_adjust_meta(xdp_buff, -METADATA_SIZE) --|
|
||||
new xdp_buff->data_meta old xdp_buff->data_meta
|
||||
| |
|
||||
| xdp_buff->data
|
||||
| |
|
||||
+----------+----------------------------------------------------+------+
|
||||
| headroom | custom metadata | data |
|
||||
+----------+----------------------------------------------------+------+
|
||||
| |
|
||||
| xdp_desc->addr
|
||||
|<------ xsk_umem__get_data() - METADATA_SIZE -------|
|
||||
|
||||
``bpf_xdp_adjust_meta`` ensures that ``METADATA_SIZE`` is aligned to 4 bytes,
|
||||
does not exceed 252 bytes, and leaves sufficient space for building the
|
||||
xdp_frame. If these conditions are not met, it returns a negative error. In this
|
||||
case, the BPF program should not proceed to populate data into the ``data_meta``
|
||||
area.
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue