|
|
5593c8 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
5593c8 |
From: Peter Jones <pjones@redhat.com>
|
|
|
5593c8 |
Date: Fri, 12 Jul 2019 09:53:32 +0200
|
|
|
5593c8 |
Subject: [PATCH] x86-efi: Use bounce buffers for reading to addresses > 4GB
|
|
|
5593c8 |
|
|
|
5593c8 |
Lots of machines apparently can't DMA correctly above 4GB during UEFI,
|
|
|
5593c8 |
so use bounce buffers for the initramfs read.
|
|
|
5593c8 |
|
|
|
5593c8 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
5593c8 |
---
|
|
|
5593c8 |
grub-core/loader/i386/efi/linux.c | 52 +++++++++++++++++++++++++++++++++------
|
|
|
5593c8 |
1 file changed, 45 insertions(+), 7 deletions(-)
|
|
|
5593c8 |
|
|
|
5593c8 |
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
|
|
fd0330 |
index 33e981e76e..2f0336809e 100644
|
|
|
5593c8 |
--- a/grub-core/loader/i386/efi/linux.c
|
|
|
5593c8 |
+++ b/grub-core/loader/i386/efi/linux.c
|
|
|
5593c8 |
@@ -35,11 +35,16 @@ static grub_dl_t my_mod;
|
|
|
5593c8 |
static int loaded;
|
|
|
5593c8 |
static void *kernel_mem;
|
|
|
5593c8 |
static grub_uint64_t kernel_size;
|
|
|
5593c8 |
-static grub_uint8_t *initrd_mem;
|
|
|
5593c8 |
+static void *initrd_mem;
|
|
|
5593c8 |
static grub_uint32_t handover_offset;
|
|
|
5593c8 |
struct linux_kernel_params *params;
|
|
|
5593c8 |
static char *linux_cmdline;
|
|
|
5593c8 |
|
|
|
5593c8 |
+#define MIN(a, b) \
|
|
|
5593c8 |
+ ({ typeof (a) _a = (a); \
|
|
|
5593c8 |
+ typeof (b) _b = (b); \
|
|
|
5593c8 |
+ _a < _b ? _a : _b; })
|
|
|
5593c8 |
+
|
|
|
5593c8 |
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
|
|
|
5593c8 |
|
|
|
5593c8 |
static grub_err_t
|
|
|
5593c8 |
@@ -73,6 +78,44 @@ grub_linuxefi_unload (void)
|
|
|
5593c8 |
return GRUB_ERR_NONE;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
+#define BOUNCE_BUFFER_MAX 0x10000000ull
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+static grub_ssize_t
|
|
|
5593c8 |
+read(grub_file_t file, grub_uint8_t *bufp, grub_size_t len)
|
|
|
5593c8 |
+{
|
|
|
5593c8 |
+ grub_ssize_t bufpos = 0;
|
|
|
5593c8 |
+ static grub_size_t bbufsz = 0;
|
|
|
5593c8 |
+ static char *bbuf = NULL;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (bbufsz == 0)
|
|
|
5593c8 |
+ bbufsz = MIN(BOUNCE_BUFFER_MAX, len);
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ while (!bbuf && bbufsz)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ bbuf = grub_malloc(bbufsz);
|
|
|
5593c8 |
+ if (!bbuf)
|
|
|
5593c8 |
+ bbufsz >>= 1;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ if (!bbuf)
|
|
|
5593c8 |
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate bounce buffer"));
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ while (bufpos < (long long)len)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ grub_ssize_t sz;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ sz = grub_file_read (file, bbuf, MIN(bbufsz, len - bufpos));
|
|
|
5593c8 |
+ if (sz < 0)
|
|
|
5593c8 |
+ return sz;
|
|
|
5593c8 |
+ if (sz == 0)
|
|
|
5593c8 |
+ break;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ grub_memcpy(bufp + bufpos, bbuf, sz);
|
|
|
5593c8 |
+ bufpos += sz;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ return bufpos;
|
|
|
5593c8 |
+}
|
|
|
5593c8 |
+
|
|
|
5593c8 |
static grub_err_t
|
|
|
5593c8 |
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
|
5593c8 |
int argc, char *argv[])
|
|
|
5593c8 |
@@ -126,7 +169,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
|
5593c8 |
for (i = 0; i < nfiles; i++)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
grub_ssize_t cursize = grub_file_size (files[i]);
|
|
|
5593c8 |
- if (grub_file_read (files[i], ptr, cursize) != cursize)
|
|
|
5593c8 |
+ if (read (files[i], ptr, cursize) != cursize)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
if (!grub_errno)
|
|
|
5593c8 |
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
|
|
5593c8 |
@@ -152,11 +195,6 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
|
5593c8 |
return grub_errno;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
-#define MIN(a, b) \
|
|
|
5593c8 |
- ({ typeof (a) _a = (a); \
|
|
|
5593c8 |
- typeof (b) _b = (b); \
|
|
|
5593c8 |
- _a < _b ? _a : _b; })
|
|
|
5593c8 |
-
|
|
|
5593c8 |
static grub_err_t
|
|
|
5593c8 |
grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|
|
5593c8 |
int argc, char *argv[])
|