diff options
author | Jesper Dangaard Brouer <brouer@redhat.com> | 2018-02-20 08:32:20 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-02-21 15:09:29 -0500 |
commit | 8dcc5b0ab0ec9a2efb3362d380272546b8b2ee26 (patch) | |
tree | 5986e0b30af64482afd65ea8e6013cf2fff241bb | |
parent | 11b7d897ccc1fb5a3d3f9eb1e6b4574671e5dd7d (diff) |
virtio_net: fix ndo_xdp_xmit crash towards dev not ready for XDP
When a driver implements the ndo_xdp_xmit() function, there is
(currently) no generic way to determine whether it is safe to call.
It is e.g. unsafe to call the drivers ndo_xdp_xmit, if it have not
allocated the needed XDP TX queues yet. This is the case for
virtio_net, which first allocates the XDP TX queues once an XDP/bpf
prog is attached (in virtnet_xdp_set()).
Thus, a crash will occur for virtio_net when redirecting to another
virtio_net device's ndo_xdp_xmit, which have not attached a XDP prog.
The sample xdp_redirect_map tries to attach a dummy XDP prog to take
this into account, but it can also easily fail if the virtio_net (or
actually underlying vhost driver) have not allocated enough extra
queues for the device.
Allocating more queue this is currently a manual config.
Hint for libvirt XML add:
<driver name='vhost' queues='16'>
<host mrg_rxbuf='off'/>
<guest tso4='off' tso6='off' ecn='off' ufo='off'/>
</driver>
The solution in this patch is to check that the device have loaded an
XDP/bpf prog before proceeding. This is similar to the check
performed in driver ixgbe.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/virtio_net.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 1e0e0fce3ab2..9bb9e562b893 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -452,8 +452,18 @@ static bool __virtnet_xdp_xmit(struct virtnet_info *vi, | |||
452 | static int virtnet_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp) | 452 | static int virtnet_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp) |
453 | { | 453 | { |
454 | struct virtnet_info *vi = netdev_priv(dev); | 454 | struct virtnet_info *vi = netdev_priv(dev); |
455 | bool sent = __virtnet_xdp_xmit(vi, xdp); | 455 | struct receive_queue *rq = vi->rq; |
456 | struct bpf_prog *xdp_prog; | ||
457 | bool sent; | ||
458 | |||
459 | /* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this | ||
460 | * indicate XDP resources have been successfully allocated. | ||
461 | */ | ||
462 | xdp_prog = rcu_dereference(rq->xdp_prog); | ||
463 | if (!xdp_prog) | ||
464 | return -ENXIO; | ||
456 | 465 | ||
466 | sent = __virtnet_xdp_xmit(vi, xdp); | ||
457 | if (!sent) | 467 | if (!sent) |
458 | return -ENOSPC; | 468 | return -ENOSPC; |
459 | return 0; | 469 | return 0; |