From patchwork Tue Jan 19 16:45:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 8064191 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E3D5D9F744 for ; Tue, 19 Jan 2016 16:48:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 14F8D20306 for ; Tue, 19 Jan 2016 16:48:09 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D594420303 for ; Tue, 19 Jan 2016 16:48:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLZP9-0006JY-G4; Tue, 19 Jan 2016 16:45:15 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLZP7-0006JT-Di for xen-devel@lists.xenproject.org; Tue, 19 Jan 2016 16:45:13 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id 17/BB-17089-8186E965; Tue, 19 Jan 2016 16:45:12 +0000 X-Env-Sender: prvs=819d94e87=ross.lagerwall@citrix.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1453221910!16509433!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33556 invoked from network); 19 Jan 2016 16:45:12 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 19 Jan 2016 16:45:12 -0000 X-IronPort-AV: E=Sophos;i="5.22,318,1449532800"; d="scan'208";a="332465178" To: Konrad Rzeszutek Wilk , , , , , , , , , References: <1452808031-706-1-git-send-email-konrad.wilk@oracle.com> <1452808031-706-9-git-send-email-konrad.wilk@oracle.com> From: Ross Lagerwall Message-ID: <569E6815.2060806@citrix.com> Date: Tue, 19 Jan 2016 16:45:09 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <1452808031-706-9-git-send-email-konrad.wilk@oracle.com> X-DLP: MIA1 Subject: Re: [Xen-devel] [PATCH v2 08/13] xsplice: Implement payload loading (v2) X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 01/14/2016 09:47 PM, Konrad Rzeszutek Wilk wrote: snip > +static int move_payload(struct payload *payload, struct xsplice_elf *elf) > +{ > + uint8_t *buf; > + unsigned int i; > + size_t core_size = 0; > + > + /* Compute text regions */ > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( (elf->sec[i].sec->sh_flags & (SHF_ALLOC|SHF_EXECINSTR)) == > + (SHF_ALLOC|SHF_EXECINSTR) ) > + calc_section(&elf->sec[i], &core_size); > + } > + > + /* Compute rw data */ > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) && > + !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) && > + (elf->sec[i].sec->sh_flags & SHF_WRITE) ) > + calc_section(&elf->sec[i], &core_size); > + } > + > + /* Compute ro data */ > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) && > + !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) && > + !(elf->sec[i].sec->sh_flags & SHF_WRITE) ) > + calc_section(&elf->sec[i], &core_size); > + } > + > + buf = alloc_payload(core_size); > + if ( !buf ) { > + printk(XENLOG_ERR "%s: Could not allocate memory for module\n", > + elf->name); > + return -ENOMEM; > + } > + memset(buf, 0, core_size); > + > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( elf->sec[i].sec->sh_flags & SHF_ALLOC ) > + { > + elf->sec[i].load_addr = buf + elf->sec[i].sec->sh_entsize; > + memcpy(elf->sec[i].load_addr, elf->sec[i].data, > + elf->sec[i].sec->sh_size); > + printk(XENLOG_DEBUG "%s: Loaded %s at 0x%p\n", > + elf->name, elf->sec[i].name, elf->sec[i].load_addr); > + } > + } I found this bug a while back but didn't get round to pushing it anywhere. 8-<------------------------------------------------ commit 72803a4c765026c54f31988a4c689048c8723575 Author: Ross Lagerwall Date: Fri Nov 6 12:48:39 2015 +0000 Don't copy NOBITS sections (fixes BSS initialization) } diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 9450b2a..799ccb5 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -600,8 +600,9 @@ static int move_module(struct payload *payload, struct xsplice_elf *elf) if ( elf->sec[i].sec->sh_flags & SHF_ALLOC ) { elf->sec[i].load_addr = buf + elf->sec[i].sec->sh_entsize; - memcpy(elf->sec[i].load_addr, elf->sec[i].data, - elf->sec[i].sec->sh_size); + if ( elf->sec[i].sec->sh_type != SHT_NOBITS ) + memcpy(elf->sec[i].load_addr, elf->sec[i].data, + elf->sec[i].sec->sh_size); printk(XENLOG_DEBUG "Loaded %s at 0x%p\n", elf->sec[i].name, elf->sec[i].load_addr);