[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v3 44/51] ivshmem: do not keep shm_fd open
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PULL v3 44/51] ivshmem: do not keep shm_fd open |
Date: |
Tue, 13 Oct 2015 16:26:11 +0200 |
From: Marc-André Lureau <address@hidden>
Remove shm_fd from device state, closing it as early as possible to avoid leaks.
Signed-off-by: Marc-André Lureau <address@hidden>
Reviewed-by: Claudio Fontana <address@hidden>
---
hw/misc/ivshmem.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 3b6acd6..b873c23 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -88,7 +88,6 @@ typedef struct IVShmemState {
MemoryRegion ivshmem;
uint64_t ivshmem_size; /* size of shared memory region */
uint32_t ivshmem_64bit;
- int shm_fd; /* shared memory file descriptor */
Peer *peers;
int nb_peers; /* how many peers we have space for */
@@ -235,7 +234,7 @@ static uint64_t ivshmem_io_read(void *opaque, hwaddr addr,
case IVPOSITION:
/* return my VM ID if the memory is mapped */
- if (s->shm_fd >= 0) {
+ if (memory_region_is_mapped(&s->ivshmem)) {
ret = s->vm_id;
} else {
ret = -1;
@@ -356,8 +355,6 @@ static int create_shared_memory_BAR(IVShmemState *s, int
fd, uint8_t attr,
return -1;
}
- s->shm_fd = fd;
-
memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
s->ivshmem_size, ptr);
vmstate_register_ram(&s->ivshmem, DEVICE(s));
@@ -535,7 +532,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf,
int size)
if (incoming_posn == -1) {
void * map_ptr;
- if (s->shm_fd >= 0) {
+ if (memory_region_is_mapped(&s->ivshmem)) {
error_report("shm already initialized");
close(incoming_fd);
return;
@@ -564,9 +561,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf,
int size)
memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
- /* only store the fd if it is successfully mapped */
- s->shm_fd = incoming_fd;
-
+ close(incoming_fd);
return;
}
@@ -707,8 +702,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
**errp)
PCI_BASE_ADDRESS_MEM_PREFETCH;
Error *local_err = NULL;
- s->shm_fd = -1;
-
if (s->sizearg == NULL) {
s->ivshmem_size = 4 << 20; /* 4 MB default */
} else {
@@ -830,6 +823,7 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
**errp)
}
create_shared_memory_BAR(s, fd, attr, errp);
+ close(fd);
}
}
@@ -845,7 +839,7 @@ static void pci_ivshmem_exit(PCIDevice *dev)
error_free(s->migration_blocker);
}
- if (s->shm_fd >= 0) {
+ if (memory_region_is_mapped(&s->ivshmem)) {
void *addr = memory_region_get_ram_ptr(&s->ivshmem);
vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
--
2.4.3
- [Qemu-devel] [PULL v3 26/51] ivshmem: check shm isn't already initialized, (continued)
- [Qemu-devel] [PULL v3 26/51] ivshmem: check shm isn't already initialized, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 24/51] ivshmem: migrate with VMStateDescription, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 28/51] ivshmem: fix pci_ivshmem_exit(), marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 31/51] ivshmem: reset mask on device reset, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 35/51] ivshmem-server: use a uint16 for client ID, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 29/51] ivshmem: replace 'guest' for 'peer' appropriately, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 34/51] ivshmem-client: check the number of vectors, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 30/51] ivshmem: error on too many eventfd received, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 33/51] contrib: add ivshmem client and server, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 43/51] tests: add ivshmem qtest, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 44/51] ivshmem: do not keep shm_fd open,
marcandre . lureau <=
- [Qemu-devel] [PULL v3 36/51] ivshmem-server: fix hugetlbfs support, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 37/51] docs: update ivshmem device spec, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 42/51] glib-compat: add 2.38/2.40/2.46 asserts, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 48/51] ivshmem: rename MSI eventfd_table, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 50/51] ivshmem: use little-endian int64_t for the protocol, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 47/51] ivshmem: remove EventfdEntry.vector, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 51/51] doc: document ivshmem & hugepages, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 12/51] ivshmem: limit maximum number of peers to G_MAXUINT16, marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 14/51] ivshmem: allocate eventfds in resize_peers(), marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 27/51] ivshmem: add device description, marcandre . lureau, 2015/10/15