qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Albert Esteve <aesteve@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Raphael Norwitz" <raphael.norwitz@nutanix.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	qemu-block@nongnu.org, "Eric Blake" <eblake@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Mathieu Poirier" <mathieu.poirier@linaro.org>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Erik Schilling" <erik.schilling@linaro.org>,
	"Gonglei (Arei)" <arei.gonglei@huawei.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Fam Zheng" <fam@euphon.net>,
	virtio-fs@redhat.com, "Stefan Hajnoczi" <stefanha@redhat.com>
Subject: Re: [RFC PATCH v3 20/20] hw/virtio: allow vhost-user-device to be driven by backend
Date: Fri, 1 Sep 2023 12:00:44 +0200	[thread overview]
Message-ID: <CADSE00KVM=xgRDjFcnePXcPr+uqHk15BRpotJr3G2_uR8N1U1A@mail.gmail.com> (raw)
In-Reply-To: <20230710153522.3469097-21-alex.bennee@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 4255 bytes --]

On Mon, Jul 10, 2023 at 6:44 PM Alex Bennée <alex.bennee@linaro.org> wrote:

> Instead of requiring all the information up front allow the
> vhost_dev_init to complete and then see what information we have from
> the backend.
>
> This does change the order around somewhat.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  hw/virtio/vhost-user-device.c | 45 +++++++++++++++++++++++++----------
>  1 file changed, 32 insertions(+), 13 deletions(-)
>
> diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c
> index 0109d4829d..b30b6265fb 100644
> --- a/hw/virtio/vhost-user-device.c
> +++ b/hw/virtio/vhost-user-device.c
> @@ -243,7 +243,6 @@ static void vub_device_realize(DeviceState *dev, Error
> **errp)
>  {
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>      VHostUserBase *vub = VHOST_USER_BASE(dev);
> -    int ret;
>
>      if (!vub->chardev.chr) {
>          error_setg(errp, "vhost-user-device: missing chardev");
> @@ -254,13 +253,43 @@ static void vub_device_realize(DeviceState *dev,
> Error **errp)
>          return;
>      }
>
> +    if (vhost_dev_init(&vub->vhost_dev, &vub->vhost_user,
> +                       VHOST_BACKEND_TYPE_USER, 0, errp)!=0) {
> +        error_setg(errp, "vhost-user-device: unable to start connection");
> +        return;
> +    }
> +
> +    if (vub->vhost_dev.specs.device_id) {
> +        if (vub->virtio_id && vub->virtio_id !=
> vub->vhost_dev.specs.device_id) {
> +            error_setg(errp, "vhost-user-device: backend id %d doesn't
> match cli %d",
> +                       vub->vhost_dev.specs.device_id, vub->virtio_id);
> +            return;
> +        }
> +        vub->virtio_id = vub->vhost_dev.specs.device_id;
> +    }
> +
>      if (!vub->virtio_id) {
> -        error_setg(errp, "vhost-user-device: need to define device id");
> +        error_setg(errp, "vhost-user-device: need to define or be told
> device id");
>          return;
>      }
>
> +    if (vub->vhost_dev.specs.min_vqs) {
> +        if (vub->num_vqs) {
> +            if (vub->num_vqs < vub->vhost_dev.specs.min_vqs ||
> +                vub->num_vqs > vub->vhost_dev.specs.max_vqs) {
> +                error_setg(errp,
> +                           "vhost-user-device: selected nvqs (%d) out of
> bounds (%d->%d)",
> +                           vub->num_vqs,
> +                           vub->vhost_dev.specs.min_vqs,
> vub->vhost_dev.specs.max_vqs);
> +                return;
> +            }
> +        } else {
> +            vub->num_vqs = vub->vhost_dev.specs.min_vqs;
> +        }
> +    }
> +
>      if (!vub->num_vqs) {
> -        vub->num_vqs = 1; /* reasonable default? */
> +        error_setg(errp, "vhost-user-device: need to define number of
> vqs");
>      }
>
>      /*
> @@ -287,16 +316,6 @@ static void vub_device_realize(DeviceState *dev,
> Error **errp)
>                          virtio_add_queue(vdev, 4, vub_handle_output));
>      }
>
> -    vub->vhost_dev.nvqs = vub->num_vqs;
>

Who sets `vub->vhost_dev.nvqs` after removing this line?
Why having `vub->num_vqs` in the first place? In vub_start for example we
still
use `vub->vhost_dev.nvqs`, and we pass `vhost_dev` to other functions that
use its `nvqs`, so `num_vqs` is redundant and requires a logic to
copy/initialise `vhost_dev.nvqs`.

Maybe it would be better to initialse `nvqs` through a function, in the
device file, instead of doing:
`vub->num_vqs = 2;`
We could have:
`vub_set_nvqs(vub, 2);`
Or something along those lines. And the function will have all the internal
logic in this commit, i.e.,
checking the boundaries, setting the `vhost_dev.nvqs` value, printing the
error, etc.
So we can save the extra variable, and the logic to copy the value to the
device.


> -
> -    /* connect to backend */
> -    ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user,
> -                         VHOST_BACKEND_TYPE_USER, 0, errp);
> -
> -    if (ret < 0) {
> -        do_vhost_user_cleanup(vdev, vub);
> -    }
> -
>      qemu_chr_fe_set_handlers(&vub->chardev, NULL, NULL, vub_event, NULL,
>                               dev, NULL, true);
>  }
> --
> 2.39.2
>
>
>

[-- Attachment #2: Type: text/html, Size: 5643 bytes --]

      reply	other threads:[~2023-09-01 10:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 15:35 [PATCH v3 00/20] virtio: add vhost-user-generic, reduce c&p and support standalone Alex Bennée
2023-07-10 15:35 ` [PATCH v3 01/20] include: attempt to document device_class_set_props Alex Bennée
2023-07-10 15:35 ` [PATCH v3 02/20] include/hw: document the device_class_set_parent_* fns Alex Bennée
2023-07-10 15:35 ` [PATCH v3 03/20] hw/virtio: fix typo in VIRTIO_CONFIG_IRQ_IDX comments Alex Bennée
2023-07-10 21:56   ` Philippe Mathieu-Daudé
2023-07-10 15:35 ` [PATCH v3 04/20] include/hw/virtio: document virtio_notify_config Alex Bennée
2023-07-10 15:35 ` [PATCH v3 05/20] include/hw/virtio: add kerneldoc for virtio_init Alex Bennée
2023-07-10 21:58   ` Philippe Mathieu-Daudé
2023-07-10 15:35 ` [PATCH v3 06/20] include/hw/virtio: document some more usage of notifiers Alex Bennée
2023-07-10 15:35 ` [PATCH v3 07/20] virtio: add vhost-user-base and a generic vhost-user-device Alex Bennée
2023-07-10 20:15   ` Michael S. Tsirkin
2023-09-05 14:19   ` Matias Ezequiel Vara Larsen
2023-09-05 17:01     ` Alex Bennée
2023-09-06  9:21       ` Matias Ezequiel Vara Larsen
2023-07-10 15:35 ` [PATCH v3 08/20] virtio: add PCI stub for vhost-user-device Alex Bennée
2023-07-10 15:35 ` [PATCH v3 09/20] hw/virtio: derive vhost-user-rng from vhost-user-device Alex Bennée
2023-07-10 15:35 ` [PATCH v3 10/20] hw/virtio: add config support to vhost-user-device Alex Bennée
2023-07-10 19:58   ` Michael S. Tsirkin
2023-08-31 14:23     ` Albert Esteve
2023-08-31 15:47       ` Alex Bennée
2023-09-01  5:56         ` Erik Schilling
2023-09-01  8:34         ` Albert Esteve
2023-07-10 15:35 ` [PATCH v3 11/20] hw/virtio: derive vhost-user-gpio from vhost-user-device Alex Bennée
2023-07-10 15:35 ` [PATCH v3 12/20] hw/virtio: derive vhost-user-i2c from vhost-user-base Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 13/20] docs/system: add a basic enumeration of vhost-user devices Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 14/20] docs/interop: define STANDALONE protocol feature for vhost-user Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 15/20] hw/virtio: move vhost_user_init earlier Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 16/20] hw/virtio: move virtq initialisation into internal helper Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 17/20] hw/virtio: push down allocation responsibility for vhost_dev->vqs Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 18/20] hw/virtio: validate F_STANDALONE also supports other protocol features Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 19/20] hw/virtio: probe backend for specs if it supports it Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 20/20] hw/virtio: allow vhost-user-device to be driven by backend Alex Bennée
2023-09-01 10:00   ` Albert Esteve [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='CADSE00KVM=xgRDjFcnePXcPr+uqHk15BRpotJr3G2_uR8N1U1A@mail.gmail.com' \
    --to=aesteve@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=arei.gonglei@huawei.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=erik.schilling@linaro.org \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mathieu.poirier@linaro.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    --cc=stefanha@redhat.com \
    --cc=viresh.kumar@linaro.org \
    --cc=virtio-fs@redhat.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).