From patchwork Wed Apr 9 11:51:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 28085 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6C57C2145B for ; Wed, 9 Apr 2014 11:53:30 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id fb1sf7485780pad.8 for ; Wed, 09 Apr 2014 04:53:29 -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=7zgZUWLndFUxUM8uvwvzTWWTb/NIXnQg86gOgMocu80=; b=iBs0vR7Gib2BS6jP+b2YLiXMz/iFMHftNYcIxqCh0JDFOxXtHZutTUtQjrnWVjO24+ 19hrisew3bruD8+gO0NELMyayV6PPm6xSsXpMNEMqpLHO3AB0EMEyNf2fLUD4lXOYGom OjocU3klWKTGInR5twZHxQNlSdIQWJ/FXPWIOsspBlISHFT21lQrlfL4tjDXO0+ytmCS CrUXpp7OIay12epvP11ckQQsMWO4FyIqKoWGIehW72k9KAtY90Q0VSktAOj39ZgK+bP8 9spOHjT0XqAbcHVO8jlq3n+3xkilPzxh3FLSs/D2xT7t8UTOaLx3nHpRTZBoUaYcXqy0 Nwpg== X-Gm-Message-State: ALoCoQmL3UcEdRafDdtY7mWgcPAOSiOfjNP554eENKhPRtRtaUVJQ+Qy55mO7Ib4hzHR5iRRt7AD X-Received: by 10.66.233.65 with SMTP id tu1mr4211579pac.35.1397044409417; Wed, 09 Apr 2014 04:53:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.100.137 with SMTP id s9ls642699qge.57.gmail; Wed, 09 Apr 2014 04:53:29 -0700 (PDT) X-Received: by 10.220.106.7 with SMTP id v7mr101730vco.46.1397044409194; Wed, 09 Apr 2014 04:53:29 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id o6si93926vcz.184.2014.04.09.04.53.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 09 Apr 2014 04:53:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id db11so1918995veb.21 for ; Wed, 09 Apr 2014 04:53:29 -0700 (PDT) X-Received: by 10.58.1.97 with SMTP id 1mr753478vel.23.1397044409109; Wed, 09 Apr 2014 04:53:29 -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 v8csp323199vcv; Wed, 9 Apr 2014 04:53:28 -0700 (PDT) X-Received: by 10.140.32.139 with SMTP id h11mr11154898qgh.49.1397044408405; Wed, 09 Apr 2014 04:53:28 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id t10si278641qci.39.2014.04.09.04.53.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 09 Apr 2014 04:53:28 -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 1WXr2K-00026p-GK; Wed, 09 Apr 2014 11:51:24 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXr2I-00026D-8C for xen-devel@lists.xen.org; Wed, 09 Apr 2014 11:51:22 +0000 Received: from [85.158.137.68:27832] by server-9.bemta-3.messagelabs.com id D9/3A-30063-93435435; Wed, 09 Apr 2014 11:51:21 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1397044277!879209!2 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.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11090 invoked from network); 9 Apr 2014 11:51:20 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 9 Apr 2014 11:51:20 -0000 X-IronPort-AV: E=Sophos;i="4.97,826,1389744000"; d="scan'208";a="119455031" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 09 Apr 2014 11:51:17 +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; Wed, 9 Apr 2014 07:51:17 -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 1WXr2C-00034e-Qr; Wed, 09 Apr 2014 11:51:16 +0000 From: Ian Campbell To: Date: Wed, 9 Apr 2014 12:51:14 +0100 Message-ID: <1397044276-30185-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1397044259.6275.15.camel@kazak.uk.xensource.com> References: <1397044259.6275.15.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Jackson , julien.grall@linaro.org, tim@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH 1/3] tools: arm: improve placement of initial modules. 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.128.176 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: 314c9815e2f5 "tools: implement initial ramdisk support for ARM." broke starting guests with <= 128 MB ram by placing the boot modules (dtb and initrd) immediately after the kernel in this case, running the risk of them being overwritten. Instead place the modules at the end of RAM, as the hypervisor does for dom0. The hypervisor also falls back to placing things before the kernel as a last resort before failing, so add that here too. Tested with the Debian installer initrd and guests of 96MB, 128MB, 256MB and 1GB. All work, also tested with 64MB but the installer doesn't run with so little RAM (but our placement of the initrd is correct). Signed-off-by: Ian Campbell Cc: Ian Jackson Acked-by: Julien Grall --- This should be added to 4.4.1 along with 314c9815e2f5. --- tools/libxc/xc_dom_arm.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c index f051515..60ac51a 100644 --- a/tools/libxc/xc_dom_arm.c +++ b/tools/libxc/xc_dom_arm.c @@ -253,8 +253,11 @@ int arch_setup_meminit(struct xc_dom_image *dom) /* 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 = dom->total_pages << XC_PAGE_SHIFT; + const uint64_t ramend = rambase + ramsize; + 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; const uint64_t dtb_size = dom->devicetree_blob ? ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0; const uint64_t ramdisk_size = dom->ramdisk_blob ? @@ -262,6 +265,13 @@ int arch_setup_meminit(struct xc_dom_image *dom) const uint64_t modsize = dtb_size + ramdisk_size; const uint64_t ram128mb = rambase + (128<<20); + if ( modsize + kernsize > ramsize ) + { + DOMPRINTF("%s: Not enough memory for the kernel+dtb+initrd", + __FUNCTION__); + return -1; + } + rc = set_mode(dom->xch, dom->guest_domid, dom->guest_type); if ( rc ) return rc; @@ -290,17 +300,20 @@ int arch_setup_meminit(struct xc_dom_image *dom) 0, 0, &dom->p2m_host[i]); } - /* - * Place boot modules at 128MB into 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. + * We try to place dtb+initrd at 128MB or if we have less RAM + * as high as possible. If there is no space then fallback to + * just before the kernel. + * + * If changing this then consider + * xen/arch/arm/kernel.c:place_modules as well. */ if ( ramend >= ram128mb + modsize && kernend < ram128mb ) modbase = ram128mb; - else if ( ramend >= kernend + modsize ) - modbase = kernend; + else if ( ramend - modsize > kernend ) + modbase = ramend - modsize; + else if (kernbase - rambase > modsize ) + modbase = kernbase - modsize; else return -1;