diff --git a/grub.patches b/grub.patches index 4603e76fdf27b1f43442e7282c7112c9463b04a3..425afc9f1fd0b0252251b9ea22769a2efcbec2d3 100644 --- a/grub.patches +++ b/grub.patches @@ -288,4 +288,5 @@ Patch0288: backport-font-Assign-null_font-to-glyphs-in-ascii_font_glyph.patch Patch0289: backport-normal-charset-Fix-an-integer-overflow-in-grub_unico.patch %ifarch loongarch64 Patch0290: port-Add-LoongArch-support.patch +Patch0291: loongarch-Adjust-initrd-load-location.patch %endif diff --git a/grub2.spec b/grub2.spec index 53bcd9e67a2c53b3fadf660cff2b827fb51f7d75..4845f04b28c2704ed2a4b7208f8d4683795c0939 100644 --- a/grub2.spec +++ b/grub2.spec @@ -14,7 +14,7 @@ Name: grub2 Epoch: 1 Version: 2.06 -Release: 18 +Release: 19 Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -439,6 +439,12 @@ fi %{_datadir}/man/man* %changelog +* Thu Feb 2 2023 mengyingkun - 1:2.06-19 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:loongarch adjust initrd load location + * Tue Jan 10 2023 mengyingkun - 1:2.06-18 - Type:bugfix - CVE:NA diff --git a/loongarch-Adjust-initrd-load-location.patch b/loongarch-Adjust-initrd-load-location.patch new file mode 100644 index 0000000000000000000000000000000000000000..97495b8659957b57d37d0a9bf924dbae154d367a --- /dev/null +++ b/loongarch-Adjust-initrd-load-location.patch @@ -0,0 +1,81 @@ +From 96279e83f8bc6c9b842653e66cd35ac6f8df5053 Mon Sep 17 00:00:00 2001 +From: mengyingkun +Date: Thu, 2 Feb 2023 20:32:17 +0800 +Subject: [PATCH] loongarch: Adjust initrd load location + +Try to allocate memory from higher than 256MB to +avoid kernel relocation overlaying initrd. If failed, +allocate memory in range 0~256MB, and high address +takes precedence. + +Signed-off-by: mengyingkun +--- + grub-core/loader/loongarch64/linux-elf.c | 21 +++++++++++++++++++++ + grub-core/loader/loongarch64/linux.c | 2 +- + include/grub/loongarch64/linux.h | 5 +++++ + 3 files changed, 27 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/loongarch64/linux-elf.c b/grub-core/loader/loongarch64/linux-elf.c +index 85585b4..8260e4c 100644 +--- a/grub-core/loader/loongarch64/linux-elf.c ++++ b/grub-core/loader/loongarch64/linux-elf.c +@@ -304,6 +304,27 @@ grub_linux_loongarch_alloc_virtual_mem_align (grub_size_t size, + return get_virtual_current_address (ch); + } + ++void* ++grub_linux_loongarch_alloc_initrd_mem_align (grub_size_t size, ++ grub_size_t align, ++ grub_err_t *err) ++{ ++ grub_relocator_chunk_t ch; ++ ++ /* Firstly try to allocate from memory higher than 256MB */ ++ *err = grub_relocator_alloc_chunk_align (relocator, &ch, ++ 0x10000000, (0xffffffff - size) + 1, size, align, ++ GRUB_RELOCATOR_PREFERENCE_LOW, 0); ++ if (*err != GRUB_ERR_NONE) ++ { ++ /* Failed, try to allocate in range 0 ~ 256MB */ ++ *err = grub_relocator_alloc_chunk_align (relocator, &ch, ++ 0, (0xfffffff - size) + 1, size, align, ++ GRUB_RELOCATOR_PREFERENCE_HIGH, 0); ++ } ++ return get_virtual_current_address (ch); ++} ++ + int + grub_linux_loongarch_elf_get_boot_params (struct boot_params_interface **boot_params) + { +diff --git a/grub-core/loader/loongarch64/linux.c b/grub-core/loader/loongarch64/linux.c +index 783054b..4c02194 100644 +--- a/grub-core/loader/loongarch64/linux.c ++++ b/grub-core/loader/loongarch64/linux.c +@@ -351,7 +351,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + initrd_mem = allocate_initrd_mem (initrd_pages); + } else { + grub_err_t err; +- initrd_mem = grub_linux_loongarch_alloc_virtual_mem_align (initrd_size, 0x10000, &err); ++ initrd_mem = grub_linux_loongarch_alloc_initrd_mem_align (initrd_size, 0x10000, &err); + if (err) + goto fail; + } +diff --git a/include/grub/loongarch64/linux.h b/include/grub/loongarch64/linux.h +index af1f51d..f4b198a 100644 +--- a/include/grub/loongarch64/linux.h ++++ b/include/grub/loongarch64/linux.h +@@ -129,6 +129,11 @@ grub_linux_loongarch_alloc_virtual_mem_align (grub_size_t size, + grub_size_t align, + grub_err_t *err); + ++void* ++grub_linux_loongarch_alloc_initrd_mem_align (grub_size_t size, ++ grub_size_t align, ++ grub_err_t *err); ++ + void + grub_linux_loongarch_elf_relocator_unload (void); + +-- +2.33.0 +