qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2 1/4] memory: Avoid to create tiny RAM regions, ha


From: Philippe Mathieu-Daudé
Subject: [Qemu-devel] [PATCH v2 1/4] memory: Avoid to create tiny RAM regions, handled as subpages
Date: Wed, 4 Apr 2018 22:22:38 -0300

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é <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]