From patchwork Wed May 8 08:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 13658222 X-Patchwork-Delegate: kuba@kernel.org Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B1AE3DB97; Wed, 8 May 2024 08:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715155527; cv=none; b=Igt1PlEp0bjfByIt/0KzpiOCwX/ZQ2ugbIy2CrL+YdTgSD9M1e+A8h45B2vHghS1eqIyaTl/Zqm1EyzLIba2zcVAB7A8jz95neCnkNg2sY5BRnBn6eYk5h3OcNGHAT7DKiVEZpL/DeWMm8VQgqzInTGKLcppbXk2yXLGn6J4pYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715155527; c=relaxed/simple; bh=VMUxWSl8uUVpLwAHa7JqMJtkdB/te4DfTUeCmh/Veps=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j7l3QOBIOcQcxDc0n0kbemCmNTgHH4EmnA5B88ppBXzuMsPVpGrR6vpxrzRK3iYNHO3RJtT3raPCPyLtyjLZ2XjeK9Z3nZmpZtejxsxQkPHgJ5ijqCcv88XrkQP1uX7FMKesrLD7DHfEq6B2Txsnwt+5I7Jk4CKMbiGGx3l17YQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=s4Hiev37; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="s4Hiev37" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715155522; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=numEyLfKrc8BrggaD6w89XqKLobUp/B878FtwYeJTmA=; b=s4Hiev379bDMbNedmBwFwoz5aD/bQV2mbXlZWFdbKL3YYIg4KupKJPr1YM81+PtimYUAAJ3WVyC+mwvENQBuDx+4aR0PX007PgAJS/x4oNOw3qN6xrbK3h8bmjAwi6TGa1QTWz2U/CBY842WUYP8MpXkK4GMmjZYMC2sDtrgW7k= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045046011;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0W62sQgk_1715155520; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W62sQgk_1715155520) by smtp.aliyun-inc.com; Wed, 08 May 2024 16:05:21 +0800 From: Xuan Zhuo To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , virtualization@lists.linux.dev, bpf@vger.kernel.org Subject: [PATCH net-next 4/7] virtio_net: separate virtnet_rx_resize() Date: Wed, 8 May 2024 16:05:11 +0800 Message-Id: <20240508080514.99458-5-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240508080514.99458-1-xuanzhuo@linux.alibaba.com> References: <20240508080514.99458-1-xuanzhuo@linux.alibaba.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Git-Hash: 7cdcbabd0b89 X-Patchwork-Delegate: kuba@kernel.org This patch separates two sub-functions from virtnet_rx_resize(): * virtnet_rx_pause * virtnet_rx_resume Then the subsequent reset rx for xsk can share these two functions. Signed-off-by: Xuan Zhuo Acked-by: Jason Wang --- drivers/net/virtio/virtnet.h | 3 +++ drivers/net/virtio/virtnet_main.c | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/net/virtio/virtnet.h b/drivers/net/virtio/virtnet.h index 4d902a79bde7..f95a75751a9b 100644 --- a/drivers/net/virtio/virtnet.h +++ b/drivers/net/virtio/virtnet.h @@ -234,4 +234,7 @@ struct virtnet_info { u64 device_stats_cap; }; + +void virtnet_rx_pause(struct virtnet_info *vi, struct virtnet_rq *rq); +void virtnet_rx_resume(struct virtnet_info *vi, struct virtnet_rq *rq); #endif diff --git a/drivers/net/virtio/virtnet_main.c b/drivers/net/virtio/virtnet_main.c index f9f01c10dff6..aa382fbc52d6 100644 --- a/drivers/net/virtio/virtnet_main.c +++ b/drivers/net/virtio/virtnet_main.c @@ -2358,28 +2358,41 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } -static int virtnet_rx_resize(struct virtnet_info *vi, - struct virtnet_rq *rq, u32 ring_num) +void virtnet_rx_pause(struct virtnet_info *vi, struct virtnet_rq *rq) { bool running = netif_running(vi->dev); - int err, qindex; - - qindex = rq - vi->rq; if (running) { napi_disable(&rq->napi); cancel_work_sync(&rq->dim.work); } +} - err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf); - if (err) - netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err); +void virtnet_rx_resume(struct virtnet_info *vi, struct virtnet_rq *rq) +{ + bool running = netif_running(vi->dev); if (!try_fill_recv(vi, rq, GFP_KERNEL)) schedule_delayed_work(&vi->refill, 0); if (running) virtnet_napi_enable(rq->vq, &rq->napi); +} + +static int virtnet_rx_resize(struct virtnet_info *vi, + struct virtnet_rq *rq, u32 ring_num) +{ + int err, qindex; + + qindex = rq - vi->rq; + + virtnet_rx_pause(vi, rq); + + err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf); + if (err) + netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err); + + virtnet_rx_resume(vi, rq); return err; }