From patchwork Thu May 22 09:46:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 30587 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4A11820671 for ; Thu, 22 May 2014 09:49:03 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id va2sf14144980obc.1 for ; Thu, 22 May 2014 02:49:02 -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=PwIICPhfs8TyruGzSPIyApxhvN1T/TsV8rEUrjNlvkU=; b=HPUPGxyGwXS3DNBuhO7FKTpkwleu4TuEXciEeIIr3B+S/jQJkcYNPTeO1L0kLhVKgR BewC4mbZ6JJnoZFSnNqxak++GKFV491rgq08jfn12/lfpQ5dcq+stZ6I3j4MuX/7fVpe xtAZsfnmx/kuGfk3DDIEuUKERiuDffJ6Z+Zg/b3/JHQQtBpLu42KFeRNE7DVK1I+fT1H 8TjV3C8RNWRry9pIvFTK33XIkkMPQMgd/nLOQZqpe1hRc3Op5FATUiDvqI0xiCP/8Go0 cQzjmKBE8rAhkut1i9ryt1Mg28xsU4emCsFy8BEoz0BiSEOohhrzu8qmMIuwJdzgFaFt v9ig== X-Gm-Message-State: ALoCoQnmMmRugnzTDCGWa6lRUKLYMApcl54LjEATPDi4sEwabdmd1OebUqtK/Smc5h9tj8n6eEM0 X-Received: by 10.42.86.145 with SMTP id u17mr6054306icl.11.1400752142895; Thu, 22 May 2014 02:49:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.38.133 with SMTP id t5ls1227026qgt.43.gmail; Thu, 22 May 2014 02:49:02 -0700 (PDT) X-Received: by 10.58.46.231 with SMTP id y7mr2777552vem.5.1400752142780; Thu, 22 May 2014 02:49:02 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id pi7si2246686veb.13.2014.05.22.02.49.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 May 2014 02:49:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id ij19so728065vcb.9 for ; Thu, 22 May 2014 02:49:02 -0700 (PDT) X-Received: by 10.58.161.101 with SMTP id xr5mr732855veb.36.1400752142696; Thu, 22 May 2014 02:49:02 -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 ib8csp183766vcb; Thu, 22 May 2014 02:49:02 -0700 (PDT) X-Received: by 10.140.25.37 with SMTP id 34mr73000123qgs.60.1400752142029; Thu, 22 May 2014 02:49:02 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id b5si8749455qcm.19.2014.05.22.02.49.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 22 May 2014 02:49:02 -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 1WnPaj-0005HK-FI; Thu, 22 May 2014 09:47:13 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WnPah-0005F6-Nm for xen-devel@lists.xen.org; Thu, 22 May 2014 09:47:12 +0000 Received: from [85.158.137.68:41865] by server-2.bemta-3.messagelabs.com id 7C/22-23530-E97CD735; Thu, 22 May 2014 09:47:10 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1400752026!5465608!3 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 30769 invoked from network); 22 May 2014 09:47:09 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 22 May 2014 09:47:09 -0000 X-IronPort-AV: E=Sophos;i="4.98,886,1392163200"; d="scan'208";a="134487234" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 22 May 2014 09:46:52 +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; Thu, 22 May 2014 05:46:51 -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 1WnPaM-0000mI-7h; Thu, 22 May 2014 10:46:51 +0100 Received: by localhost.localdomain (sSMTP sendmail emulation); Thu, 22 May 2014 10:46:50 +0100 From: Ian Campbell To: , , , Date: Thu, 22 May 2014 10:46:41 +0100 Message-ID: <1400752004-9731-6-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1400751582.11409.46.camel@kazak.uk.xensource.com> References: <1400751582.11409.46.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Campbell , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH v5 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.220.178 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 Acked-by: Julien Grall Acked-by: Ian Jackson --- 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 +#include #include #include @@ -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