From patchwork Tue May 13 11:29:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 30037 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 86B6420369 for ; Tue, 13 May 2014 11:31:57 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id ih12sf493019qab.0 for ; Tue, 13 May 2014 04:31:57 -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=bPdyGSU5L8o1aq387nvthH5PAj4qpRexXEilgmeuFYM=; b=eH8wv8E1yytY8NwtFuWUfCMg71R4esvEh4RpYkj34dJB5c07CFuZOh02VD76aXaDcq EuU0GjY6La5M3hzsaWDAkth1uWfSfYWcmm/dfPSj3lXMjYseNmT8g9iLQU7dfxODvmWL VIJpZAUkgbYyk6ZhdNYMVFUQEvgERC+VZfuUEJRevVfdywoSOfMt6or84/CBQRACB89r VdSjHKkPLJdFKBe+o47H1mzFKEESas4aSEWCMcuUfPWFMvvf1umUYB4S9InhOx+oBSiv tQ/gI8m3y7cKgVwyjBCABcEqzqkzozVW7lZCL1XGiDCgcQYIWqGPCe6o7xgwRuFb5Qmy 2IJw== X-Gm-Message-State: ALoCoQnMZ+nElvU5Xccv4S+qaZRbR++GY+ojIkM/JtabJb0MxQYcqfY8DVg142bNw6JpPCz90Eef X-Received: by 10.236.128.112 with SMTP id e76mr14654369yhi.38.1399980717399; Tue, 13 May 2014 04:31:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.82.37 with SMTP id g34ls740057qgd.64.gmail; Tue, 13 May 2014 04:31:57 -0700 (PDT) X-Received: by 10.52.0.193 with SMTP id 1mr23954210vdg.0.1399980717263; Tue, 13 May 2014 04:31:57 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id sn5si2585908vdc.101.2014.05.13.04.31.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 04:31:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id oy12so228366veb.38 for ; Tue, 13 May 2014 04:31:57 -0700 (PDT) X-Received: by 10.58.216.34 with SMTP id on2mr28048372vec.22.1399980717141; Tue, 13 May 2014 04:31:57 -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.221.72 with SMTP id ib8csp143428vcb; Tue, 13 May 2014 04:31:56 -0700 (PDT) X-Received: by 10.50.47.12 with SMTP id z12mr55656821igm.37.1399980716378; Tue, 13 May 2014 04:31:56 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id z11si15763903igm.39.2014.05.13.04.31.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 May 2014 04:31:56 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) 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 1WkAu1-0007wd-Nl; Tue, 13 May 2014 11:29:45 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WkAtz-0007tX-DJ for xen-devel@lists.xen.org; Tue, 13 May 2014 11:29:43 +0000 Received: from [85.158.139.211:58089] by server-14.bemta-5.messagelabs.com id 00/53-15696-62202735; Tue, 13 May 2014 11:29:42 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1399980578!3948814!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1909 invoked from network); 13 May 2014 11:29:41 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 13 May 2014 11:29:41 -0000 X-IronPort-AV: E=Sophos; i="4.97,1043,1389744000"; d="scan'208"; a="130584591" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 13 May 2014 11:29:43 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.3.181.6; Tue, 13 May 2014 07:29:41 -0400 Received: from marilith-n13-p0.uk.xensource.com ([10.80.229.115] helo=localhost.localdomain) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1WkAtv-0004Xl-Mo; Tue, 13 May 2014 12:29:40 +0100 Received: by localhost.localdomain (sSMTP sendmail emulation); Tue, 13 May 2014 12:29:39 +0100 From: Ian Campbell To: Date: Tue, 13 May 2014 12:29:30 +0100 Message-ID: <1399980574-12515-6-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399980488.21867.19.camel@kazak.uk.xensource.com> References: <1399980488.21867.19.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: ian.jackson@eu.citrix.com, julien.grall@linaro.org, tim@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH v4 6/9] tools: arm: prepare domain builder for multiple banks 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) 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: 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 --- 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 | 71 ++++++++++++++++++++++++++++++----------- xen/include/public/arch-arm.h | 10 ++++-- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c index 8c6a317..6c255ac 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 @@ -279,17 +280,20 @@ 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_BANKS] = { + GUEST_RAM0_BASE + }; + const uint64_t bankmax[GUEST_RAM_BANKS] = { + GUEST_RAM0_SIZE + }; + /* 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 +302,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 = GUEST_RAM0_BASE + (128<<20); + + xen_pfn_t p2m_size; + xen_pfn_t rambank_size[GUEST_RAM_BANKS]; + uint64_t bank0end; - if ( modsize + kernsize > ramsize ) + assert(dom->rambase_pfn << XC_PAGE_SHIFT == GUEST_RAM0_BASE); + + 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" > %"PRIx64, - __FUNCTION__, ramsize, GUEST_RAM_SIZE); + __FUNCTION__, ramsize, GUEST_RAM_MAX); return -1; } @@ -321,6 +337,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 +358,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 +374,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 - GUEST_RAM0_BASE > 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..96c8786 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -375,8 +375,14 @@ 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) /* Interrupts */ #define GUEST_TIMER_VIRT_PPI 27