Hi! This is the RFC about the memory issue I mentioned in our last KVM call.
In our use case, QEMU is used as a library, where RAM and Alias MemoryRegions are created by listening to read/write events through MemoryRegionOps callbacks. In this case, no read/write happened yet, so we did not have a chance to create those memory regions yet. The callstack looks like this: - virtio_blk_get_request - virtqueue_pop -> virtqueue_split_pop -> virtqueue_map_desc - dma_memory_map -> address_space_map The address_space_map function calls flatview_translate to get the memory region for a certain address. If the memory region is not directly accessible, the bounce buffer is used which only allows one mapping at a time, forcing to unmap before mapping again. The virtqueue_map_desc function calls iteratively address_space_map for a region of 4KB but address_space_map is only mapping 1KB using the bounce buffer. Then virtqueue_map_desc calls address_space_map again for mapping the missing 3KB, but address_space_map returns NULL as the bounce is in use now. With this patch a MemoryListener callback is introduced for listening to address space map events, before calling flatview_translate, so that listeners might have a chance to create any needed alias or RAM memory region for that address space. Effectively making flatview_translate return a directly accessible memory region, and avoiding address_space_map to use the bounce buffer. This will require a change to the memory listener callbacks: while it currently uses "self" as first argument for the callbacks, this new approach is going to use an "opaque" member, effectively following the model used for MemoryRegion and MemoryRegionOps. Antonio Caggiano (1): memory: Address space map listener include/exec/memory.h | 19 +++++++++++++++++++ softmmu/physmem.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) -- 2.40.0