From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E7F1C433ED for ; Wed, 19 May 2021 14:35:27 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A45A61355 for ; Wed, 19 May 2021 14:35:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A45A61355 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.130184.243997 (Exim 4.92) (envelope-from ) id 1ljNHs-0001E6-QU; Wed, 19 May 2021 14:35:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 130184.243997; Wed, 19 May 2021 14:35:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ljNHs-0001Dz-Mq; Wed, 19 May 2021 14:35:04 +0000 Received: by outflank-mailman (input) for mailman id 130184; Wed, 19 May 2021 14:35:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ljNHr-0001Dt-EY for xen-devel@lists.xenproject.org; Wed, 19 May 2021 14:35:03 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7ca89015-c81d-458a-ad65-f81a33a7c288; Wed, 19 May 2021 14:35:01 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2B375AEA6; Wed, 19 May 2021 14:35:00 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7ca89015-c81d-458a-ad65-f81a33a7c288 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1621434900; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B34+PNn0NfMzZMKy6F3i6BO9UdAQaX51iUoim72t5tU=; b=ovRkkyp63RcIRlynvAO+YI12INTi+aHO6RnuyODinoSQ0gt5C6P0AkbFZt9KIbT4wwxeUy 5zKtyfsN2PBEPIlomPnD+GVlCWfKSRqPOqDfwflD46VSb/6QauEfkDmlEXVccmQAdhcP3o HLNcNJCg09eJcRqgjCesY5u0AZFchN8= Subject: Re: [PATCH v3 2/5] xen/x86: manually build xen.mb.efi binary To: Daniel Kiper Cc: Bob Eshleman , Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu , Xen-devel References: <28d5536a2f7691e8f79d55f1470fa89ce4fae93d.1611273359.git.bobbyeshleman@gmail.com> <3c621726-31c4-6a79-a020-88c59644111b@suse.com> <74ea104d-3826-d80d-3af5-f444d065c73f@gmail.com> <20210517132039.6czppjfge27x4mwg@tomti.i.net-space.pl> <20210518174633.spo5kmgcbuo6dg5k@tomti.i.net-space.pl> <51333867-d693-38e2-bd1c-fce28241a604@suse.com> <20210519124846.go3zyqzojsaj35in@tomti.i.net-space.pl> From: Jan Beulich Message-ID: Date: Wed, 19 May 2021 16:35:00 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210519124846.go3zyqzojsaj35in@tomti.i.net-space.pl> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 19.05.2021 14:48, Daniel Kiper wrote: > On Wed, May 19, 2021 at 11:29:43AM +0200, Jan Beulich wrote: >> On 18.05.2021 19:46, Daniel Kiper wrote: >>> On Mon, May 17, 2021 at 03:24:28PM +0200, Jan Beulich wrote: >>>> On 17.05.2021 15:20, Daniel Kiper wrote: >>>>> On Mon, May 17, 2021 at 08:48:32AM +0200, Jan Beulich wrote: >>>>>> On 07.05.2021 22:26, Bob Eshleman wrote: >>>>>>> What is your intuition WRT the idea that instead of trying add a PE/COFF hdr >>>>>>> in front of Xen's mb2 bin, we instead go the route of introducing valid mb2 >>>>>>> entry points into xen.efi? >>>>>> >>>>>> At the first glance I think this is going to be less intrusive, and hence >>>>>> to be preferred. But of course I haven't experimented in any way ... >>>>> >>>>> When I worked on this a few years ago I tried that way. Sadly I failed >>>>> because I was not able to produce "linear" PE image using binutils >>>>> exiting that days. >>>> >>>> What is a "linear" PE image? >>> >>> The problem with Multiboot family protocols is that all code and data >>> sections have to be glued together in the image and as such loaded into >>> the memory (IIRC BSS is an exception but it has to live behind the >>> image). So, you cannot use PE image which has different representation >>> in file and memory. IIRC by default at least code and data sections in >>> xen.efi have different sizes in PE file and in memory. I tried to fix >>> that using linker script and objcopy but it did not work. Sadly I do >>> not remember the details but there is pretty good chance you can find >>> relevant emails in Xen-devel archive with me explaining what kind of >>> problems I met. >> >> Ah, this rings a bell. Even the .bss-is-last assumption doesn't hold, >> because .reloc (for us as well as in general) comes later, but needs >> loading (in the right place). Since even xen.gz isn't simply the > > However, IIRC it is not used when Xen is loaded through Multiboot2 > protocol. So, I think it may stay in the image as is and the Mutliboot2 > header should not cover .reloc section. > > By the way, why do we need .reloc section in the PE image? Is not %rip > relative addressing sufficient? IIRC the Linux kernel just contains > a stub .reloc section. Could not we do the same? %rip-relative addressing can (obviously, I think) help only for text. But we also have data containing pointers, which need relocating. >> compressed linker output, but a post-processed (by mkelf32) image, >> maybe what we need is a build tool doing similar post-processing on >> xen.efi? Otoh getting disk image and in-memory image aligned ought > > Yep, this should work too. > >> to be possible by setting --section-alignment= and --file-alignment= >> to the same value (resulting in a much larger file) - adjusting file > > IIRC this did not work for some reason. Maybe it would be better to > enforce correct alignment and required padding using linker script. I'm not convinced the linker script is the correct vehicle here. It is mainly about placement in the address space (i.e. laying out how things will end up in memory), not about file layout. >> positions would effectively be what a post-processing tool would need >> to do (like with mkelf32 perhaps we could then at least save the >> first ~2Mb of space). Which would still leave .reloc to be dealt with >> - maybe we could place this after .init, but still ahead of >> __init_end (such that the memory would get freed late in the boot >> process). Not sure whether EFI loaders would "like" such an unusual >> placement. > > Yeah, good question... > >> Also not sure what to do with Dwarf debug info, which just recently >> we managed to avoid needing to strip unconditionally. > > I think debug info may stay as is. Just Multiboot2 header should not > cover it if it is not needed. You did say that .bss is expected to be last, which both .reloc and debug info violate. >>>>> Maybe >>>>> newer binutils are more flexible and will be able to produce a PE image >>>>> with properties required by Multiboot2 protocol. >>>> >>>> Isn't all you need the MB2 header within the first so many bytes of the >>>> (disk) image? Or was it the image as loaded into memory? Both should be >>>> possible to arrange for. >>> >>> IIRC Multiboot2 protocol requires the header in first 32 kiB of an image. >>> So, this is not a problem. >> >> I was about to ask "Disk image or in-memory image?" But this won't >> matter if the image as a whole got linearized, as long as the first >> section doesn't start to high up. I notice that xen-syms doesn't fit >> this requirement either, only the output of mkelf32 does. Which >> suggests that there may not be a way around a post-processing tool. > > Could not we drop 2 MiB padding at the beginning of xen-syms by changing > some things in the linker script? Not sure, but at the first glance I don't think so. If we want section and file alignment to match, and if we want sections at 2Mb boundaries, then the first section - since it cannot start at 0 - will need to be at 2Mb. In xen-syms the linker manages to put it at 32kb, but I think arranging for such also for PE output (despite both alignments set to match) would require a linker change, perhaps even a new command line option (because the two alignment requests can't be silently ignored). Jan