If an user creates a RAM region smaller than TARGET_PAGE_SIZE, this region will be handled as a subpage. While the subpage behavior can be noticed by an experienced QEMU developper, it might takes hours to a novice to figure it out. To save time to novices, do not allow subpage creation via the memory_region_init_ram_*() functions.
Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> --- memory.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/memory.c b/memory.c index e70b64b8b9..51d27b7b26 100644 --- a/memory.c +++ b/memory.c @@ -1519,6 +1519,15 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, bool share, Error **errp) { + if (size < TARGET_PAGE_SIZE) { + /* Region less than PAGE_SIZE are handled as subpages, which are + * surely not what the caller expects. + * Limit the minimum ram region size to avoid annoying debugging. + */ + error_setg(errp, "Invalid RAM size: %ld (minimum required: %d)", + size, TARGET_PAGE_SIZE); + return; + } memory_region_init(mr, owner, name, size); mr->ram = true; mr->terminates = true; -- 2.16.3