From: "Michael S. Tsirkin" <mst@redhat.com>
To: zhaoguohan@kylinos.cn
Cc: qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
"Stefano Garzarella" <sgarzare@redhat.com>
Subject: Re: [PATCH 2/2] vhost-user-base: clean up vhost_dev on realize failure
Date: Mon, 29 Jun 2026 05:57:55 -0400 [thread overview]
Message-ID: <20260629055709-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260629092619.2607275-2-zhaoguohan@kylinos.cn>
On Mon, Jun 29, 2026 at 05:26:19PM +0800, zhaoguohan@kylinos.cn wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
>
> vhost-user-base queries the backend shared memory configuration after
> vhost_dev_init() succeeds. If that query fails, or if the shared memory
> configuration fails validation, realization jumps to the error path
> without cleaning up the initialized vhost_dev.
>
> Track whether vhost_dev_init() succeeded and call vhost_dev_cleanup()
> from the error path in that case. Keep a copy of vhost_dev.vqs so the
> allocation can still be freed after vhost_dev_cleanup() clears struct
> vhost_dev.
>
> Fixes: 6608dca74ecf (vhost-user-device: Add shared memory BAR)
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> ---
> hw/virtio/vhost-user-base.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c
> index 6ac523f9ebef..000e91d50331 100644
> --- a/hw/virtio/vhost-user-base.c
> +++ b/hw/virtio/vhost-user-base.c
> @@ -287,6 +287,8 @@ static void vub_device_realize(DeviceState *dev, Error **errp)
> VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> VHostUserBase *vub = VHOST_USER_BASE(dev);
> uint64_t memory_sizes[VIRTIO_MAX_SHMEM_REGIONS];
> + struct vhost_virtqueue *vhost_vqs = NULL;
> + bool vhost_dev_initialized = false;
> int i, ret, nregions, regions_processed = 0;
>
> if (!vub->chardev.chr) {
> @@ -338,6 +340,7 @@ static void vub_device_realize(DeviceState *dev, Error **errp)
>
> vub->vhost_dev.nvqs = vub->num_vqs;
> vub->vhost_dev.vqs = g_new0(struct vhost_virtqueue, vub->vhost_dev.nvqs);
> + vhost_vqs = vub->vhost_dev.vqs;
>
> /* connect to backend */
> ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user,
> @@ -346,6 +349,7 @@ static void vub_device_realize(DeviceState *dev, Error **errp)
> if (ret < 0) {
> goto err;
> }
> + vhost_dev_initialized = true;
>
> ret = vub->vhost_dev.vhost_ops->vhost_get_shmem_config(&vub->vhost_dev,
> &nregions,
> @@ -386,6 +390,10 @@ static void vub_device_realize(DeviceState *dev, Error **errp)
> dev, NULL, true);
> return;
> err:
> + if (vhost_dev_initialized) {
> + vhost_dev_cleanup(&vub->vhost_dev);
> + }
> + g_free(vhost_vqs);
> do_vhost_user_cleanup(vdev, vub);
> }
Pls just add another label.
> --
> 2.43.0
next prev parent reply other threads:[~2026-06-29 9:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 9:26 [PATCH 1/2] vhost-user-base: free virtqueue array during cleanup zhaoguohan
2026-06-29 9:26 ` [PATCH 2/2] vhost-user-base: clean up vhost_dev on realize failure zhaoguohan
2026-06-29 9:57 ` Michael S. Tsirkin [this message]
2026-06-30 1:20 ` [PATCH v2 " zhaoguohan
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=20260629055709-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=zhaoguohan@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.