Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ag8mo-0006DV-Tn for mharc-grub-devel@gnu.org; Wed, 16 Mar 2016 06:34:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8mm-0006DP-Ql for grub-devel@gnu.org; Wed, 16 Mar 2016 06:34:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ag8mi-0005ed-Js for grub-devel@gnu.org; Wed, 16 Mar 2016 06:34:40 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:41890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag8mi-0005eX-Bs for grub-devel@gnu.org; Wed, 16 Mar 2016 06:34:36 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u2GAYRXk012164 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 16 Mar 2016 10:34:27 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u2GAYRUU022562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 16 Mar 2016 10:34:27 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u2GAYQtK018484; Wed, 16 Mar 2016 10:34:26 GMT Received: from olila.local.net-space.pl (/10.175.192.181) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 16 Mar 2016 03:34:25 -0700 Date: Wed, 16 Mar 2016 11:34:19 +0100 From: Daniel Kiper To: Konrad Rzeszutek Wilk Subject: Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images Message-ID: <20160316103419.GG31771@olila.local.net-space.pl> References: <1458055562-24950-1-git-send-email-daniel.kiper@oracle.com> <1458055562-24950-6-git-send-email-daniel.kiper@oracle.com> <20160315214221.GE31771@olila.local.net-space.pl> <20160315235408.GF29495@char.us.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160315235408.GF29495@char.us.oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 Cc: "jgross@suse.com" , "grub-devel@gnu.org" , "eric.snowberg@oracle.com" , "arvidjaar@gmail.com" , Vladimir 'phcoder' Serbinenko , "stefano.stabellini@eu.citrix.com" , "cardoe@cardoe.com" , "pgnet.dev@gmail.com" , "roy.franz@linaro.org" , "ning.sun@intel.com" , "david.vrabel@citrix.com" , "jbeulich@suse.com" , "andrew.cooper3@citrix.com" , "xen-devel@lists.xenproject.org" , "qiaowei.ren@intel.com" , "richard.l.maliszewski@intel.com" , "gang.wei@intel.com" , "fu.wei@linaro.org" , "seth.goldberg@oracle.com" X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Mar 2016 10:34:42 -0000 On Tue, Mar 15, 2016 at 07:54:08PM -0400, Konrad Rzeszutek Wilk wrote: > On Tue, Mar 15, 2016 at 10:42:21PM +0100, Daniel Kiper wrote: > > On Tue, Mar 15, 2016 at 05:30:20PM +0100, Vladimir 'phcoder' Serbinenko wrote: > > > On Tuesday, March 15, 2016, Vladimir 'phcoder' Serbinenko > > > wrote: > > > > > > > > > > >> + if (mld->relocatable) > > > >> + err = grub_relocator_alloc_chunk_align > > > >> (grub_multiboot_relocator, &ch, > > > >> + mld->min_addr, > > > >> mld->max_addr - phdr(i)->p_memsz, > > > >> + phdr(i)->p_memsz, > > > >> mld->align ? mld->align : 1, > > > >> + mld->preference, > > > >> mld->avoid_efi_boot_services); > > > >> + else > > > >> + err = grub_relocator_alloc_chunk_addr > > > >> (grub_multiboot_relocator, > > > >> + &ch, > > > >> phdr(i)->p_paddr, > > > >> + phdr(i)->p_memsz); > > > >> > > > > I believe this is faulty if you have more than one PHDR. You load every > > > > Argh... You are right! > > > > > > PHDR individually to essentially random address. Pieces have no reasonable > > > > way to find each other. Moreover entry point calculation is also faulty. > > > > Imagine sth like this: > > > > PHDR 1M-2M > > > > PHDR 2M-5M > > > > Entry point 2.5M (in second PHDR) > > > > then if first PHDR is loaded to 1M and second to 10M then base and link > > > > addr are both 1M, so entry point will be calculated as 2.5M, which points > > > > to no segment. I see 2 solutions: > > > > 1) Look where entry falls in original layout, then adjust it in accordance > > > > with where this phdr will be loaded. This requires least efforts. Finding > > > > different PHDRs is still impossible but it will be possible in the future > > > > with relocations. > > > > It looks that we should store somewhere and export to image via relevant tags > > link addresses and load addresses. Hmmm... Maybe we should just provide load > > addresses to image. Image can have link addresses in its data. And this > > probably does not require huge changes. > > > > > > 2) Allocate a buffer of size highest - lowest and load everything into > > > > this buffer keeping relative offsets. If we do this, then we need to > > > > document if it's required for boorloader to behave this way or not. If it > > > > is, we can in future provide a tag to say that image is fine with > > > > rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). > > > > I guess that xen is a single phdr image and so essentially any code will > > > > work with it. > > Won't be in Xen 4.7. > > > > This problem appears in couple of other places, I'll skip commenting on > > > > them explicitly. > > > > > > > I take back the part "requires least effort" for solution 1. Solution 2 is > > > probably simpler and less error-prone as developper doesn't control if > > > binutils decode to put several phdrs. > > > > #2 looks promising but what if PHDR_1 is at 1 MiB - 2 MiB and PHDR_2 is at > > 808 MiB - 809 MiB? Then we will allocate more than 800 MiB just for an > > unusable hole. So, I think that we should go that way if solution #1 > > is too complicated. > > Daniel, my xSplice patches make the Xen have two ELF PHDRS: 1)the PT_LOAD > and 2) PT_NOTE (which points to smack in the .text section) so you can try > that as an example payload. > > (If you want to put your patches on top of mine: > git://xenbits.xen.org/people/konradwilk/xen.git #xsplice.v4) Thanks, but multiboot2 loads just PT_LOAD segments. Daniel