[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 1/9] memory: Initialize MemoryRegionOps for RAM memory region
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 1/9] memory: Initialize MemoryRegionOps for RAM memory regions |
Date: |
Mon, 17 Aug 2020 18:18:45 +0200 |
There is an issue when using memory_region_dispatch_read() or
memory_region_dispatch_write() on RAM memory regions.
RAM memory regions are initialized as:
memory_region_init_ram()
-> memory_region_init_ram_nomigrate()
-> memory_region_init_ram_shared_nomigrate()
-> memory_region_init()
-> object_initialize(TYPE_MEMORY_REGION)
-> memory_region_initfn()
-> mr->ops = &unassigned_mem_ops;
Later when accessing the alias, the memory_region_dispatch_read()
flow is:
memory_region_dispatch_read()
-> memory_region_dispatch_read1()
-> if (mr->ops->read) { /* not taken */ } else ...
-> access_with_adjusted_size
-> memory_region_read_with_attrs_accessor
-> memory_region_dispatch_read
-> unassigned_mem_read
<- MEMTX_DECODE_ERROR
The caller gets a MEMTX_DECODE_ERROR while the access is OK.
(Similar flow with memory_region_dispatch_write).
Fix by initializing the MemoryRegionOps to ram_device_mem_ops,
this way the memory accesses are properly dispatched using
memory_region_ram_device_read() / memory_region_ram_device_write().
Fixes: 4a2e242bbb ("memory: Don't use memcpy for ram_device regions")
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Since v1: Corrected description (PJP)
Cc: P J P <ppandit@redhat.com>
---
softmmu/memory.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 651705b7d1..8139da1a58 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1517,6 +1517,8 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion
*mr,
Error *err = NULL;
memory_region_init(mr, owner, name, size);
mr->ram = true;
+ mr->ops = &ram_device_mem_ops;
+ mr->opaque = mr;
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
mr->ram_block = qemu_ram_alloc(size, share, mr, &err);
@@ -1541,6 +1543,8 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
Error *err = NULL;
memory_region_init(mr, owner, name, size);
mr->ram = true;
+ mr->ops = &ram_device_mem_ops;
+ mr->opaque = mr;
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
mr->ram_block = qemu_ram_alloc_resizeable(size, max_size, resized,
@@ -1566,6 +1570,8 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
Error *err = NULL;
memory_region_init(mr, owner, name, size);
mr->ram = true;
+ mr->ops = &ram_device_mem_ops;
+ mr->opaque = mr;
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
mr->align = align;
@@ -1589,6 +1595,8 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
Error *err = NULL;
memory_region_init(mr, owner, name, size);
mr->ram = true;
+ mr->ops = &ram_device_mem_ops;
+ mr->opaque = mr;
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
@@ -1611,6 +1619,8 @@ void memory_region_init_ram_ptr(MemoryRegion *mr,
{
memory_region_init(mr, owner, name, size);
mr->ram = true;
+ mr->ops = &ram_device_mem_ops;
+ mr->opaque = mr;
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
--
2.26.2
- [RFC PATCH 0/9] hw/misc: Add support for interleaved memory accesses, Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 2/9] qtest: Add local qtest_mem_as() getter, Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 3/9] qtest: Directly use global address_space_memory when no CPU available, Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 4/9] hw/misc: Add interleaver device to make interleaved memory accesses, Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 1/9] memory: Initialize MemoryRegionOps for RAM memory regions,
Philippe Mathieu-Daudé <=
- [RFC PATCH 5/9] hw/misc: Add MMIO test device, Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 9/9] hw/misc/interleaver: Display subregions in 'info mtree', Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 6/9] hw/core/null-machine: Allow to use the MMIO 'test' device, Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 7/9] tests/qtest: Add generic MMIO tests, Philippe Mathieu-Daudé, 2020/08/17
- [RFC PATCH 8/9] memory: Allow memory region to display its subregions own descriptions, Philippe Mathieu-Daudé, 2020/08/17
- Re: [RFC PATCH 0/9] hw/misc: Add support for interleaved memory accesses, no-reply, 2020/08/17
- Re: [RFC PATCH 0/9] hw/misc: Add support for interleaved memory accesses, Philippe Mathieu-Daudé, 2020/08/22
- Re: [RFC PATCH 0/9] hw/misc: Add support for interleaved memory accesses, Philippe Mathieu-Daudé, 2020/08/22