Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nhPJd-0005vj-9B for mharc-grub-devel@gnu.org; Thu, 21 Apr 2022 01:25:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhPJa-0005lQ-1X for grub-devel@gnu.org; Thu, 21 Apr 2022 01:25:14 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:38762) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhPJY-0005h3-Bx for grub-devel@gnu.org; Thu, 21 Apr 2022 01:25:13 -0400 Received: by mail-pj1-x1032.google.com with SMTP id s14-20020a17090a880e00b001caaf6d3dd1so6784255pjn.3 for ; Wed, 20 Apr 2022 22:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=znFADXRanjb663aM2cv3g9QlTik8vHTS5UQcj1HRMuM=; b=H6S+0Dno/5lWoWqIhloM16DHk8PDx5SEZMeauEVjr6GVtSDH/OcPMXH1fVDcYI2icl vHvmUzu65KcohReL1IFkRm/f0FXjTWBg4K05bdOWUOMuaE3uLp360xTdKGuKLOWMwfts DST3Y8k/Ilt/SOhEM2C4e1gAvGIazr+H4aWdw= 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:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=znFADXRanjb663aM2cv3g9QlTik8vHTS5UQcj1HRMuM=; b=liMixsphk0/ijjUexcl8/NRjhJqEohZRlhyHsYltfZyGQyrhQ1gLZ9ehlABfh5EOwR Z02CnvGHFF+ENzByRUyh9dDxadlkibHoB0gC/tkIH8tk/BhLGzl/r58IXnzzRLmBYH3j XxUYeOw1Gi6HLgO7wrp2BunGXIn0JwA2GzyV6Q57uzCRH3dgA8gNLgrereaiDPEVtzma sO9SYsEX+6dWgcGLR736UHmMELBbfBCIHrOUMGyx6TO9KC7OObkzUE3yhb4ea497KJb8 plSF0xQoI7MBeYtwKM0WpJRMpCfmM27EkGw2Mw3MyaS0ZEvf9PAUed2A+zKsOALpzPdM dbog== X-Gm-Message-State: AOAM533JCLYp/3Etj/cxdBhPFOaMVnEmQWaQ4dESF6MjF0hrseHLu9Qy UNyjiscDbvMawxIh/60Y4sdoS9i1rcnYrg== X-Google-Smtp-Source: ABdhPJx+tPGWvFokdJkFsW0OBufVcncEfCyDYqTd0Ua/EptaJ2H7dye/6lWInaZ5sjiEu2quUZQHNQ== X-Received: by 2002:a17:90b:33cc:b0:1ce:a3fe:af41 with SMTP id lk12-20020a17090b33cc00b001cea3feaf41mr8434607pjb.229.1650518710896; Wed, 20 Apr 2022 22:25:10 -0700 (PDT) Received: from localhost ([2001:4479:e000:e400:4260:be14:52a8:8c94]) by smtp.gmail.com with ESMTPSA id k6-20020a17090ac50600b001cd4c118b07sm1023707pjt.16.2022.04.20.22.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 22:25:10 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: leif@nuviainc.com, stefanb@linux.ibm.com, ps@pks.im, dkiper@net-space.pl, Daniel Axtens , Daniel Kiper Subject: [PATCH v3 10/15] efi: mm: Implement runtime addition of pages Date: Thu, 21 Apr 2022 15:24:22 +1000 Message-Id: <20220421052427.1389987-11-dja@axtens.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220421052427.1389987-1-dja@axtens.net> References: <20220421052427.1389987-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=dja@axtens.net; helo=mail-pj1-x1032.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, RCVD_IN_DNSWL_NONE=-0.0001, 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: Thu, 21 Apr 2022 05:25:14 -0000 From: Patrick Steinhardt Adjust the interface of `grub_efi_mm_add_regions ()` to take a set of `GRUB_MM_ADD_REGION_*` flags, which most notably is currently only the `CONSECUTVE` flag. This allows us to set the function up as callback for the memory subsystem and have it call out to us in case there's not enough pages available in the current heap. Signed-off-by: Patrick Steinhardt Signed-off-by: Daniel Axtens Reviewed-by: Daniel Kiper --- grub-core/kern/efi/mm.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 4e594659a1ff..b5160bdffc67 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -482,7 +482,8 @@ 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, - grub_efi_uint64_t required_pages) + grub_efi_uint64_t required_pages, + unsigned int flags) { grub_efi_memory_descriptor_t *desc; @@ -496,6 +497,10 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, start = desc->physical_start; pages = desc->num_pages; + + if (pages < required_pages && (flags & GRUB_MM_ADD_REGION_CONSECUTIVE)) + continue; + if (pages > required_pages) { start += PAGES_TO_BYTES (pages - required_pages); @@ -561,7 +566,7 @@ print_memory_map (grub_efi_memory_descriptor_t *memory_map, #endif static grub_err_t -grub_efi_mm_add_regions (grub_efi_uint64_t required_bytes) +grub_efi_mm_add_regions (grub_efi_uint64_t required_bytes, unsigned int flags) { grub_efi_memory_descriptor_t *memory_map; grub_efi_memory_descriptor_t *memory_map_end; @@ -616,7 +621,8 @@ grub_efi_mm_add_regions (grub_efi_uint64_t required_bytes) /* 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), + flags); if (err != GRUB_ERR_NONE) return err; @@ -643,8 +649,9 @@ grub_efi_mm_add_regions (grub_efi_uint64_t required_bytes) void grub_efi_mm_init (void) { - if (grub_efi_mm_add_regions (DEFAULT_HEAP_SIZE) != GRUB_ERR_NONE) + if (grub_efi_mm_add_regions (DEFAULT_HEAP_SIZE, GRUB_MM_ADD_REGION_NONE) != GRUB_ERR_NONE) grub_fatal ("%s", grub_errmsg); + grub_mm_add_region_fn = grub_efi_mm_add_regions; } #if defined (__aarch64__) || defined (__arm__) || defined (__riscv) -- 2.32.0