Skip to content

Commit 754b8a2

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
virtio_net: setup xdp_rxq_info
The virtio_net driver doesn't dynamically change the RX-ring queue layout and backing pages, but instead reject XDP setup if all the conditions for XDP is not meet. Thus, the xdp_rxq_info also remains fairly static. This allow us to simply add the reg/unreg to net_device open/close functions. Driver hook points for xdp_rxq_info: * reg : virtnet_open * unreg: virtnet_close V3: - bugfix, also setup xdp.rxq in receive_mergeable() - Tested bpf-sample prog inside guest on a virtio_net device Cc: "Michael S. Tsirkin" <[email protected]> Cc: Jason Wang <[email protected]> Cc: [email protected] Signed-off-by: Jesper Dangaard Brouer <[email protected]> Reviewed-by: Jason Wang <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 8bf5c4e commit 754b8a2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/net/virtio_net.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/average.h>
3232
#include <linux/filter.h>
3333
#include <net/route.h>
34+
#include <net/xdp.h>
3435

3536
static int napi_weight = NAPI_POLL_WEIGHT;
3637
module_param(napi_weight, int, 0444);
@@ -115,6 +116,8 @@ struct receive_queue {
115116

116117
/* Name of this receive queue: input.$index */
117118
char name[40];
119+
120+
struct xdp_rxq_info xdp_rxq;
118121
};
119122

120123
struct virtnet_info {
@@ -559,6 +562,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
559562
xdp.data = xdp.data_hard_start + xdp_headroom;
560563
xdp_set_data_meta_invalid(&xdp);
561564
xdp.data_end = xdp.data + len;
565+
xdp.rxq = &rq->xdp_rxq;
562566
orig_data = xdp.data;
563567
act = bpf_prog_run_xdp(xdp_prog, &xdp);
564568

@@ -692,6 +696,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
692696
xdp.data = data + vi->hdr_len;
693697
xdp_set_data_meta_invalid(&xdp);
694698
xdp.data_end = xdp.data + (len - vi->hdr_len);
699+
xdp.rxq = &rq->xdp_rxq;
700+
695701
act = bpf_prog_run_xdp(xdp_prog, &xdp);
696702

697703
if (act != XDP_PASS)
@@ -1225,13 +1231,18 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
12251231
static int virtnet_open(struct net_device *dev)
12261232
{
12271233
struct virtnet_info *vi = netdev_priv(dev);
1228-
int i;
1234+
int i, err;
12291235

12301236
for (i = 0; i < vi->max_queue_pairs; i++) {
12311237
if (i < vi->curr_queue_pairs)
12321238
/* Make sure we have some buffers: if oom use wq. */
12331239
if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL))
12341240
schedule_delayed_work(&vi->refill, 0);
1241+
1242+
err = xdp_rxq_info_reg(&vi->rq[i].xdp_rxq, dev, i);
1243+
if (err < 0)
1244+
return err;
1245+
12351246
virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
12361247
virtnet_napi_tx_enable(vi, vi->sq[i].vq, &vi->sq[i].napi);
12371248
}
@@ -1560,6 +1571,7 @@ static int virtnet_close(struct net_device *dev)
15601571
cancel_delayed_work_sync(&vi->refill);
15611572

15621573
for (i = 0; i < vi->max_queue_pairs; i++) {
1574+
xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
15631575
napi_disable(&vi->rq[i].napi);
15641576
virtnet_napi_tx_disable(&vi->sq[i].napi);
15651577
}

0 commit comments

Comments
 (0)