[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] hostmem-file: add offset option
From: |
David Hildenbrand |
Subject: |
Re: [PATCH] hostmem-file: add offset option |
Date: |
Fri, 3 Feb 2023 09:25:07 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 |
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 <graf@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