Skip to contentSkip to conversation

memory: Fix assertion for flash devices

PATCH In review Stefan Weil 3 participants 3 messages Jan 7, 2012 – Jan 8, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memory: Fix assertion for flash devices

There is a regression since commit c5705a7728b4a6bc9e4f2d35911adbaf28042b25 or some other recent change.

System emulation with a flash device raises an assertion in function qemu_ram_set_idstr because no new_block is found at the requested addr.

The address of the memory region (mr->ram_addr) is set by memory_region_init_rom_device:

    mr->ram_addr = qemu_ram_alloc(size, mr);
    mr->ram_addr |= cpu_register_io_memory(mr);

The 2nd line adds a small offset to mr->ram_addr, and this offset makes ram_set_idstr fail with an assertion.

Masking mr->ram_addr with the target's page mask removes the small offset and makes flash devices work again.

---
 memory.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
memory.c +1 -1
index 394cbab..1b2f9e8 100644
@@ -1386,7 +1386,7 @@ void memory_region_set_alias_offset(MemoryRegion *mr, target_phys_addr_t offset)
 
 ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr)
 {
-    return mr->ram_addr;
+    return mr->ram_addr & TARGET_PAGE_MASK;
 }
 
 static int cmp_flatrange_addr(const void *addr_, const void *fr_)
Signature · 1 line
1.7.0.4
Tested-by on v1 1/1
#1 lore raw
Quoted 15 lines · Stefan Weil

There is a regression since commit c5705a7728b4a6bc9e4f2d35911adbaf28042b25 or some other recent change.

System emulation with a flash device raises an assertion in function qemu_ram_set_idstr because no new_block is found at the requested addr.

The address of the memory region (mr->ram_addr) is set by memory_region_init_rom_device:

    mr->ram_addr = qemu_ram_alloc(size, mr);
    mr->ram_addr |= cpu_register_io_memory(mr);

The 2nd line adds a small offset to mr->ram_addr, and this offset makes ram_set_idstr fail with an assertion.

Quoted 9 lines

Masking mr->ram_addr with the target's page mask removes the small offset and makes flash devices work again.

---
 memory.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

I can't confirm the patch is correct, but at least I can confirm it fix the breakage.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#2 lore raw
In reply to Stefan Weil
Quoted 24 lines · Stefan Weil

There is a regression since commit c5705a7728b4a6bc9e4f2d35911adbaf28042b25 or some other recent change.

System emulation with a flash device raises an assertion in function qemu_ram_set_idstr because no new_block is found at the requested addr.

The address of the memory region (mr->ram_addr) is set by memory_region_init_rom_device:

    mr->ram_addr = qemu_ram_alloc(size, mr);
    mr->ram_addr |= cpu_register_io_memory(mr);

The 2nd line adds a small offset to mr->ram_addr, and this offset makes ram_set_idstr fail with an assertion.

Masking mr->ram_addr with the target's page mask removes the small offset and makes flash devices work again.

memory.c +0 -0
index 394cbab..1b2f9e8 100644

memory.c void memory_region_set_alias_offset(MemoryRegion *mr, target_phys_addr_t offset) · line 1391

Quoted 7 lines
memory.c +1 -1
@@ -1386,7 +1386,7 @@ void memory_region_set_alias_offset(MemoryRegion *mr, target_phys_addr_t offset)
 
 ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr)
 {
-    return mr->ram_addr;
+    return mr->ram_addr & TARGET_PAGE_MASK;
 }
 

This makes get_ram_addr() lie about the return value - it's no longer the ram_addr. Doesn't matter much since it's temporary, but I patched vmstate_register_ram() instead.

Signature · 1 line
error compiling committee.c: too many arguments to function