[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 29/66] memory: ref/unref memory across address_space
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 29/66] memory: ref/unref memory across address_space_map/unmap |
Date: |
Thu, 4 Jul 2013 17:13:25 +0200 |
The iothread mutex might be released between map and unmap, so the
mapped region might disappear.
Reviewed-by: Jan Kiszka <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
exec.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/exec.c b/exec.c
index a994bc8..b339c23 100644
--- a/exec.c
+++ b/exec.c
@@ -1986,6 +1986,7 @@ void cpu_physical_memory_write_rom(hwaddr addr,
}
typedef struct {
+ MemoryRegion *mr;
void *buffer;
hwaddr addr;
hwaddr len;
@@ -2083,6 +2084,9 @@ void *address_space_map(AddressSpace *as,
bounce.buffer = qemu_memalign(TARGET_PAGE_SIZE, TARGET_PAGE_SIZE);
bounce.addr = addr;
bounce.len = l;
+
+ memory_region_ref(mr);
+ bounce.mr = mr;
if (!is_write) {
address_space_read(as, addr, bounce.buffer, l);
}
@@ -2109,6 +2113,7 @@ void *address_space_map(AddressSpace *as,
}
}
+ memory_region_ref(mr);
*plen = done;
return qemu_ram_ptr_length(raddr + base, plen);
}
@@ -2121,10 +2126,12 @@ void address_space_unmap(AddressSpace *as, void
*buffer, hwaddr len,
int is_write, hwaddr access_len)
{
if (buffer != bounce.buffer) {
+ MemoryRegion *mr;
+ ram_addr_t addr1;
+
+ mr = qemu_ram_addr_from_host(buffer, &addr1);
+ assert(mr != NULL);
if (is_write) {
- ram_addr_t addr1;
- MemoryRegion *mr = qemu_ram_addr_from_host(buffer, &addr1);
- assert(mr != NULL);
while (access_len) {
unsigned l;
l = TARGET_PAGE_SIZE;
@@ -2138,6 +2145,7 @@ void address_space_unmap(AddressSpace *as, void *buffer,
hwaddr len,
if (xen_enabled()) {
xen_invalidate_map_cache_entry(buffer);
}
+ memory_region_unref(mr);
return;
}
if (is_write) {
@@ -2145,6 +2153,7 @@ void address_space_unmap(AddressSpace *as, void *buffer,
hwaddr len,
}
qemu_vfree(bounce.buffer);
bounce.buffer = NULL;
+ memory_region_unref(bounce.mr);
cpu_notify_map_clients();
}
--
1.8.1.4
- [Qemu-devel] [PATCH 20/66] exec: simplify destruction of the phys map, (continued)
- [Qemu-devel] [PATCH 20/66] exec: simplify destruction of the phys map, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 21/66] memory: add getter for owner, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 22/66] memory: add ref/unref, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 23/66] memory: introduce memory_region_present, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 24/66] memory: add ref/unref calls, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 25/66] exec: check MRU in qemu_ram_addr_from_host, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 26/66] exec: move qemu_ram_addr_from_host_nofail to cputlb.c, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 27/66] memory: return MemoryRegion from qemu_ram_addr_from_host, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 28/66] exec: reorganize address_space_map, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 29/66] memory: ref/unref memory across address_space_map/unmap,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 30/66] escc: rename struct to ESCCState, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 31/66] vga: pass owner to vga_init, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 32/66] vga: pass owner to vga_common_init, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 33/66] vga: pass owner to cirrus_init_common, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 34/66] vga: pass owner to vga_init_vbe, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 35/66] vga: pass owner to vga_init_io, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 36/66] vga: set owner in vga_update_memory_access, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 37/66] ne2000: pass device to ne2000_setup_io, use it as owner, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 38/66] vfio: pass device to vfio_mmap_bar and use it to set owner, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 39/66] spapr_iommu: pass device to spapr_tce_new_table and use it to set owner, Paolo Bonzini, 2013/07/04