qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Raphael Norwitz <raphael.s.norwitz@gmail.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: mst@redhat.com, sgarzare@redhat.com, raphael@enfabrica.net,
	 qemu-devel@nongnu.org, yc-core@yandex-team.ru,
	d-tatianin@yandex-team.ru
Subject: Re: [PATCH v3 10/23] vhost: vhost_virtqueue_start(): fix failure path
Date: Mon, 20 Oct 2025 14:24:14 -0400	[thread overview]
Message-ID: <CAFubqFuZjy2kmQtuxsbVQrh3AQR2X5hW7BKxwA0J0KfqFbaQOQ@mail.gmail.com> (raw)
In-Reply-To: <20251015145808.1112843-11-vsementsov@yandex-team.ru>

Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>

On Wed, Oct 15, 2025 at 11:07 AM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> We miss call to unmap in cases when vhost_memory_map() returns
> lenght less than requested (still we consider such cases as an
> error). Let's fix it in vhost_memory_map().
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> Reviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> ---
>  hw/virtio/vhost.c | 35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 94efa409aa..be2245cc7e 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -453,11 +453,20 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)
>  }
>
>  static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,
> -                              hwaddr *plen, bool is_write)
> +                              hwaddr len, bool is_write)
>  {
>      if (!vhost_dev_has_iommu(dev)) {
> -        return address_space_map(dev->vdev->dma_as, addr, plen, is_write,
> -                                 MEMTXATTRS_UNSPECIFIED);
> +        hwaddr mapped_len = len;
> +        void *res = address_space_map(dev->vdev->dma_as, addr, &mapped_len,
> +                                      is_write, MEMTXATTRS_UNSPECIFIED);
> +        if (!res) {
> +            return NULL;
> +        }
> +        if (len != mapped_len) {
> +            address_space_unmap(dev->vdev->dma_as, res, mapped_len, 0, 0);
> +            return NULL;
> +        }
> +        return res;
>      } else {
>          return (void *)(uintptr_t)addr;
>      }
> @@ -1261,7 +1270,7 @@ int vhost_virtqueue_start(struct vhost_dev *dev,
>      BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
>      VirtioBusState *vbus = VIRTIO_BUS(qbus);
>      VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
> -    hwaddr s, l, a;
> +    hwaddr l, a;
>      int r;
>      int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx);
>      struct vhost_vring_file file = {
> @@ -1301,24 +1310,24 @@ int vhost_virtqueue_start(struct vhost_dev *dev,
>          }
>      }
>
> -    vq->desc_size = s = l = virtio_queue_get_desc_size(vdev, idx);
> +    vq->desc_size = l = virtio_queue_get_desc_size(vdev, idx);
>      vq->desc_phys = a;
> -    vq->desc = vhost_memory_map(dev, a, &l, false);
> -    if (!vq->desc || l != s) {
> +    vq->desc = vhost_memory_map(dev, a, l, false);
> +    if (!vq->desc) {
>          r = -ENOMEM;
>          goto fail_alloc_desc;
>      }
> -    vq->avail_size = s = l = virtio_queue_get_avail_size(vdev, idx);
> +    vq->avail_size = l = virtio_queue_get_avail_size(vdev, idx);
>      vq->avail_phys = a = virtio_queue_get_avail_addr(vdev, idx);
> -    vq->avail = vhost_memory_map(dev, a, &l, false);
> -    if (!vq->avail || l != s) {
> +    vq->avail = vhost_memory_map(dev, a, l, false);
> +    if (!vq->avail) {
>          r = -ENOMEM;
>          goto fail_alloc_avail;
>      }
> -    vq->used_size = s = l = virtio_queue_get_used_size(vdev, idx);
> +    vq->used_size = l = virtio_queue_get_used_size(vdev, idx);
>      vq->used_phys = a = virtio_queue_get_used_addr(vdev, idx);
> -    vq->used = vhost_memory_map(dev, a, &l, true);
> -    if (!vq->used || l != s) {
> +    vq->used = vhost_memory_map(dev, a, l, true);
> +    if (!vq->used) {
>          r = -ENOMEM;
>          goto fail_alloc_used;
>      }
> --
> 2.48.1
>
>


  reply	other threads:[~2025-10-20 18:25 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 14:57 [PATCH v3 00/23] vhost refactoring and fixes Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 01/23] vhost-user: rework enabling vrings Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 02/23] vhost: drop backend_features field Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 03/23] vhost-user: introduce vhost_user_has_protocol_feature() helper Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 04/23] vhost: move protocol_features to vhost_user Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 05/23] vhost-user-gpu: drop code duplication Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 06/23] vhost: make vhost_dev.features private Vladimir Sementsov-Ogievskiy
