aboutsummaryrefslogtreecommitdiff
path: root/hw/misc/ivshmem.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-06-02 18:12:25 +0400
committerPaolo Bonzini <pbonzini@redhat.com>2017-06-15 11:04:05 +0200
commit8381d89bec0ca233c45c03939735e6eb89aab022 (patch)
tree3b59838292b82baca3b90e4406345f2437a48081 /hw/misc/ivshmem.c
parentfea617c58b777495b9285f3dc6b33f2898352886 (diff)
downloadqemu-8381d89bec0ca233c45c03939735e6eb89aab022.zip
qemu-8381d89bec0ca233c45c03939735e6eb89aab022.tar.gz
qemu-8381d89bec0ca233c45c03939735e6eb89aab022.tar.bz2
ivshmem: use ram_from_fd()
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> Message-Id: <20170602141229.15326-6-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/misc/ivshmem.c')
-rw-r--r--hw/misc/ivshmem.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 6367d04..2f0819d 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;
}