Revert patches to claim more memory for the arena

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
This commit is contained in:
Robbie Harwood 2022-09-07 23:51:40 +00:00
parent 2fa153d5c6
commit db229abffb
14 changed files with 14 additions and 120 deletions

View file

@ -1,73 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 29 Jul 2022 15:57:57 -0400
Subject: [PATCH] efi: make the default arena most of ram
Currently when populating the initial memory arena on EFI systems, we
count the available regions below GRUB_EFI_MAX_ALLOCATION_ADDRESS from
the EFI memory map and then allocates one quarter of that for our arena.
Because many systems come up without IOMMUs, we currently set
GRUB_EFI_MAX_ALLOCATION_ADDRESS to 0x7fffffff, i.e. all addresses
allocated must be below 2G[0]. Due to firmware and other
considerations, this makes the most memory we can possibly have in our
arena 512M.
Because our EFI loader doesn't get kernel and initrd memory from grub's
allocator, but rather reserves it directly from UEFI and then simply
marks those as allocated if they're within grub's arena, it was
historically possible to have initrds that are larger than 512M, because
we could use any memory region below 4G, without concern for grub's
choice of arena size.
Unfortunately, when we switched to using the "verifiers" API (and thus
the file_filter_t API) to do measurement of kernel and initrd, this
introduced a pattern that allocates the entire file when we call
grub_file_open(), and buffers it to pass to the filter. This results in
needing to have enough space for the initramfs in the grub arena.
This is bad.
Since it's unlikely you're going to do anything *other* than loading a
kernel and initramfs that takes much of the available free memory from
UEFI, this patch introduces a workaround by changing the amount we give
to the arena be three quarters of the available memory, rather than one
quarter, thus changing our theoretical initrd limit to 1.5G. In
practice, it may still be smaller than that depending on allocation
fragmentation, but generally it will be most of it.
Note that this doesn't fix the underlying flaw, which is that there is
no safe way to do the validation correctly using the "verifiers" system
with the current file API without buffering the whole file before
grub_file_read() is ever called, and thus you can't set an allocation
policy for the initial buffer of the file at all, so unless we raise the
allocation limit to >4G, it can't be allocated in the big region.
[0] I'm not sure there was a good reason not to pick 4G, but even if we
had, at least one common firmware routes the first 2G of physical
RAM to 0x0, and any additional memory starting at 0x100000000.
Related: rhbz#2112134
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/kern/efi/mm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index e460b072e6..150e412ee7 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -737,10 +737,10 @@ grub_efi_mm_init (void)
filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map,
desc_size, memory_map_end);
- /* By default, request a quarter of the available memory. */
+ /* By default, request three quarters of the available memory. */
total_pages = get_total_pages (filtered_memory_map, desc_size,
filtered_memory_map_end);
- required_pages = (total_pages >> 2);
+ required_pages = (total_pages >> 1) + (total_pages >> 2);
if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE))
required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE);
else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))

View file

@ -1,34 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 8 Aug 2022 11:23:59 -0400
Subject: [PATCH] Try reserving less ram...
In 005a0aaaad2a00a1fa1e60d94cc4fd5407c22e7d, we switched from reserving
one quarter of the available free memory to three quarters. Apparently
this has some unfortunate side-affects for some workloads, and has
negatively effected chainloading[0] as well as Fedora CoreOS[1].
This patch changes it to reserve /half/ of available memory, in hopes
that this is a working compromise.
[0] https://bugzilla.redhat.com/show_bug.cgi?id=2115202
[1] https://github.com/coreos/fedora-coreos-tracker/issues/1271
Signed-off-by: Peter Jones <pjones@redhat.com>
---
grub-core/kern/efi/mm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 150e412ee7..b4e012f5e7 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -740,7 +740,7 @@ grub_efi_mm_init (void)
/* By default, request three quarters of the available memory. */
total_pages = get_total_pages (filtered_memory_map, desc_size,
filtered_memory_map_end);
- required_pages = (total_pages >> 1) + (total_pages >> 2);
+ required_pages = (total_pages >> 1);
if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE))
required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE);
else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))

View file

@ -268,15 +268,13 @@ Patch0267: 0267-grub-probe-document-the-behavior-of-multiple-v.patch
Patch0268: 0268-grub_fs_probe-dprint-errors-from-filesystems.patch
Patch0269: 0269-fs-fat-don-t-error-when-mtime-is-0.patch
Patch0270: 0270-Make-debug-file-show-which-file-filters-get-run.patch
Patch0271: 0271-efi-make-the-default-arena-most-of-ram.patch
Patch0272: 0272-efi-use-enumerated-array-positions-for-our-allocatio.patch
Patch0273: 0273-efi-split-allocation-policy-for-kernel-vs-initrd-mem.patch
Patch0274: 0274-efi-allocate-the-initrd-within-the-bounds-expressed-.patch
Patch0275: 0275-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch
Patch0276: 0276-BLS-create-etc-kernel-cmdline-during-mkconfig.patch
Patch0277: 0277-Try-reserving-less-ram.patch
Patch0278: 0278-squish-don-t-dup-rhgb-quiet-check-mtimes.patch
Patch0279: 0279-squish-give-up-on-rhgb-quiet.patch
Patch0280: 0280-squish-BLS-only-write-etc-kernel-cmdline-if-writable.patch
Patch0281: 0281-ieee1275-implement-vec5-for-cas-negotiation.patch
Patch0282: 0282-blscfg-Don-t-root-device-in-emu-builds.patch
Patch0271: 0271-efi-use-enumerated-array-positions-for-our-allocatio.patch
Patch0272: 0272-efi-split-allocation-policy-for-kernel-vs-initrd-mem.patch
Patch0273: 0273-efi-allocate-the-initrd-within-the-bounds-expressed-.patch
Patch0274: 0274-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch
Patch0275: 0275-BLS-create-etc-kernel-cmdline-during-mkconfig.patch
Patch0276: 0276-squish-don-t-dup-rhgb-quiet-check-mtimes.patch
Patch0277: 0277-squish-give-up-on-rhgb-quiet.patch
Patch0278: 0278-squish-BLS-only-write-etc-kernel-cmdline-if-writable.patch
Patch0279: 0279-ieee1275-implement-vec5-for-cas-negotiation.patch
Patch0280: 0280-blscfg-Don-t-root-device-in-emu-builds.patch

View file

@ -17,7 +17,7 @@
Name: grub2
Epoch: 1
Version: 2.06
Release: 55%{?dist}
Release: 56%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more
License: GPLv3+
URL: http://www.gnu.org/software/grub/
@ -530,6 +530,9 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
%endif
%changelog
* Wed Sep 07 2022 Robbie Harwood <rharwood@redhat.com> - 2.06-56
- Revert patches to claim more memory for the arena
* Thu Aug 25 2022 Robbie Harwood <rharwood@redhat.com> - 2.06-55
- Fix root definition for blscfg in emu