From: "Michael S. Tsirkin" <mst@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: virtualization@lists.linux-foundation.org,
Jason Wang <jasowang@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@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,
Christoph Hellwig <hch@infradead.org>
Subject: Re: [PATCH vhost v13 11/12] virtio_ring: introduce dma sync api for virtqueue
Date: Thu, 30 Nov 2023 05:10:42 -0500 [thread overview]
Message-ID: <20231130050852-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1701337778.899533-1-xuanzhuo@linux.alibaba.com>
On Thu, Nov 30, 2023 at 05:49:38PM +0800, Xuan Zhuo wrote:
> On Thu, 30 Nov 2023 04:45:58 -0500, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > On Thu, Aug 10, 2023 at 08:30:56PM +0800, Xuan Zhuo wrote:
> > > These API has been introduced:
> > >
> > > * virtqueue_dma_need_sync
> > > * virtqueue_dma_sync_single_range_for_cpu
> > > * virtqueue_dma_sync_single_range_for_device
> > >
> > > These APIs can be used together with the premapped mechanism to sync the
> > > DMA address.
> > >
> > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > ---
> > > drivers/virtio/virtio_ring.c | 76 ++++++++++++++++++++++++++++++++++++
> > > include/linux/virtio.h | 8 ++++
> > > 2 files changed, 84 insertions(+)
> > >
> > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > > index 916479c9c72c..81ecb29c88f1 100644
> > > --- a/drivers/virtio/virtio_ring.c
> > > +++ b/drivers/virtio/virtio_ring.c
> > > @@ -3175,4 +3175,80 @@ int virtqueue_dma_mapping_error(struct virtqueue *_vq, dma_addr_t addr)
> > > }
> > > EXPORT_SYMBOL_GPL(virtqueue_dma_mapping_error);
> > >
> > > +/**
> > > + * virtqueue_dma_need_sync - check a dma address needs sync
> > > + * @_vq: the struct virtqueue we're talking about.
> > > + * @addr: DMA address
> > > + *
> > > + * Check if the dma address mapped by the virtqueue_dma_map_* APIs needs to be
> > > + * synchronized
> > > + *
> > > + * return bool
> > > + */
> > > +bool virtqueue_dma_need_sync(struct virtqueue *_vq, dma_addr_t addr)
> > > +{
> > > + struct vring_virtqueue *vq = to_vvq(_vq);
> > > +
> > > + if (!vq->use_dma_api)
> > > + return false;
> > > +
> > > + return dma_need_sync(vring_dma_dev(vq), addr);
> > > +}
> > > +EXPORT_SYMBOL_GPL(virtqueue_dma_need_sync);
> > > +
> > > +/**
> > > + * virtqueue_dma_sync_single_range_for_cpu - dma sync for cpu
> > > + * @_vq: the struct virtqueue we're talking about.
> > > + * @addr: DMA address
> > > + * @offset: DMA address offset
> > > + * @size: buf size for sync
> > > + * @dir: DMA direction
> > > + *
> > > + * Before calling this function, use virtqueue_dma_need_sync() to confirm that
> > > + * the DMA address really needs to be synchronized
> > > + *
> > > + */
> > > +void virtqueue_dma_sync_single_range_for_cpu(struct virtqueue *_vq,
> > > + dma_addr_t addr,
> > > + unsigned long offset, size_t size,
> > > + enum dma_data_direction dir)
> > > +{
> > > + struct vring_virtqueue *vq = to_vvq(_vq);
> > > + struct device *dev = vring_dma_dev(vq);
> > > +
> > > + if (!vq->use_dma_api)
> > > + return;
> > > +
> > > + dma_sync_single_range_for_cpu(dev, addr, offset, size,
> > > + DMA_BIDIRECTIONAL);
> > > +}
> >
> >
> > Why did you use DMA_BIDIRECTIONAL here?
> > Why is "dir" ignored?
>
> This is a mistake.
>
> I see Jason has a fix patch.
the one he sent in response to the bug report? it's incomplete though.
> How can I help?
>
> Thanks.
develop a full patch with commit log, explanation of what
the result of the bug is, Fixes tag etc, test
in some environment where dir makes a difference and post.
>
> >
> >
> > > +EXPORT_SYMBOL_GPL(virtqueue_dma_sync_single_range_for_cpu);
> > > +
> > > +/**
> > > + * virtqueue_dma_sync_single_range_for_device - dma sync for device
> > > + * @_vq: the struct virtqueue we're talking about.
> > > + * @addr: DMA address
> > > + * @offset: DMA address offset
> > > + * @size: buf size for sync
> > > + * @dir: DMA direction
> > > + *
> > > + * Before calling this function, use virtqueue_dma_need_sync() to confirm that
> > > + * the DMA address really needs to be synchronized
> > > + */
> > > +void virtqueue_dma_sync_single_range_for_device(struct virtqueue *_vq,
> > > + dma_addr_t addr,
> > > + unsigned long offset, size_t size,
> > > + enum dma_data_direction dir)
> > > +{
> > > + struct vring_virtqueue *vq = to_vvq(_vq);
> > > + struct device *dev = vring_dma_dev(vq);
> > > +
> > > + if (!vq->use_dma_api)
> > > + return;
> > > +
> > > + dma_sync_single_range_for_device(dev, addr, offset, size,
> > > + DMA_BIDIRECTIONAL);
> > > +}
> > > +EXPORT_SYMBOL_GPL(virtqueue_dma_sync_single_range_for_device);
> > > +
> > > MODULE_LICENSE("GPL");
> >
> > same question here.
> >
> > > diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> > > index 79e3c74391e0..1311a7fbe675 100644
> > > --- a/include/linux/virtio.h
> > > +++ b/include/linux/virtio.h
> > > @@ -220,4 +220,12 @@ void virtqueue_dma_unmap_single_attrs(struct virtqueue *_vq, dma_addr_t addr,
> > > size_t size, enum dma_data_direction dir,
> > > unsigned long attrs);
> > > int virtqueue_dma_mapping_error(struct virtqueue *_vq, dma_addr_t addr);
> > > +
> > > +bool virtqueue_dma_need_sync(struct virtqueue *_vq, dma_addr_t addr);
> > > +void virtqueue_dma_sync_single_range_for_cpu(struct virtqueue *_vq, dma_addr_t addr,
> > > + unsigned long offset, size_t size,
> > > + enum dma_data_direction dir);
> > > +void virtqueue_dma_sync_single_range_for_device(struct virtqueue *_vq, dma_addr_t addr,
> > > + unsigned long offset, size_t size,
> > > + enum dma_data_direction dir);
> > > #endif /* _LINUX_VIRTIO_H */
> > > --
> > > 2.32.0.3.g01195cf9f
> >
> >
next prev parent reply other threads:[~2023-11-30 10:10 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 12:30 [PATCH vhost v13 00/12] virtio core prepares for AF_XDP Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 01/12] virtio_ring: check use_dma_api before unmap desc for indirect Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 02/12] virtio_ring: put mapping error check in vring_map_one_sg Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 03/12] virtio_ring: introduce virtqueue_set_dma_premapped() Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 04/12] virtio_ring: support add premapped buf Xuan Zhuo
2024-06-04 16:07 ` Ilya Leoshkevich
2024-06-04 16:17 ` Alexander Potapenko
2024-06-05 16:02 ` Ilya Leoshkevich
2024-06-06 3:23 ` Xuan Zhuo
[not found] ` <CAG_fn=UsqAhH57s08+prkj2iJshhxuLznzDNft4dPXHKX9V72Q@mail.gmail.com>
2024-06-06 8:24 ` Xuan Zhuo
2024-06-06 9:49 ` Alexander Potapenko
2024-06-06 8:26 ` Alexander Potapenko
2023-08-10 12:30 ` [PATCH vhost v13 05/12] virtio_ring: introduce virtqueue_dma_dev() Xuan Zhuo
2023-08-14 3:05 ` Jason Wang
2023-08-14 8:56 ` Xuan Zhuo
2023-08-14 11:24 ` Michael S. Tsirkin
2023-08-14 11:55 ` Xuan Zhuo
2023-08-15 6:30 ` Xuan Zhuo
2023-08-15 7:50 ` Jason Wang
2023-08-15 9:27 ` Xuan Zhuo
2023-08-16 1:13 ` Jason Wang
2023-08-16 2:08 ` Xuan Zhuo
2023-08-16 2:19 ` Jason Wang
2023-08-16 2:21 ` Xuan Zhuo
2023-08-16 2:33 ` Jason Wang
2023-08-16 3:22 ` Xuan Zhuo
2023-08-15 11:57 ` Michael S. Tsirkin
2023-08-10 12:30 ` [PATCH vhost v13 06/12] virtio_ring: skip unmap for premapped Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 07/12] virtio_ring: correct the expression of the description of virtqueue_resize() Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 08/12] virtio_ring: separate the logic of reset/enable from virtqueue_resize Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 09/12] virtio_ring: introduce virtqueue_reset() Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 10/12] virtio_ring: introduce dma map api for virtqueue Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 11/12] virtio_ring: introduce dma sync " Xuan Zhuo
2023-11-30 9:45 ` Michael S. Tsirkin
2023-11-30 9:49 ` Xuan Zhuo
2023-11-30 10:10 ` Michael S. Tsirkin [this message]
2023-11-30 10:15 ` Xuan Zhuo
2023-08-10 12:30 ` [PATCH vhost v13 12/12] virtio_net: merge dma operations when filling mergeable buffers Xuan Zhuo
2023-09-26 16:01 ` Michael S. Tsirkin
2023-09-27 1:50 ` Xuan Zhuo
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=20231130050852-mutt-send-email-mst@kernel.org \
--to=mst@redhat.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=hch@infradead.org \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xuanzhuo@linux.alibaba.com \
/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).