xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: tim@xen.org, stefano.stabellini@eu.citrix.com,
	julien.grall@linaro.org, ian.jackson@eu.citrix.com
Cc: Ian Campbell <ian.campbell@citrix.com>, xen-devel@lists.xen.org
Subject: [PATCH v5 6/9] tools: arm: prepare domain builder for multiple banks of guest RAM
Date: Thu, 22 May 2014 10:46:41 +0100	[thread overview]
Message-ID: <1400752004-9731-6-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1400751582.11409.46.camel@kazak.uk.xensource.com>

Prepare for adding more banks of guest RAM by renaming a bunch of defines
as RAM0 and replacing variables with arrays and introducing loops.

Also in preparation switch to using GUEST_RAM0_BASE explicitly instead of
implicitly via dom->rambase_pfn (while asserting that they must be the same).
This makes the multiple bank case cleaner (although it looks a bit odd for
now).

GUEST_RAM_BASE is defined as the address of the lowest RAM bank, it is used in
tools/libxl/libxl_dom.c to call xc_dom_rambase_init().

Lastly for now ramsize (total size) and rambank_size[0] (size of first bank)
are the same, but use the appropriate one for each context.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
v5: Use rambase[0] instead of GUEST_RAM0_BASE
    Define and use GUEST_RAM_BANK_{BASE,SIZE}S
    Coding Style
v4: Substantial rework, hence dropped existing acks
    Switched to using arrays instead of ram{0,1}* variables.
v3: Mention why GUEST_RAM_BASE is still defined.
v2: New patch
---
 tools/libxc/xc_dom_arm.c      |   67 ++++++++++++++++++++++++++++++-----------
 xen/include/public/arch-arm.h |   13 ++++++--
 2 files changed, 60 insertions(+), 20 deletions(-)

diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
index f663206..beec1f1 100644
--- a/tools/libxc/xc_dom_arm.c
+++ b/tools/libxc/xc_dom_arm.c
@@ -18,6 +18,7 @@
  * Copyright (c) 2011, Citrix Systems
  */
 #include <inttypes.h>
+#include <assert.h>
 
 #include <xen/xen.h>
 #include <xen/io/protocols.h>
@@ -279,17 +280,16 @@ static int populate_guest_memory(struct xc_dom_image *dom,
 
 int arch_setup_meminit(struct xc_dom_image *dom)
 {
-    int rc;
+    int i, rc;
     xen_pfn_t pfn;
     uint64_t modbase;
 
-    /* Convenient */
-    const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
-    const uint64_t ramsize = dom->total_pages << XC_PAGE_SHIFT;
-    const uint64_t ramend = rambase + ramsize;
+    uint64_t ramsize = (uint64_t)dom->total_pages << XC_PAGE_SHIFT;
 
-    const xen_pfn_t p2m_size = dom->total_pages;
+    const uint64_t bankbase[] = GUEST_RAM_BANK_BASES;
+    const uint64_t bankmax[] = GUEST_RAM_BANK_SIZES;
 
+    /* Convenient */
     const uint64_t kernbase = dom->kernel_seg.vstart;
     const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/);
     const uint64_t kernsize = kernend - kernbase;
@@ -298,20 +298,32 @@ int arch_setup_meminit(struct xc_dom_image *dom)
     const uint64_t ramdisk_size = dom->ramdisk_blob ?
         ROUNDUP(dom->ramdisk_size, XC_PAGE_SHIFT) : 0;
     const uint64_t modsize = dtb_size + ramdisk_size;
-    const uint64_t ram128mb = rambase + (128<<20);
+    const uint64_t ram128mb = bankbase[0] + (128<<20);
+
+    xen_pfn_t p2m_size;
+    xen_pfn_t rambank_size[GUEST_RAM_BANKS];
+    uint64_t bank0end;
+
+    assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);
 
-    if ( modsize + kernsize > ramsize )
+    if ( modsize + kernsize > bankmax[0] )
     {
         DOMPRINTF("%s: Not enough memory for the kernel+dtb+initrd",
                   __FUNCTION__);
         return -1;
     }
 
-    if ( ramsize > GUEST_RAM_SIZE )
+    if ( ramsize == 0 )
+    {
+        DOMPRINTF("%s: ram size is 0", __FUNCTION__);
+        return -1;
+    }
+
+    if ( ramsize > GUEST_RAM_MAX )
     {
         DOMPRINTF("%s: ram size is too large for guest address space: "
                   "%"PRIx64" > %llx",
-                  __FUNCTION__, ramsize, GUEST_RAM_SIZE);
+                  __FUNCTION__, ramsize, GUEST_RAM_MAX);
         return -1;
     }
 
@@ -321,6 +333,20 @@ int arch_setup_meminit(struct xc_dom_image *dom)
 
     dom->shadow_enabled = 1;
 
+    for ( i = 0; ramsize && i < GUEST_RAM_BANKS; i++ )
+    {
+        uint64_t banksize = ramsize > bankmax[i] ? bankmax[i] : ramsize;
+
+        ramsize -= banksize;
+
+        p2m_size = ( bankbase[i] + banksize - bankbase[0] ) >> XC_PAGE_SHIFT;
+
+        rambank_size[i] = banksize >> XC_PAGE_SHIFT;
+    }
+
+    assert(rambank_size[0] != 0);
+    assert(ramsize == 0); /* Too much RAM is rejected above */
+
     dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * p2m_size);
     if ( dom->p2m_host == NULL )
         return -EINVAL;
