2021-05-20 14:16:09

by Stefan Hajnoczi

[permalink] [raw]
Subject: [PATCH 1/3] virtio: add virtioqueue_more_used()

Add an API to check whether there are pending used buffers. There is
already a similar API called virtqueue_poll() but it only works together
with virtqueue_enable_cb_prepare(). The patches that follow add blk-mq
->poll() support to virtio_blk and they need to check for used buffers
without re-enabling virtqueue callbacks, so introduce an API for it.

Signed-off-by: Stefan Hajnoczi <[email protected]>
---
include/linux/virtio.h | 2 ++
drivers/virtio/virtio_ring.c | 17 +++++++++++++++++
2 files changed, 19 insertions(+)

diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index b1894e0323fa..c6ad0f25f412 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -63,6 +63,8 @@ bool virtqueue_kick_prepare(struct virtqueue *vq);

bool virtqueue_notify(struct virtqueue *vq);

+bool virtqueue_more_used(const struct virtqueue *vq);
+
void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);

void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len,
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 71e16b53e9c1..7c3da75da462 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -2032,6 +2032,23 @@ static inline bool more_used(const struct vring_virtqueue *vq)
return vq->packed_ring ? more_used_packed(vq) : more_used_split(vq);
}

+/**
+ * virtqueue_more_used - check if there are used buffers pending
+ * @_vq: the struct virtqueue we're talking about.
+ *
+ * Returns true if there are used buffers, false otherwise. May be called at
+ * the same time as other virtqueue operations, but actually calling
+ * virtqueue_get_buf() requires serialization so be mindful of the race between
+ * calling virtqueue_more_used() and virtqueue_get_buf().
+ */
+bool virtqueue_more_used(const struct virtqueue *_vq)
+{
+ struct vring_virtqueue *vq = to_vvq(_vq);
+
+ return more_used(vq);
+}
+EXPORT_SYMBOL_GPL(virtqueue_more_used);
+
irqreturn_t vring_interrupt(int irq, void *_vq)
{
struct vring_virtqueue *vq = to_vvq(_vq);
--
2.31.1


2021-05-25 02:47:31

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH 1/3] virtio: add virtioqueue_more_used()


?? 2021/5/20 ????10:13, Stefan Hajnoczi д??:
> Add an API to check whether there are pending used buffers. There is
> already a similar API called virtqueue_poll() but it only works together
> with virtqueue_enable_cb_prepare(). The patches that follow add blk-mq
> ->poll() support to virtio_blk and they need to check for used buffers
> without re-enabling virtqueue callbacks, so introduce an API for it.
>
> Signed-off-by: Stefan Hajnoczi <[email protected]>


Typo in the subject.


> ---
> include/linux/virtio.h | 2 ++
> drivers/virtio/virtio_ring.c | 17 +++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> index b1894e0323fa..c6ad0f25f412 100644
> --- a/include/linux/virtio.h
> +++ b/include/linux/virtio.h
> @@ -63,6 +63,8 @@ bool virtqueue_kick_prepare(struct virtqueue *vq);
>
> bool virtqueue_notify(struct virtqueue *vq);
>
> +bool virtqueue_more_used(const struct virtqueue *vq);
> +
> void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
>
> void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len,
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 71e16b53e9c1..7c3da75da462 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -2032,6 +2032,23 @@ static inline bool more_used(const struct vring_virtqueue *vq)
> return vq->packed_ring ? more_used_packed(vq) : more_used_split(vq);
> }
>
> +/**
> + * virtqueue_more_used - check if there are used buffers pending
> + * @_vq: the struct virtqueue we're talking about.
> + *
> + * Returns true if there are used buffers, false otherwise. May be called at
> + * the same time as other virtqueue operations, but actually calling
> + * virtqueue_get_buf() requires serialization so be mindful of the race between
> + * calling virtqueue_more_used() and virtqueue_get_buf().
> + */
> +bool virtqueue_more_used(const struct virtqueue *_vq)
> +{
> + struct vring_virtqueue *vq = to_vvq(_vq);
> +
> + return more_used(vq);
> +}
> +EXPORT_SYMBOL_GPL(virtqueue_more_used);


It's worth to mention that the function is not serialized (no barriers).

Thanks


> +
> irqreturn_t vring_interrupt(int irq, void *_vq)
> {
> struct vring_virtqueue *vq = to_vvq(_vq);

2021-05-25 10:13:30

by Stefan Hajnoczi

[permalink] [raw]
Subject: Re: [PATCH 1/3] virtio: add virtioqueue_more_used()

On Tue, May 25, 2021 at 10:23:39AM +0800, Jason Wang wrote:
>
> 在 2021/5/20 下午10:13, Stefan Hajnoczi 写道:
> > Add an API to check whether there are pending used buffers. There is
> > already a similar API called virtqueue_poll() but it only works together
> > with virtqueue_enable_cb_prepare(). The patches that follow add blk-mq
> > ->poll() support to virtio_blk and they need to check for used buffers
> > without re-enabling virtqueue callbacks, so introduce an API for it.
> >
> > Signed-off-by: Stefan Hajnoczi <[email protected]>
>
>
> Typo in the subject.

Thanks, will fix.

> > +/**
> > + * virtqueue_more_used - check if there are used buffers pending
> > + * @_vq: the struct virtqueue we're talking about.
> > + *
> > + * Returns true if there are used buffers, false otherwise. May be called at
> > + * the same time as other virtqueue operations, but actually calling
> > + * virtqueue_get_buf() requires serialization so be mindful of the race between
> > + * calling virtqueue_more_used() and virtqueue_get_buf().
> > + */
> > +bool virtqueue_more_used(const struct virtqueue *_vq)
> > +{
> > + struct vring_virtqueue *vq = to_vvq(_vq);
> > +
> > + return more_used(vq);
> > +}
> > +EXPORT_SYMBOL_GPL(virtqueue_more_used);
>
>
> It's worth to mention that the function is not serialized (no barriers).

Thanks, will fix.

Stefan


Attachments:
(No filename) (1.37 kB)
signature.asc (499.00 B)
Download all attachments