From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1maCFy-0007T0-8E for mharc-grub-devel@gnu.org; Tue, 12 Oct 2021 03:31:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maCFh-0007Ih-NL for grub-devel@gnu.org; Tue, 12 Oct 2021 03:31:13 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:39584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maCFg-0006lw-5Y for grub-devel@gnu.org; Tue, 12 Oct 2021 03:31:09 -0400 Received: by mail-pj1-x1035.google.com with SMTP id ls18-20020a17090b351200b001a00250584aso1233535pjb.4 for ; Tue, 12 Oct 2021 00:31:07 -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=4YpAAEua0IQ85euitbSuMWUoVuDUrBiLEeiBlva//58=; b=nPwWuHAAh5zUUy3mnUbjD9K05rAzhZPGSxWD7L1+o1ux6WCCETIWpzeJnfz6hWQ4o8 1H2oY0fWz5a2fPYu/Ew0POME+CK5RSmrh2Gc+XkActQMyBfpT8aIQcFQugGGnTAljXFf 8fTO0WAuUF2nZWljieK6zXc9Y7jgoCuOa3Uro= 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=4YpAAEua0IQ85euitbSuMWUoVuDUrBiLEeiBlva//58=; b=YhCyIVIEqcWVAkPJK5cAhd+ByZlkr+zHmArps4tRtuACqsnDo6+1nV9mbTj+LiX3b6 dWsVyCU26BCwMJE4w+YH4o5CV3s4g2+rS/rw8UH1plp8kaJ+cP/grk8kRpO5XvPwSlyB wQknRmxZl5fJ0bpxlLhF23xy6+k05a697TQWzp3fXyEeg6+hiFA+ApDdZohAGoprSybA /XLQyAXKq6TJzfVJybxpEEDOQ++WvuCzdepCuH+OJ7Cb17QFIwIjGH02tcl2Ak4s1+63 fQJbLz0Y8nbH+SkYx8zD7wC0XAWta3ra/1ka2qfigKGk/XCXFGCcFzQxJcBmDXcGkqSH 7VZg== X-Gm-Message-State: AOAM530m8+kKGzfC7C1DNbw1vSvaCylqbEXu4yYvYO9ohkUjOlysAyTH G5dwwZieS01K1SJD7L4Q1n3i42P1t129wQ== X-Google-Smtp-Source: ABdhPJwaWVxKPx3vsTVdrUbfiQ0XkAZbR+iU5Hy+GTl4Ngq5NHD3JfKFmLmY8eSA3mhjs4VufqtG1Q== X-Received: by 2002:a17:90a:fb4a:: with SMTP id iq10mr4127470pjb.117.1634023866226; Tue, 12 Oct 2021 00:31:06 -0700 (PDT) Received: from localhost ([2001:4479:e300:600:41fe:d15:934f:4029]) by smtp.gmail.com with ESMTPSA id c25sm9822522pfn.159.2021.10.12.00.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 00:31:05 -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 Subject: [PATCH 13/19] efi: mm: Implement runtime addition of pages Date: Tue, 12 Oct 2021 18:30:02 +1100 Message-Id: <20211012073008.4059133-14-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211012073008.4059133-1-dja@axtens.net> References: <20211012073008.4059133-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=dja@axtens.net; helo=mail-pj1-x1035.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 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: Tue, 12 Oct 2021 07:31: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 --- 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 ced3ee5e7537..f3d2e2b99830 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); @@ -559,7 +564,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; @@ -614,7 +619,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; @@ -641,8 +647,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.30.2