On 11/10/26 04:56, Tianyi Gao wrote:
Reserve the skb core extension area in the headroom, right after the
xdp_frame. An XDP program stores RX metadata there for the skb that is
built later.

The area begins with a header, struct xdp_skb_ext. It records the offset
of each entry and the end of the last entry, in 4-byte units.
bpf_xdp_adjust_head(), bpf_xdp_adjust_meta() and bpf_xdp_pull_data() use
xdp_skb_ext_end() as their lower bound, so packet data and metadata
cannot overwrite the entries.

The XDP_FLAGS_HAS_SKB_EXT flag indicates that the header is valid. Most
drivers reuse the xdp_buff between packets, so xdp_prepare_buff() clears
it. With BPF_F_TEST_XDP_LIVE_FRAMES, reset_ctx() restores the flags
before each run, and ctx_was_changed() compares them.

Suggested-by: Jesper Dangaard Brouer <[email protected]>
Link: 
https://lore.kernel.org/all/[email protected]/
Signed-off-by: Tianyi Gao <[email protected]>
---
  include/net/xdp.h  | 45 +++++++++++++++++++++++++++++++++++++++++++++
  net/bpf/test_run.c |  4 +++-
  net/core/filter.c  |  8 +++-----
  3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f8..c888353425d4 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -81,6 +81,9 @@ enum xdp_buff_flags {
         * XDP program is not attached.
         */
        XDP_FLAGS_FRAGS_UNREADABLE      = BIT(2),
+       XDP_FLAGS_HAS_SKB_EXT           = BIT(3), /* skb core extension header
+                                                  * is valid
+                                                  */

This can be on 1-line (80 chars) of you change the comment to be:
 /* skb core ext hdr valid */

  };
The rest looks good to me.

Acked-by: Jesper Dangaard Brouer <[email protected]>

Reply via email to