From patchwork Tue Nov 7 03:12:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 13447841 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 8849BDF6C; Tue, 7 Nov 2023 03:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CE40D71; Mon, 6 Nov 2023 19:12:47 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0VvsPa.7_1699326764; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0VvsPa.7_1699326764) by smtp.aliyun-inc.com; Tue, 07 Nov 2023 11:12:45 +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-foundation.org, bpf@vger.kernel.org Subject: [PATCH net-next v2 14/21] virtio_net: xsk: tx: virtnet_free_old_xmit() distinguishes xsk buffer Date: Tue, 7 Nov 2023 11:12:20 +0800 Message-Id: <20231107031227.100015-15-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20231107031227.100015-1-xuanzhuo@linux.alibaba.com> References: <20231107031227.100015-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: 59a160d210e8 X-Patchwork-Delegate: kuba@kernel.org virtnet_free_old_xmit distinguishes three type ptr(skb, xdp frame, xsk buffer) by the last bits of the pointer. Signed-off-by: Xuan Zhuo --- drivers/net/virtio/virtio_net.h | 18 ++++++++++++++++-- drivers/net/virtio/xsk.h | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio/virtio_net.h b/drivers/net/virtio/virtio_net.h index a431a2c1ee47..a13d6d301fdb 100644 --- a/drivers/net/virtio/virtio_net.h +++ b/drivers/net/virtio/virtio_net.h @@ -225,6 +225,11 @@ struct virtnet_info { struct failover *failover; }; +static inline bool virtnet_is_skb_ptr(void *ptr) +{ + return !((unsigned long)ptr & VIRTIO_XMIT_DATA_MASK); +} + static inline bool virtnet_is_xdp_frame(void *ptr) { return (unsigned long)ptr & VIRTIO_XDP_FLAG; @@ -235,6 +240,8 @@ static inline struct xdp_frame *virtnet_ptr_to_xdp(void *ptr) return (struct xdp_frame *)((unsigned long)ptr & ~VIRTIO_XDP_FLAG); } +static inline u32 virtnet_ptr_to_xsk(void *ptr); + static inline void *virtnet_sq_unmap(struct virtnet_sq *sq, void *data) { struct virtnet_sq_dma *next, *head; @@ -261,11 +268,12 @@ static inline void *virtnet_sq_unmap(struct virtnet_sq *sq, void *data) static inline void virtnet_free_old_xmit(struct virtnet_sq *sq, bool in_napi, u64 *bytes, u64 *packets) { + unsigned int xsknum = 0; unsigned int len; void *ptr; while ((ptr = virtqueue_get_buf(sq->vq, &len)) != NULL) { - if (!virtnet_is_xdp_frame(ptr)) { + if (virtnet_is_skb_ptr(ptr)) { struct sk_buff *skb; if (sq->do_dma) @@ -277,7 +285,7 @@ static inline void virtnet_free_old_xmit(struct virtnet_sq *sq, bool in_napi, *bytes += skb->len; napi_consume_skb(skb, in_napi); - } else { + } else if (virtnet_is_xdp_frame(ptr)) { struct xdp_frame *frame; if (sq->do_dma) @@ -287,9 +295,15 @@ static inline void virtnet_free_old_xmit(struct virtnet_sq *sq, bool in_napi, *bytes += xdp_get_frame_len(frame); xdp_return_frame(frame); + } else { + *bytes += virtnet_ptr_to_xsk(ptr); + ++xsknum; } (*packets)++; } + + if (xsknum) + xsk_tx_completed(sq->xsk.pool, xsknum); } static inline bool virtnet_is_xdp_raw_buffer_queue(struct virtnet_info *vi, int q) diff --git a/drivers/net/virtio/xsk.h b/drivers/net/virtio/xsk.h index 1bd19dcda649..7ebc9bda7aee 100644 --- a/drivers/net/virtio/xsk.h +++ b/drivers/net/virtio/xsk.h @@ -14,6 +14,11 @@ static inline void *virtnet_xsk_to_ptr(u32 len) return (void *)(p | VIRTIO_XSK_FLAG); } +static inline u32 virtnet_ptr_to_xsk(void *ptr) +{ + return ((unsigned long)ptr) >> VIRTIO_XSK_FLAG_OFFSET; +} + int virtnet_xsk_pool_setup(struct net_device *dev, struct netdev_bpf *xdp); bool virtnet_xsk_xmit(struct virtnet_sq *sq, struct xsk_buff_pool *pool, int budget);