qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Albert Esteve <aesteve@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
	hi@alyssa.is, stefanha@redhat.com, jasowang@redhat.com,
	dbassey@redhat.com, stevensd@chromium.org,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	slp@redhat.com, manos.pitsidianakis@linaro.org
Subject: Re: [PATCH v10 1/7] vhost-user: Add VirtIO Shared Memory map request
Date: Mon, 20 Oct 2025 16:06:58 +0200	[thread overview]
Message-ID: <CADSE00+Rp5+YqM7MP2MVJecHmUGHL271eq-2gFgSuFAC_H-cMA@mail.gmail.com> (raw)
In-Reply-To: <a74da624-8665-46d6-846d-15fc932775cc@redhat.com>

On Mon, Oct 20, 2025 at 3:50 PM David Hildenbrand <david@redhat.com> wrote:
>
> > + * Returns: 0 on success, negative errno on failure
> > + */
> > +static int
> > +vhost_user_backend_handle_shmem_map(struct vhost_dev *dev,
> > +                                    QIOChannel *ioc,
> > +                                    VhostUserHeader *hdr,
> > +                                    VhostUserPayload *payload,
> > +                                    int fd)
> > +{
> > +    VirtioSharedMemory *shmem;
> > +    VhostUserMMap *vu_mmap = &payload->mmap;
> > +    VirtioSharedMemoryMapping *existing;
> > +    Error *local_err = NULL;
> > +    int ret = 0;
> > +
> > +    if (fd < 0) {
> > +        error_report("Bad fd for map");
> > +        ret = -EBADF;
> > +        goto send_reply;
> > +    }
> > +
> > +    if (QSIMPLEQ_EMPTY(&dev->vdev->shmem_list)) {
> > +        error_report("Device has no VIRTIO Shared Memory Regions. "
> > +                     "Requested ID: %d", vu_mmap->shmid);
> > +        ret = -EFAULT;
> > +        goto send_reply;
> > +    }
> > +
> > +    shmem = virtio_find_shmem_region(dev->vdev, vu_mmap->shmid);
> > +    if (!shmem) {
> > +        error_report("VIRTIO Shared Memory Region at "
> > +                     "ID %d not found or uninitialized", vu_mmap->shmid);
> > +        ret = -EFAULT;
> > +        goto send_reply;
> > +    }
> > +
> > +    if ((vu_mmap->shm_offset + vu_mmap->len) < vu_mmap->len ||
> > +        (vu_mmap->shm_offset + vu_mmap->len) > shmem->mr.size) {
> > +        error_report("Bad offset/len for mmap %" PRIx64 "+%" PRIx64,
> > +                     vu_mmap->shm_offset, vu_mmap->len);
> > +        ret = -EFAULT;
> > +        goto send_reply;
> > +    }
> > +
> > +    QTAILQ_FOREACH(existing, &shmem->mmaps, link) {
> > +        if (ranges_overlap(existing->offset, existing->len,
> > +                           vu_mmap->shm_offset, vu_mmap->len)) {
> > +            error_report("VIRTIO Shared Memory mapping overlap");
> > +            ret = -EFAULT;
> > +            goto send_reply;
> > +        }
> > +    }
> > +
> > +    memory_region_transaction_begin();
>
> My only comment would be whether the
> memory_region_transaction_begin()/memory_region_transaction_commit()
> should be hidden behind some
> virtio_add_shmem_map_start()/virtio_add_shmem_map_end() helpers.
>
> Talking about memory regions in this function sounds odd given that it's
> more an implementation detail hidden by other helpers.
>
> Then, we can also document why these functions exists, and what the
> contract is for calling them.

I understand. I will send a follow up patch with this, and we can
discuss the solution there. Thanks for giving it another spin!

>
> --
> Cheers
>
> David / dhildenb
>



  reply	other threads:[~2025-10-20 14:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 14:38 [PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests Albert Esteve
2025-10-16 14:38 ` [PATCH v10 1/7] vhost-user: Add VirtIO Shared Memory map request Albert Esteve
2025-10-16 15:18   ` Albert Esteve
2025-10-16 18:31     ` Stefan Hajnoczi
2025-10-17  6:58       ` Albert Esteve
2025-10-17  9:22   ` Stefano Garzarella
2025-10-17  9:29     ` Manos Pitsidianakis
2025-10-17 11:24     ` Albert Esteve
2025-10-17 12:12       ` Stefano Garzarella
2025-10-17 12:35         ` Albert Esteve
2025-10-20 13:50   ` David Hildenbrand
2025-10-20 14:06     ` Albert Esteve [this message]
2025-10-16 14:38 ` [PATCH v10 2/7] vhost_user.rst: Align VhostUserMsg excerpt members Albert Esteve
2025-10-16 14:38 ` [PATCH v10 3/7] vhost_user.rst: Add SHMEM_MAP/_UNMAP to spec Albert Esteve
2025-10-20 13:27   ` Stefan Hajnoczi
2025-10-20 13:49     ` Albert Esteve
2025-10-16 14:38 ` [PATCH v10 4/7] vhost_user: Add frontend get_shmem_config command Albert Esteve
2025-10-16 14:38 ` [PATCH v10 5/7] vhost_user.rst: Add GET_SHMEM_CONFIG message Albert Esteve
2025-10-16 14:38 ` [PATCH v10 6/7] qmp: add shmem feature map Albert Esteve
2025-10-16 14:38 ` [PATCH v10 7/7] vhost-user-device: Add shared memory BAR Albert Esteve
2025-10-16 15:05 ` [PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests Stefan Hajnoczi
2025-10-17 12:42   ` Stefano Garzarella
2025-10-17 13:52   ` Michael S. Tsirkin
2025-10-20 13:51   ` David Hildenbrand

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=CADSE00+Rp5+YqM7MP2MVJecHmUGHL271eq-2gFgSuFAC_H-cMA@mail.gmail.com \
    --to=aesteve@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=david@redhat.com \
    --cc=dbassey@redhat.com \
    --cc=farosas@suse.de \
    --cc=hi@alyssa.is \
    --cc=jasowang@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=slp@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=stevensd@chromium.org \
    /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).