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 Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5BE7CC7EE2E for ; Fri, 2 Jun 2023 09:22:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id F103F4177D; Fri, 2 Jun 2023 09:22:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org F103F4177D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 83Sxj4Zsf_03; Fri, 2 Jun 2023 09:22:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 2ED3041774; Fri, 2 Jun 2023 09:22:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 2ED3041774 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 17CDCC008B; Fri, 2 Jun 2023 09:22:25 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1FCDDC0029 for ; Fri, 2 Jun 2023 09:22:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DA9694175C for ; Fri, 2 Jun 2023 09:22:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org DA9694175C X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VMWb2OWyJ5vU for ; Fri, 2 Jun 2023 09:22:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A850941773 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by smtp2.osuosl.org (Postfix) with ESMTPS id A850941773 for ; Fri, 2 Jun 2023 09:22:22 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R861e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046049; MF=xuanzhuo@linux.alibaba.com; NM=1; PH=DS; RN=14; SR=0; TI=SMTPD_---0Vk9LPE-_1685697737; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0Vk9LPE-_1685697737) by smtp.aliyun-inc.com; Fri, 02 Jun 2023 17:22:17 +0800 From: Xuan Zhuo To: virtualization@lists.linux-foundation.org Subject: [PATCH vhost v10 09/10] virtio_ring: introduce virtqueue_add_sg() Date: Fri, 2 Jun 2023 17:22:05 +0800 Message-Id: <20230602092206.50108-10-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20230602092206.50108-1-xuanzhuo@linux.alibaba.com> References: <20230602092206.50108-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: 3bf1b1dbeb8a Cc: Xuan Zhuo , Jesper Dangaard Brouer , Daniel Borkmann , "Michael S. Tsirkin" , netdev@vger.kernel.org, John Fastabend , Alexei Starovoitov , Eric Dumazet , Jakub Kicinski , bpf@vger.kernel.org, Paolo Abeni , "David S. Miller" X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" Introduce virtqueueu_add_sg(), so that in virtio-net we can create an unify api for rq and sq. Signed-off-by: Xuan Zhuo --- drivers/virtio/virtio_ring.c | 23 +++++++++++++++++++++++ include/linux/virtio.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 56444f872967..a00f049ea442 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2356,6 +2356,29 @@ static inline int virtqueue_add(struct virtqueue *_vq, out_sgs, in_sgs, data, ctx, gfp); } +/** + * virtqueue_add_sg - expose buffers to other end + * @vq: the struct virtqueue we're talking about. + * @sg: a scatterlist + * @num: the number of entries in @sg + * @out: whether the sg is readable by other side + * @data: the token identifying the buffer. + * @ctx: extra context for the token + * @gfp: how to do memory allocations (if necessary). + * + * Caller must ensure we don't call this with other virtqueue operations + * at the same time (except where noted). + * + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO). + */ +int virtqueue_add_sg(struct virtqueue *vq, struct scatterlist *sg, + unsigned int num, bool out, void *data, + void *ctx, gfp_t gfp) +{ + return virtqueue_add(vq, &sg, num, (int)out, (int)!out, data, ctx, gfp); +} +EXPORT_SYMBOL_GPL(virtqueue_add_sg); + /** * virtqueue_add_sgs - expose buffers to other end * @_vq: the struct virtqueue we're talking about. diff --git a/include/linux/virtio.h b/include/linux/virtio.h index b24f0a665390..1a4aa4382c53 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -55,6 +55,10 @@ struct virtqueue_detach_cursor { unsigned pos:16; }; +int virtqueue_add_sg(struct virtqueue *vq, struct scatterlist *sg, + unsigned int num, bool out, void *data, + void *ctx, gfp_t gfp); + int virtqueue_add_outbuf(struct virtqueue *vq, struct scatterlist sg[], unsigned int num, void *data, -- 2.32.0.3.g01195cf9f _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization From mboxrd@z Thu Jan 1 00:00:00 1970 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 636B2174C4; Fri, 2 Jun 2023 09:22:23 +0000 (UTC) Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D32E7C; Fri, 2 Jun 2023 02:22:21 -0700 (PDT) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R861e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0Vk9LPE-_1685697737; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0Vk9LPE-_1685697737) by smtp.aliyun-inc.com; Fri, 02 Jun 2023 17:22:17 +0800 From: Xuan Zhuo To: virtualization@lists.linux-foundation.org Cc: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH vhost v10 09/10] virtio_ring: introduce virtqueue_add_sg() Date: Fri, 2 Jun 2023 17:22:05 +0800 Message-Id: <20230602092206.50108-10-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20230602092206.50108-1-xuanzhuo@linux.alibaba.com> References: <20230602092206.50108-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: 3bf1b1dbeb8a Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Introduce virtqueueu_add_sg(), so that in virtio-net we can create an unify api for rq and sq. Signed-off-by: Xuan Zhuo --- drivers/virtio/virtio_ring.c | 23 +++++++++++++++++++++++ include/linux/virtio.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 56444f872967..a00f049ea442 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2356,6 +2356,29 @@ static inline int virtqueue_add(struct virtqueue *_vq, out_sgs, in_sgs, data, ctx, gfp); } +/** + * virtqueue_add_sg - expose buffers to other end + * @vq: the struct virtqueue we're talking about. + * @sg: a scatterlist + * @num: the number of entries in @sg + * @out: whether the sg is readable by other side + * @data: the token identifying the buffer. + * @ctx: extra context for the token + * @gfp: how to do memory allocations (if necessary). + * + * Caller must ensure we don't call this with other virtqueue operations + * at the same time (except where noted). + * + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO). + */ +int virtqueue_add_sg(struct virtqueue *vq, struct scatterlist *sg, + unsigned int num, bool out, void *data, + void *ctx, gfp_t gfp) +{ + return virtqueue_add(vq, &sg, num, (int)out, (int)!out, data, ctx, gfp); +} +EXPORT_SYMBOL_GPL(virtqueue_add_sg); + /** * virtqueue_add_sgs - expose buffers to other end * @_vq: the struct virtqueue we're talking about. diff --git a/include/linux/virtio.h b/include/linux/virtio.h index b24f0a665390..1a4aa4382c53 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -55,6 +55,10 @@ struct virtqueue_detach_cursor { unsigned pos:16; }; +int virtqueue_add_sg(struct virtqueue *vq, struct scatterlist *sg, + unsigned int num, bool out, void *data, + void *ctx, gfp_t gfp); + int virtqueue_add_outbuf(struct virtqueue *vq, struct scatterlist sg[], unsigned int num, void *data, -- 2.32.0.3.g01195cf9f