* [Qemu-devel] [PATCH 0/2] fixups for ivshmem unplug/migration
@ 2010-11-30 21:03 Cam Macdonell
2010-11-30 21:03 ` [Qemu-devel] [PATCH 1/2] add qemu_ram_free_from_ptr Cam Macdonell
2010-11-30 21:03 ` [Qemu-devel] [PATCH 2/2] Unregister shared memory on unplug Cam Macdonell
0 siblings, 2 replies; 3+ messages in thread
From: Cam Macdonell @ 2010-11-30 21:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Cam Macdonell, kvm
We added qemu_ram_alloc_from_ptr, but we need its corresponding "free" function. With that, we can properly remove the ivshmem memory on unplug.
Cam Macdonell (2):
add qemu_ram_free_from_ptr
Unregister shared memory on unplug.
cpu-common.h | 1 +
exec.c | 13 +++++++++++++
hw/ivshmem.c | 12 ++++++++----
3 files changed, 22 insertions(+), 4 deletions(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 1/2] add qemu_ram_free_from_ptr
2010-11-30 21:03 [Qemu-devel] [PATCH 0/2] fixups for ivshmem unplug/migration Cam Macdonell
@ 2010-11-30 21:03 ` Cam Macdonell
2010-11-30 21:03 ` [Qemu-devel] [PATCH 2/2] Unregister shared memory on unplug Cam Macdonell
1 sibling, 0 replies; 3+ messages in thread
From: Cam Macdonell @ 2010-11-30 21:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Cam Macdonell, kvm
add function to free memory from Qemu that was added via qemu_ram_alloc_from_ptr. Name is a little weird. This is copied from qemu_ram_unmap from qemu-kvm.
Signed-off-by: Cam Macdonell <cam@cs.ualberta.ca>
---
cpu-common.h | 1 +
exec.c | 13 +++++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/cpu-common.h b/cpu-common.h
index a543b5d..3f802e1 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -44,6 +44,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
ram_addr_t size, void *host);
ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
void qemu_ram_free(ram_addr_t addr);
+void qemu_ram_free_from_ptr(ram_addr_t addr);
/* This should only be used for ram local to a device. */
void *qemu_get_ram_ptr(ram_addr_t addr);
/* This should not be used by devices. */
diff --git a/exec.c b/exec.c
index db9ff55..1f5c8f8 100644
--- a/exec.c
+++ b/exec.c
@@ -2875,6 +2875,19 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size)
return qemu_ram_alloc_from_ptr(dev, name, size, NULL);
}
+void qemu_ram_free_from_ptr(ram_addr_t addr)
+{
+ RAMBlock *block;
+
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ if (addr == block->offset) {
+ QLIST_REMOVE(block, next);
+ qemu_free(block);
+ return;
+ }
+ }
+}
+
void qemu_ram_free(ram_addr_t addr)
{
RAMBlock *block;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] Unregister shared memory on unplug.
2010-11-30 21:03 [Qemu-devel] [PATCH 0/2] fixups for ivshmem unplug/migration Cam Macdonell
2010-11-30 21:03 ` [Qemu-devel] [PATCH 1/2] add qemu_ram_free_from_ptr Cam Macdonell
@ 2010-11-30 21:03 ` Cam Macdonell
1 sibling, 0 replies; 3+ messages in thread
From: Cam Macdonell @ 2010-11-30 21:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Cam Macdonell, kvm
This allows 'peer' ivshmem guests to detach from shared memory before migration
and re-attach after migration is complete.
Signed-off-by: Cam Macdonell <cam@cs.ualberta.ca>
---
hw/ivshmem.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 06dce70..9254fad 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -68,6 +68,7 @@ typedef struct IVShmemState {
int nb_peers; /* how many guests we have space for */
int max_peer; /* maximum numbered peer */
+ void *shm_ptr;
int vm_id;
uint32_t vectors;
uint32_t features;
@@ -365,14 +366,13 @@ static int check_shm_size(IVShmemState *s, int fd) {
* create the BAR and map the memory immediately */
static void create_shared_memory_BAR(IVShmemState *s, int fd) {
- void * ptr;
-
s->shm_fd = fd;
- ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ s->shm_ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE,
+ MAP_SHARED, fd, 0);
s->ivshmem_offset = qemu_ram_alloc_from_ptr(&s->dev.qdev, "ivshmem.bar2",
- s->ivshmem_size, ptr);
+ s->ivshmem_size, s->shm_ptr);
/* region for shared memory */
pci_register_bar(&s->dev, 2, s->ivshmem_size,
@@ -797,6 +797,10 @@ static int pci_ivshmem_uninit(PCIDevice *dev)
{
IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+ cpu_register_physical_memory(s->shm_pci_addr, s->ivshmem_size,
+ IO_MEM_UNASSIGNED);
+ qemu_ram_free_from_ptr(s->ivshmem_offset);
+ munmap(s->shm_ptr, s->ivshmem_size);
cpu_unregister_io_memory(s->ivshmem_mmio_io_addr);
unregister_savevm(&dev->qdev, "ivshmem", s);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-01 3:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-30 21:03 [Qemu-devel] [PATCH 0/2] fixups for ivshmem unplug/migration Cam Macdonell
2010-11-30 21:03 ` [Qemu-devel] [PATCH 1/2] add qemu_ram_free_from_ptr Cam Macdonell
2010-11-30 21:03 ` [Qemu-devel] [PATCH 2/2] Unregister shared memory on unplug Cam Macdonell
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).