From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50A66C4BA06 for ; Wed, 26 Feb 2020 00:58:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22FD222464 for ; Wed, 26 Feb 2020 00:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582678685; bh=lZKyUgaTT6f+F71KbAvc2/3FwiSgqPc3XQVqexI06+o=; h=From:To:Cc:Subject:Date:List-ID:From; b=y43vqXZ9VEbMP1mzapVuCUwsPm8Gez51ApvAb08IXMVUy+FTl5kxyTY/EbqAlRj9p Aoj2lXV0tj8mGb2MutlLlxH1QMJaBQC+UxKH4RLnBkfWpcUWMT1esOlu0ddwIydDoA N7vf6lnN2TXD6wohIOibDMxM3qwM4A/XJbyA+w8g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729450AbgBZA6E (ORCPT ); Tue, 25 Feb 2020 19:58:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:60290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729277AbgBZA6E (ORCPT ); Tue, 25 Feb 2020 19:58:04 -0500 Received: from C02YQ0RWLVCF.internal.digitalocean.com (c-73-181-34-237.hsd1.co.comcast.net [73.181.34.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 41E8221927; Wed, 26 Feb 2020 00:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582678683; bh=lZKyUgaTT6f+F71KbAvc2/3FwiSgqPc3XQVqexI06+o=; h=From:To:Cc:Subject:Date:From; b=LPU+PsxcNkGTOJbGKWPnKhMXXD+7u/kSsgUbyZzb75qJj3XUfOdvCII+6yTAjNNeM 89RmprvzkqF2QX4czODCz8J09qfYR86I7v5FHJrZiTMs0nH3AQXs2VRVlv/bX7km/v 0LG6JF8AlTdq4vwnTEc9jWcbrIjgOK5AH7LrwBZM= From: David Ahern To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, David Ahern , Jason Wang , "Michael S . Tsirkin" Subject: [PATCH RFC net-next] virtio_net: Relax queue requirement for using XDP Date: Tue, 25 Feb 2020 17:57:44 -0700 Message-Id: <20200226005744.1623-1-dsahern@kernel.org> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Ahern 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 Cc: Michael S. Tsirkin Signed-off-by: David Ahern --- 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