mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Li,Rongqing" <lirongqing@baidu.com>
To: Jason Wang <jasowangio@gmail.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"virtualization@lists.linux.dev" <virtualization@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: 答复: [外部邮件] Re: [PATCH] virtio_ring: reset IN_ORDER state in virtqueue_init()
Date: Fri, 11 Sep 2026 06:05:25 +0000	[thread overview]
Message-ID: <fe5e4fb1b68d4203812e253d722cbe69@baidu.com> (raw)
In-Reply-To: <CAAf7B_M=tfyL33WGkxSX68FwPaRRRBcASVx92EGwPMXaFtUdzQ@mail.gmail.com>

> >
> > The IN_ORDER feature uses additional software state to track the next
> > available descriptor and in-flight descriptor batches.
> >
> > virtqueue_init() resets the common virtqueue state, but free_head and
> > batch_last.id are initialized only when the virtqueue is created. When
> > an IN_ORDER virtqueue is reset, these fields can retain state from the
> > previous queue instance.
> >
> > Reset free_head and invalidate batch_last when initializing an
> > IN_ORDER virtqueue. Keep this in virtqueue_init() so the state is
> > initialized consistently for both newly created and reset virtqueues.
> >
> > Fixes: f6a15d854986 ("virtio_ring: add in order support")
> 
> I think this is needed for -stable.
> 
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > ---
> >  drivers/virtio/virtio_ring.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/virtio/virtio_ring.c
> > b/drivers/virtio/virtio_ring.c index db678f5..d0dc464 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -559,6 +559,11 @@ static void virtqueue_init(struct vring_virtqueue *vq,
> u32 num)
> >         vq->in_use = false;
> >         vq->last_add_time_valid = false;  #endif
> > +
> > +       if (virtqueue_is_in_order(vq)) {
> > +               vq->free_head = 0;
> > +               vq->batch_last.id = UINT_MAX;
> > +       }
> 
> I would try to reuse or refactor virtqueue_vring_attach_split() to reduce code
> duplication.
> 
> Btw have you checked Qemu shadow virtqueue as it might suffer from the same
> issue.
> 

I checked QEMU's shadow virtqueue implementation. batch_last is reinitialized in vhost_svq_start(), 
but free_head is not. Since the SVQ object can be reused across stop/start, free_head may retain stale 
state. So a corresponding fix should be needed

void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev,
                      VirtQueue *vq, VhostIOVATree *iova_tree)
 {
     ...
     svq->shadow_avail_idx = 0;
     svq->shadow_used_idx = 0;
+    svq->free_head = 0;
     memset(&svq->batch_last, 0, sizeof(svq->batch_last));
     svq->last_used = 0;
     svq->last_used_idx = 0;

thanks
 
[Li,Rongqing] 


> Thanks
> 
> >  }
> >
> >
> > --
> > 2.9.4
> >

      reply	other threads:[~2026-09-11  6:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 12:39 lirongqing
2026-09-11  2:17 ` Jason Wang
2026-09-11  6:05   ` Li,Rongqing [this message]

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=fe5e4fb1b68d4203812e253d722cbe69@baidu.com \
    --to=lirongqing@baidu.com \
    --cc=eperezma@redhat.com \
    --cc=jasowangio@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --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

all inboxes | Powered by JetHome®