From patchwork Tue Apr 8 14:19:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 27983 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6FC6B20447 for ; Tue, 8 Apr 2014 14:21:09 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id n16sf4385774oag.5 for ; Tue, 08 Apr 2014 07:21:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=k4uKN3lhaRSgvhjMaYuVbwBeVxfanyIECYwlXyM+iVQ=; b=SvklzqVbHKCaiMnk6UF1PgT75VTrMb14cfe1GQFFuQnbGdhOCEGF4XN8XnIioZ+iy0 w0HQTK93BsOhRxpsHaC9dwOvqCKo6xA6xT1hdet7tp9XuX/Rw/66kxDVkcpa5VO/iEWj ILzmldtUDO6e+RxsoxGwnUNTy8mlLn+rFwGlqrqIUziRuy+lKctXuir5kLekUhtJ+YJR UL437RCoFa6vLJSfQbfQmZmpj2hmC1TsIRaCVC5wR97iiotO6u/nk+bZDCFqil2jI5Om gbcy/NvKZACYdwem98ZcWOGVF00YQPofw/VFtDFAy/ZqTbiYKHzmkPch3qtxt1GNTrEx l8+w== X-Gm-Message-State: ALoCoQl+1dLUznhLN8l16/qxivvA37EM5/cIm7ZHhpNZ3/74VejteVa779SlvVIuA4UxlOuqp2RH X-Received: by 10.182.108.136 with SMTP id hk8mr1904588obb.11.1396966869001; Tue, 08 Apr 2014 07:21:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.45 with SMTP id l42ls221007qga.50.gmail; Tue, 08 Apr 2014 07:21:08 -0700 (PDT) X-Received: by 10.220.133.80 with SMTP id e16mr3466086vct.13.1396966868801; Tue, 08 Apr 2014 07:21:08 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id ca6si422300vcb.55.2014.04.08.07.21.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:21:08 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id ib6so842555vcb.27 for ; Tue, 08 Apr 2014 07:21:08 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr3201036veb.21.1396966868692; Tue, 08 Apr 2014 07:21:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp249717vcv; Tue, 8 Apr 2014 07:21:08 -0700 (PDT) X-Received: by 10.58.88.8 with SMTP id bc8mr52173veb.39.1396966868292; Tue, 08 Apr 2014 07:21:08 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ui2si414559vdc.154.2014.04.08.07.21.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:21:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXWs6-00052u-2k; Tue, 08 Apr 2014 14:19:30 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXWs3-0004zK-Uy for xen-devel@lists.xen.org; Tue, 08 Apr 2014 14:19:28 +0000 Received: from [85.158.143.35:30034] by server-1.bemta-4.messagelabs.com id 50/38-09853-F6504435; Tue, 08 Apr 2014 14:19:27 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1396966765!7767084!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8230 invoked from network); 8 Apr 2014 14:19:26 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-2.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 8 Apr 2014 14:19:26 -0000 X-IronPort-AV: E=Sophos;i="4.97,818,1389744000"; d="scan'208";a="117888866" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 08 Apr 2014 14:19:23 +0000 Received: from norwich.cam.xci-test.com (10.80.248.129) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.2.342.4; Tue, 8 Apr 2014 10:19:21 -0400 Received: from marilith-n13-p0.uk.xensource.com ([10.80.229.115] helo=marilith-n13.uk.xensource.com.) by norwich.cam.xci-test.com with esmtp (Exim 4.72) (envelope-from ) id 1WXWrx-0005Fw-C6; Tue, 08 Apr 2014 14:19:21 +0000 From: Ian Campbell To: Date: Tue, 8 Apr 2014 15:19:20 +0100 Message-ID: <1396966760-7752-4-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396966739.22845.233.camel@kazak.uk.xensource.com> References: <1396966739.22845.233.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: julien.grall@linaro.org, tim@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH 4/4] xen: arm: support up to (almost) 1TB of guest RAM X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This creates a second bank of RAM starting at 8GB and potentially extending to the 1TB boundary, which is the limit imposed by our current use of a 3 level p2m with 2 pages at level 0 (2^40 bits). I've deliberately left a gap between the two banks just to exercise those code paths. The second bank is 1016GB in size which plus the 3GB below 4GB is 1019GB maximum guest RAM. At the point where the fact that this is slightly less than a full TB starts to become an issue for people then we can switch to a 4 level p2m, which would be needed to support guests larger than 1TB anyhow. Tested on 32-bit with 1, 4 and 6GB guests. Anything more than ~3GB requires an LPAE enabled kernel, or a 64-bit guest. Signed-off-by: Ian Campbell --- tools/libxc/xc_dom_arm.c | 95 +++++++++++++++++++++++++++++------------ tools/libxl/libxl_arm.c | 27 +++++++++--- xen/include/public/arch-arm.h | 13 +++++- 3 files changed, 100 insertions(+), 35 deletions(-) diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c index 36b1487..65464c7 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 +#include #include #include @@ -245,28 +246,73 @@ static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) return rc; } +static int populate_guest_memory(struct xc_dom_image *dom, + xen_pfn_t base_pfn, xen_pfn_t nr_pfns) +{ + int rc; + xen_pfn_t allocsz, pfn; + + if (!nr_pfns) + return 0; + + DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)", + __FUNCTION__, + (uint64_t)base_pfn << XC_PAGE_SHIFT, + (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT, + (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT)); + + for ( pfn = 0; pfn < nr_pfns; pfn++ ) + dom->p2m_host[pfn] = base_pfn + pfn; + + for ( pfn = rc = allocsz = 0; (pfn < nr_pfns) && !rc; pfn += allocsz ) + { + allocsz = nr_pfns - pfn; + if ( allocsz > 1024*1024 ) + allocsz = 1024*1024; + + rc = xc_domain_populate_physmap_exact( + dom->xch, dom->guest_domid, allocsz, + 0, 0, &dom->p2m_host[pfn]); + } + + return rc; +} + int arch_setup_meminit(struct xc_dom_image *dom) { int rc; - xen_pfn_t pfn, allocsz, i; + xen_pfn_t pfn; uint64_t modbase; /* Convenient */ - const uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT; - const uint64_t ramend = rambase + ( dom->total_pages << XC_PAGE_SHIFT ); + const uint64_t ramsize = (uint64_t)dom->total_pages << XC_PAGE_SHIFT; + + const uint64_t ram0size = + ramsize > GUEST_RAM0_SIZE ? GUEST_RAM0_SIZE : ramsize; + const uint64_t ram0end = GUEST_RAM0_BASE + ram0size; + const uint64_t ram1size = + ramsize > ram0size ? ramsize - ram0size : 0; + const uint64_t ram1end = GUEST_RAM1_BASE + ram1size; + + const xen_pfn_t p2m_size = ram1size ? + (ram1end - GUEST_RAM0_BASE) >> XC_PAGE_SHIFT : + (ram0end - GUEST_RAM0_BASE) >> XC_PAGE_SHIFT; + const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/); const uint64_t dtb_size = dom->devicetree_blob ? ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0; 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 = GUEST_RAM0_BASE + (128<<20); - if ( ramend - 1 > GUEST_RAM_END ) + assert(dom->rambase_pfn << XC_PAGE_SHIFT == GUEST_RAM0_BASE); + + if ( ramsize > GUEST_RAM_MAX ) { DOMPRINTF("%s: ram size is too large for guest address space: " "%"PRIx64" > %"PRIx64, - __FUNCTION__, ramend, GUEST_RAM_END); + __FUNCTION__, ramsize, GUEST_RAM_MAX); return -1; } @@ -276,38 +322,31 @@ int arch_setup_meminit(struct xc_dom_image *dom) dom->shadow_enabled = 1; - dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages); + dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * p2m_size); if ( dom->p2m_host == NULL ) return -EINVAL; + for ( pfn = 0; pfn < p2m_size; pfn++ ) + dom->p2m_host[pfn] = INVALID_MFN; - /* setup initial p2m */ - for ( pfn = 0; pfn < dom->total_pages; pfn++ ) - dom->p2m_host[pfn] = pfn + dom->rambase_pfn; - - /* allocate guest memory */ - for ( i = rc = allocsz = 0; - (i < dom->total_pages) && !rc; - i += allocsz ) - { - allocsz = dom->total_pages - i; - if ( allocsz > 1024*1024 ) - allocsz = 1024*1024; - - rc = xc_domain_populate_physmap_exact( - dom->xch, dom->guest_domid, allocsz, - 0, 0, &dom->p2m_host[i]); - } - + /* setup initial p2m and allocate guest memory */ + if ((rc = populate_guest_memory(dom, + GUEST_RAM0_BASE >> XC_PAGE_SHIFT, + ram0size >> XC_PAGE_SHIFT))) + return rc; + if ((rc = populate_guest_memory(dom, + GUEST_RAM1_BASE >> XC_PAGE_SHIFT, + ram1size >> XC_PAGE_SHIFT))) + return rc; /* - * Place boot modules at 128MB into RAM if there is enough RAM and + * Place boot modules at 128MB into low RAM if there is enough RAM and * the kernel does not overlap. Otherwise place them immediately * after the kernel. If there is no space after the kernel then * there is insufficient RAM and we fail. */ - if ( ramend >= ram128mb + modsize && kernend < ram128mb ) + if ( ram0end >= ram128mb + modsize && kernend < ram128mb ) modbase = ram128mb; - else if ( ramend >= kernend + modsize ) + else if ( ram0end >= kernend + modsize ) modbase = kernend; else return -1; diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index 4f0f0e2..6170454 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -255,9 +255,9 @@ static int make_psci_node(libxl__gc *gc, void *fdt) return 0; } -static int make_memory_node(libxl__gc *gc, void *fdt, - unsigned long long base, - unsigned long long size) +static int make_one_memory_node(libxl__gc *gc, void *fdt, + unsigned long long base, + unsigned long long size) { int res; const char *name = GCSPRINTF("memory@%08llx", base); @@ -269,7 +269,7 @@ static int make_memory_node(libxl__gc *gc, void *fdt, if (res) return res; res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS, - 1, (uint64_t)base, (uint64_t)size); + 1, base, size); if (res) return res; res = fdt_end_node(fdt); @@ -278,6 +278,24 @@ static int make_memory_node(libxl__gc *gc, void *fdt, return 0; } +static int make_memory_node(libxl__gc *gc, void *fdt, + unsigned long long size) +{ + int res; + /* This had better match libxc's arch_setup_meminit... */ + const uint64_t size0 = size > GUEST_RAM0_SIZE ? GUEST_RAM0_SIZE : size; + const uint64_t size1 = size > GUEST_RAM0_SIZE ? size - size0 : 0; + + res = make_one_memory_node(gc, fdt, GUEST_RAM0_BASE, size0); + if (res) return res; + if (size1) { + res = make_one_memory_node(gc, fdt, GUEST_RAM1_BASE, size1); + if (res) return res; + } + + return 0; +} + static int make_intc_node(libxl__gc *gc, void *fdt, unsigned long long gicd_base, unsigned long long gicd_size, @@ -493,7 +511,6 @@ next_resize: FDT( make_psci_node(gc, fdt) ); FDT( make_memory_node(gc, fdt, - dom->rambase_pfn << XC_PAGE_SHIFT, info->target_memkb * 1024) ); FDT( make_intc_node(gc, fdt, GUEST_GICD_BASE, GUEST_GICD_SIZE, diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 5840453..d15a977 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -374,8 +374,17 @@ typedef uint64_t xen_callback_t; #define GUEST_MAGIC_BASE 0x39000000ULL -#define GUEST_RAM_BASE 0x40000000ULL /* 3GB of RAM @ 1GB */ -#define GUEST_RAM_END 0xffffffffULL +#define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */ +#define GUEST_RAM0_SIZE 0xc0000000ULL +#define GUEST_RAM0_END 0xffffffffULL + +#define GUEST_RAM1_BASE 0x0200000000ULL /* 1016GB of RAM @ 8GB */ +#define GUEST_RAM1_SIZE 0xfe00000000ULL +#define GUEST_RAM1_END 0xffffffffffULL + +#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 + GUEST_RAM1_SIZE) /* Interrupts */ #define GUEST_TIMER_VIRT_PPI 27