@@ -328,10 +354,13 @@ int arch_setup_meminit(struct xc_dom_image *dom)
         dom->p2m_host[pfn] = INVALID_MFN;
 
     /* setup initial p2m and allocate guest memory */
-    if ((rc = populate_guest_memory(dom,
-                                    GUEST_RAM_BASE >> XC_PAGE_SHIFT,
-                                    ramsize >> XC_PAGE_SHIFT)))
-        return rc;
+    for ( i = 0; rambank_size[i] && i < GUEST_RAM_BANKS; i++ )
+    {
+        if ((rc = populate_guest_memory(dom,
+                                        bankbase[i] >> XC_PAGE_SHIFT,
+                                        rambank_size[i])))
+            return rc;
+    }
 
     /*
      * We try to place dtb+initrd at 128MB or if we have less RAM
@@ -341,11 +370,13 @@ int arch_setup_meminit(struct xc_dom_image *dom)
      * If changing this then consider
      * xen/arch/arm/kernel.c:place_modules as well.
      */
-    if ( ramend >= ram128mb + modsize && kernend < ram128mb )
+    bank0end = bankbase[0] + ((uint64_t)rambank_size[0] << XC_PAGE_SHIFT);
+
+    if ( bank0end >= ram128mb + modsize && kernend < ram128mb )
         modbase = ram128mb;
-    else if ( ramend - modsize > kernend )
-        modbase = ramend - modsize;
-    else if (kernbase - rambase > modsize )
+    else if ( bank0end - modsize > kernend )
+        modbase = bank0end - modsize;
+    else if (kernbase - bankbase[0] > modsize )
         modbase = kernbase - modsize;
     else
         return -1;
diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
index d5090fb..ea74295 100644
--- a/xen/include/public/arch-arm.h
+++ b/xen/include/public/arch-arm.h
@@ -375,8 +375,17 @@ typedef uint64_t xen_callback_t;
 #define GUEST_MAGIC_BASE  0x39000000ULL
 #define GUEST_MAGIC_SIZE  0x01000000ULL
 
-#define GUEST_RAM_BASE    0x40000000ULL /* 3GB of RAM @ 1GB */
-#define GUEST_RAM_SIZE    0xc0000000ULL
+#define GUEST_RAM_BANKS   1
+
+#define GUEST_RAM0_BASE   0x40000000ULL /* 3GB of RAM @ 1GB */
+#define GUEST_RAM0_SIZE   0xc0000000ULL
+
+#define GUEST_RAM_BASE    GUEST_RAM0_BASE /* Lowest RAM address */
+/* Largest amount of actual RAM, not including holes */
+#define GUEST_RAM_MAX     (GUEST_RAM0_SIZE)
+/* Suitable for e.g. const uint64_t ramfoo[] = GUEST_RAM_BANK_FOOS; */
+#define GUEST_RAM_BANK_BASES   { GUEST_RAM0_BASE }
+#define GUEST_RAM_BANK_SIZES   { GUEST_RAM0_SIZE }
 
 /* Interrupts */
 #define GUEST_TIMER_VIRT_PPI    27
-- 
1.7.10.4

  parent reply	other threads:[~2014-05-22  9:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22  9:39 [PATCH v5 0/9] xen: arm: support up to (almost) 1TB of guest RAM Ian Campbell
2014-05-22  9:46 ` [PATCH v5 1/9] tools: libxl: use uint64_t not unsigned long long for addresses Ian Campbell
2014-05-22  9:46 ` [PATCH v5 2/9] tools: arm: report an error if the guest RAM is too large Ian Campbell
2014-07-02 15:06   ` Ian Jackson
2014-05-22  9:46 ` [PATCH v5 3/9] tools: arm: move magic pfns out of guest RAM region Ian Campbell
2014-05-22  9:46 ` [PATCH v5 4/9] tools: arm: rearrange guest physical address space to increase max RAM Ian Campbell
2014-05-22  9:46 ` [PATCH v5 5/9] tools: arm: refactor code to setup guest p2m and fill it with RAM Ian Campbell
2014-05-22 16:50   ` Ian Jackson
2014-05-22  9:46 ` Ian Campbell [this message]
2014-05-22 10:18   ` [PATCH v5 6/9] tools: arm: prepare domain builder for multiple banks of guest RAM Julien Grall
2014-05-22 16:52   ` Ian Jackson
2014-05-22  9:46 ` [PATCH v5 7/9] tools: arm: prepare guest FDT building for multiple RAM banks Ian Campbell
2014-05-22 10:22   ` Julien Grall
2014-05-22 16:55     ` Ian Jackson
2014-05-23  8:43       ` Ian Campbell
2014-05-22  9:46 ` [PATCH v5 8/9] tools: arm: support up to (almost) 1TB of guest RAM Ian Campbell
2014-05-22 10:25   ` Julien Grall
2014-05-22 16:55   ` Ian Jackson
2014-05-22  9:46 ` [PATCH v5 9/9] tools: arm: increase size of region set aside for guest grant table Ian Campbell
2014-06-02 14:42 ` [PATCH v5 0/9] xen: arm: support up to (almost) 1TB of guest RAM Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400752004-9731-6-git-send-email-ian.campbell@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=julien.grall@linaro.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).