Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oQA2y-0000zW-A1 for mharc-grub-devel@gnu.org; Mon, 22 Aug 2022 12:13:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQA2w-0000wa-3L for grub-devel@gnu.org; Mon, 22 Aug 2022 12:13:02 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:45640) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQA2n-0000CU-LB for grub-devel@gnu.org; Mon, 22 Aug 2022 12:13:00 -0400 Received: by mail-pg1-x534.google.com with SMTP id f4so7956599pgc.12 for ; Mon, 22 Aug 2022 09:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :from:to:cc; bh=mO29/kZFXzJciyKODvsC9eVTC7ti3b2Ask2Rx8CWse0=; b=DJOw237Tk9R3CpHLR5oclMyRQTynnvV1lM0ilo93hoLS6ZBSsDV3lf3XVdNnOTAadr ow8BAKy7lgVeC0Bei0keplf0hY+aC30puMh9dcZUtg0MlIohBR/JAvloGAMr5LseRgBV CG9jinWhrHeRz1t2aII1ZVJ2BZjIgZSY487ms= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc; bh=mO29/kZFXzJciyKODvsC9eVTC7ti3b2Ask2Rx8CWse0=; b=4KHUdw3dtY09vT/NaDmiH85dVyW6CerX+THL9nsqv6xBDlob+Z/XCibRWbSvPc0IRQ 76yeqN1TaNAWIkyq5N0C8jeVzWTckYsM7x2L3I4jSyv84tJ1/tE8ieyhFnehBRqGUEXI Hrcwh4iCDF45CY9o4+/6H6yaZMB+XTwv7hr+Y651Q1uZ1sIkd1DeZ3w5YmvFPyoRSTWH s5IdjT7CA8UK7AAnd5MlzEMaLOz/iX9v3yqzRnNXeqlQn23xo7bJCJP3rJpGQeOkgQub 6JXytI3ASpDajJpWXt4nH6UnjvnqwaUoIBYIc0ikKQrRqQxh+j814yrSWVtuxil97TIt APCQ== X-Gm-Message-State: ACgBeo0rwOjz6Ru9Mnhe52SH2tm8YsnD121GyLDFzP1dktci6xLYaHiv 5FUtjy/lJPr24Y+2ikQYR7oK5Q== X-Google-Smtp-Source: AA6agR4tlaKhIOhR2PmVrVNeXgFMnb0VtzEFT4K+McEYWBG3Nae4GsE356D4+VZf1B6erZNzC+M/gg== X-Received: by 2002:a63:2bcc:0:b0:40c:95b5:46a4 with SMTP id r195-20020a632bcc000000b0040c95b546a4mr17463065pgr.535.1661184769234; Mon, 22 Aug 2022 09:12:49 -0700 (PDT) Received: from localhost ([2001:4479:e300:5b00:acde:3bd9:ec2b:7e5e]) by smtp.gmail.com with ESMTPSA id s24-20020a639258000000b0042a3d9a1275sm5700661pgn.16.2022.08.22.09.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 09:12:48 -0700 (PDT) From: Daniel Axtens To: Hector Martin , grub-devel@gnu.org, Patrick Steinhardt Subject: Re: [PATCH] kern/efi/mm: Double the default heap size In-Reply-To: References: <20220820152412.158952-1-marcan@marcan.st> <87mtbxojuk.fsf@dja-thinkpad.axtens.net> Date: Tue, 23 Aug 2022 02:12:44 +1000 Message-ID: <874jy4uuir.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=dja@axtens.net; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: Mon, 22 Aug 2022 16:13:02 -0000 Hector Martin writes: > On 21/08/2022 21.35, Daniel Axtens wrote: >> Hi Hector, >> >> Thanks for your patch and for taking the trouble to put it together. >> >>> GRUB is already running out of memory on Apple M1 systems, causing >>> graphics init to fail, as of the latest Git changes. Since dynamic >>> growing of the heap isn't done yet, double the default heap size for >>> now. >> >> Huh, weird - those changes have landed in git, see commit 887f98f0db43 >> ("mm: Allow dynamically requesting additional memory regions") for the >> overarching support and commit 1df2934822df ("kern/efi/mm: Implement >> runtime addition of pages"). It's not done on PowerPC, but if you're in >> EFI-land then it should complete. >> >> The only reason I can think of off the top of my head where you would be >> having issues that your patch fixes is if we somehow need more memory to >> even get to the point where we can ask firmware for more memory. I >> suppose that's within the realm of possibility. > > Interesting. I missed the indirection through the function pointer... > but either way, I do indeed have those commits in the broken tree that > Arch Linux ARM started shipping yesterday (0c6c1aff2a, which isn't > actually current master but it's from a couple weeks ago). The previous > version was 2f4430cc0, which doesn't have it, so I wonder if there was > actually a regression involved? Hmm. So I wonder if you're hitting an edge case which I tried to fix for powerpc but apparently didn't fix for EFI (or, on reflection, in the generic code where I should have tried to fix it). If you look at kern/mm.c, we request `size` bytes from firmware: case 1: /* Request additional pages, contiguous */ count++; if (grub_mm_add_region_fn != NULL && grub_mm_add_region_fn (size, GRUB_MM_ADD_REGION_CONSECUTIVE) == GRUB_ERR_NONE) goto again; but the problem is that we need some of those `size` bytes for grub mm metadata. (We also don't respect `align`, eek.) The mm code doesn't account for this (which it should, my bad) and the EFI code doesn't seem to account for this either: (kern/efi/mm.c::grub_efi_mm_add_regions, which is the function exposed as grub_mm_add_region_fn). /* Allocate memory regions for GRUB's memory management. */ err = add_memory_regions (filtered_memory_map, desc_size, filtered_memory_map_end, BYTES_TO_PAGES (required_bytes), flags); Would you be able to try doing something like this instead? modified grub-core/kern/efi/mm.c @@ -621,7 +621,7 @@ grub_efi_mm_add_regions (grub_size_t required_bytes, unsigned int flags) /* Allocate memory regions for GRUB's memory management. */ err = add_memory_regions (filtered_memory_map, desc_size, filtered_memory_map_end, - BYTES_TO_PAGES (required_bytes), + BYTES_TO_PAGES (required_bytes) + 1, flags); if (err != GRUB_ERR_NONE) return err; > What I see is that GRUB briefly flashes an out of memory error and fails > to set the graphics mode, then ends up in text mode. My best guess > without digging further is that it fails to allocate a framebuffer or > console text buffer (since these machines have higher resolution screens > than most, this might not have come up elsewhere). But I don't see why > that would have to happen before it's allowed? > Yeah that doesn't make much sense to me either. Being a high dpi screen might make it more likely to line up with a page size, thus hitting the edge case where we don't allocate metadata space? That is one hypothesis. Another would be whether the EFI implementation uses the page size grub expects (which is 0x1000 - ISTR you're using 16k pages in the kernel?) But I figure things would probably have broken in more interesting ways if that was wrong... >> I f my maths are right, this bumps up the initial allocation from 1M to >> 2M. > > Correct. > >> I think your experience tends to disprove the hypothesis that we >> could get away with a very small initial allocation (which was the >> thinking when the initial dynamic allocation patch set went in), so I'm >> wondering if we should take this opportunity to allocate 16M or 32M or >> something. My powerpc proposal kept the initial allocation at 32MB, I >> think that's probably sane for EFI too? > > I think that makes sense. (I still think this is worth doing even if it turns out that you just got unlucky and hit the edge case.) Kind regards, Daniel