2025-10-17 10:32   ` Daniil Tatianin
2025-10-17 17:02     ` Vladimir Sementsov-Ogievskiy
2025-10-31 17:31       ` Daniil Tatianin
2025-10-15 14:57 ` [PATCH v3 07/23] virtio: move common part of _set_guest_notifier to generic code Vladimir Sementsov-Ogievskiy
2025-11-07 13:01   ` Michael S. Tsirkin
2025-10-15 14:57 ` [PATCH v3 08/23] virtio: drop *_set_guest_notifier_fd_handler() helpers Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 09/23] vhost-user: keep QIOChannelSocket for backend channel Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 10/23] vhost: vhost_virtqueue_start(): fix failure path Vladimir Sementsov-Ogievskiy
2025-10-20 18:24   ` Raphael Norwitz [this message]
2025-10-15 14:57 ` [PATCH v3 11/23] vhost: make vhost_memory_unmap() null-safe Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 12/23] vhost: simplify calls to vhost_memory_unmap() Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 13/23] vhost: move vrings mapping to the top of vhost_virtqueue_start() Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 14/23] vhost: vhost_virtqueue_start(): drop extra local variables Vladimir Sementsov-Ogievskiy
2025-10-15 14:57 ` [PATCH v3 15/23] vhost: final refactoring of vhost vrings map/unmap Vladimir Sementsov-Ogievskiy
2025-10-15 14:58 ` [PATCH v3 16/23] vhost: simplify vhost_dev_init() error-path Vladimir Sementsov-Ogievskiy
2025-10-15 14:58 ` [PATCH v3 17/23] vhost: move busyloop timeout initialization to vhost_virtqueue_init() Vladimir Sementsov-Ogievskiy
2025-10-15 14:58 ` [PATCH v3 18/23] vhost: introduce check_memslots() helper Vladimir Sementsov-Ogievskiy
2025-11-03 22:19   ` Michael S. Tsirkin
2025-11-04 10:59     ` Vladimir Sementsov-Ogievskiy
2025-10-15 14:58 ` [PATCH v3 19/23] vhost: vhost_dev_init(): simplify features initialization Vladimir Sementsov-Ogievskiy
2025-10-15 14:58 ` [PATCH v3 20/23] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier() Vladimir Sementsov-Ogievskiy
2025-10-15 14:58 ` [PATCH v3 21/23] vhost-user: make trace events more readable Vladimir Sementsov-Ogievskiy
2025-11-03 22:22   ` Michael S. Tsirkin
2025-10-15 14:58 ` [PATCH v3 22/23] vhost-user-blk: add some useful trace-points Vladimir Sementsov-Ogievskiy
2025-11-03 21:28   ` Michael S. Tsirkin
2025-11-04 11:08     ` Vladimir Sementsov-Ogievskiy
2025-10-15 14:58 ` [PATCH v3 23/23] vhost: " Vladimir Sementsov-Ogievskiy
2025-11-03 21:26   ` Michael S. Tsirkin
2025-10-18 15:33 ` [PATCH v3 00/23] vhost refactoring and fixes Lei Yang

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=CAFubqFuZjy2kmQtuxsbVQrh3AQR2X5hW7BKxwA0J0KfqFbaQOQ@mail.gmail.com \
    --to=raphael.s.norwitz@gmail.com \
    --cc=d-tatianin@yandex-team.ru \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael@enfabrica.net \
    --cc=sgarzare@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    --cc=yc-core@yandex-team.ru \
    /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).