[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 58/59] ivshmem: Store file descriptor for vhost-us
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL v2 58/59] ivshmem: Store file descriptor for vhost-user negotiation |
Date: |
Sat, 9 Jan 2016 23:42:17 +0200 |
From: Tetsuya Mukawa <address@hidden>
If virtio-net driver allocates memory in ivshmem shared memory,
vhost-net will work correctly, but vhost-user will not work because
a fd of shared memory will not be sent to vhost-user backend.
This patch fixes ivshmem to store file descriptor of shared memory.
It will be used when vhost-user negotiates vhost-user backend.
Signed-off-by: Tetsuya Mukawa <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/exec/ram_addr.h | 1 +
exec.c | 10 ++++++++++
hw/misc/ivshmem.c | 9 +++++++--
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index ba4c04d..ef1489d 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -72,6 +72,7 @@ ram_addr_t qemu_ram_alloc_resizeable(ram_addr_t size,
ram_addr_t max_size,
void *host),
MemoryRegion *mr, Error **errp);
int qemu_get_ram_fd(ram_addr_t addr);
+void qemu_set_ram_fd(ram_addr_t addr, int fd);
void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
void qemu_ram_free(ram_addr_t addr);
diff --git a/exec.c b/exec.c
index 8718a75..7f0ce42 100644
--- a/exec.c
+++ b/exec.c
@@ -1757,6 +1757,16 @@ int qemu_get_ram_fd(ram_addr_t addr)
return fd;
}
+void qemu_set_ram_fd(ram_addr_t addr, int fd)
+{
+ RAMBlock *block;
+
+ rcu_read_lock();
+ block = qemu_get_ram_block(addr);
+ block->fd = fd;
+ rcu_read_unlock();
+}
+
void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
{
RAMBlock *block;
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index f73f0c2..df585de 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -29,6 +29,7 @@
#include "sysemu/char.h"
#include "sysemu/hostmem.h"
#include "qapi/visitor.h"
+#include "exec/ram_addr.h"
#include "hw/misc/ivshmem.h"
@@ -422,6 +423,7 @@ static int create_shared_memory_BAR(IVShmemState *s, int
fd, uint8_t attr,
memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
s->ivshmem_size, ptr);
+ qemu_set_ram_fd(s->ivshmem.ram_addr, fd);
vmstate_register_ram(&s->ivshmem, DEVICE(s));
memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
@@ -682,6 +684,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf,
int size)
}
memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s),
"ivshmem.bar2", s->ivshmem_size, map_ptr);
+ qemu_set_ram_fd(s->ivshmem.ram_addr, incoming_fd);
vmstate_register_ram(&s->ivshmem, DEVICE(s));
IVSHMEM_DPRINTF("guest h/w addr = %p, size = %" PRIu64 "\n",
@@ -689,7 +692,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf,
int size)
memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
- close(incoming_fd);
return;
}
@@ -991,7 +993,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
**errp)
}
create_shared_memory_BAR(s, fd, attr, errp);
- close(fd);
}
}
@@ -1010,11 +1011,15 @@ static void pci_ivshmem_exit(PCIDevice *dev)
if (memory_region_is_mapped(&s->ivshmem)) {
if (!s->hostmem) {
void *addr = memory_region_get_ram_ptr(&s->ivshmem);
+ int fd;
if (munmap(addr, s->ivshmem_size) == -1) {
error_report("Failed to munmap shared memory %s",
strerror(errno));
}
+
+ if ((fd = qemu_get_ram_fd(s->ivshmem.ram_addr)) != -1)
+ close(fd);
}
vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
--
MST
- [Qemu-devel] [PULL v2 47/59] pc: acpi: q35: move PRTA routing table into SSDT, (continued)
- [Qemu-devel] [PULL v2 47/59] pc: acpi: q35: move PRTA routing table into SSDT, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 49/59] pc: acpi: q35: move _PIC() method into SSDT, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 48/59] pc: acpi: q35: move PRTP routing table into SSDT, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 50/59] pc: acpi: q35: move PCI0._OSC() method into SSDT, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 51/59] pc: acpi: q35: move PCI0 device definition into SSDT, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 52/59] pc: acpi: q35: PCST, PCSB opregions and PCIB field into SSDT, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 53/59] pc: acpi: switch to AML API composed DSDT, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 55/59] i386/pc: expose identifying the floppy controller, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 56/59] Add VMSTATE_STRUCT_VARRAY_KNOWN, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 57/59] migration/virtio: Remove simple .get/.put use, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 58/59] ivshmem: Store file descriptor for vhost-user negotiation,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL v2 59/59] virtio: fix error message for number of queues, Michael S. Tsirkin, 2016/01/09
- [Qemu-devel] [PULL v2 54/59] pc: acpi: remove unused ASL templates and related blobs/utils, Michael S. Tsirkin, 2016/01/09
- Re: [Qemu-devel] [PULL v2 00/59] acpi dsdt rework, misc fixes, Peter Maydell, 2016/01/11