From: Wei Liu Subject: Re: [PATCH for-4.6] tools/libxc: arm: Check the index before accessing the bank Date: Fri, 18 Sep 2015 11:30:19 +0100 Message-ID: <20150918103019.GB19801@zion.uk.xensource.com> References: <1442511396-21344-1-git-send-email-julien.grall@citrix.com> <55FAFB9D.7090107@citrix.com> <1442566364.18856.251.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Zcsw1-0001Gj-Eg for xen-devel@lists.xenproject.org; Fri, 18 Sep 2015 10:30:29 +0000 Content-Disposition: inline In-Reply-To: <1442566364.18856.251.camel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: Julien Grall , xen-devel@lists.xenproject.org, Ian Jackson , stefano.stabellini@citrix.com, Wei.Liu2@citrix.com List-Id: xen-devel@lists.xenproject.org On Fri, Sep 18, 2015 at 09:52:44AM +0100, Ian Campbell wrote: > On Thu, 2015-09-17 at 18:42 +0100, Julien Grall wrote: > > On 17/09/15 18:36, Julien Grall wrote: > > > When creating a guest with more than 3GB of memory, the 2 banks will be > > > used and the loop with overrunning. The code will fail later on because > > > Xen will deny to populate the region: > > > > > > domainbuilder: detail: xc_dom_devicetree_mem: called > > > domainbuilder: detail: xc_dom_mem_init: mem 3096 MB, pages 0xc1800 > > > pages, 4k each > > > domainbuilder: detail: xc_dom_mem_init: 0xc1800 pages > > > domainbuilder: detail: xc_dom_boot_mem_init: called > > > domainbuilder: detail: set_mode: guest xen-3.0-aarch64, address size 64 > > > domainbuilder: detail: xc_dom_malloc : 14384 kB > > > domainbuilder: detail: populate_guest_memory: populating RAM > > > @0000000040000000-0000000100000000 (3072MB) > > > domainbuilder: detail: populate_one_size: populated 0x3/0x3 entries > > > with shift 18 > > > domainbuilder: detail: populate_guest_memory: populating RAM > > > @0000000200000000-0000000201800000 (24MB) > > > domainbuilder: detail: populate_one_size: populated 0xc/0xc entries > > > with shift 9 > > > domainbuilder: detail: populate_guest_memory: populating RAM > > > @0000007fad41c000-0007fb39dd42c000 (2141954816MB) > > > domainbuilder: detail: populate_one_size: populated 0x100/0x1e4 entries > > > with shift 0 > > > domainbuilder: detail: populate_guest_memory: Not enough RAM > > > > > > This is because we are currently accessing the bank before checking the > > > validity of the index. AFAICT, on Debian Jessie, the compiler (gcc > > > 4.9.2) is > > > assuming that it's not necessary to verify the index because it's used > > > before. This is a valid assumption because the operand of && are > > > execute from from left to right. > > > > > > Re-order the checks to verify the validity of the index before > > > accessing > > > the bank. > > > > > > The problem has been present since the introduction of the multi-bank > > > feature in commit 45d9867837f099e9eed4189dac5ed39d1fe2ed49 " tools: > > > arm: > > > prepare domain builder for multiple banks of guest RAM". > > > > Hmmmm I forgot my Signed-off-by :(. > > > > Signed-off-by: Julien Grall > > Acked-by: Ian Campbell > > This is a no brainer for 4.6 (and further) IMHO and with Wei not being > around I shall plan to apply later today unless there are objections. > No objection from me of course. Wei.