memory: Directly dispatch alias accesses on origin memory region
PATCH v2 1/1 memory: Directly dispatch alias accesses on origin memory region
There is an issue when accessing an alias memory region via the memory_region_dispatch_read() / memory_region_dispatch_write() calls.
Since commit 2cdfcf272d ("memory: assign MemoryRegionOps to all regions") we assign &unassigned_mem_ops to all MemoryRegions.
The memory_region_init_alias() flow is:
memory_region_init_alias()
-> memory_region_init()
-> object_initialize(TYPE_MEMORY_REGION)
-> memory_region_initfn()
-> mr->ops = &unassigned_mem_ops;When accessing the alias using memory_region_dispatch_read(), flow is:
memory_region_dispatch_read()
-> memory_region_access_valid(mr)
-> mr->ops->valid.accepts()
-> unassigned_mem_accepts()
<- false
<- false <- MEMTX_DECODE_ERROR
The caller gets a MEMTX_DECODE_ERROR while the access is OK.
Fix by directly dispatching aliases accesses to its origin region.
---
Since v1:
- reword as not a bugfix (Paolo)
- access the aliases recursively (Paolo)
--- softmmu/memory.c | 8 ++++++++ 1 file changed, 8 insertions(+)
softmmu/memory.c +8 -0
@@ -1405,6 +1405,10 @@ MemTxResult memory_region_dispatch_read(MemoryRegion *mr,unsigned size =memop_size (op);MemTxResult r; +while (mr->alias) { + addr += mr->alias_offset; + mr = mr->alias; + }if (!memory_region_access_valid (mr, addr, size, false, attrs)) { *pval =unassigned_mem_read (mr, addr, size);return MEMTX_DECODE_ERROR ;
@@ -1449,6 +1453,10 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr, {unsigned size =memop_size (op); +while (mr->alias) { + addr += mr->alias_offset; + mr = mr->alias; + }if (!memory_region_access_valid (mr, addr, size, true, attrs)) {unassigned_mem_write (mr, addr, data, size);return MEMTX_DECODE_ERROR ;
Signature · 1 line
2.26.2
Quoted 32 lines · Philippe Mathieu-Daudé
There is an issue when accessing an alias memory region via the
memory_region_dispatch_read()/memory_region_dispatch_write()calls.Since commit
2cdfcf272d("memory: assign MemoryRegionOps to all regions") we assign&unassigned_mem_opsto all MemoryRegions.The
memory_region_init_alias()flow is:memory_region_init_alias() -> memory_region_init() -> object_initialize(TYPE_MEMORY_REGION) -> memory_region_initfn() -> mr->ops = &unassigned_mem_ops;When accessing the alias using
memory_region_dispatch_read(), flow is:
memory_region_dispatch_read()
->memory_region_access_valid(mr)-> mr->ops->valid.accepts() -> unassigned_mem_accepts() <- false <- false<-
MEMTX_DECODE_ERRORThe caller gets a
MEMTX_DECODE_ERRORwhile the access is OK.Fix by directly dispatching aliases accesses to its origin region.
Fixes 2cdfcf272d ("memory: assign MemoryRegionOps to all regions")Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 7 lines
---
Since v1:
- reword as not a bugfix (Paolo)
- access the aliases recursively (Paolo)--- softmmu/memory.c | 8 ++++++++ 1 file changed, 8 insertions(+)
r~
Quoted 24 lines · Philippe Mathieu-Daudé
There is an issue when accessing an alias memory region via the
memory_region_dispatch_read()/memory_region_dispatch_write()calls.Since commit
2cdfcf272d("memory: assign MemoryRegionOps to all regions") we assign&unassigned_mem_opsto all MemoryRegions.The
memory_region_init_alias()flow is:memory_region_init_alias() -> memory_region_init() -> object_initialize(TYPE_MEMORY_REGION) -> memory_region_initfn() -> mr->ops = &unassigned_mem_ops;When accessing the alias using
memory_region_dispatch_read(), flow is:
memory_region_dispatch_read()
->memory_region_access_valid(mr)-> mr->ops->valid.accepts() -> unassigned_mem_accepts() <- false <- false
Quoted 8 lines
<-
MEMTX_DECODE_ERRORThe caller gets a
MEMTX_DECODE_ERRORwhile the access is OK.Fix by directly dispatching aliases accesses to its origin region.
Fixes 2cdfcf272d ("memory: assign MemoryRegionOps to all regions")Signed-off-by Philippe Mathieu-Daudé <[email protected]>
It's still not clear from the commit message what is the case where you get this. I can integrate it in the commit message myself, but can you explain it and/or link to a bug report?
Paolo