All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC net-next] virtio_net: Relax queue requirement for using XDP
@ 2020-02-26  0:57 David Ahern
  2020-02-26  1:37 ` Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: David Ahern @ 2020-02-26  0:57 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, David Ahern, Jason Wang, Michael S . Tsirkin

From: David Ahern <dahern@digitalocean.com>

virtio_net currently requires extra queues to install an XDP program,
with the rule being twice as many queues as vcpus. From a host
perspective this means the VM needs to have 2*vcpus vhost threads
for each guest NIC for which XDP is to be allowed. For example, a
16 vcpu VM with 2 tap devices needs 64 vhost threads.

The extra queues are only needed in case an XDP program wants to
return XDP_TX. XDP_PASS, XDP_DROP and XDP_REDIRECT do not need
additional queues. Relax the queue requirement and allow XDP
functionality based on resources. If an XDP program is loaded and
there are insufficient queues, then return a warning to the user
and if a program returns XDP_TX just drop the packet. This allows
the use of the rest of the XDP functionality to work without
putting an unreasonable burden on the host.

Cc: Jason Wang <jasowang@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David Ahern <dahern@digitalocean.com>
---
 drivers/net/virtio_net.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2fe7a3188282..2f4c5b2e674d 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -190,6 +190,8 @@ struct virtnet_info {
 	/* # of XDP queue pairs currently used by the driver */
 	u16 xdp_queue_pairs;
 
+	bool can_do_xdp_tx;
+
 	/* I like... big packets and I cannot lie! */
 	bool big_packets;
 
@@ -697,6 +699,8 @@ static struct sk_buff *receive_small(struct net_device *dev,
 			len = xdp.data_end - xdp.data;
 			break;
 		case XDP_TX:
+			if (!vi->can_do_xdp_tx)
+				goto err_xdp;
 			stats->xdp_tx++;
 			xdpf = convert_to_xdp_frame(&xdp);
 			if (unlikely(!xdpf))
@@ -870,6 +874,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			break;
 		case XDP_TX:
+			if (!vi->can_do_xdp_tx)
+				goto err_xdp;
 			stats->xdp_tx++;
 			xdpf = convert_to_xdp_frame(&xdp);
 			if (unlikely(!xdpf))
@@ -2435,10 +2441,10 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 
 	/* XDP requires extra queues for XDP_TX */
 	if (curr_qp + xdp_qp > vi->max_queue_pairs) {
-		NL_SET_ERR_MSG_MOD(extack, "Too few free TX rings available");
-		netdev_warn(dev, "request %i queues but max is %i\n",
-			    curr_qp + xdp_qp, vi->max_queue_pairs);
-		return -ENOMEM;
+		NL_SET_ERR_MSG_MOD(extack, "Too few free TX rings available; XDP_TX will not be allowed");
+		vi->can_do_xdp_tx = false;
+	} else {
+		vi->can_do_xdp_tx = true;
 	}
 
 	old_prog = rtnl_dereference(vi->rq[0].xdp_prog);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2020-09-29  2:44 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26  0:57 [PATCH RFC net-next] virtio_net: Relax queue requirement for using XDP David Ahern
2020-02-26  1:37 ` Jakub Kicinski
2020-02-26  3:00 ` Jason Wang
2020-02-26  3:24   ` David Ahern
2020-02-26  3:29     ` Jason Wang
2020-02-26  3:34       ` David Ahern
2020-02-26  3:52         ` Jason Wang
2020-02-26  4:35           ` David Ahern
2020-02-26  5:51             ` Jason Wang
2020-02-26  8:19     ` Toke Høiland-Jørgensen
2020-02-26  8:23       ` Michael S. Tsirkin
2020-02-26  8:34         ` Toke Høiland-Jørgensen
2020-02-26  8:42           ` Michael S. Tsirkin
2020-02-26  9:02             ` Toke Høiland-Jørgensen
2020-02-26  9:32               ` Michael S. Tsirkin
2020-02-26 15:58           ` David Ahern
2020-02-26 16:21             ` Toke Høiland-Jørgensen
2020-02-26 17:08             ` Michael S. Tsirkin
2020-02-26 21:31               ` Toke Høiland-Jørgensen
2020-02-27  3:27           ` David Ahern
2020-02-27 10:19             ` Toke Høiland-Jørgensen
2020-02-27 10:41               ` Magnus Karlsson
2020-09-28  3:13                 ` David Ahern
2020-09-28 14:25                   ` Magnus Karlsson
2020-09-29  2:44                     ` David Ahern
2020-02-26  6:48   ` Michael S. Tsirkin
2020-02-26  7:28     ` Jason Wang
2020-02-26  8:21       ` Michael S. Tsirkin
2020-02-26  6:43 ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.