Commit dfde4e6e authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

memory: add ref/unref calls



Add ref/unref calls at the following places:

- places where memory regions are stashed by a listener and
  used outside the BQL (including in Xen or KVM).

- memory_region_find callsites

- creation of aliases and containers (only the aliased/contained
  region gets a reference to avoid loops)

- around calls to del_subregion/add_subregion, where the region
  could disappear after the first call

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 3ce10901
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -763,11 +763,14 @@ static uint16_t phys_section_add(MemoryRegionSection *section)
                                phys_sections_nb_alloc);
    }
    phys_sections[phys_sections_nb] = *section;
    memory_region_ref(section->mr);
    return phys_sections_nb++;
}

static void phys_section_destroy(MemoryRegion *mr)
{
    memory_region_unref(mr);

    if (mr->subpage) {
        subpage_t *subpage = container_of(mr, subpage_t, iomem);
        memory_region_destroy(&subpage->iomem);
+1 −0
Original line number Diff line number Diff line
@@ -727,6 +727,7 @@ int rom_load_all(void)
        addr += rom->romsize;
        section = memory_region_find(get_system_memory(), rom->addr, 1);
        rom->isrom = int128_nz(section.size) && memory_region_is_rom(section.mr);
        memory_region_unref(section.mr);
    }
    qemu_register_reset(rom_reset, NULL);
    roms_loaded = 1;
+6 −0
Original line number Diff line number Diff line
@@ -1126,6 +1126,11 @@ static void fimd_update_memory_section(Exynos4210fimdState *s, unsigned win)
    /* Total number of bytes of virtual screen used by current window */
    w->fb_len = fb_mapped_len = (w->virtpage_width + w->virtpage_offsize) *
            (w->rightbot_y - w->lefttop_y + 1);

    /* TODO: add .exit and unref the region there.  Not needed yet since sysbus
     * does not support hot-unplug.
     */
    memory_region_unref(w->mem_section.mr);
    w->mem_section = memory_region_find(sysbus_address_space(&s->busdev),
            fb_start_addr, w->fb_len);
    assert(w->mem_section.mr);
@@ -1154,6 +1159,7 @@ static void fimd_update_memory_section(Exynos4210fimdState *s, unsigned win)
    return;

error_return:
    memory_region_unref(w->mem_section.mr);
    w->mem_section.mr = NULL;
    w->mem_section.size = int128_zero();
    w->host_fb_addr = NULL;
+7 −5
Original line number Diff line number Diff line
@@ -54,11 +54,11 @@ void framebuffer_update_display(
    src_len = src_width * rows;

    mem_section = memory_region_find(address_space, base, src_len);
    mem = mem_section.mr;
    if (int128_get64(mem_section.size) != src_len ||
            !memory_region_is_ram(mem_section.mr)) {
        return;
        goto out;
    }
    mem = mem_section.mr;
    assert(mem);
    assert(mem_section.offset_within_address_space == base);

@@ -68,10 +68,10 @@ void framebuffer_update_display(
       but it's not really worth it as dirty flag tracking will probably
       already have failed above.  */
    if (!src_base)
        return;
        goto out;
    if (src_len != src_width * rows) {
        cpu_physical_memory_unmap(src_base, src_len, 0, 0);
        return;
        goto out;
    }
    src = src_base;
    dest = surface_data(ds);
@@ -102,10 +102,12 @@ void framebuffer_update_display(
    }
    cpu_physical_memory_unmap(src_base, src_len, 0, 0);
    if (first < 0) {
        return;
        goto out;
    }
    memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,
                              DIRTY_MEMORY_VGA);
    *first_row = first;
    *last_row = last;
out:
    memory_region_unref(mem);
}
+1 −0
Original line number Diff line number Diff line
@@ -605,6 +605,7 @@ static void vapic_map_rom_writable(VAPICROMState *s)
                             rom_size);
    memory_region_add_subregion_overlap(as, rom_paddr, &s->rom, 1000);
    s->rom_mapped_writable = true;
    memory_region_unref(section.mr);
}

static int vapic_prepare(VAPICROMState *s)
Loading