From: Stefan Hajnoczi <stefanha@redhat.com>
To: Albert Esteve <aesteve@redhat.com>
Cc: qemu-devel@nongnu.org, stevensd@chromium.org, dbassey@redhat.com,
"Laurent Vivier" <lvivier@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
mst@redhat.com, slp@redhat.com, hi@alyssa.is,
"Fabiano Rosas" <farosas@suse.de>,
"Stefano Garzarella" <sgarzare@redhat.com>,
jasowang@redhat.com, david@redhat.com,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH v8 1/7] vhost-user: Add VirtIO Shared Memory map request
Date: Mon, 29 Sep 2025 15:15:04 -0400 [thread overview]
Message-ID: <20250929191504.GH81824@fedora> (raw)
In-Reply-To: <20250910115420.1012191-2-aesteve@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2190 bytes --]
On Wed, Sep 10, 2025 at 01:54:14PM +0200, Albert Esteve wrote:
> +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;
> + Error *local_err = NULL;
> + g_autoptr(GString) shm_name = g_string_new(NULL);
> +
> + if (fd < 0) {
> + error_report("Bad fd for map");
> + return -EBADF;
> + }
> +
> + if (QSIMPLEQ_EMPTY(&dev->vdev->shmem_list)) {
> + error_report("Device has no VIRTIO Shared Memory Regions. "
> + "Requested ID: %d", vu_mmap->shmid);
> + return -EFAULT;
> + }
> +
> + shmem = virtio_find_shmem_region(dev->vdev, vu_mmap->shmid);
> + if (!shmem) {
> + error_report("VIRTIO Shared Memory Region at "
> + "ID %d not found or unitialized", vu_mmap->shmid);
> + return -EFAULT;
> + }
> +
> + 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);
> + return -EFAULT;
> + }
> +
> + g_string_printf(shm_name, "virtio-shm%i-%lu",
> + vu_mmap->shmid, vu_mmap->shm_offset);
> +
> + memory_region_transaction_begin();
> +
> + /* Create VirtioSharedMemoryMapping object */
> + VirtioSharedMemoryMapping *mapping = virtio_shared_memory_mapping_new(
> + vu_mmap->shmid, fd, vu_mmap->fd_offset, vu_mmap->shm_offset,
> + vu_mmap->len, vu_mmap->flags & VHOST_USER_FLAG_MAP_RW);
> +
> + if (!mapping) {
> + memory_region_transaction_commit();
> + return -EFAULT;
> + }
> +
> + /* Add the mapping to the shared memory region */
> + if (virtio_add_shmem_map(shmem, mapping) != 0) {
Missing check for overlap with existing mappings. The spec does not
allow overlap.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2025-09-29 19:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 11:54 [PATCH v8 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests Albert Esteve
2025-09-10 11:54 ` [PATCH v8 1/7] vhost-user: Add VirtIO Shared Memory map request Albert Esteve
2025-09-29 18:39 ` Stefan Hajnoczi
2025-09-29 19:15 ` Stefan Hajnoczi [this message]
2025-09-10 11:54 ` [PATCH v8 2/7] vhost_user.rst: Align VhostUserMsg excerpt members Albert Esteve
2025-09-10 11:54 ` [PATCH v8 3/7] vhost_user.rst: Add SHMEM_MAP/_UNMAP to spec Albert Esteve
2025-09-29 18:48 ` Stefan Hajnoczi
2025-09-10 11:54 ` [PATCH v8 4/7] vhost_user: Add frontend get_shmem_config command Albert Esteve
2025-09-29 18:50 ` Stefan Hajnoczi
2025-09-10 11:54 ` [PATCH v8 5/7] vhost_user.rst: Add GET_SHMEM_CONFIG message Albert Esteve
2025-09-10 11:54 ` [PATCH v8 6/7] qmp: add shmem feature map Albert Esteve
2025-09-10 11:54 ` [PATCH v8 7/7] vhost-user-device: Add shared memory BAR Albert Esteve
2025-09-29 19:00 ` Stefan Hajnoczi
2025-10-13 15:37 ` Albert Esteve
2025-09-26 8:28 ` [PATCH v8 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests Albert Esteve
2025-09-29 19:15 ` Stefan Hajnoczi
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=20250929191504.GH81824@fedora \
--to=stefanha@redhat.com \
--cc=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=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=slp@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).