diff mbox series

[net-next,v2,4/5] virtio_ring: add 'flushed' as an argument to virtqueue_reset()

Message ID 20241203073025.67065-5-koichiro.den@canonical.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series virtio_net: correct netdev_tx_reset_queue() invocation points | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success Errors and warnings before: 0 (+0) this patch: 0 (+0)
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 326 this patch: 326
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 63 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 21 this patch: 21
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-12-03--09-00 (tests: 760)

Commit Message

Koichiro Den Dec. 3, 2024, 7:30 a.m. UTC
When virtqueue_reset() has actually recycled all unused buffers,
additional work may be required in some cases. Relying solely on its
return status is fragile, so introduce a new argument 'flushed' to
explicitly indicate whether it has really occurred.

Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
---
 drivers/net/virtio_net.c     | 6 ++++--
 drivers/virtio/virtio_ring.c | 6 +++++-
 include/linux/virtio.h       | 3 ++-
 3 files changed, 11 insertions(+), 4 deletions(-)

Comments

Jason Wang Dec. 4, 2024, 2:49 a.m. UTC | #1
On Tue, Dec 3, 2024 at 3:31 PM Koichiro Den <koichiro.den@canonical.com> wrote:
>
> When virtqueue_reset() has actually recycled all unused buffers,
> additional work may be required in some cases. Relying solely on its
> return status is fragile, so introduce a new argument 'flushed' to
> explicitly indicate whether it has really occurred.
>
> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> ---
>  drivers/net/virtio_net.c     | 6 ++++--
>  drivers/virtio/virtio_ring.c | 6 +++++-
>  include/linux/virtio.h       | 3 ++-
>  3 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 0103d7990e44..d5240a03b7d6 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -5695,6 +5695,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
>                                     struct xsk_buff_pool *pool)
>  {
>         int err, qindex;
> +       bool flushed;
>
>         qindex = rq - vi->rq;
>
> @@ -5713,7 +5714,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
>
>         virtnet_rx_pause(vi, rq);
>
> -       err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf);
> +       err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf, &flushed);
>         if (err) {
>                 netdev_err(vi->dev, "reset rx fail: rx queue index: %d err: %d\n", qindex, err);
>
> @@ -5737,12 +5738,13 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi,
>                                     struct xsk_buff_pool *pool)
>  {
>         int err, qindex;
> +       bool flushed;
>
>         qindex = sq - vi->sq;
>
>         virtnet_tx_pause(vi, sq);
>
> -       err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf);
> +       err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf, &flushed);
>         if (err) {
>                 netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err);
>                 pool = NULL;
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 34a068d401ec..b522ef798946 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -2828,6 +2828,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
>   * virtqueue_reset - detach and recycle all unused buffers
>   * @_vq: the struct virtqueue we're talking about.
>   * @recycle: callback to recycle unused buffers
> + * @flushed: whether or not unused buffers are all flushed
>   *
>   * Caller must ensure we don't call this with other virtqueue operations
>   * at the same time (except where noted).
> @@ -2839,14 +2840,17 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
>   * -EPERM: Operation not permitted
>   */
>  int virtqueue_reset(struct virtqueue *_vq,
> -                   void (*recycle)(struct virtqueue *vq, void *buf))
> +                   void (*recycle)(struct virtqueue *vq, void *buf),
> +                   bool *flushed)
>  {
>         struct vring_virtqueue *vq = to_vvq(_vq);
>         int err;
>
> +       *flushed = false;
>         err = virtqueue_disable_and_recycle(_vq, recycle);
>         if (err)
>                 return err;
> +       *flushed = true;
>

This makes me think if it would be easier if we just find a way to
reset the tx queue inside virtqueue_disable_and_recycle().

For example, introducing a recycle_done callback?

Thanks
Koichiro Den Dec. 4, 2024, 4:14 a.m. UTC | #2
On Wed, Dec 04, 2024 at 10:49:02AM +0800, Jason Wang wrote:
> On Tue, Dec 3, 2024 at 3:31 PM Koichiro Den <koichiro.den@canonical.com> wrote:
> >
> > When virtqueue_reset() has actually recycled all unused buffers,
> > additional work may be required in some cases. Relying solely on its
> > return status is fragile, so introduce a new argument 'flushed' to
> > explicitly indicate whether it has really occurred.
> >
> > Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> > ---
> >  drivers/net/virtio_net.c     | 6 ++++--
> >  drivers/virtio/virtio_ring.c | 6 +++++-
> >  include/linux/virtio.h       | 3 ++-
> >  3 files changed, 11 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 0103d7990e44..d5240a03b7d6 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -5695,6 +5695,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
> >                                     struct xsk_buff_pool *pool)
> >  {
> >         int err, qindex;
> > +       bool flushed;
> >
> >         qindex = rq - vi->rq;
> >
> > @@ -5713,7 +5714,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
> >
> >         virtnet_rx_pause(vi, rq);
> >
> > -       err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf);
> > +       err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf, &flushed);
> >         if (err) {
> >                 netdev_err(vi->dev, "reset rx fail: rx queue index: %d err: %d\n", qindex, err);
> >
> > @@ -5737,12 +5738,13 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi,
> >                                     struct xsk_buff_pool *pool)
> >  {
> >         int err, qindex;
> > +       bool flushed;
> >
> >         qindex = sq - vi->sq;
> >
> >         virtnet_tx_pause(vi, sq);
> >
> > -       err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf);
> > +       err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf, &flushed);
> >         if (err) {
> >                 netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err);
> >                 pool = NULL;
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index 34a068d401ec..b522ef798946 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -2828,6 +2828,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
> >   * virtqueue_reset - detach and recycle all unused buffers
> >   * @_vq: the struct virtqueue we're talking about.
> >   * @recycle: callback to recycle unused buffers
> > + * @flushed: whether or not unused buffers are all flushed
> >   *
> >   * Caller must ensure we don't call this with other virtqueue operations
> >   * at the same time (except where noted).
> > @@ -2839,14 +2840,17 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
> >   * -EPERM: Operation not permitted
> >   */
> >  int virtqueue_reset(struct virtqueue *_vq,
> > -                   void (*recycle)(struct virtqueue *vq, void *buf))
> > +                   void (*recycle)(struct virtqueue *vq, void *buf),
> > +                   bool *flushed)
> >  {
> >         struct vring_virtqueue *vq = to_vvq(_vq);
> >         int err;
> >
> > +       *flushed = false;
> >         err = virtqueue_disable_and_recycle(_vq, recycle);
> >         if (err)
> >                 return err;
> > +       *flushed = true;
> >
> 
> This makes me think if it would be easier if we just find a way to
> reset the tx queue inside virtqueue_disable_and_recycle().
> 
> For example, introducing a recycle_done callback?

It sounds reasonable and much cleaner. I'll prepare and send v3 shortly.
Thanks for the review.

-Koichiro Den

> 
> Thanks
>
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 0103d7990e44..d5240a03b7d6 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -5695,6 +5695,7 @@  static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
 				    struct xsk_buff_pool *pool)
 {
 	int err, qindex;
+	bool flushed;
 
 	qindex = rq - vi->rq;
 
@@ -5713,7 +5714,7 @@  static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
 
 	virtnet_rx_pause(vi, rq);
 
-	err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf);
+	err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf, &flushed);
 	if (err) {
 		netdev_err(vi->dev, "reset rx fail: rx queue index: %d err: %d\n", qindex, err);
 
@@ -5737,12 +5738,13 @@  static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi,
 				    struct xsk_buff_pool *pool)
 {
 	int err, qindex;
+	bool flushed;
 
 	qindex = sq - vi->sq;
 
 	virtnet_tx_pause(vi, sq);
 
-	err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf);
+	err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf, &flushed);
 	if (err) {
 		netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err);
 		pool = NULL;
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 34a068d401ec..b522ef798946 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -2828,6 +2828,7 @@  EXPORT_SYMBOL_GPL(virtqueue_resize);
  * virtqueue_reset - detach and recycle all unused buffers
  * @_vq: the struct virtqueue we're talking about.
  * @recycle: callback to recycle unused buffers
