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 46A10AD48 for ; Sun, 4 Jun 2023 13:45:25 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8FE83 for ; Sun, 4 Jun 2023 06:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685886322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FtWXr+699Hb3Bt46ASXuF1J0GM1OW7yEJvH6TifZCko=; b=FQwkU2Yw9SnRq97JhCFAPxTjw8xYSFsLlH6MrDr4+Enc3fhZHBC0OLyw65n0TW/qEWHiZ8 c3OKfWkyDXtK0EkiUYpOh+g6h9MpkmMIHrhyt86h2PcayOiGz63xiQgJom1wisFiXAokek y7KItefC3863aTx292utBorYTKPVaeE= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-X3Zxcu2DMQ-GM6nNM-JAVQ-1; Sun, 04 Jun 2023 09:45:20 -0400 X-MC-Unique: X3Zxcu2DMQ-GM6nNM-JAVQ-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-4f4e15ce82aso18942e87.1 for ; Sun, 04 Jun 2023 06:45:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685886319; x=1688478319; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FtWXr+699Hb3Bt46ASXuF1J0GM1OW7yEJvH6TifZCko=; b=WKHnuJPKAGN7cMNMf4Dl3E+MI2dLnGjJ4jVK2CgzbrEQUbYisbnooMorSlk9mejesI Kh5Jp6nAJv75Z1Rd1lKyxucabGqWkJA5vjgJSObKG+/G7R/8CEJpblHWvuOZUFUahCig aub0JsQJmQ9zLNK+wie/4rmgaQVEw+ias1k/MY2YIu1t8/wao4zuDONVuz57YBaTtCeo tQRmq4bfgkPuSvq75eN0eM68LESh5Gy0qjm1QftSm2sLa2c7M9da7qe2t9qFgO258bRp Ptpk5hoQDClY59Fv5LER/TnZ16nh4E/KlrB82DK2Dm7ThORLH6c+yD4GALpJPrBfwELH YGkg== X-Gm-Message-State: AC+VfDzJ9WUh+ej7M39Cl5saoh0W8yo/6RJnyxbFAzLeaWqHcFSJrTdK WBMcA8zcpXBBK4Qf4SDxXmLjPmS5ow/KfnA11sRZEJIfrI392Qq8dKr6tkd2grkbmXEFPHqBCTJ Y63GwtCkr4PI5 X-Received: by 2002:ac2:42c6:0:b0:4f3:9930:5b8c with SMTP id n6-20020ac242c6000000b004f399305b8cmr3679160lfl.25.1685886319428; Sun, 04 Jun 2023 06:45:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50ipioWzajptAHNCN3t7vMpbwHQFVFHQocI8w0p9FDECMVbrkC4nACxASbyPY4XZ1V+SC8gg== X-Received: by 2002:ac2:42c6:0:b0:4f3:9930:5b8c with SMTP id n6-20020ac242c6000000b004f399305b8cmr3679148lfl.25.1685886319052; Sun, 04 Jun 2023 06:45:19 -0700 (PDT) Received: from redhat.com ([2.55.4.169]) by smtp.gmail.com with ESMTPSA id y7-20020a1c4b07000000b003f60455de07sm7837888wma.15.2023.06.04.06.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jun 2023 06:45:18 -0700 (PDT) Date: Sun, 4 Jun 2023 09:45:14 -0400 From: "Michael S. Tsirkin" To: Xuan Zhuo Cc: virtualization@lists.linux-foundation.org, Jason Wang , "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: Re: [PATCH vhost v10 07/10] virtio_ring: introduce helpers for premapped Message-ID: <20230604094122-mutt-send-email-mst@kernel.org> References: <20230602092206.50108-1-xuanzhuo@linux.alibaba.com> <20230602092206.50108-8-xuanzhuo@linux.alibaba.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230602092206.50108-8-xuanzhuo@linux.alibaba.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On Fri, Jun 02, 2023 at 05:22:03PM +0800, Xuan Zhuo wrote: > This patch introduces three helpers for premapped mode. > > * virtqueue_get_buf_premapped > * virtqueue_detach_unused_buf_premapped > > The above helpers work like the non-premapped funcs. But a cursor is > passed. > > virtqueue_detach is used to get the dma info of the last buf by > cursor. This isn't very clear from the description but virtqueue_detach is also introduced by this patch as opposed to being used. > Signed-off-by: Xuan Zhuo > --- > drivers/virtio/virtio_ring.c | 83 ++++++++++++++++++++++++++++++++++++ > include/linux/virtio.h | 10 +++++ > 2 files changed, 93 insertions(+) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index cbc22daae7e1..6771b9661798 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -2555,6 +2555,66 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) > return virtqueue_get_buf_ctx(_vq, len, NULL); > } > EXPORT_SYMBOL_GPL(virtqueue_get_buf); > + > +/** > + * virtqueue_get_buf_premapped - get the next used buffer > + * @_vq: the struct virtqueue we're talking about. > + * @len: the length written into the buffer > + * @ctx: extra context for the token > + * @cursor: detach cursor > + * > + * If the device wrote data into the buffer, @len will be set to the > + * amount written. This means you don't need to clear the buffer > + * beforehand to ensure there's no data leakage in the case of short > + * writes. > + * > + * Caller must ensure we don't call this with other virtqueue > + * operations at the same time (except where noted). > + * > + * This is used for the premapped vq. The cursor is passed by the dirver, that > + * is used for virtqueue_detach. That will be initialized by virtio core > + * internally. > + * > + * Returns NULL if there are no used buffers, or the "data" token > + * handed to virtqueue_add_*(). > + */ > +void *virtqueue_get_buf_premapped(struct virtqueue *_vq, unsigned int *len, > + void **ctx, > + struct virtqueue_detach_cursor *cursor) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + > + return vq->packed_ring ? virtqueue_get_buf_ctx_packed(_vq, len, ctx, cursor) : > + virtqueue_get_buf_ctx_split(_vq, len, ctx, cursor); > +} > +EXPORT_SYMBOL_GPL(virtqueue_get_buf_premapped); > + > +/** > + * virtqueue_detach - get the dma info of last buf detach what from what then? I am guessing this is not the only thing this function does? sounds like a bad name for a function. > + * @_vq: the struct virtqueue we're talking about. > + * @cursor: detach cursor > + * @addr: the dma address what address? it's the 1st time you mention an address ... > + * @len: the length of the dma address > + * @dir: the direction of the dma address > + * > + * This is used for the premapped vq. The cursor is initialized by > + * virtqueue_get_buf_premapped or virtqueue_detach_unused_buf_premapped. > + * > + * Returns: > + * -EAGAIN: there are more dma info, this function should be called more. here too, pls don't return -EAGAIN not in an error case. something like "1" will do. > + * -EINVAL: the process is done, should not call this function > + * 0: no more dma info > + */ > +int virtqueue_detach(struct virtqueue *_vq, struct virtqueue_detach_cursor *cursor, > + dma_addr_t *addr, u32 *len, enum dma_data_direction *dir) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + > + return vq->packed_ring ? virtqueue_detach_packed(_vq, cursor, addr, len, dir) : > + virtqueue_detach_split(_vq, cursor, addr, len, dir); > +} > +EXPORT_SYMBOL_GPL(virtqueue_detach); > + > /** > * virtqueue_disable_cb - disable callbacks > * @_vq: the struct virtqueue we're talking about. > @@ -2682,6 +2742,29 @@ void *virtqueue_detach_unused_buf(struct virtqueue *_vq) > } > EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf); > > +/** > + * virtqueue_detach_unused_buf_premapped - detach first unused buffer > + * @_vq: the struct virtqueue we're talking about. > + * @cursor: detach cursor > + * > + * This is used for the premapped vq. The cursor is passed by the dirver, that > + * is used for virtqueue_detach. That will be initialized by virtio core > + * internally. > + * > + * Returns NULL or the "data" token handed to virtqueue_add_*(). > + * This is not valid on an active queue; it is useful for device > + * shutdown or the reset queue. > + */ > +void *virtqueue_detach_unused_buf_premapped(struct virtqueue *_vq, > + struct virtqueue_detach_cursor *cursor) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + > + return vq->packed_ring ? virtqueue_detach_unused_buf_packed(_vq, cursor) : > + virtqueue_detach_unused_buf_split(_vq, cursor); > +} > +EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf_premapped); > + > static inline bool more_used(const struct vring_virtqueue *vq) > { > return vq->packed_ring ? more_used_packed(vq) : more_used_split(vq); > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > index 7f137c7a9034..0a11c5b32fe5 100644 > --- a/include/linux/virtio.h > +++ b/include/linux/virtio.h > @@ -3,6 +3,7 @@ > #define _LINUX_VIRTIO_H > /* Everything a virtio driver needs to work with any particular virtio > * implementation. */ > +#include > #include > #include > #include > @@ -88,6 +89,10 @@ void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); > void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len, > void **ctx); > > +void *virtqueue_get_buf_premapped(struct virtqueue *_vq, unsigned int *len, > + void **ctx, > + struct virtqueue_detach_cursor *cursor); > + > void virtqueue_disable_cb(struct virtqueue *vq); > > bool virtqueue_enable_cb(struct virtqueue *vq); > @@ -101,6 +106,8 @@ bool virtqueue_poll(struct virtqueue *vq, unsigned); > bool virtqueue_enable_cb_delayed(struct virtqueue *vq); > > void *virtqueue_detach_unused_buf(struct virtqueue *vq); > +void *virtqueue_detach_unused_buf_premapped(struct virtqueue *_vq, > + struct virtqueue_detach_cursor *cursor); > > unsigned int virtqueue_get_vring_size(const struct virtqueue *vq); > > @@ -114,6 +121,9 @@ dma_addr_t virtqueue_get_used_addr(const struct virtqueue *vq); > int virtqueue_resize(struct virtqueue *vq, u32 num, > void (*recycle)(struct virtqueue *vq, void *buf)); > > +int virtqueue_detach(struct virtqueue *_vq, struct virtqueue_detach_cursor *cursor, > + dma_addr_t *addr, u32 *len, enum dma_data_direction *dir); > + > /** > * struct virtio_device - representation of a device using virtio > * @index: unique position on the virtio bus > -- > 2.32.0.3.g01195cf9f 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 smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (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 0191FC77B73 for ; Sun, 4 Jun 2023 13:45:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 4D1FD41B92; Sun, 4 Jun 2023 13:45:32 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 4D1FD41B92 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Lk3WSOcn X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NdKy2a8TAIuV; Sun, 4 Jun 2023 13:45:31 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 5203D418EA; Sun, 4 Jun 2023 13:45:30 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 5203D418EA Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 279A1C0037; Sun, 4 Jun 2023 13:45:30 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 24C08C0029 for ; Sun, 4 Jun 2023 13:45:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id DF37E60E31 for ; Sun, 4 Jun 2023 13:45:27 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org DF37E60E31 Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Lk3WSOcn X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id P2p6yW_nDGYw for ; Sun, 4 Jun 2023 13:45:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 74D9760E29 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 74D9760E29 for ; Sun, 4 Jun 2023 13:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685886324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FtWXr+699Hb3Bt46ASXuF1J0GM1OW7yEJvH6TifZCko=; b=Lk3WSOcnYRRsbahuh3ZCP90218j4YiRdan5Lw+LIIIIK7+8/jde5/J1ucRzqxxRa6bG09q tJFD78TGK1I2cKX/hS2OzBqS3u43r2ckGKFM+vQY6g89BZPfAGP6qJ6xvOvPvIPRhLFHTb /rC2VWuYPnI7a29dATKTILcNrTU6WCo= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-HYW8Y7iZM8eIeWLFJ9JMHA-1; Sun, 04 Jun 2023 09:45:20 -0400 X-MC-Unique: HYW8Y7iZM8eIeWLFJ9JMHA-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-4edbdd8268bso18769e87.2 for ; Sun, 04 Jun 2023 06:45:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685886319; x=1688478319; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FtWXr+699Hb3Bt46ASXuF1J0GM1OW7yEJvH6TifZCko=; b=GgFaGmS84mptZJauEoXkZ+AFTvbSHhobgJug8E2Ldq1RxLmfhYDjxPxXIqXwpxXnWz rH72SUn9zXzBr2QanH3WyJ42hVIU/zhKbZnVGjywOaLkhAbC9O3O17WmfxAe6RVQlnCf kWrTOcUI3mvImxQ9P3G+UmgJTul9nMyv5wjFvS7CoZHRDHrQwKFIAdg5HwVgusKth5HZ fYqaRSGz+Y5c0LuX4Hd/rT25khU1j3kfLx/3XqgLyATnHg/JOFKz5QFI5c8fFgmD2/y4 aTQNAe/R9z9pspj6xJlRrUqRbYSkwxHIhYKnqMmrUhcjOpUrAAgYImycFyKuTk04Akdx 24lA== X-Gm-Message-State: AC+VfDxhqAtK4z5EC2T1EJFXSS+okqH0ZgXZPkbuNWubS5TE7epbaylp kNglp/bBMSLFCxLnG8TyEawwPh1aL3LjS788+FZ56yiM9J39GnmY68PbpNcSPq9CEvL3OWLndM2 lJyaJSP81b3BXhOGlMc00jyjcazTyS/5Vo6hHKSK1/g== X-Received: by 2002:ac2:42c6:0:b0:4f3:9930:5b8c with SMTP id n6-20020ac242c6000000b004f399305b8cmr3679159lfl.25.1685886319425; Sun, 04 Jun 2023 06:45:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50ipioWzajptAHNCN3t7vMpbwHQFVFHQocI8w0p9FDECMVbrkC4nACxASbyPY4XZ1V+SC8gg== X-Received: by 2002:ac2:42c6:0:b0:4f3:9930:5b8c with SMTP id n6-20020ac242c6000000b004f399305b8cmr3679148lfl.25.1685886319052; Sun, 04 Jun 2023 06:45:19 -0700 (PDT) Received: from redhat.com ([2.55.4.169]) by smtp.gmail.com with ESMTPSA id y7-20020a1c4b07000000b003f60455de07sm7837888wma.15.2023.06.04.06.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jun 2023 06:45:18 -0700 (PDT) Date: Sun, 4 Jun 2023 09:45:14 -0400 From: "Michael S. Tsirkin" To: Xuan Zhuo Subject: Re: [PATCH vhost v10 07/10] virtio_ring: introduce helpers for premapped Message-ID: <20230604094122-mutt-send-email-mst@kernel.org> References: <20230602092206.50108-1-xuanzhuo@linux.alibaba.com> <20230602092206.50108-8-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 In-Reply-To: <20230602092206.50108-8-xuanzhuo@linux.alibaba.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Cc: Jesper Dangaard Brouer , Daniel Borkmann , netdev@vger.kernel.org, John Fastabend , Alexei Starovoitov , virtualization@lists.linux-foundation.org, 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" On Fri, Jun 02, 2023 at 05:22:03PM +0800, Xuan Zhuo wrote: > This patch introduces three helpers for premapped mode. > > * virtqueue_get_buf_premapped > * virtqueue_detach_unused_buf_premapped > > The above helpers work like the non-premapped funcs. But a cursor is > passed. > > virtqueue_detach is used to get the dma info of the last buf by > cursor. This isn't very clear from the description but virtqueue_detach is also introduced by this patch as opposed to being used. > Signed-off-by: Xuan Zhuo > --- > drivers/virtio/virtio_ring.c | 83 ++++++++++++++++++++++++++++++++++++ > include/linux/virtio.h | 10 +++++ > 2 files changed, 93 insertions(+) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index cbc22daae7e1..6771b9661798 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -2555,6 +2555,66 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) > return virtqueue_get_buf_ctx(_vq, len, NULL); > } > EXPORT_SYMBOL_GPL(virtqueue_get_buf); > + > +/** > + * virtqueue_get_buf_premapped - get the next used buffer > + * @_vq: the struct virtqueue we're talking about. > + * @len: the length written into the buffer > + * @ctx: extra context for the token > + * @cursor: detach cursor > + * > + * If the device wrote data into the buffer, @len will be set to the > + * amount written. This means you don't need to clear the buffer > + * beforehand to ensure there's no data leakage in the case of short > + * writes. > + * > + * Caller must ensure we don't call this with other virtqueue > + * operations at the same time (except where noted). > + * > + * This is used for the premapped vq. The cursor is passed by the dirver, that > + * is used for virtqueue_detach. That will be initialized by virtio core > + * internally. > + * > + * Returns NULL if there are no used buffers, or the "data" token > + * handed to virtqueue_add_*(). > + */ > +void *virtqueue_get_buf_premapped(struct virtqueue *_vq, unsigned int *len, > + void **ctx, > + struct virtqueue_detach_cursor *cursor) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + > + return vq->packed_ring ? virtqueue_get_buf_ctx_packed(_vq, len, ctx, cursor) : > + virtqueue_get_buf_ctx_split(_vq, len, ctx, cursor); > +} > +EXPORT_SYMBOL_GPL(virtqueue_get_buf_premapped); > + > +/** > + * virtqueue_detach - get the dma info of last buf detach what from what then? I am guessing this is not the only thing this function does? sounds like a bad name for a function. > + * @_vq: the struct virtqueue we're talking about. > + * @cursor: detach cursor > + * @addr: the dma address what address? it's the 1st time you mention an address ... > + * @len: the length of the dma address > + * @dir: the direction of the dma address > + * > + * This is used for the premapped vq. The cursor is initialized by > + * virtqueue_get_buf_premapped or virtqueue_detach_unused_buf_premapped. > + * > + * Returns: > + * -EAGAIN: there are more dma info, this function should be called more. here too, pls don't return -EAGAIN not in an error case. something like "1" will do. > + * -EINVAL: the process is done, should not call this function > + * 0: no more dma info > + */ > +int virtqueue_detach(struct virtqueue *_vq, struct virtqueue_detach_cursor *cursor, > + dma_addr_t *addr, u32 *len, enum dma_data_direction *dir) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + > + return vq->packed_ring ? virtqueue_detach_packed(_vq, cursor, addr, len, dir) : > + virtqueue_detach_split(_vq, cursor, addr, len, dir); > +} > +EXPORT_SYMBOL_GPL(virtqueue_detach); > + > /** > * virtqueue_disable_cb - disable callbacks > * @_vq: the struct virtqueue we're talking about. > @@ -2682,6 +2742,29 @@ void *virtqueue_detach_unused_buf(struct virtqueue *_vq) > } > EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf); > > +/** > + * virtqueue_detach_unused_buf_premapped - detach first unused buffer > + * @_vq: the struct virtqueue we're talking about. > + * @cursor: detach cursor > + * > + * This is used for the premapped vq. The cursor is passed by the dirver, that > + * is used for virtqueue_detach. That will be initialized by virtio core > + * internally. > + * > + * Returns NULL or the "data" token handed to virtqueue_add_*(). > + * This is not valid on an active queue; it is useful for device > + * shutdown or the reset queue. > + */ > +void *virtqueue_detach_unused_buf_premapped(struct virtqueue *_vq, > + struct virtqueue_detach_cursor *cursor) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + > + return vq->packed_ring ? virtqueue_detach_unused_buf_packed(_vq, cursor) : > + virtqueue_detach_unused_buf_split(_vq, cursor); > +} > +EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf_premapped); > + > static inline bool more_used(const struct vring_virtqueue *vq) > { > return vq->packed_ring ? more_used_packed(vq) : more_used_split(vq); > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > index 7f137c7a9034..0a11c5b32fe5 100644 > --- a/include/linux/virtio.h > +++ b/include/linux/virtio.h > @@ -3,6 +3,7 @@ > #define _LINUX_VIRTIO_H > /* Everything a virtio driver needs to work with any particular virtio > * implementation. */ > +#include > #include > #include > #include > @@ -88,6 +89,10 @@ void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); > void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len, > void **ctx); > > +void *virtqueue_get_buf_premapped(struct virtqueue *_vq, unsigned int *len, > + void **ctx, > + struct virtqueue_detach_cursor *cursor); > + > void virtqueue_disable_cb(struct virtqueue *vq); > > bool virtqueue_enable_cb(struct virtqueue *vq); > @@ -101,6 +106,8 @@ bool virtqueue_poll(struct virtqueue *vq, unsigned); > bool virtqueue_enable_cb_delayed(struct virtqueue *vq); > > void *virtqueue_detach_unused_buf(struct virtqueue *vq); > +void *virtqueue_detach_unused_buf_premapped(struct virtqueue *_vq, > + struct virtqueue_detach_cursor *cursor); > > unsigned int virtqueue_get_vring_size(const struct virtqueue *vq); > > @@ -114,6 +121,9 @@ dma_addr_t virtqueue_get_used_addr(const struct virtqueue *vq); > int virtqueue_resize(struct virtqueue *vq, u32 num, > void (*recycle)(struct virtqueue *vq, void *buf)); > > +int virtqueue_detach(struct virtqueue *_vq, struct virtqueue_detach_cursor *cursor, > + dma_addr_t *addr, u32 *len, enum dma_data_direction *dir); > + > /** > * struct virtio_device - representation of a device using virtio > * @index: unique position on the virtio bus > -- > 2.32.0.3.g01195cf9f _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization