linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Eugenio Perez Martin <eperezma@redhat.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
	Cindy Lu <lulu@redhat.com>,
	 Stefano Garzarella <sgarzare@redhat.com>,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
	 Laurent Vivier <lvivier@redhat.com>,
	virtualization@lists.linux.dev,  linux-kernel@vger.kernel.org,
	Yongji Xie <xieyongji@bytedance.com>,
	 Maxime Coquelin <mcoqueli@redhat.com>
Subject: Re: [PATCH 2/6] vduse: add vq group support
Date: Wed, 3 Sep 2025 11:57:26 +0800	[thread overview]
Message-ID: <CACGkMEuoH3J9HwRU_G5wsDoeP7EjYfUU-aCDRbsjmcv45OG2mw@mail.gmail.com> (raw)
In-Reply-To: <CAJaqyWeHLw9CUEkH1KF8np2zJMC-zMRU6AFRJEhczzuF7MNU8A@mail.gmail.com>

On Mon, Sep 1, 2025 at 4:40 PM Eugenio Perez Martin <eperezma@redhat.com> wrote:
>
> On Mon, Sep 1, 2025 at 3:59 AM Jason Wang <jasowang@redhat.com> wrote:
> >
> > On Tue, Aug 26, 2025 at 7:27 PM Eugenio Pérez <eperezma@redhat.com> wrote:
> > >
> > > This allows sepparate the different virtqueues in groups that shares the
> > > same address space.  Asking the VDUSE device for the groups of the vq at
> > > the beginning as they're needed for the DMA API.
> > >
> > > Allocating 3 vq groups as net is the device that need the most groups:
> > > * Dataplane (guest passthrough)
> > > * CVQ
> > > * Shadowed vrings.
> > >
> > > Future versions of the series can include dynamic allocation of the
> > > groups array so VDUSE can declare more groups.
> > >
> > > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > > ---
> > > v1: Fix: Remove BIT_ULL(VIRTIO_S_*), as _S_ is already the bit (Maxime)
> > >
> > > RFC v3:
> > > * Increase VDUSE_MAX_VQ_GROUPS to 0xffff (Jason). It was set to a lower
> > >   value to reduce memory consumption, but vqs are already limited to
> > >   that value and userspace VDUSE is able to allocate that many vqs.
> > > * Remove the descs vq group capability as it will not be used and we can
> > >   add it on top.
> > > * Do not ask for vq groups in number of vq groups < 2.
> > > * Move the valid vq groups range check to vduse_validate_config.
> > >
> > > RFC v2:
> > > * Cache group information in kernel, as we need to provide the vq map
> > >   tokens properly.
> > > * Add descs vq group to optimize SVQ forwarding and support indirect
> > >   descriptors out of the box.
> > > ---
> > >  drivers/vdpa/vdpa_user/vduse_dev.c | 51 ++++++++++++++++++++++++++++--
> > >  include/uapi/linux/vduse.h         | 21 +++++++++++-
> > >  2 files changed, 68 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> > > index e7bced0b5542..0f4e36dd167e 100644
> > > --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> > > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> > > @@ -58,6 +58,7 @@ struct vduse_virtqueue {
> > >         struct vdpa_vq_state state;
> > >         bool ready;
> > >         bool kicked;
> > > +       u32 vq_group;
> > >         spinlock_t kick_lock;
> > >         spinlock_t irq_lock;
> > >         struct eventfd_ctx *kickfd;
> > > @@ -114,6 +115,7 @@ struct vduse_dev {
> > >         u8 status;
> > >         u32 vq_num;
> > >         u32 vq_align;
> > > +       u32 ngroups;
> > >         struct vduse_umem *umem;
> > >         struct mutex mem_lock;
> > >         unsigned int bounce_size;
> > > @@ -592,6 +594,13 @@ static int vduse_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 idx,
> > >         return 0;
> > >  }
> > >
> > > +static u32 vduse_get_vq_group(struct vdpa_device *vdpa, u16 idx)
> > > +{
> > > +       struct vduse_dev *dev = vdpa_to_vduse(vdpa);
> > > +
> > > +       return dev->vqs[idx]->vq_group;
> > > +}
> > > +
> > >  static int vduse_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 idx,
> > >                                 struct vdpa_vq_state *state)
> > >  {
> > > @@ -678,6 +687,28 @@ static u8 vduse_vdpa_get_status(struct vdpa_device *vdpa)
> > >         return dev->status;
> > >  }
> > >
> > > +static int vduse_fill_vq_groups(struct vduse_dev *dev)
> > > +{
> > > +       /* All vqs and descs must be in vq group 0 if ngroups < 2 */
> > > +       if (dev->ngroups < 2)
> > > +               return 0;
> > > +
> > > +       for (int i = 0; i < dev->vdev->vdpa.nvqs; ++i) {
> > > +               struct vduse_dev_msg msg = { 0 };
> > > +               int ret;
> > > +
> > > +               msg.req.type = VDUSE_GET_VQ_GROUP;
> > > +               msg.req.vq_group.index = i;
> > > +               ret = vduse_dev_msg_sync(dev, &msg);
> > > +               if (ret)
> > > +                       return ret;
> > > +
> > > +               dev->vqs[i]->vq_group = msg.resp.vq_group.group;
> > > +       }
> > > +
> > > +       return 0;
> > > +}
> > > +
> > >  static void vduse_vdpa_set_status(struct vdpa_device *vdpa, u8 status)
> > >  {
> > >         struct vduse_dev *dev = vdpa_to_vduse(vdpa);
> > > @@ -685,6 +716,11 @@ static void vduse_vdpa_set_status(struct vdpa_device *vdpa, u8 status)
> > >         if (vduse_dev_set_status(dev, status))
> > >                 return;
> > >
> > > +       if (((dev->status ^ status) & VIRTIO_CONFIG_S_FEATURES_OK) &&
> > > +           (status & VIRTIO_CONFIG_S_FEATURES_OK))
> > > +               if (vduse_fill_vq_groups(dev))
> > > +                       return;
> >
> > I may lose some context but I think we've agreed that we need to
> > extend the status response for this instead of having multiple
> > indepdent response.
> >
>
> My understanding was it is ok to start with this version by [1]. We
> can even make it asynchronous on top if we find this is a bottleneck
> and the VDUSE device would need no change, would that work?
>
> > > +
> > >         dev->status = status;
> > >  }
> > >
> > > @@ -789,6 +825,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = {
> > >         .set_vq_cb              = vduse_vdpa_set_vq_cb,
> > >         .set_vq_num             = vduse_vdpa_set_vq_num,
> > >         .get_vq_size            = vduse_vdpa_get_vq_size,
> > > +       .get_vq_group           = vduse_get_vq_group,
> > >         .set_vq_ready           = vduse_vdpa_set_vq_ready,
> > >         .get_vq_ready           = vduse_vdpa_get_vq_ready,
> > >         .set_vq_state           = vduse_vdpa_set_vq_state,
> > > @@ -1737,12 +1774,19 @@ static bool features_is_valid(struct vduse_dev_config *config)
> > >         return true;
> > >  }
> > >
> > > -static bool vduse_validate_config(struct vduse_dev_config *config)
> > > +static bool vduse_validate_config(struct vduse_dev_config *config,
> > > +                                 u64 api_version)
> > >  {
> > >         if (!is_mem_zero((const char *)config->reserved,
> > >                          sizeof(config->reserved)))
> > >                 return false;
> > >
> > > +       if (api_version < VDUSE_API_VERSION_1 && config->ngroups)
> > > +               return false;
> > > +
> > > +       if (api_version >= VDUSE_API_VERSION_1 && config->ngroups > 0xffff)
> > > +               return false;
> >
> > Let's use a macro instead of magic number.
> >
>
> The rest of the limits are hardcoded, but I'm ok with changing this.
> Is UINT16_MAX ok here, or do you prefer something like MAX_NGROUPS and
> MAX_ASID?

MAX_NGROUPS and MAX_ASID seem to be better.

Thanks

>
> [...]
>
> [1] https://patchew.org/linux/20250807115752.1663383-1-eperezma@redhat.com/20250807115752.1663383-3-eperezma@redhat.com/#CACGkMEuVngGjgPZXnajiPC+pcbt+dr6jqKRQr8OcX7HK1W3WNQ@mail.gmail.com
>


  reply	other threads:[~2025-09-03  3:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-26 11:27 [PATCH 0/6] Add multiple address spaces support to VDUSE Eugenio Pérez
2025-08-26 11:27 ` [PATCH 1/6] vduse: add v1 API definition Eugenio Pérez
2025-08-26 11:27 ` [PATCH 2/6] vduse: add vq group support Eugenio Pérez
2025-09-01  1:59   ` Jason Wang
2025-09-01  2:31     ` Jason Wang
2025-09-01  8:39     ` Eugenio Perez Martin
2025-09-03  3:57       ` Jason Wang [this message]
2025-09-03  3:58       ` Jason Wang
2025-09-03  6:28         ` Eugenio Perez Martin
2025-09-03  7:40           ` Jason Wang
2025-09-03 10:30             ` Eugenio Perez Martin
2025-09-04  3:08               ` Jason Wang
2025-09-04  3:20                 ` Jason Wang
2025-09-05  8:47                   ` Eugenio Perez Martin
2025-09-08  2:12                     ` Jason Wang
2025-08-26 11:27 ` [PATCH 3/6] vduse: return internal vq group struct as map token Eugenio Pérez
2025-09-01  2:25   ` Jason Wang
2025-09-01  7:27     ` Eugenio Perez Martin
2025-08-26 11:27 ` [PATCH 4/6] vduse: create vduse_as to make it an array Eugenio Pérez
2025-09-01  2:27   ` Jason Wang
2025-08-26 11:27 ` [PATCH 5/6] vduse: add vq group asid support Eugenio Pérez
2025-09-01  2:46   ` Jason Wang
2025-09-01  9:11     ` Eugenio Perez Martin
2025-09-03  3:56       ` Jason Wang
2025-09-03  6:39         ` Eugenio Perez Martin
2025-09-08 12:12   ` Yongji Xie
2025-09-16  9:30     ` Eugenio Perez Martin
2025-08-26 11:27 ` [PATCH 6/6] vduse: bump version number Eugenio Pérez
2025-09-15 22:42 ` [PATCH 0/6] Add multiple address spaces support to VDUSE Michael S. Tsirkin
2025-09-16  6:37   ` Eugenio Perez Martin

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=CACGkMEuoH3J9HwRU_G5wsDoeP7EjYfUU-aCDRbsjmcv45OG2mw@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;
as well as URLs for NNTP newsgroup(s).