+ * @flushed: whether or not unused buffers are all flushed
  *
  * Caller must ensure we don't call this with other virtqueue operations
  * at the same time (except where noted).
@@ -2839,14 +2840,17 @@  EXPORT_SYMBOL_GPL(virtqueue_resize);
  * -EPERM: Operation not permitted
  */
 int virtqueue_reset(struct virtqueue *_vq,
-		    void (*recycle)(struct virtqueue *vq, void *buf))
+		    void (*recycle)(struct virtqueue *vq, void *buf),
+		    bool *flushed)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
 	int err;
 
+	*flushed = false;
 	err = virtqueue_disable_and_recycle(_vq, recycle);
 	if (err)
 		return err;
+	*flushed = true;
 
 	if (vq->packed_ring)
 		virtqueue_reinit_packed(vq);
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 878feda08af9..e5072d64a364 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -112,7 +112,8 @@  int virtqueue_resize(struct virtqueue *vq, u32 num,
 		     void (*recycle)(struct virtqueue *vq, void *buf),
 		     bool *flushed);
 int virtqueue_reset(struct virtqueue *vq,
-		    void (*recycle)(struct virtqueue *vq, void *buf));
+		    void (*recycle)(struct virtqueue *vq, void *buf),
+		    bool *flushed);
 
 struct virtio_admin_cmd {
 	__le16 opcode;