Skip to content

Commit 293b493

Browse files
josh8551021kuba-moo
authored andcommitted
gve: add XDP DROP and PASS support for DQ
This patch adds support for running XDP programs on DQ, along with rudimentary processing for XDP_DROP and XDP_PASS. These actions require very limited driver functionality when it comes to processing an XDP buffer, so currently if the XDP action is not XDP_PASS, the packet is dropped and stats are updated. Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: Praveen Kaliginedi <[email protected]> Signed-off-by: Joshua Washington <[email protected]> Signed-off-by: Harshitha Ramamurthy<[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 346fb86 commit 293b493

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

drivers/net/ethernet/google/gve/gve_rx_dqo.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,29 @@ static int gve_rx_append_frags(struct napi_struct *napi,
546546
return 0;
547547
}
548548

549+
static void gve_xdp_done_dqo(struct gve_priv *priv, struct gve_rx_ring *rx,
550+
struct xdp_buff *xdp, struct bpf_prog *xprog,
551+
int xdp_act,
552+
struct gve_rx_buf_state_dqo *buf_state)
553+
{
554+
u64_stats_update_begin(&rx->statss);
555+
switch (xdp_act) {
556+
case XDP_ABORTED:
557+
case XDP_DROP:
558+
default:
559+
rx->xdp_actions[xdp_act]++;
560+
break;
561+
case XDP_TX:
562+
rx->xdp_tx_errors++;
563+
break;
564+
case XDP_REDIRECT:
565+
rx->xdp_redirect_errors++;
566+
break;
567+
}
568+
u64_stats_update_end(&rx->statss);
569+
gve_free_buffer(rx, buf_state);
570+
}
571+
549572
/* Returns 0 if descriptor is completed successfully.
550573
* Returns -EINVAL if descriptor is invalid.
551574
* Returns -ENOMEM if data cannot be copied to skb.
@@ -560,6 +583,7 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx,
560583
const bool hsplit = compl_desc->split_header;
561584
struct gve_rx_buf_state_dqo *buf_state;
562585
struct gve_priv *priv = rx->gve;
586+
struct bpf_prog *xprog;
563587
u16 buf_len;
564588
u16 hdr_len;
565589

@@ -633,6 +657,34 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx,
633657
return 0;
634658
}
635659

660+
xprog = READ_ONCE(priv->xdp_prog);
661+
if (xprog) {
662+
struct xdp_buff xdp;
663+
void *old_data;
664+
int xdp_act;
665+
666+
xdp_init_buff(&xdp, buf_state->page_info.buf_size,
667+
&rx->xdp_rxq);
668+
xdp_prepare_buff(&xdp,
669+
buf_state->page_info.page_address +
670+
buf_state->page_info.page_offset,
671+
buf_state->page_info.pad,
672+
buf_len, false);
673+
old_data = xdp.data;
674+
xdp_act = bpf_prog_run_xdp(xprog, &xdp);
675+
buf_state->page_info.pad += xdp.data - old_data;
676+
buf_len = xdp.data_end - xdp.data;
677+
if (xdp_act != XDP_PASS) {
678+
gve_xdp_done_dqo(priv, rx, &xdp, xprog, xdp_act,
679+
buf_state);
680+
return 0;
681+
}
682+
683+
u64_stats_update_begin(&rx->statss);
684+
rx->xdp_actions[XDP_PASS]++;
685+
u64_stats_update_end(&rx->statss);
686+
}
687+
636688
if (eop && buf_len <= priv->rx_copybreak) {
637689
rx->ctx.skb_head = gve_rx_copy(priv->dev, napi,
638690
&buf_state->page_info, buf_len);

0 commit comments

Comments
 (0)