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

[xen master] xen/arm: Sanity test specified domain's memory for being a multiple of a page size



commit 4a864e98858696fc52bca4f1d0dce4dee60aa424
Author:     Michal Orzel <michal.orzel@xxxxxxx>
AuthorDate: Wed Oct 7 14:48:13 2026 +0200
Commit:     Michal Orzel <michal.orzel@xxxxxxx>
CommitDate: Mon Oct 12 12:08:28 2026 +0200

    xen/arm: Sanity test specified domain's memory for being a multiple of a 
page size
    
    We require memory to allocate for a domain as RAM to be a multiple of a
    page size. However, we neither document this nor sanity test. Specifying
    memory size that does not conform to this requirement fails the domain
    memory allocation in the non-obvious way that is difficult to parse for
    the user (printing over-allocation messages followed by the panic that Xen
    could not allocate the requested amount of memory).
    
    While there, fix indentation from tabs to spaces for "memory" parameter in
    booting.txt.
    
    Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
    Reviewed-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
---
 docs/misc/arm/device-tree/booting.txt   | 4 ++--
 docs/misc/xen-command-line.pandoc       | 5 +++--
 xen/arch/arm/domain_build.c             | 7 +++++++
 xen/common/device-tree/dom0less-build.c | 8 ++++++++
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/docs/misc/arm/device-tree/booting.txt 
b/docs/misc/arm/device-tree/booting.txt
index bcb06bc796..3787d2e2b6 100644
--- a/docs/misc/arm/device-tree/booting.txt
+++ b/docs/misc/arm/device-tree/booting.txt
@@ -155,8 +155,8 @@ with the following properties:
 
 - memory
 
-       A 64-bit integer specifying the amount of kilobytes of RAM to
-    allocate to the guest.
+    A 64-bit integer specifying the amount of kilobytes of RAM to
+    allocate to the guest. Must be a multiple of the page size.
 
 - cpus
 
diff --git a/docs/misc/xen-command-line.pandoc 
b/docs/misc/xen-command-line.pandoc
index ea0e3368b1..a6f08463d1 100644
--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -1020,8 +1020,9 @@ and architecture-specific domain limits.
 > `= <size>`
 
 Set the amount of memory for the initial domain (dom0). It must be
-greater than zero. This parameter is required (and only used) when the initial
-domain is not described in the Device-Tree.
+greater than zero and a multiple of the page size. This parameter is
+required (and only used) when the initial domain is not described in the
+Device-Tree.
 
 ### dom0_mem (x86)
 > `= List of ( min:<sz> | max:<sz> | <sz> )`
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 72d5316180..795b401087 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1881,6 +1881,13 @@ static int __init construct_dom0(struct domain *d)
         warning_add("PLEASE SPECIFY dom0_mem PARAMETER - USING 512M FOR 
NOW\n");
         dom0_mem = MB(512);
     }
+    else if ( dom0_mem % PAGE_SIZE )
+    {
+        printk(XENLOG_ERR
+               "%pd: specified dom0_mem (%"PRIu64"B) is not a multiple of the 
page size (%luKB)\n",
+               d, dom0_mem, PAGE_SIZE >> 10);
+        return -EINVAL;
+    }
 
     d->max_pages = dom0_mem >> PAGE_SHIFT;
 
diff --git a/xen/common/device-tree/dom0less-build.c 
b/xen/common/device-tree/dom0less-build.c
index fcbeb8adbd..2021838d38 100644
--- a/xen/common/device-tree/dom0less-build.c
+++ b/xen/common/device-tree/dom0less-build.c
@@ -789,6 +789,14 @@ static int __init construct_domU(struct kernel_info *kinfo,
     }
     kinfo->unassigned_mem = (paddr_t)mem * SZ_1K;
 
+    if ( kinfo->unassigned_mem % PAGE_SIZE )
+    {
+        printk(XENLOG_ERR
+               "%pd: specified \"memory\" (%"PRIu64"KB) is not a multiple of 
the page size (%luKB)\n",
+               d, mem, PAGE_SIZE >> 10);
+        return -EINVAL;
+    }
+
     rc = domain_p2m_set_allocation(d, mem, node);
     if ( rc != 0 )
         return rc;
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.