From: Jason Wang <jasowang@redhat.com>
To: Eugenio Perez Martin <eperezma@redhat.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Cindy Lu <lulu@redhat.com>, Laurent Vivier <lvivier@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
linux-kernel@vger.kernel.org,
Maxime Coquelin <mcoqueli@redhat.com>,
Yongji Xie <xieyongji@bytedance.com>,
virtualization@lists.linux.dev
Subject: Re: [PATCH 1/6] vduse: ensure vq->ready access is smp safe
Date: Tue, 3 Feb 2026 12:05:07 +0800 [thread overview]
Message-ID: <CACGkMEuNZzDVccF_yiinJowrfGgWRAR_-ZvOqNmFz=cLVKN-+w@mail.gmail.com> (raw)
In-Reply-To: <CAJaqyWcVdMc+xQ=oq4ipu_sGh4uMJGidC8CFYSaa+5ZcwiKZ7g@mail.gmail.com>
On Fri, Jan 30, 2026 at 3:56 PM Eugenio Perez Martin
<eperezma@redhat.com> wrote:
>
> On Fri, Jan 30, 2026 at 3:18 AM Jason Wang <jasowang@redhat.com> wrote:
> >
> > On Thu, Jan 29, 2026 at 2:21 PM Eugenio Perez Martin
> > <eperezma@redhat.com> wrote:
> > >
> > > On Thu, Jan 29, 2026 at 2:17 AM Jason Wang <jasowang@redhat.com> wrote:
> > > >
> > > > On Wed, Jan 28, 2026 at 8:45 PM Eugenio Pérez <eperezma@redhat.com> wrote:
> > > > >
> > > > > The vduse_vdpa_set_vq_ready can be called in the lifetime of the device
> > > > > well after initial setup, and the device can read it afterwards.
> > > > >
> > > > > Ensure that reads and writes to vq->ready are SMP safe so that the
> > > > > caller can trust that virtqueue kicks and calls behave as expected
> > > > > immediately after the operation returns.
> > > > >
> > > > > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > > > > ---
> > > > > drivers/vdpa/vdpa_user/vduse_dev.c | 34 +++++++++++++++++++++++-------
> > > > > 1 file changed, 26 insertions(+), 8 deletions(-)
> > > > >
> > > > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> > > > > index 73d1d517dc6c..a4963aaf9332 100644
> > > > > --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> > > > > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> > > > > @@ -460,6 +460,24 @@ static __poll_t vduse_dev_poll(struct file *file, poll_table *wait)
> > > > > return mask;
> > > > > }
> > > > >
> > > > > +static bool vduse_vq_get_ready(const struct vduse_virtqueue *vq)
> > > > > +{
> > > > > + /*
> > > > > + * Paired with vduse_vq_set_ready smp_store, as the driver may modify
> > > > > + * it while the VDUSE instance is reading it.
> > > > > + */
> > > > > + return smp_load_acquire(&vq->ready);
> > > > > +}
> > > > > +
> > > > > +static void vduse_vq_set_ready(struct vduse_virtqueue *vq, bool ready)
> > > > > +{
> > > > > + /*
> > > > > + * Paired with vduse_vq_get_ready smp_load, as the driver may modify
> > > > > + * it while the VDUSE instance is reading it.
> > > > > + */
> > > > > + smp_store_release(&vq->ready, ready);
> > > >
> > > > Assuming this is not used in the datapath, I wonder if we can simply
> > > > use vq_lock mutex.
> > > >
> > >
> > > The function vduse_vq_set/get_ready are not in the datapath, but
> > > vduse_vq_kick and vduse_vq_signal_irqfd are. I'm ok if you want to
> > > switch to vq_mutex if you want though, maybe it's even comparable with
> > > the cost of the ioctls or eventfd signaling.
> >
> > I'd like to use mutex for simplicity.
> >
>
> I cannot move it to a mutex, as we need to take it in the critical
> sections of the kick_lock and irq_lock spinlocks.
>
> I can move it to a spinlock, but it seems more complicated to me. We
> need to make sure we always take these kick_lock and irq_lock in the
> same order as the ready_lock, to not create deadlocks, and they always
> protect just the ready boolean. But sure, I'll send the spinlock
> version for V2.
Thinking about this, I'm not sure I understand the issue.
Maybe you can give me an example of the race.
THanks
>
next prev parent reply other threads:[~2026-02-03 4:05 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 12:45 [PATCH 0/6] Add queue ready message to VDUSE Eugenio Pérez
2026-01-28 12:45 ` [PATCH 1/6] vduse: ensure vq->ready access is smp safe Eugenio Pérez
2026-01-29 1:16 ` Jason Wang
2026-01-29 6:20 ` Eugenio Perez Martin
2026-01-30 2:18 ` Jason Wang
2026-01-30 7:56 ` Eugenio Perez Martin
2026-02-03 4:05 ` Jason Wang [this message]
2026-02-03 10:35 ` Eugenio Perez Martin
2026-02-04 2:48 ` Jason Wang
2026-02-04 8:53 ` Eugenio Perez Martin
2026-02-05 4:04 ` Jason Wang
2026-02-05 6:30 ` Eugenio Perez Martin
2026-01-28 12:45 ` [PATCH 2/6] vduse: store control device pointer Eugenio Pérez
2026-01-28 12:45 ` [PATCH 3/6] vduse: Add API v2 definition Eugenio Pérez
2026-01-29 2:00 ` Jason Wang
2026-01-29 8:07 ` Eugenio Perez Martin
2026-01-30 2:17 ` Jason Wang
2026-01-30 8:12 ` Eugenio Perez Martin
2026-01-28 12:45 ` [PATCH 4/6] vduse: add VDUSE_GET_FEATURES ioctl Eugenio Pérez
2026-01-29 2:10 ` Jason Wang
2026-01-29 8:03 ` Eugenio Perez Martin
2026-01-28 12:45 ` [PATCH 5/6] vduse: add F_QUEUE_READY feature Eugenio Pérez
2026-01-29 2:12 ` Jason Wang
2026-01-29 6:26 ` Eugenio Perez Martin
2026-01-30 2:17 ` Jason Wang
2026-01-30 8:14 ` Eugenio Perez Martin
2026-02-03 4:00 ` Jason Wang
2026-02-03 7:27 ` Eugenio Perez Martin
2026-02-04 2:44 ` Jason Wang
2026-02-04 7:34 ` Eugenio Perez Martin
2026-02-05 4:08 ` Jason Wang
2026-02-05 6:38 ` Eugenio Perez Martin
2026-01-28 12:45 ` [PATCH 6/6] vduse: advertise API V2 support Eugenio Pérez
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='CACGkMEuNZzDVccF_yiinJowrfGgWRAR_-ZvOqNmFz=cLVKN-+w@mail.gmail.com' \
--to=jasowang@redhat.com \
--cc=eperezma@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lulu@redhat.com \
--cc=lvivier@redhat.com \
--cc=mcoqueli@redhat.com \
--cc=mst@redhat.com \
--cc=sgarzare@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xieyongji@bytedance.com \
--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