From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mkThN-0000hJ-W7 for mharc-grub-devel@gnu.org; Tue, 09 Nov 2021 11:10:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkThM-0000h9-Pn for grub-devel@gnu.org; Tue, 09 Nov 2021 11:10:12 -0500 Received: from dibed.net-space.pl ([84.10.22.86]:47958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:192) (Exim 4.90_1) (envelope-from ) id 1mkThL-0007NS-0c for grub-devel@gnu.org; Tue, 09 Nov 2021 11:10:12 -0500 Received: from router-fw.i.net-space.pl ([192.168.52.1]:41376 "EHLO tomti.i.net-space.pl") by router-fw-old.i.net-space.pl with ESMTP id S2093858AbhKIQKG (ORCPT ); Tue, 9 Nov 2021 17:10:06 +0100 X-Comment: RFC 2476 MSA function at dibed.net-space.pl logged sender identity as: dkiper Date: Tue, 9 Nov 2021 17:10:02 +0100 From: Daniel Kiper To: Daniel Axtens Cc: grub-devel@gnu.org, leif@nuviainc.com, stefanb@linux.ibm.com, ps@pks.im Subject: Re: [PATCH 12/19] efi: mm: Pass up errors from `add_memory_regions ()` Message-ID: <20211109161002.ezettxbescsnvybd@tomti.i.net-space.pl> References: <20211012073008.4059133-1-dja@axtens.net> <20211012073008.4059133-13-dja@axtens.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211012073008.4059133-13-dja@axtens.net> User-Agent: NeoMutt/20170113 (1.7.2) Received-SPF: pass client-ip=84.10.22.86; envelope-from=dkiper@net-space.pl; helo=dibed.net-space.pl X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 16:10:13 -0000 On Tue, Oct 12, 2021 at 06:30:01PM +1100, Daniel Axtens wrote: > From: Patrick Steinhardt > > The function `add_memory_regions ()` is currently only called on system > initialization to allocate a fixed amount of pages. As such, it didn't > need to return any errors: in case it failed, we cannot proceed anyway. > This will change with the upcoming support for requesting more memory > from the firmware at runtime, where it doesn't make sense anymore to > fail hard. > > Refactor the function to return an error to prepare for this. Note that > this does not change the behaviour when initializing the memory system > because `grub_efi_mm_init ()` knows to call `grub_fatal ()` in case > `grub_efi_mm_add_regions ()` returns an error. > > Signed-off-by: Patrick Steinhardt > --- > grub-core/kern/efi/mm.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c > index cfc6a67fc0cc..ced3ee5e7537 100644 > --- a/grub-core/kern/efi/mm.c > +++ b/grub-core/kern/efi/mm.c > @@ -478,7 +478,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, > } > > /* Add memory regions. */ > -static void > +static grub_err_t > add_memory_regions (grub_efi_memory_descriptor_t *memory_map, > grub_efi_uintn_t desc_size, > grub_efi_memory_descriptor_t *memory_map_end, > @@ -506,9 +506,9 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, > GRUB_EFI_ALLOCATE_ADDRESS, > GRUB_EFI_LOADER_CODE); > if (! addr) > - grub_fatal ("cannot allocate conventional memory %p with %u pages", > - (void *) ((grub_addr_t) start), > - (unsigned) pages); > + return grub_error (GRUB_ERR_OUT_OF_MEMORY, > + "cannot allocate conventional memory %p with %u pages", > + (void *) ((grub_addr_t) start), (unsigned) pages); > > grub_mm_init_region (addr, PAGES_TO_BYTES (pages)); > > @@ -518,7 +518,9 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, > } > > if (required_pages > 0) > - grub_fatal ("too little memory"); > + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "too little memory"); I agree with Glenn. The message is a bit imprecise here. Maybe we should make more clear that the UEFI allocation somehow failed. I think I would improve message above too. Daniel