Skip to content

Commit 366a88f

Browse files
borkmanndavem330
authored andcommitted
bpf, ixgbe: add meta data support
Implement support for transferring XDP meta data into skb for ixgbe driver; before calling into the program, xdp.data_meta points to xdp.data, where on program return with pass verdict, we call into skb_metadata_set(). We implement this for the default ixgbe_build_skb() variant. For the ixgbe_construct_skb() that is used when legacy-rx buffer mananagement mode is turned on via ethtool, I found that XDP gets 0 headroom, so neither xdp_adjust_head() nor xdp_adjust_meta() can be used with this. Just add a comment with explanation for this operating mode. Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Acked-by: John Fastabend <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 65d88fd commit 366a88f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,21 @@ static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
21332133
#if L1_CACHE_BYTES < 128
21342134
prefetch(xdp->data + L1_CACHE_BYTES);
21352135
#endif
2136+
/* Note, we get here by enabling legacy-rx via:
2137+
*
2138+
* ethtool --set-priv-flags <dev> legacy-rx on
2139+
*
2140+
* In this mode, we currently get 0 extra XDP headroom as
2141+
* opposed to having legacy-rx off, where we process XDP
2142+
* packets going to stack via ixgbe_build_skb(). The latter
2143+
* provides us currently with 192 bytes of headroom.
2144+
*
2145+
* For ixgbe_construct_skb() mode it means that the
2146+
* xdp->data_meta will always point to xdp->data, since
2147+
* the helper cannot expand the head. Should this ever
2148+
* change in future for legacy-rx mode on, then lets also
2149+
* add xdp->data_meta handling here.
2150+
*/
21362151

21372152
/* allocate a skb to store the frags */
21382153
skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
@@ -2165,6 +2180,7 @@ static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
21652180
struct xdp_buff *xdp,
21662181
union ixgbe_adv_rx_desc *rx_desc)
21672182
{
2183+
unsigned int metasize = xdp->data - xdp->data_meta;
21682184
#if (PAGE_SIZE < 8192)
21692185
unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
21702186
#else
@@ -2174,10 +2190,14 @@ static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
21742190
#endif
21752191
struct sk_buff *skb;
21762192

2177-
/* prefetch first cache line of first page */
2178-
prefetch(xdp->data);
2193+
/* Prefetch first cache line of first page. If xdp->data_meta
2194+
* is unused, this points extactly as xdp->data, otherwise we
2195+
* likely have a consumer accessing first few bytes of meta
2196+
* data, and then actual data.
2197+
*/
2198+
prefetch(xdp->data_meta);
21792199
#if L1_CACHE_BYTES < 128
2180-
prefetch(xdp->data + L1_CACHE_BYTES);
2200+
prefetch(xdp->data_meta + L1_CACHE_BYTES);
21812201
#endif
21822202

21832203
/* build an skb to around the page buffer */
@@ -2188,6 +2208,8 @@ static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
21882208
/* update pointers within the skb to store the data */
21892209
skb_reserve(skb, xdp->data - xdp->data_hard_start);
21902210
__skb_put(skb, xdp->data_end - xdp->data);
2211+
if (metasize)
2212+
skb_metadata_set(skb, metasize);
21912213

21922214
/* record DMA address if this is the start of a chain of buffers */
21932215
if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
@@ -2326,7 +2348,7 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
23262348
if (!skb) {
23272349
xdp.data = page_address(rx_buffer->page) +
23282350
rx_buffer->page_offset;
2329-
xdp_set_data_meta_invalid(&xdp);
2351+
xdp.data_meta = xdp.data;
23302352
xdp.data_hard_start = xdp.data -
23312353
ixgbe_rx_offset(rx_ring);
23322354
xdp.data_end = xdp.data + size;

0 commit comments

Comments
 (0)