Skip to content

Commit 6dfbf20

Browse files
netoptimizerKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
net: xdp: update documentation for xdp-rx-metadata.rst
Update the documentation[1] based on the changes in this patchset. [1] https://docs.kernel.org/networking/xdp-rx-metadata.html Signed-off-by: Jesper Dangaard Brouer <[email protected]>
1 parent 422501c commit 6dfbf20

File tree

2 files changed

+90
-16
lines changed

2 files changed

+90
-16
lines changed

Documentation/networking/xdp-rx-metadata.rst

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,64 @@ the ``data_meta`` pointer.
9090
In the future, we'd like to support a case where an XDP program
9191
can override some of the metadata used for building ``skbs``.
9292

93-
bpf_redirect_map
94-
================
95-
96-
``bpf_redirect_map`` can redirect the frame to a different device.
97-
Some devices (like virtual ethernet links) support running a second XDP
98-
program after the redirect. However, the final consumer doesn't have
99-
access to the original hardware descriptor and can't access any of
100-
the original metadata. The same applies to XDP programs installed
101-
into devmaps and cpumaps.
102-
103-
This means that for redirected packets only custom metadata is
104-
currently supported, which has to be prepared by the initial XDP program
105-
before redirect. If the frame is eventually passed to the kernel, the
106-
``skb`` created from such a frame won't have any hardware metadata populated
107-
in its ``skb``. If such a packet is later redirected into an ``XSK``,
108-
that will also only have access to the custom metadata.
93+
XDP_REDIRECT
94+
============
95+
96+
The ``XDP_REDIRECT`` action forwards an XDP frame to another net device or a CPU
97+
(via cpumap/devmap) for further processing. It is invoked using BPF helpers like
98+
``bpf_redirect_map()`` or ``bpf_redirect()``. When an XDP frame is redirected,
99+
the recipient (e.g., an XDP program on a veth device, or the kernel stack via
100+
cpumap) loses direct access to the original NIC's hardware descriptor and thus
101+
its hardware metadata
102+
103+
By default, this loss of access means that if an ``xdp_frame`` is redirected and
104+
then converted to an ``skb``, its ``skb`` fields for hardware-derived metadata
105+
(like ``skb->hash`` or VLAN info) are not populated from the original
106+
packet. This can impact features like Generic Receive Offload (GRO). While XDP
107+
programs can manually save custom data (e.g., using ``bpf_xdp_adjust_meta()``),
108+
propagating specific *hardware* RX hints to ``skb`` creation requires using the
109+
kfuncs described below.
110+
111+
To enable propagating selected hardware RX hints, store BPF kfuncs allow an
112+
XDP program on the initial NIC to read these hints and then explicitly
113+
*store* them. The kfuncs place this metadata in locations associated with
114+
the XDP packet buffer, making it available if an ``skb`` is later built or
115+
the frame is otherwise processed. For instance, RX hash and VLAN tags are
116+
stored within the XDP frame's addressable headroom, while RX timestamps are
117+
typically written to an area corresponding to ``skb_shared_info``.
118+
119+
**Crucially, the BPF programmer must call these "store" kfuncs to save the
120+
desired hardware hints for propagation.** The system does not do this
121+
automatically. The NIC driver is responsible for ensuring sufficient headroom is
122+
available; kfuncs may return ``-ENOSPC`` if space is inadequate for storing
123+
these hints.
124+
125+
When these kfuncs are used to store hints before redirection:
126+
127+
* If the ``xdp_frame`` is converted to an ``skb``, the networking stack can use
128+
the stored hints to populate ``skb`` fields (e.g., ``skb->hash``,
129+
``skb->vlan_tci``, timestamps), aiding netstack features like GRO.
130+
* When running a second XDP-program after the redirect. The veth driver supports
131+
access to the previous stored metadata is accessed though the normal reader
132+
kfuncs.
133+
134+
Kfuncs are available for storing RX hash (``bpf_xdp_store_rx_hash()``),
135+
VLAN information (``bpf_xdp_store_rx_vlan()``), and hardware timestamps
136+
(``bpf_xdp_store_rx_ts()``). Consult the kfunc API documentation for usage
137+
details, expected data, return codes, and relevant XDP flags that may
138+
indicate success or metadata availability.
139+
140+
Kfuncs for **store** operations:
141+
142+
.. kernel-doc:: net/core/xdp.c
143+
:identifiers: bpf_xdp_store_rx_timestamp
144+
145+
.. kernel-doc:: net/core/xdp.c
146+
:identifiers: bpf_xdp_store_rx_hash
147+
148+
.. kernel-doc:: net/core/xdp.c
149+
:identifiers: bpf_xdp_store_rx_vlan_tag
150+
109151

110152
bpf_tail_call
111153
=============

net/core/xdp.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,18 @@ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
990990
return -EOPNOTSUPP;
991991
}
992992

993+
/**
994+
* bpf_xdp_store_rx_hash - Store XDP frame RX hash.
995+
* @ctx: XDP context pointer.
996+
* @hash: 32-bit hash value.
997+
* @rss_type: RSS hash type.
998+
*
999+
* The RSS hash type (@rss_type) is as descibed in bpf_xdp_metadata_rx_hash.
1000+
*
1001+
* Return:
1002+
* * Returns 0 on success or ``-errno`` on error.
1003+
* * ``-NOSPC`` : means device driver doesn't provide enough headroom for storing
1004+
*/
9931005
__bpf_kfunc int bpf_xdp_store_rx_hash(struct xdp_md *ctx, u32 hash,
9941006
enum xdp_rss_hash_type rss_type)
9951007
{
@@ -1005,6 +1017,18 @@ __bpf_kfunc int bpf_xdp_store_rx_hash(struct xdp_md *ctx, u32 hash,
10051017
return 0;
10061018
}
10071019

1020+
/**
1021+
* bpf_xdp_store_rx_vlan_tag - Store XDP packet outermost VLAN tag
1022+
* @ctx: XDP context pointer.
1023+
* @vlan_proto: VLAN protocol stored in **network byte order (BE)**
1024+
* @vlan_tci: VLAN TCI (VID + DEI + PCP) stored in **host byte order**
1025+
*
1026+
* See bpf_xdp_metadata_rx_vlan_tag() for byte order reasoning.
1027+
*
1028+
* Return:
1029+
* * Returns 0 on success or ``-errno`` on error.
1030+
* * ``-NOSPC`` : means device driver doesn't provide enough headroom for storing
1031+
*/
10081032
__bpf_kfunc int bpf_xdp_store_rx_vlan(struct xdp_md *ctx, __be16 vlan_proto,
10091033
u16 vlan_tci)
10101034
{
@@ -1020,6 +1044,14 @@ __bpf_kfunc int bpf_xdp_store_rx_vlan(struct xdp_md *ctx, __be16 vlan_proto,
10201044
return 0;
10211045
}
10221046

1047+
/**
1048+
* bpf_xdp_metadata_rx_timestamp - Store XDP frame RX timestamp.
1049+
* @ctx: XDP context pointer.
1050+
* @timestamp: Timestamp value.
1051+
*
1052+
* Return:
1053+
* * Returns 0 on success or ``-errno`` on error.
1054+
*/
10231055
__bpf_kfunc int bpf_xdp_store_rx_ts(struct xdp_md *ctx, u64 ts)
10241056
{
10251057
struct xdp_buff *xdp = (struct xdp_buff *)ctx;

0 commit comments

Comments
 (0)