On 11/12/26 15:55, Tianyi Gao wrote:
> Hi Alexei,
>
> On Thu, 12 Nov 2026 00:34:54 +0000, Alexei Starovoitov wrote:
>> I'm with Stan on this. It looks heavy.
>>
>> How about the following idea:
>
> Thank you very much for the patch and the idea. I really appreciate it!
>
> v1 uses the skb_ext-like layout mainly because of the earlier pushback
> on a fixed struct [1][2]. This series adds only the three most commonly
> needed types of RX metadata. A 12-byte fixed struct that takes headroom
> only when any RX metadata is stored can be a reasonable middle ground.
>
> I would like to hear from Jesper and Jakub before I move to v2.
>
Short version: the RX metadata must travel with the xdp_frame, in a
format the kernel knows. Fixed struct or skb_ext-like is secondary.
Jakub, this builds on your "driver always populates" idea [1].
I like Alexei's fixed struct, and I have changed my mind. In July I
proposed the skb_ext-like layout [2]. A fixed struct is simpler and
good enough. The fields are HW offloads that map to fixed skb members
(hash, VLAN, csum). The list is short and stable: 12 bytes today, and
below 24 bytes even with RX timestamp and RX queue index. It stays
inside the cache line of the xdp_frame.
Our main use case is XDP_REDIRECT into cpumap and veth. There, core
code builds the skb from the xdp_frame on another CPU: the cpumap
kthread, or veth in threaded NAPI mode, which we run in production.
Today the RX hash and the csum status are lost on the way. GRO on the
remote CPU then puts all flows in one bucket, and veth verifies every
checksum in software.
The values could travel in data_meta, with a second XDP prog at the
target that calls a setter. We do not want that. data_meta is a
contract between BPF progs, in a format the kernel does not know. And
it needs a BPF prog at every place an skb is built, also on veths
where a service owns the XDP prog.
Jakub, I know your objection is the model, not only the layout [3].
How I see it: the RX descriptor is a HW ABI. The NIC defines and
writes it, the kernel only reads it. The xmo callbacks (xmo_rx_hash,
xmo_rx_vlan_tag, ...) read the descriptor and decode it into one
common format, which maps to the skb.
A per-driver setter must store the value in one of two places:
- Back in the descriptor, in HW format. That is device-owned memory,
and some values have no field there (e.g. csum_level).
- In driver memory, in the decoded format. Then every driver keeps
its own copy of the same struct, with the same setter.
A kernel-known area after the xdp_frame is that copy, done once.
The bigger reason is the direction. When the kernel knows the format
(fixed struct or skb_ext-like), the xdp_frame becomes a mini-SKB: it
carries what the skb needs, so core code can build the skb. The end
goal is that NIC drivers stop allocating skbs, and send the xdp_frame
into the netstack instead. ice is already close: it builds the skb
with the generic xdp_build_skb_from_buff(), and then fills the fields
from its descriptor. Later, GRO can check an xdp_frame against the
current GRO packet, and skip the skb for every packet it merges. A
per-driver setter cannot get there. Driver-local state is gone when
the frame leaves the driver, and core code cannot read it.
Jakub, I agree with you that the driver should always populate the
area [1]. The difference is when: after the XDP prog has run.
1. The prog runs first. Nothing is populated, so XDP_DROP stays as
fast as today.
2. The prog stores the values it changed, for example the csum status
after a decap [4], or a new or cleared VLAN tag.
3. On XDP_PASS and XDP_REDIRECT, the driver fills the other fields
from its descriptor.
This also fixes XDP_PASS. Today the kernel does not know what XDP
changed, so the driver applies HW info that may no longer match the
packet, and XDP cannot change a stripped VLAN tag at all. We run with
VLAN offload disabled for this reason. A return code like
XDP_PASS_MODIFIED would only say "something changed". With a store,
the BPF-prog corrects exactly the fields it changed. This is the
explicit update/invalidate plan Jakub asked for [5].
--Jesper
[1] https://lore.kernel.org/all/2025…@kernel.org/
[2] https://lore.kernel.org/all/1d55…@kernel.org/
[3] https://lore.kernel.org/all/2026…@kernel.org/
[4] https://lore.kernel.org/all/2026…@kernel.org/
[5] https://lore.kernel.org/all/2026…@kernel.org/