Skip to content

Commit 88a938e

Browse files
josh8551021NipaLocal
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]> Signed-off-by: NipaLocal <nipa@local>
1 parent 2a4c04d commit 88a938e

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
@@ -547,6 +547,29 @@ static int gve_rx_append_frags(struct napi_struct *napi,
547547
return 0;
548548
}
549549

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

@@ -634,6 +658,34 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx,
634658
return 0;
635659
}
636660

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

0 commit comments

Comments
 (0)