On 02.02.23 23:56, Alexander Graf wrote:
Add an option for hostmem-file to start the memory object at an offset
into the target file. This is useful if multiple memory objects reside
inside the same target file, such as a device node.
In particular, it's useful to map guest memory directly into /dev/mem
for experimentation.
Signed-off-by: Alexander Graf <g...@amazon.com>
---
[...]
- block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, readonly, errp);
+ block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, offset, readonly,
+ errp);
IIUC, the existing offset implementation is a bit broken:
(1) qemu_ram_alloc_from_fd() does not handle the offset parameter
correctly: The "file_size > 0 && file_size < size" calculation does not
seem to consider the offset when checking for file sizes.
(2) file_ram_alloc() most probably does not handle ftruncate()
correctly. Especially on a yet empty file (where we set truncate=true),
that might be insufficient.
(3) file_ram_alloc() and/or qemu_ram_alloc_from_fd() do not verify that
the offset is properly aligned to block->page_size.
--
Thanks,
David / dhildenb