Merge ~dannf/grub:ubuntu-flush-cache into ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu

Proposed by dann frazier
Status: Merged
Merge reported by: Julian Andres Klode
Merged at revision: 36cf5eafedf6c15760a48a09127ef69e1f8f161d
Proposed branch: ~dannf/grub:ubuntu-flush-cache
Merge into: ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu
Diff against target: 109 lines (+95/-0)
2 files modified
debian/patches/linuxefi-Invalidate-i-cache-before-starting-the-kern.patch (+94/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+429024@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Julian Andres Klode (juliank) wrote :

Rebased and merged

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/patches/linuxefi-Invalidate-i-cache-before-starting-the-kern.patch b/debian/patches/linuxefi-Invalidate-i-cache-before-starting-the-kern.patch
2new file mode 100644
3index 0000000..9e93c00
4--- /dev/null
5+++ b/debian/patches/linuxefi-Invalidate-i-cache-before-starting-the-kern.patch
6@@ -0,0 +1,94 @@
7+From: dann frazier <dann.frazier@canonical.com>
8+Date: Thu, 25 Aug 2022 17:08:09 -0600
9+Subject: [PATCH] linuxefi: Invalidate i-cache before starting the kernel
10+
11+We need to flush the memory range of the code we are about to execute
12+from the instruction cache before we can safely execute it. Not doing
13+so appears to be the source of rare synchronous exceptions a user
14+is seeing on a Cortex-A72-based platform while executing the Linux EFI
15+stub. Notably they seem to correlate with an instruction on a cache
16+line boundary.
17+
18+Signed-off-by: dann frazier <dann.frazier@canonical.com>
19+
20+Bug-Ubuntu: https://launchpad.net/bugs/1987924
21+Forwarded: https://github.com/rhboot/grub2/pull/107
22+Last-Updated: 2022-08-27
23+
24+--- a/grub-core/loader/efi/linux.c
25++++ b/grub-core/loader/efi/linux.c
26+@@ -221,7 +221,8 @@
27+ */
28+ #ifndef __riscv
29+ if (grub_efi_get_secureboot() == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
30+- retval = grub_efi_linux_boot (kernel_addr, handover_offset, kernel_addr);
31++ retval = grub_efi_linux_boot (kernel_addr, kernel_size,
32++ handover_offset, kernel_addr);
33+ else
34+ #endif
35+ retval = grub_efi_run_image (kernel_addr, kernel_size, linux_args);
36+--- a/grub-core/loader/efi/linux_sb.c
37++++ b/grub-core/loader/efi/linux_sb.c
38+@@ -16,6 +16,7 @@
39+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
40+ */
41+
42++#include <grub/cache.h>
43+ #include <grub/err.h>
44+ #include <grub/mm.h>
45+ #include <grub/types.h>
46+@@ -28,8 +29,8 @@
47+ typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
48+
49+ grub_err_t
50+-grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
51+- void *kernel_params)
52++grub_efi_linux_boot (void *kernel_addr, grub_size_t kernel_size,
53++ grub_off_t handover_offset, void *kernel_params)
54+ {
55+ grub_efi_loaded_image_t *loaded_image = NULL;
56+ handover_func hf;
57+@@ -54,6 +55,9 @@
58+ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n",
59+ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params);
60+
61++ /* Invalidate the instruction cache */
62++ grub_arch_sync_caches((void *)kernel_addr, kernel_size);
63++
64+ hf = (handover_func)((char *)kernel_addr + handover_offset + offset);
65+ hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
66+
67+--- a/grub-core/loader/i386/efi/linux.c
68++++ b/grub-core/loader/i386/efi/linux.c
69+@@ -55,6 +55,7 @@
70+ asm volatile ("cli");
71+
72+ return grub_efi_linux_boot ((char *)context->kernel_mem,
73++ context->kernel_size,
74+ context->handover_offset,
75+ context->params);
76+ }
77+--- a/grub-core/kern/arm/coreboot/coreboot.S
78++++ b/grub-core/kern/arm/coreboot/coreboot.S
79+@@ -43,6 +43,6 @@
80+ bx lr
81+
82+ grub_err_t
83+-EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset,
84+- void *kernel_param);
85++EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_size_t kernel_size,
86++ grub_off_t offset, void *kernel_param);
87+
88+--- a/include/grub/efi/linux.h
89++++ b/include/grub/efi/linux.h
90+@@ -23,8 +23,8 @@
91+ #include <grub/symbol.h>
92+
93+ grub_err_t
94+-EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset,
95+- void *kernel_param);
96++EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_size_t kernel_size,
97++ grub_off_t offset, void *kernel_param);
98+ grub_efi_boolean_t
99+ EXPORT_FUNC(grub_efi_run_image) (void *data, grub_efi_uint32_t data_size,
100+ const char *args);
101diff --git a/debian/patches/series b/debian/patches/series
102index 39d91e4..db2962b 100644
103--- a/debian/patches/series
104+++ b/debian/patches/series
105@@ -161,3 +161,4 @@ ubuntu-disable-LOAD-FILE2-protocol-for-initrd-on-ARM.patch
106 0161-fs-btrfs-Fix-more-fuzz-issues-related-to-chunks.patch
107 linux_xen-Properly-load-multiple-initrd-files.patch
108 linux_xen-Properly-order-multiple-initrd-files.patch
109+linuxefi-Invalidate-i-cache-before-starting-the-kern.patch

Subscribers

People subscribed via source and target branches