Skip to content

Commit

Permalink
xdp: Add frame size to xdp_buff
Browse files Browse the repository at this point in the history
XDP have evolved to support several frame sizes, but xdp_buff was not
updated with this information. The frame size (frame_sz) member of
xdp_buff is introduced to know the real size of the memory the frame is
delivered in.

When introducing this also make it clear that some tailroom is
reserved/required when creating SKBs using build_skb().

It would also have been an option to introduce a pointer to
data_hard_end (with reserved offset). The advantage with frame_sz is
that (like rxq) drivers only need to setup/assign this value once per
NAPI cycle. Due to XDP-generic (and some drivers) it's not possible to
store frame_sz inside xdp_rxq_info, because it's varies per packet as it
can be based/depend on packet length.

V2: nitpick: deduct -> deduce

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/158945334261.97035.555255657490688547.stgit@firesoul
  • Loading branch information
Jesper Dangaard Brouer authored and Alexei Starovoitov committed May 15, 2020
1 parent d00f26b commit f95f0f9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/net/xdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef __LINUX_NET_XDP_H__
#define __LINUX_NET_XDP_H__

#include <linux/skbuff.h> /* skb_shared_info */

/**
* DOC: XDP RX-queue information
*
Expand Down Expand Up @@ -70,8 +72,19 @@ struct xdp_buff {
void *data_hard_start;
unsigned long handle;
struct xdp_rxq_info *rxq;
u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
};

/* Reserve memory area at end-of data area.
*
* This macro reserves tailroom in the XDP buffer by limiting the
* XDP/BPF data access to data_hard_end. Notice same area (and size)
* is used for XDP_PASS, when constructing the SKB via build_skb().
*/
#define xdp_data_hard_end(xdp) \
((xdp)->data_hard_start + (xdp)->frame_sz - \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))

struct xdp_frame {
void *data;
u16 len;
Expand Down

0 comments on commit f95f0f9

Please sign in to comment.