From patchwork Tue May 13 11:29:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 30033 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8CC9820369 for ; Tue, 13 May 2014 11:31:26 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id l6sf908788oag.11 for ; Tue, 13 May 2014 04:31:26 -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=p5MWOeMd60JymR107cmhN6Y9J8TenibFjv9JIux1fzc=; b=af3bWoBU/ZJ6seckGdnlFGzFU1woBUaAd+ka9/m09AxEKWlmZ3EepW8DTKPr0W+uBj 9l9WioiSE7X/gVQOuhFQ5rH6rGj5WY5kp9CthZSo1ZauxcAdF3WYuQSyBZntI2Tpbbjo DXttc2Up6b8WWTn86OyIXmoKdlkBjpwTT2Ik8BoZihbI4FbSDScDq5ok0J+AeBL8qGTh nBA9JSB8kvF0u7V9hwpidKLxTxL21VxTt9tNpG3GoF/zx7YxMZoEcLhXoEQFmDHoAIOJ J05DXL9/o/nc0Y4IJ+5TgJvnj5WtB/A/VQNo5ZA+lR60OL5PAHoa9EAWdWbe6BrIbmu4 wOAQ== X-Gm-Message-State: ALoCoQmJijkflirkLwmqVlmLf79kVsO2Ko6M33H8wzTJGHCcf1NR9RjaEBFK26K1V9hoXHlv3qvA X-Received: by 10.182.230.132 with SMTP id sy4mr6901755obc.48.1399980686196; Tue, 13 May 2014 04:31:26 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.9 with SMTP id 9ls1730751qgg.75.gmail; Tue, 13 May 2014 04:31:26 -0700 (PDT) X-Received: by 10.221.37.1 with SMTP id tc1mr1674369vcb.32.1399980686092; Tue, 13 May 2014 04:31:26 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id sv4si1123106vdc.43.2014.05.13.04.31.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 04:31:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so238130vcb.29 for ; Tue, 13 May 2014 04:31:26 -0700 (PDT) X-Received: by 10.58.216.34 with SMTP id on2mr28046631vec.22.1399980686007; Tue, 13 May 2014 04:31:26 -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 ib8csp143374vcb; Tue, 13 May 2014 04:31:25 -0700 (PDT) X-Received: by 10.224.126.9 with SMTP id a9mr46878989qas.39.1399980685208; Tue, 13 May 2014 04:31:25 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id h90si7595606qgh.183.2014.05.13.04.31.24 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 May 2014 04:31:25 -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-0007vx-9D; 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-0007tW-Gm for xen-devel@lists.xen.org; Tue, 13 May 2014 11:29:43 +0000 Received: from [85.158.139.211:58081] by server-7.bemta-5.messagelabs.com id 13/73-20531-62202735; Tue, 13 May 2014 11:29:42 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1399980579!3968363!2 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.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28115 invoked from network); 13 May 2014 11:29:41 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.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="129769983" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 13 May 2014 11:29:40 +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:40 -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 1WkAtu-0004Xi-LL; Tue, 13 May 2014 12:29:39 +0100 Received: by localhost.localdomain (sSMTP sendmail emulation); Tue, 13 May 2014 12:29:38 +0100 From: Ian Campbell To: Date: Tue, 13 May 2014 12:29:29 +0100 Message-ID: <1399980574-12515-5-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 5/9] tools: arm: refactor code to setup guest p2m and fill it with 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.170 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: This will help when we have more guest RAM banks. Mostly code motion of the p2m_host initialisation and allocation loop into the new function populate_guest_memory, but in addition in the caller we now initialise the p2m all the INVALID_MFN to handle any holes, although in this patch we still fill in the entire allocated region. Signed-off-by: Ian Campbell Acked-by: Julien Grall --- v4: Moved before "prepare for multiple banks of guest RAM" to allow for refactoring of that patch. Dropped unnecessary !nr_pfns early return from populate_guest_memory. v2: New patch --- tools/libxc/xc_dom_arm.c | 60 +++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c index 74917c3..8c6a317 100644 --- a/tools/libxc/xc_dom_arm.c +++ b/tools/libxc/xc_dom_arm.c @@ -248,16 +248,48 @@ 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; + + 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 ramsize = dom->total_pages << XC_PAGE_SHIFT; const uint64_t ramend = rambase + ramsize; + + const xen_pfn_t p2m_size = dom->total_pages; + 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; @@ -289,27 +321,17 @@ 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_RAM_BASE >> XC_PAGE_SHIFT, + ramsize >> XC_PAGE_SHIFT))) + return rc; /* * We try to place dtb+initrd at 128MB or if we have less RAM