netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux-foundation.org,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH vhost 01/22] virtio_ring: virtqueue_set_dma_premapped support disable
Date: Thu, 12 Oct 2023 17:18:54 +0800	[thread overview]
Message-ID: <1697102334.7060938-2-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <20231012051416-mutt-send-email-mst@kernel.org>

On Thu, 12 Oct 2023 05:15:52 -0400, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Wed, Oct 11, 2023 at 05:27:07PM +0800, Xuan Zhuo wrote:
> > virtqueue_set_dma_premapped() adds a new parameter to disable the
> > virtqueue premapped mode.
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> >  drivers/net/virtio_net.c     |  2 +-
> >  drivers/virtio/virtio_ring.c | 11 ++++++++---
> >  include/linux/virtio.h       |  2 +-
> >  3 files changed, 10 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index fe7f314d65c9..6b5f47ebf9b2 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -737,7 +737,7 @@ static void virtnet_rq_set_premapped(struct virtnet_info *vi)
> >  		return;
> >
> >  	for (i = 0; i < vi->max_queue_pairs; i++) {
> > -		if (virtqueue_set_dma_premapped(vi->rq[i].vq))
> > +		if (virtqueue_set_dma_premapped(vi->rq[i].vq, true))
> >  			continue;
> >
> >  		vi->rq[i].do_dma = true;
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index 51d8f3299c10..b3ded56722f4 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -2784,7 +2784,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
> >   * 0: success.
> >   * -EINVAL: vring does not use the dma api, so we can not enable premapped mode.
> >   */
> > -int virtqueue_set_dma_premapped(struct virtqueue *_vq)
> > +int virtqueue_set_dma_premapped(struct virtqueue *_vq, bool mode)
> >  {
> >  	struct vring_virtqueue *vq = to_vvq(_vq);
> >  	u32 num;
> > @@ -2803,8 +2803,13 @@ int virtqueue_set_dma_premapped(struct virtqueue *_vq)
> >  		return -EINVAL;
> >  	}
> >
> > -	vq->premapped = true;
> > -	vq->do_unmap = false;
> > +	if (mode) {
> > +		vq->premapped = true;
> > +		vq->do_unmap = false;
> > +	} else {
> > +		vq->premapped = false;
> > +		vq->do_unmap = vq->use_dma_api;
> > +	}
> >
> >  	END_USE(vq);
> >
> > diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> > index 4cc614a38376..1cf7b004348b 100644
> > --- a/include/linux/virtio.h
> > +++ b/include/linux/virtio.h
> > @@ -81,7 +81,7 @@ bool virtqueue_enable_cb(struct virtqueue *vq);
> >
> >  unsigned virtqueue_enable_cb_prepare(struct virtqueue *vq);
> >
> > -int virtqueue_set_dma_premapped(struct virtqueue *_vq);
> > +int virtqueue_set_dma_premapped(struct virtqueue *_vq, bool mode);
> >
> >  bool virtqueue_poll(struct virtqueue *vq, unsigned);
>
> Wait a sec I thought we never change premapped. If you make this
> dynamic don't you need a bunch of locking?
> Or maybe queue is empty when you change this?
> If yes pls add a bunch of BUG_ON checks to make sure this is not misused.


Actually, this api is called immediately after the vq init or vq reset.

We already have such a check.

Thanks.

/**
 * virtqueue_set_dma_premapped - set the vring premapped mode
 * @_vq: the struct virtqueue we're talking about.
 *
 * Enable the premapped mode of the vq.
 *
 * The vring in premapped mode does not do dma internally, so the driver must
 * do dma mapping in advance. The driver must pass the dma_address through
 * dma_address of scatterlist. When the driver got a used buffer from
 * the vring, it has to unmap the dma address.
 *
 * This function must be called immediately after creating the vq, or after vq
 * reset, and before adding any buffers to it.
 *
 * 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.
 * 0: success.
 * -EINVAL: vring does not use the dma api, so we can not enable premapped mode.
 */
int virtqueue_set_dma_premapped(struct virtqueue *_vq, bool mode)
{
	struct vring_virtqueue *vq = to_vvq(_vq);
	u32 num;

	START_USE(vq);

	num = vq->packed_ring ? vq->packed.vring.num : vq->split.vring.num;

-->	if (num != vq->vq.num_free) {
		END_USE(vq);
		return -EINVAL;
	}

	if (!vq->use_dma_api) {
		END_USE(vq);
		return -EINVAL;
	}

	if (mode) {
		vq->premapped = true;
		vq->do_unmap = false;
	} else {
		vq->premapped = false;
		vq->do_unmap = vq->use_dma_api;
	}

	END_USE(vq);

	return 0;
}
EXPORT_SYMBOL_GPL(virtqueue_set_dma_premapped);


>
>
> > --
> > 2.32.0.3.g01195cf9f
>

  reply	other threads:[~2023-10-12  9:21 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11  9:27 [PATCH vhost 00/22] virtio-net: support AF_XDP zero copy Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 01/22] virtio_ring: virtqueue_set_dma_premapped support disable Xuan Zhuo
2023-10-11 14:13   ` kernel test robot
2023-10-12  9:15   ` Michael S. Tsirkin
2023-10-12  9:18     ` Xuan Zhuo [this message]
2023-10-12  9:40       ` Michael S. Tsirkin
2023-10-12 11:36         ` Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 02/22] virtio_ring: introduce virtqueue_dma_[un]map_page_attrs Xuan Zhuo
2023-10-18  7:53   ` Xuan Zhuo
2023-10-18  7:59     ` Michael S. Tsirkin
2023-10-18  8:00       ` Xuan Zhuo
2023-10-18  8:44         ` Michael S. Tsirkin
2023-10-18  8:57           ` Xuan Zhuo
2023-10-18  9:13             ` Michael S. Tsirkin
2023-10-18  9:17               ` Xuan Zhuo
2023-10-18  8:09     ` Michael S. Tsirkin
2023-10-11  9:27 ` [PATCH vhost 03/22] virtio_net: rename free_old_xmit_skbs to free_old_xmit Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 04/22] virtio_net: unify the code for recycling the xmit ptr Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 05/22] virtio_net: independent directory Xuan Zhuo
2023-10-11 23:22   ` kernel test robot
2023-10-11  9:27 ` [PATCH vhost 06/22] virtio_net: move to virtio_net.h Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 07/22] virtio_net: add prefix virtnet to all struct/api inside virtio_net.h Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 08/22] virtio_net: virtnet_poll_tx support rescheduled Xuan Zhuo
2023-10-12  9:13   ` Michael S. Tsirkin
2023-10-11  9:27 ` [PATCH vhost 09/22] virtio_net: separate virtnet_rx_resize() Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 10/22] virtio_net: separate virtnet_tx_resize() Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 11/22] virtio_net: sq support premapped mode Xuan Zhuo
2023-10-13 10:13   ` kernel test robot
2023-10-11  9:27 ` [PATCH vhost 12/22] virtio_net: xsk: bind/unbind xsk Xuan Zhuo
2023-10-15 19:17   ` Simon Horman
2023-10-11  9:27 ` [PATCH vhost 13/22] virtio_net: xsk: prevent disable tx napi Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 14/22] virtio_net: xsk: tx: support tx Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 15/22] virtio_net: xsk: tx: support wakeup Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 16/22] virtio_net: xsk: tx: virtnet_free_old_xmit() distinguishes xsk buffer Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 17/22] virtio_net: xsk: tx: virtnet_sq_free_unused_buf() check " Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 18/22] virtio_net: xsk: rx: introduce add_recvbuf_xsk() Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 19/22] virtio_net: xsk: rx: introduce receive_xsk() to recv xsk buffer Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 20/22] virtio_net: xsk: rx: virtnet_rq_free_unused_buf() check " Xuan Zhuo
2023-10-11  9:27 ` [PATCH vhost 21/22] virtio_net: update tx timeout record Xuan Zhuo
2023-10-12  9:10   ` Michael S. Tsirkin
2023-10-12  9:12     ` Xuan Zhuo
2023-10-12  9:36       ` Michael S. Tsirkin
2023-10-12 11:54         ` Xuan Zhuo
2023-10-12 13:07           ` Michael S. Tsirkin
2023-10-11  9:27 ` [PATCH vhost 22/22] virtio_net: xdp_features add NETDEV_XDP_ACT_XSK_ZEROCOPY Xuan Zhuo
2023-10-11 17:00 ` [PATCH vhost 00/22] virtio-net: support AF_XDP zero copy Jakub Kicinski
2023-10-12  1:53   ` Xuan Zhuo
2023-10-12  7:50     ` Jason Wang
2023-10-12  8:32       ` Xuan Zhuo
2023-10-12 14:50         ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1697102334.7060938-2-xuanzhuo@linux.alibaba.com \
    --to=xuanzhuo@linux.alibaba.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=jasowang@redhat.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).