From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lXUr0-00010f-Ld for mharc-grub-devel@gnu.org; Fri, 16 Apr 2021 16:14:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lXUqy-0000yw-Hr for grub-devel@gnu.org; Fri, 16 Apr 2021 16:14:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42015) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lXUqv-0005cL-GN for grub-devel@gnu.org; Fri, 16 Apr 2021 16:14:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618604048; h=from:from:reply-to:subject:subject: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=4ZxTQu5VMXC13RXmjTjIyiONfNxfi2zaqoiQOsgPy0k=; b=HjuqjARmx5YnNGfgG7k278t0zTxqMTf9j/SR7o+6NMhYuLUqRoFd8ibqiSeMZ7YSx9TJWe +PdUpx9T95w3js4r5cy6oMwbLw5SkVmzrbJvzxEp6Fk9bguO9pj5euQG7VU/2GLybYutml oiDWqZggSBZ+lM2lXtEdRd0nm8MoD0o= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-MBkT5VxBMee8MVNn_HD7CA-1; Fri, 16 Apr 2021 16:14:05 -0400 X-MC-Unique: MBkT5VxBMee8MVNn_HD7CA-1 Received: by mail-wr1-f69.google.com with SMTP id m2-20020a5d64a20000b02900fd24e6af66so4974858wrp.21 for ; Fri, 16 Apr 2021 13:14:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4ZxTQu5VMXC13RXmjTjIyiONfNxfi2zaqoiQOsgPy0k=; b=CsgxjNMbMuS9+GiOkxKwo6maHgADN4wL5FZyUxT6EnyitV/NYuYhJtzYA3iwWpliw8 JA5Da9/yp3Ik/aGBisB0a6WtrbgRx0A9n7UEp9vIVo2RnXmgNa3GuBhNPW6qoC5sgaCh DC5GDkGwq4Pwv/GzBNzH5A8f2JxtVXBmT/aXRDso0AqW3mwuxYz4fvwGUoSbBv4bWk+8 Zvt8oVxFgxIlLaquLJruswZRYBIyvye6NQo66swdOJyNH+YkbcvUidplnQileMaCyuss 31E+lMABLpHh5VRhXXCzQHrr/O3x7XH27gihc23SD1C0wAjeVXpZZWS0B3FLh8er3hhd lYYQ== X-Gm-Message-State: AOAM531saOBDNEjrMM2nkBnkVmbLSrhhI6BnpMeIO6jAxNT0x04TFk/Q gq3kQBT2lHVWE23Onpe22llgBHJiA/FDAtAHzzAciblGWVZfxv2ogOo/6+CY0o0dlChIUdhL4Hf qgdd3pr2Z8VU= X-Received: by 2002:a7b:ce09:: with SMTP id m9mr9973395wmc.150.1618604044536; Fri, 16 Apr 2021 13:14:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydCithzZYX7gXZClx3Rwx1PE8Y7QaR0XokpYBuH1epgfc1LlVwoQKLblgtNfR7VxDVbjqKVg== X-Received: by 2002:a7b:ce09:: with SMTP id m9mr9973387wmc.150.1618604044358; Fri, 16 Apr 2021 13:14:04 -0700 (PDT) Received: from [192.168.1.101] ([92.176.231.106]) by smtp.gmail.com with ESMTPSA id h2sm10519678wmc.24.2021.04.16.13.14.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Apr 2021 13:14:03 -0700 (PDT) Subject: Re: GRUB error: unknown filesystem on ia64 To: John Paul Adrian Glaubitz , The development of GNU GRUB Cc: Daniel Kiper , Peter Jones References: <20210326180133.z5qjvtwt7loxvuqt@tomti.i.net-space.pl> <20210326184315.awfdlparysi3hqii@tomti.i.net-space.pl> <5b041746-09e9-0557-9f2a-ac3b37837728@physik.fu-berlin.de> <8affe4f2-5e8d-1bd5-35e2-6ef108086009@redhat.com> <2b2d1558-ad3b-afe8-3e96-c150533ae59f@physik.fu-berlin.de> From: Javier Martinez Canillas Message-ID: <35141d37-a745-eaae-5c1d-d23ed2d3ae09@redhat.com> Date: Fri, 16 Apr 2021 22:14:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <2b2d1558-ad3b-afe8-3e96-c150533ae59f@physik.fu-berlin.de> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=fmartine@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=fmartine@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Apr 2021 20:14:12 -0000 On 4/16/21 6:55 PM, John Paul Adrian Glaubitz wrote: > Hi! > > On 4/16/21 6:43 PM, John Paul Adrian Glaubitz wrote: >> It seems the patch no longer applies due to the changes introduced by the --sbat >> option [1]. > > I have manually rebased the patch like this. Rebuilding GRUB with that change > fixes the problem for me. So you'll just have to rebase your patch and we should > be good to go. > Oh, sorry about that. I checked out the problematic commit and then forgot that was not in the latest HEAD. [snip] > - scn_size = pe_size - layout.reloc_size - sbat_size - raw_data; > + scn_size = ALIGN_UP (pe_size - layout.reloc_size - sbat_size - raw_data, GRUB_PE32_FILE_ALIGNMENT); > section = init_pe_section (image_target, section, "mods", > &vma, scn_size, image_target->section_align, > - &raw_data, scn_size, > + &raw_data, pe_size - layout.reloc_size - raw_data, I think this should to be: > + &raw_data, pe_size - layout.reloc_size - sbat_size - raw_data, but I've forward ported to current master branch now and also made the patch more clear. I've only tested on x64 so it would be great if can test it on ia64: >From 767fdee805ce4bdd19c23c15c1f29a314282eaaf Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Fri, 16 Apr 2021 21:37:23 +0200 Subject: [PATCH] util/mkimage: Some fixes to PE binaries section size calculation Commit f60ba9e5945 (util/mkimage: Refactor section setup to use a helper) added a helper function to setup PE sections, but it caused regressions in some arches where the natural alignment lead to wrong section sizes. This patch fixes a few things that were caused the section sizes to be calculated wrongly. These fixes are: * Only align the virtual memory addresses but not the raw data offsets. * Use aligned sizes for virtual memory sizes but not for raw data sizes. * Always align the sizes to set the virtual memory sizes. These seems to not cause problems for x64 and aa64 EFI platforms but was a problem for ia64. Because the size of the ".data" and "mods" sections were wrong and didn't have the correct content. Which lead to GRUB not being able to load any built-in module. Reported-by: John Paul Adrian Glaubitz Signed-off-by: Javier Martinez Canillas --- util/mkimage.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/util/mkimage.c b/util/mkimage.c index a26cf76f72f..b84311f1ffb 100644 --- a/util/mkimage.c +++ b/util/mkimage.c @@ -841,7 +841,7 @@ init_pe_section(const struct grub_install_image_target_desc *image_target, section->raw_data_offset = grub_host_to_target32 (*rda); section->raw_data_size = grub_host_to_target32 (rsz); - (*rda) = ALIGN_UP (*rda + rsz, GRUB_PE32_FILE_ALIGNMENT); + (*rda) = *rda + rsz; section->characteristics = grub_host_to_target32 (characteristics); @@ -1309,7 +1309,7 @@ grub_install_generate_image (const char *dir, const char *prefix, char *pe_img, *pe_sbat, *header; struct grub_pe32_section_table *section; size_t n_sections = 4; - size_t scn_size; + size_t scn_size, raw_size; grub_uint32_t vma, raw_data; size_t pe_size, header_size; struct grub_pe32_coff_header *c; @@ -1410,7 +1410,8 @@ grub_install_generate_image (const char *dir, const char *prefix, GRUB_PE32_SCN_MEM_EXECUTE | GRUB_PE32_SCN_MEM_READ); - scn_size = ALIGN_UP (layout.kernel_size - layout.exec_size, GRUB_PE32_FILE_ALIGNMENT); + raw_size = layout.kernel_size - layout.exec_size; + scn_size = ALIGN_UP (raw_size, GRUB_PE32_FILE_ALIGNMENT); /* ALIGN_UP (sbat_size, GRUB_PE32_FILE_ALIGNMENT) is done earlier. */ PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (scn_size + sbat_size + ALIGN_UP (total_module_size, @@ -1418,15 +1419,16 @@ grub_install_generate_image (const char *dir, const char *prefix, section = init_pe_section (image_target, section, ".data", &vma, scn_size, image_target->section_align, - &raw_data, scn_size, + &raw_data, raw_size, GRUB_PE32_SCN_CNT_INITIALIZED_DATA | GRUB_PE32_SCN_MEM_READ | GRUB_PE32_SCN_MEM_WRITE); - scn_size = pe_size - layout.reloc_size - sbat_size - raw_data; + raw_size = pe_size - layout.reloc_size - sbat_size - raw_data; + scn_size = ALIGN_UP (raw_size, GRUB_PE32_FILE_ALIGNMENT); section = init_pe_section (image_target, section, "mods", &vma, scn_size, image_target->section_align, - &raw_data, scn_size, + &raw_data, raw_size, GRUB_PE32_SCN_CNT_INITIALIZED_DATA | GRUB_PE32_SCN_MEM_READ | GRUB_PE32_SCN_MEM_WRITE); @@ -1436,21 +1438,22 @@ grub_install_generate_image (const char *dir, const char *prefix, pe_sbat = pe_img + raw_data; grub_util_load_image (sbat_path, pe_sbat); + scn_size = ALIGN_UP (sbat_size, GRUB_PE32_FILE_ALIGNMENT); section = init_pe_section (image_target, section, ".sbat", - &vma, sbat_size, + &vma, scn_size, image_target->section_align, &raw_data, sbat_size, GRUB_PE32_SCN_CNT_INITIALIZED_DATA | GRUB_PE32_SCN_MEM_READ); } - scn_size = layout.reloc_size; + scn_size = ALIGN_UP (layout.reloc_size, GRUB_PE32_FILE_ALIGNMENT); PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (vma); PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (scn_size); memcpy (pe_img + raw_data, layout.reloc_section, scn_size); init_pe_section (image_target, section, ".reloc", &vma, scn_size, image_target->section_align, - &raw_data, scn_size, + &raw_data, layout.reloc_size, GRUB_PE32_SCN_CNT_INITIALIZED_DATA | GRUB_PE32_SCN_MEM_DISCARDABLE | GRUB_PE32_SCN_MEM_READ); -- 2.30.2