Commit 73b7123d authored by Jesper Dangaard Brouer's avatar Jesper Dangaard Brouer Committed by Daniel Borkmann

igc: Add igc_xdp_buff wrapper for xdp_buff in driver

Driver specific metadata data for XDP-hints kfuncs are propagated via tail
extending the struct xdp_buff with a locally scoped driver struct.

Zero-Copy AF_XDP/XSK does similar tricks via struct xdp_buff_xsk. This
xdp_buff_xsk struct contains a CB area (24 bytes) that can be used for
extending the locally scoped driver into. The XSK_CHECK_PRIV_TYPE define
catch size violations build time.

The changes needed for AF_XDP zero-copy in igc_clean_rx_irq_zc()
is done in next patch, because the member rx_desc isn't available
at this point.
Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarSong Yoong Siang <yoong.siang.song@intel.com>
Link: https://lore.kernel.org/bpf/168182464779.616355.3761989884165609387.stgit@firesoul
parent 84214ab4
...@@ -499,6 +499,11 @@ struct igc_rx_buffer { ...@@ -499,6 +499,11 @@ struct igc_rx_buffer {
}; };
}; };
/* context wrapper around xdp_buff to provide access to descriptor metadata */
struct igc_xdp_buff {
struct xdp_buff xdp;
};
struct igc_q_vector { struct igc_q_vector {
struct igc_adapter *adapter; /* backlink */ struct igc_adapter *adapter; /* backlink */
void __iomem *itr_register; void __iomem *itr_register;
......
...@@ -2233,6 +2233,8 @@ static bool igc_alloc_rx_buffers_zc(struct igc_ring *ring, u16 count) ...@@ -2233,6 +2233,8 @@ static bool igc_alloc_rx_buffers_zc(struct igc_ring *ring, u16 count)
if (!count) if (!count)
return ok; return ok;
XSK_CHECK_PRIV_TYPE(struct igc_xdp_buff);
desc = IGC_RX_DESC(ring, i); desc = IGC_RX_DESC(ring, i);
bi = &ring->rx_buffer_info[i]; bi = &ring->rx_buffer_info[i];
i -= ring->count; i -= ring->count;
...@@ -2517,8 +2519,8 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) ...@@ -2517,8 +2519,8 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
union igc_adv_rx_desc *rx_desc; union igc_adv_rx_desc *rx_desc;
struct igc_rx_buffer *rx_buffer; struct igc_rx_buffer *rx_buffer;
unsigned int size, truesize; unsigned int size, truesize;
struct igc_xdp_buff ctx;
ktime_t timestamp = 0; ktime_t timestamp = 0;
struct xdp_buff xdp;
int pkt_offset = 0; int pkt_offset = 0;
void *pktbuf; void *pktbuf;
...@@ -2552,13 +2554,13 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) ...@@ -2552,13 +2554,13 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
} }
if (!skb) { if (!skb) {
xdp_init_buff(&xdp, truesize, &rx_ring->xdp_rxq); xdp_init_buff(&ctx.xdp, truesize, &rx_ring->xdp_rxq);
xdp_prepare_buff(&xdp, pktbuf - igc_rx_offset(rx_ring), xdp_prepare_buff(&ctx.xdp, pktbuf - igc_rx_offset(rx_ring),
igc_rx_offset(rx_ring) + pkt_offset, igc_rx_offset(rx_ring) + pkt_offset,
size, true); size, true);
xdp_buff_clear_frags_flag(&xdp); xdp_buff_clear_frags_flag(&ctx.xdp);
skb = igc_xdp_run_prog(adapter, &xdp); skb = igc_xdp_run_prog(adapter, &ctx.xdp);
} }
if (IS_ERR(skb)) { if (IS_ERR(skb)) {
...@@ -2580,9 +2582,9 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget) ...@@ -2580,9 +2582,9 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
} else if (skb) } else if (skb)
igc_add_rx_frag(rx_ring, rx_buffer, skb, size); igc_add_rx_frag(rx_ring, rx_buffer, skb, size);
else if (ring_uses_build_skb(rx_ring)) else if (ring_uses_build_skb(rx_ring))
skb = igc_build_skb(rx_ring, rx_buffer, &xdp); skb = igc_build_skb(rx_ring, rx_buffer, &ctx.xdp);
else else
skb = igc_construct_skb(rx_ring, rx_buffer, &xdp, skb = igc_construct_skb(rx_ring, rx_buffer, &ctx.xdp,
timestamp); timestamp);
/* exit if we failed to retrieve a buffer */ /* exit if we failed to retrieve a buffer */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment