Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nXafG-0004kA-Jv for mharc-grub-devel@gnu.org; Thu, 24 Mar 2022 23:31:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXafF-0004fG-6T for grub-devel@gnu.org; Thu, 24 Mar 2022 23:31:01 -0400 Received: from [2607:f8b0:4864:20::62f] (port=37433 helo=mail-pl1-x62f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nXafD-0003p2-EH for grub-devel@gnu.org; Thu, 24 Mar 2022 23:31:00 -0400 Received: by mail-pl1-x62f.google.com with SMTP id e5so6789767pls.4 for ; Thu, 24 Mar 2022 20:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=1wFKNCJjUO9gDTm5QAMNdKI9v/FMqzGxEpBicqsi2aw=; b=L5/ga0b/Shgt58imZ2P18z2gObp2VHzpkUlLrllpJa5NOLLFPELUPZNh5FzLyTHUND 7e0lAQEg6YbN68y6d5pwpJWhG7Ut6d6ms6nTHkCz5exfL7/rwrDzTWJBnuJEYk3Gt9fu jVQd9q4VkEhFxGZ5de9BndIwt1TbgByGXwU1k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=1wFKNCJjUO9gDTm5QAMNdKI9v/FMqzGxEpBicqsi2aw=; b=v4LcEPy7MARmeWU6hnWHa3AM/jJeJq7snHwQJYsc1qv4/xWgIq7wuS5VLkfwLJ2bJr gb64yrTEAtUVQOgY2VP0k20M/UgAHyUMt9M/7SlT1I7I7guk9vt4c6Lff/ZC2QHGmbQd GEXo4w6KB1j0m8tKEPrniHuaWX57Or/85hltk1gfTRFBSVCXwW50d0VZkZdgGku5Q/5v EsrCBD3L2jDRL4+h97B4pb5bQfLKfdY31Ro6uaIAU3vRVuYKpNJ/19vxpBofYieHAYK0 tkgfbLuS6gjrFB6FW9v/8niAz/y9kCg+lUSFNA8b1utM4H1qmSxNsjoghUwyE+McnFgu TwTA== X-Gm-Message-State: AOAM531IjIpC7lxc4x3aQsI/6Nd7YHfyoIWyuInDD12OOYWectvx/I6w nqnL5z1UM7LbVZNAFwNy4qXA3A== X-Google-Smtp-Source: ABdhPJwuFp4V1DaBZzgnS5K/NLHrKdkMEStF3FWqLD0DqkC3vPlI+V/RcvVzpYal07MBROWZ49AF8A== X-Received: by 2002:a17:902:b582:b0:14c:a63d:3df6 with SMTP id a2-20020a170902b58200b0014ca63d3df6mr9457401pls.51.1648179057527; Thu, 24 Mar 2022 20:30:57 -0700 (PDT) Received: from localhost ([2001:4479:e000:e400:bc3f:1106:8bd7:f114]) by smtp.gmail.com with ESMTPSA id x2-20020a63aa42000000b0038265eb2495sm3763307pgo.88.2022.03.24.20.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 20:30:56 -0700 (PDT) From: Daniel Axtens To: development@efficientek.com Cc: The development of GNU GRUB , leif@nuviainc.com, stefanb@linux.ibm.com, ps@pks.im, dkiper@net-space.pl Subject: Re: [PATCH 11/19] efi: mm: Extract function to add memory regions In-Reply-To: <20211019165820.10a21feb@crass-HP-ZBook-15-G2> References: <20211012073008.4059133-1-dja@axtens.net> <20211012073008.4059133-12-dja@axtens.net> <20211019165820.10a21feb@crass-HP-ZBook-15-G2> Date: Fri, 25 Mar 2022 14:30:54 +1100 Message-ID: <87mthe909d.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::62f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=dja@axtens.net; helo=mail-pl1-x62f.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: Fri, 25 Mar 2022 03:31:01 -0000 >> /* Prepare a memory region to store two memory maps. */ >> memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); >> if (! memory_map) >> - grub_fatal ("cannot allocate memory"); >> + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); > > Something more descriptive would be nice, may be even "cannot allocate > memory for memory map" Yes. >> >> /* Obtain descriptors for available memory. */ >> map_size = MEMORY_MAP_SIZE; >> @@ -588,14 +588,14 @@ grub_efi_mm_init (void) >> >> memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (map_size)); >> if (! memory_map) >> - grub_fatal ("cannot allocate memory"); >> + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); > > Ditto. And maybe nice to have it slightly different, perhaps "cannot > re-allocate memory map" Yes. >> >> mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0, >> &desc_size, 0); >> } >> >> if (mm_status < 0) >> - grub_fatal ("cannot get memory map"); >> + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot get memory map"); > > What are the range of values that mm_status could be? Would it be > useful to include the status code in the error message? IOW, could a > failure here be affected by a configuration that the user could change > to make this work? Also I like the message "failed to retrieve memory > map (status=%d)". > The function says: /* Get the memory map as defined in the EFI spec. Return 1 if successful, return 0 if partial, or return -1 if an error occurs. */ So no, I don't think we could print anything more interesting without reworking the grub_efi_get_memory_map function. >> >> memory_map_end = NEXT_MEMORY_DESCRIPTOR (memory_map, map_size); >> >> @@ -610,7 +610,7 @@ grub_efi_mm_init (void) >> >> /* Allocate memory regions for GRUB's memory management. */ >> add_memory_regions (filtered_memory_map, desc_size, >> - filtered_memory_map_end, BYTES_TO_PAGES (DEFAULT_HEAP_SIZE)); >> + filtered_memory_map_end, BYTES_TO_PAGES (required_bytes)); >> >> #if 0 >> /* For debug. */ > > What about turning this on when MM_DEBUG is on? Seems like it could be > a useful (would been to get rid of/change the grub_fatal calls). > Perhaps, but I'm not sufficiently across EFI to be confident making that sort of change, and I'm not well set up to test EFI systems or evaluate the correctness or usefulness of any output. I think this would be better deferred to another patch from someone with more experience in the field. Kind regards, Daniel