qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v2 5/9] ivshmem: use ram_from_fd()
Date: Wed, 11 Jan 2017 12:33:43 +0100	[thread overview]
Message-ID: <20170111113347.7577-6-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20170111113347.7577-1-marcandre.lureau@redhat.com>

Instead of having its own mmap handling code, reuse the code from
exec.c.

Note: memory_region_init_ram_from_fd() adds some restrictions
(check for xen, kvm sync-mmu, etc) and changes (such as size
alignment). This may actually be more correct.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/misc/ivshmem.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index abeaf3da08..49db6a27aa 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -491,9 +491,9 @@ static void setup_interrupt(IVShmemState *s, int vector, Error **errp)
 
 static void process_msg_shmem(IVShmemState *s, int fd, Error **errp)
 {
+    Error *local_err = NULL;
     struct stat buf;
     size_t size;
-    void *ptr;
 
     if (s->ivshmem_bar2) {
         error_setg(errp, "server sent unexpected shared memory message");
@@ -522,15 +522,13 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp)
     }
 
     /* mmap the region and map into the BAR2 */
-    ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-    if (ptr == MAP_FAILED) {
-        error_setg_errno(errp, errno, "Failed to mmap shared memory");
-        close(fd);
+    memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s),
+                                   "ivshmem.bar2", size, true, fd, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
         return;
     }
-    memory_region_init_ram_ptr(&s->server_bar2, OBJECT(s),
-                               "ivshmem.bar2", size, ptr);
-    memory_region_set_fd(&s->server_bar2, fd);
+
     s->ivshmem_bar2 = &s->server_bar2;
 }
 
-- 
2.11.0

  parent reply	other threads:[~2017-01-11 11:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11 11:33 [Qemu-devel] [PATCH v2 0/9] Add memfd memory backend Marc-André Lureau
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 1/9] exec: check kvm mmu notifiers earlier Marc-André Lureau
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 2/9] exec: split file_ram_alloc() Marc-André Lureau
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 3/9] exec: split qemu_ram_alloc_from_file() Marc-André Lureau
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 4/9] Add memory_region_init_ram_from_fd() Marc-André Lureau
2017-01-11 11:33 ` Marc-André Lureau [this message]
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 6/9] memory: remove memory_region_set_fd Marc-André Lureau
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 7/9] memfd: split qemu_memfd_alloc() Marc-André Lureau
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 8/9] Add memfd based hostmem Marc-André Lureau
2017-01-11 11:33 ` [Qemu-devel] [PATCH v2 9/9] tests: use memfd in vhost-user-test Marc-André Lureau

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=20170111113347.7577-6-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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).