From patchwork Mon Nov 2 12:48:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1392219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CPt5l6D4wz9sWM; Mon, 2 Nov 2020 23:49:15 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kZZGn-0005yW-6X; Mon, 02 Nov 2020 12:49:09 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kZZGk-0005wT-Jj for kernel-team@lists.ubuntu.com; Mon, 02 Nov 2020 12:49:06 +0000 Received: from mail-qt1-f199.google.com ([209.85.160.199]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kZZGk-00043T-6w for kernel-team@lists.ubuntu.com; Mon, 02 Nov 2020 12:49:06 +0000 Received: by mail-qt1-f199.google.com with SMTP id i20so1776083qtr.0 for ; Mon, 02 Nov 2020 04:49:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lZENkfgIrG49WibnHgYdvJkWPI6O/ilQ5xVJKbVQDbM=; b=mTqRQJx/iBWD846SHFuLZeD1wiGcemVgbwM32s8zQiYIMz8j2EV0iIzUyvD0WMExa0 c1Uodw7wW/ciK3vaZeLHhHJ/cx+tHr8oSY7gp6ubuBDwpuvTupFZhyfeCOXBr7KxApvO ru3XuparIp90hKLemOCmJN8d6Y22FgcCRD7wpVRQLJe2HFq0D16HoJMt8FK1TX8APN6p Lv6/vU1Qyr1OjnFeHqsttO4hc5Es4OgCMe07eX1K+QPUkhJpy2AO6uwPnyjGVHO89OUm cIJ+WTJdD/S/RSXKS+JBjVHONZgsP1DRzSQZxf+MXs1dUEzgVN7o+6FRuuFrc10MlPlj pERg== X-Gm-Message-State: AOAM533MuDvWY/Rtx7FdhWBk4X0hukn2DjV+A+EMdl08ciIlVr0KLGuu DU7wDOXeKQRIGua6ukKM886ahcSSbvxD6u/SCfBq19JhtpFaVoLeXhVZYURuAw875gJGGH1Tt8l FB93eWyQ+EC5/WtbKCmeS09xPcLAbT3vt7jrZUImQwQ== X-Received: by 2002:ac8:7b92:: with SMTP id p18mr4236412qtu.105.1604321345025; Mon, 02 Nov 2020 04:49:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaZuu8VmOGneB0ceN6Ubuc04g1WTQxHs4gl0oXllCr81etbQcyRsglilf9EE6M1b8+QK2oWw== X-Received: by 2002:ac8:7b92:: with SMTP id p18mr4236396qtu.105.1604321344802; Mon, 02 Nov 2020 04:49:04 -0800 (PST) Received: from localhost.localdomain (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id q7sm7666201qtd.49.2020.11.02.04.49.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 04:49:04 -0800 (PST) From: William Breathitt Gray To: kernel-team@lists.ubuntu.com Subject: [SRU][B:linux-azure-4.15][PATCH 06/40] virtio_net: setup xdp_rxq_info Date: Mon, 2 Nov 2020 07:48:22 -0500 Message-Id: <20201102124856.4659-7-william.gray@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201102124856.4659-1-william.gray@canonical.com> References: <20201102124856.4659-1-william.gray@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jesper Dangaard Brouer BugLink: https://bugs.launchpad.net/bugs/1877654 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" Cc: Jason Wang Cc: virtualization@lists.linux-foundation.org Signed-off-by: Jesper Dangaard Brouer Reviewed-by: Jason Wang Signed-off-by: Alexei Starovoitov (backported from commit 754b8a21a96d5f11712245aef907149606b323ae) Signed-off-by: William Breathitt Gray --- drivers/net/virtio_net.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 2b6916c012d2..76a1eb622a04 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -31,6 +31,7 @@ #include #include #include +#include static int napi_weight = NAPI_POLL_WEIGHT; module_param(napi_weight, int, 0444); @@ -116,6 +117,8 @@ struct receive_queue { /* Name of this receive queue: input.$index */ char name[40]; + + struct xdp_rxq_info xdp_rxq; }; /* Control VQ buffers: protected by the rtnl lock */ @@ -565,6 +568,7 @@ static struct sk_buff *receive_small(struct net_device *dev, xdp.data = xdp.data_hard_start + xdp_headroom; xdp_set_data_meta_invalid(&xdp); xdp.data_end = xdp.data + len; + xdp.rxq = &rq->xdp_rxq; orig_data = xdp.data; act = bpf_prog_run_xdp(xdp_prog, &xdp); @@ -702,6 +706,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, xdp.data = data + vi->hdr_len; xdp_set_data_meta_invalid(&xdp); xdp.data_end = xdp.data + (len - vi->hdr_len); + xdp.rxq = &rq->xdp_rxq; + act = bpf_prog_run_xdp(xdp_prog, &xdp); if (act != XDP_PASS) @@ -1257,13 +1263,18 @@ static int virtnet_poll(struct napi_struct *napi, int budget) static int virtnet_open(struct net_device *dev) { struct virtnet_info *vi = netdev_priv(dev); - int i; + int i, err; for (i = 0; i < vi->max_queue_pairs; i++) { if (i < vi->curr_queue_pairs) /* Make sure we have some buffers: if oom use wq. */ if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL)) schedule_delayed_work(&vi->refill, 0); + + err = xdp_rxq_info_reg(&vi->rq[i].xdp_rxq, dev, i); + if (err < 0) + return err; + virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); virtnet_napi_tx_enable(vi, vi->sq[i].vq, &vi->sq[i].napi); } @@ -1601,6 +1612,7 @@ static int virtnet_close(struct net_device *dev) cancel_delayed_work_sync(&vi->refill); for (i = 0; i < vi->max_queue_pairs; i++) { + xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq); napi_disable(&vi->rq[i].napi); virtnet_napi_tx_disable(&vi->sq[i].napi); }