Skip to contentSkip to conversation

x86: only load initrd above 4g on second try

PATCH In review Yinghai Lu 6 participants 14 messages Sep 4, 2014 – Sep 8, 2014

Subsystems (2)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 1/1 x86: only load initrd above 4g on second try

Mantas found that after commit 4bf7111f5016 ("x86/efi: Support initrd loaded above 4G"), the kernel freezes at the earliest possible moment when trying to boot via UEFI on Asus laptop.

Revert to old way to load initrd under 4G on first try, second try will use above 4G buffer when initrd is too big and does not fit under 4G.

-v2: add print out for second try, and print out files buf address. -v3: can not snprintf
-v4: drop address print out for files buf

---
 arch/x86/boot/compressed/eboot.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
arch/x86/boot/compressed/eboot.c +11 -7
Index: linux-2.6/arch/x86/boot/compressed/eboot.c
===================================================================
@@ -1032,7 +1032,6 @@ struct boot_params *make_boot_params(str
 	int i;
 	unsigned long ramdisk_addr;
 	unsigned long ramdisk_size;
-	unsigned long initrd_addr_max;
 
 	efi_early = c;
 	sys_table = (efi_system_table_t *)(unsigned long)efi_early->table;
@@ -1095,15 +1094,20 @@ struct boot_params *make_boot_params(str
 
 	memset(sdt, 0, sizeof(*sdt));
 
-	if (hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G)
-		initrd_addr_max = -1UL;
-	else
-		initrd_addr_max = hdr->initrd_addr_max;
-
 	status = handle_cmdline_files(sys_table, image,
 				      (char *)(unsigned long)hdr->cmd_line_ptr,
-				      "initrd=", initrd_addr_max,
+				      "initrd=", hdr->initrd_addr_max,
 				      &ramdisk_addr, &ramdisk_size);
+
+	if (status != EFI_SUCCESS &&
+	    hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) {
+		efi_printk(sys_table, "Trying to load files to higher address\n");
+		status = handle_cmdline_files(sys_table, image,
+				      (char *)(unsigned long)hdr->cmd_line_ptr,
+				      "initrd=", -1UL,
+				      &ramdisk_addr, &ramdisk_size);
+	}
+
 	if (status != EFI_SUCCESS)
 		goto fail2;
 	hdr->ramdisk_image = ramdisk_addr & 0xffffffff;
#1 lore raw
Quoted 12 lines · Yinghai Lu

Mantas found that after commit 4bf7111f5016 ("x86/efi: Support initrd loaded above 4G"), the kernel freezes at the earliest possible moment when trying to boot via UEFI on Asus laptop.

Revert to old way to load initrd under 4G on first try, second try will use above 4G buffer when initrd is too big and does not fit under 4G.

(quoted diff) +0 -3
-v2: add print out for second try, and print out files buf address.
-v3: can not snprintf
-v4: drop address print out for files buf
Quoted 7 lines
---
 arch/x86/boot/compressed/eboot.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Thanks, I've picked this up and expanded on the commit message because a lot of useful information was discussed on the mailing list that we should definitely include.

http://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/commit/?h=urgent&id=b524e05df6d466af2f7eea1f044369109e48e641

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#2 lore raw
Quoted 25 lines · Matt Fleming
Quoted 12 lines · Yinghai Lu

Mantas found that after commit 4bf7111f5016 ("x86/efi: Support initrd loaded above 4G"), the kernel freezes at the earliest possible moment when trying to boot via UEFI on Asus laptop.

Revert to old way to load initrd under 4G on first try, second try will use above 4G buffer when initrd is too big and does not fit under 4G.

(quoted diff) +0 -3
-v2: add print out for second try, and print out files buf address.
-v3: can not snprintf
-v4: drop address print out for files buf
Quoted 7 lines
---
 arch/x86/boot/compressed/eboot.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Thanks, I've picked this up and expanded on the commit message because a lot of useful information was discussed on the mailing list that we should definitely include.

Quoted 2 lines

http://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/commit/?h=urgent&id=b524e05df6d466af2f7eea1f044369109e48e641

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

-hpa

#3 lore raw
Quoted 4 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

I'm not sure that rounding up the size of the target buffer will workaround this issue correctly.

As far as I know, the only thing that Mantas tried was rounding up the size of the source file, by padding it.

Laszlo, is there anything we can do in the kernel to avoid the EDK2 bug you fixed here,

https://github.com/tianocore/edk2/commit/4e39b75e

such as lying about the number of bytes we're trying to read or allocating a bigger target buffer than we actually need?

Assuming of course, that the bug that Laszlo fixed and the bug that Mantas is hitting are one and the same.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
author
#4 lore raw
Quoted 11 lines · Matt Fleming
Quoted 4 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

I'm not sure that rounding up the size of the target buffer will workaround this issue correctly.

As far as I know, the only thing that Mantas tried was rounding up the size of the source file, by padding it.

Hi Mantas,

Can you try attached patch on top of linus tree?

Thanks

Yinghai

---
 drivers/firmware/efi/libstub/efi-stub-helper.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/efi-stub-helper.c +1 -1
Index: linux-2.6/drivers/firmware/efi/libstub/efi-stub-helper.c
===================================================================
@@ -426,7 +426,7 @@ efi_status_t handle_cmdline_files(efi_sy
 				if (size > EFI_READ_CHUNK_SIZE)
 					chunksize = EFI_READ_CHUNK_SIZE;
 				else
-					chunksize = size;
+					chunksize = round_up(size, EFI_PAGE_SIZE);
 
 				status = efi_file_read(files[j].handle,
 						       &chunksize,
#5 lore raw
Quoted 7 lines · Yinghai Lu
Quoted 5 lines · Matt Fleming
Quoted 3 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

Quoted 7 lines
Quoted 5 lines

I'm not sure that rounding up the size of the target buffer will workaround this issue correctly.

As far as I know, the only thing that Mantas tried was rounding up the size of the source file, by padding it.

Can you try attached patch on top of linus tree?

I took the liberty to test the patch on my Dell XPS13 9333, and unfortunately I got the old hang back.

This was tested on the current Linus' tree.

Cheers,
Anders Darander

Quoted 2 lines
drivers/firmware/efi/libstub/efi-stub-helper.c +1 -1
-					chunksize = size;
+					chunksize = round_up(size, EFI_PAGE_SIZE);
Signature · 2 lines
It usually takes more than three weeks to prepare a good impromptu speech.
		-- Mark Twain
#6 lore raw
Quoted 16 lines · Anders Darander
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · Matt Fleming
Quoted 3 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

I'm not sure that rounding up the size of the target buffer will workaround this issue correctly.

As far as I know, the only thing that Mantas tried was rounding up the size of the source file, by padding it.

Quoted 6 lines
Quoted 1 line

Can you try attached patch on top of linus tree?

I took the liberty to test the patch on my Dell XPS13 9333, and unfortunately I got the old hang back.

This was tested on the current Linus' tree.

Assuming that the UEFI implementation on Mantas's and Anders's machines use edk2's FatPkg to read the file from an EFI System Partition:

this kernel patch will have no effect, because FatPkg (the ESP filesystem driver) checks the buffer size against the remainder of the file, and clips the input buffer if it would overshoot the file size.

In other words, the rounding up of the kernel will be undone in a "somewhat higher level" driver in the firmware, and the request size that reaches DiskIo (the "lowel level driver") remains the same.

https://github.com/tianocore/edk2-FatPkg/blob/master/EnhancedFatDxe/ReadWrite.c#L306

    } else {
      //
      // Access a file
      //
      EndPosition = IFile->Position + *BufferSize;
      if (EndPosition > OFile->FileSize) {
        //
        // The position goes beyond the end of file
        //
        if (IoMode == READ_DATA) {
          //
          // Adjust the actual size read
          //
          *BufferSize -= (UINTN) EndPosition - OFile->FileSize;

Thanks
Laszlo

author
#7 lore raw
Quoted 4 lines · Laszlo Ersek

On 09/05/14 07:47, Anders Darander wrote:
In other words, the rounding up of the kernel will be undone in a "somewhat higher level" driver in the firmware, and the request size that reaches DiskIo (the "lowel level driver") remains the same.

Thanks for explanation.

Is there any way to check if EFI firmware have your fix from some calling?

Thanks

Yinghai

#8 lore raw
Quoted 9 lines · Yinghai Lu
Quoted 4 lines · Laszlo Ersek

On 09/05/14 07:47, Anders Darander wrote:
In other words, the rounding up of the kernel will be undone in a "somewhat higher level" driver in the firmware, and the request size that reaches DiskIo (the "lowel level driver") remains the same.

Thanks for explanation.

Is there any way to check if EFI firmware have your fix from some calling?

I can't think of any, alas.

It might make sense to contact Mantas's and Anders's UEFI vendors; after all a reliable reproducer is available.

Thanks,
Laszlo

#9 lore raw
In reply to H. Peter Anvin
Quoted 4 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

I took a whack at the double-buffer strategy, and I think the patch is conceptually pretty straight forward.

Could someone try out the following patch? It works around the problem on my ASUS machine.

---

From 89e7fdaeb04f79d9834678e486215974986d4ac8 Mon Sep 17 00:00:00 2001
From: Matt Fleming <[email protected]>
Date: Fri, 5 Sep 2014 23:15:11 +0100
Subject: [PATCH] x86/efi: Workaround firmware bug with double-buffer read
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Mantas found that after commit 4bf7111f5016 ("x86/efi: Support initrd loaded above 4G"), the kernel freezes at the earliest possible moment when trying to boot via UEFI on Asus laptop.

The cause of the freeze appears to be a firmware bug when reading file data into buffers above 4GB, though the exact reason is unknown. Mantas reports that the hang can be avoided if the file size is a multiple of 512 bytes, but I've seen some ASUS firmware simply corrupting the file data rather than freezing.

Since the bug has only been reported when reading into a buffer above 4GB, we can workaround the problem by doing a double-buffer read, where we read a partial file chunk into a buffer < 4GB then copy it to the buffer (potentially) above 4GB.

Laszlo fixed an issue in the upstream EDK2 DiskIO code in Aug 2013 which may possibly be related, commit 4e39b75e ("MdeModulePkg/DiskIoDxe: fix source/destination pointer of overrun transfer"). Whatever the cause, it's unlikely that a fix will be forthcoming from the vendor, hence the workaround.

---
 drivers/firmware/efi/libstub/efi-stub-helper.c | 28 ++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/efi-stub-helper.c +26 -2
index 32d5cca30f49..470793ce2617 100644
@@ -297,6 +297,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 {
 	struct file_info *files;
 	unsigned long file_addr;
+	unsigned long chunkbuf;
 	u64 file_size_total;
 	efi_file_handle_t *fh = NULL;
 	efi_status_t status;
@@ -416,6 +417,24 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 			goto free_file_total;
 		}
 
+		/*
+		 * Allocate a bounce buffer below 4GB.
+		 *
+		 * Some firmware implementations cannot perform file
+		 * reads into buffers above 4G and at best corrupt the
+		 * buffer, at worst they hang completely.
+		 *
+		 * Pass chunkbuf to the firmware to perform reads in
+		 * chunksize bytes and copy them to the target buffer
+		 * 'file_addr'.
+		 */
+		status = efi_high_alloc(sys_table_arg, EFI_READ_CHUNK_SIZE,
+					0x1000, &chunkbuf, 0xffffffff);
+		if (status != EFI_SUCCESS) {
+			pr_efi_err(sys_table_arg, "Failed to alloc file chunk buffer\n");
+			goto free_chunk;
+		}
+
 		addr = file_addr;
 		for (j = 0; j < nr_files; j++) {
 			unsigned long size;
@@ -430,11 +449,13 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 
 				status = efi_file_read(files[j].handle,
 						       &chunksize,
-						       (void *)addr);
+						       (void *)chunkbuf);
 				if (status != EFI_SUCCESS) {
 					pr_efi_err(sys_table_arg, "Failed to read file\n");
-					goto free_file_total;
+					goto free_chunk;
 				}
+
+				memcpy((void *)addr, (void *)chunkbuf, chunksize);
 				addr += chunksize;
 				size -= chunksize;
 			}
@@ -442,6 +463,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 			efi_file_close(files[j].handle);
 		}
 
+		efi_free(sys_table_arg, EFI_READ_CHUNK_SIZE, chunkbuf);
 	}
 
 	efi_call_early(free_pool, files);
@@ -451,6 +473,8 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 
 	return status;
 
+free_chunk:
+	efi_free(sys_table_arg, EFI_READ_CHUNK_SIZE, chunkbuf);
 free_file_total:
 	efi_free(sys_table_arg, file_size_total, file_addr);
 
Signature · 4 lines
1.9.3

-- 
Matt Fleming, Intel Open Source Technology Center
Tested-by
#10 lore raw
Quoted 11 lines · Matt Fleming
Quoted 3 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

I took a whack at the double-buffer strategy, and I think the patch is conceptually pretty straight forward.

Could someone try out the following patch? It works around the problem on my ASUS machine.

Your patch works around the problem on my Dell machine also. With that one applied, it boots fine!

Thus,

Cheers,
Anders

Signature · 1 line
All the troubles you have will pass away very quickly.
#11 lore raw
In reply to Matt Fleming
Quoted 125 lines · Matt Fleming
Quoted 4 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

I took a whack at the double-buffer strategy, and I think the patch is conceptually pretty straight forward.

Could someone try out the following patch? It works around the problem on my ASUS machine.

---

From 89e7fdaeb04f79d9834678e486215974986d4ac8 Mon Sep 17 00:00:00 2001
From: Matt Fleming <[email protected]>
Date: Fri, 5 Sep 2014 23:15:11 +0100
Subject: [PATCH] x86/efi: Workaround firmware bug with double-buffer read
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Mantas found that after commit 4bf7111f5016 ("x86/efi: Support initrd loaded above 4G"), the kernel freezes at the earliest possible moment when trying to boot via UEFI on Asus laptop.

The cause of the freeze appears to be a firmware bug when reading file data into buffers above 4GB, though the exact reason is unknown. Mantas reports that the hang can be avoided if the file size is a multiple of 512 bytes, but I've seen some ASUS firmware simply corrupting the file data rather than freezing.

Since the bug has only been reported when reading into a buffer above 4GB, we can workaround the problem by doing a double-buffer read, where we read a partial file chunk into a buffer < 4GB then copy it to the buffer (potentially) above 4GB.

Laszlo fixed an issue in the upstream EDK2 DiskIO code in Aug 2013 which may possibly be related, commit 4e39b75e ("MdeModulePkg/DiskIoDxe: fix source/destination pointer of overrun transfer"). Whatever the cause, it's unlikely that a fix will be forthcoming from the vendor, hence the workaround.

---
 drivers/firmware/efi/libstub/efi-stub-helper.c | 28 ++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/efi-stub-helper.c +26 -3
index 32d5cca30f49..470793ce2617 100644
@@ -297,6 +297,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 {
        struct file_info *files;
        unsigned long file_addr;
+       unsigned long chunkbuf;
        u64 file_size_total;
        efi_file_handle_t *fh = NULL;
        efi_status_t status;
@@ -416,6 +417,24 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
                        goto free_file_total;
                }
 
+               /*
+                * Allocate a bounce buffer below 4GB.
+                *
+                * Some firmware implementations cannot perform file
+                * reads into buffers above 4G and at best corrupt the
+                * buffer, at worst they hang completely.
+                *
+                * Pass chunkbuf to the firmware to perform reads in
+                * chunksize bytes and copy them to the target buffer
+                * 'file_addr'.
+                */
+               status = efi_high_alloc(sys_table_arg, EFI_READ_CHUNK_SIZE,
+                                       0x1000, &chunkbuf, 0xffffffff);
+               if (status != EFI_SUCCESS) {
+                       pr_efi_err(sys_table_arg, "Failed to alloc file chunk buffer\n");
+                       goto free_chunk;
+               }
+
                addr = file_addr;
                for (j = 0; j < nr_files; j++) {
                        unsigned long size;
@@ -430,11 +449,13 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 
                                status = efi_file_read(files[j].handle,
                                                       &chunksize,
-                                                      (void *)addr);
+                                                      (void *)chunkbuf);
                                if (status != EFI_SUCCESS) {
                                        pr_efi_err(sys_table_arg, "Failed to read file\n");
-                                       goto free_file_total;
+                                       goto free_chunk;
                                }
+
+                               memcpy((void *)addr, (void *)chunkbuf, chunksize);
                                addr += chunksize;
                                size -= chunksize;
                        }
@@ -442,6 +463,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
                        efi_file_close(files[j].handle);
                }
 
+               efi_free(sys_table_arg, EFI_READ_CHUNK_SIZE, chunkbuf);
        }
 
        efi_call_early(free_pool, files);
@@ -451,6 +473,8 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 
        return status;
 
+free_chunk:
+       efi_free(sys_table_arg, EFI_READ_CHUNK_SIZE, chunkbuf);
 free_file_total:
        efi_free(sys_table_arg, file_size_total, file_addr);
 
--

1.9.3

Quoted 2 lines

--
Matt Fleming, Intel Open Source Technology Center

Finally got around to testing the patches here. Sorry for no replies earlier.

This seemed like it would work, but... it hangs at the memcpy?...

(If I add a printk before memcpy and a printk after memcpy, I never see the second one. I guess that memory location is just cursed, or something.)

Going to test Yinghai's 6aacad3513bf now, just in case.

Signature · 1 line
Mantas Mikulėnas <[email protected]>
#12 lore raw
Quoted 131 lines · Mantas Mikulėnas
Quoted 125 lines · Matt Fleming
Quoted 4 lines · H. Peter Anvin

I am fine with this patch, but at the same time I do want to note that there is an alternative to double-buffer the patch and/or (if that applies to the buggy BIOS) round up the size of the target buffer.

I took a whack at the double-buffer strategy, and I think the patch is conceptually pretty straight forward.

Could someone try out the following patch? It works around the problem on my ASUS machine.

---

From 89e7fdaeb04f79d9834678e486215974986d4ac8 Mon Sep 17 00:00:00 2001
From: Matt Fleming <[email protected]>
Date: Fri, 5 Sep 2014 23:15:11 +0100
Subject: [PATCH] x86/efi: Workaround firmware bug with double-buffer read
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Mantas found that after commit 4bf7111f5016 ("x86/efi: Support initrd loaded above 4G"), the kernel freezes at the earliest possible moment when trying to boot via UEFI on Asus laptop.

The cause of the freeze appears to be a firmware bug when reading file data into buffers above 4GB, though the exact reason is unknown. Mantas reports that the hang can be avoided if the file size is a multiple of 512 bytes, but I've seen some ASUS firmware simply corrupting the file data rather than freezing.

Since the bug has only been reported when reading into a buffer above 4GB, we can workaround the problem by doing a double-buffer read, where we read a partial file chunk into a buffer < 4GB then copy it to the buffer (potentially) above 4GB.

Laszlo fixed an issue in the upstream EDK2 DiskIO code in Aug 2013 which may possibly be related, commit 4e39b75e ("MdeModulePkg/DiskIoDxe: fix source/destination pointer of overrun transfer"). Whatever the cause, it's unlikely that a fix will be forthcoming from the vendor, hence the workaround.

---
 drivers/firmware/efi/libstub/efi-stub-helper.c | 28 ++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/efi-stub-helper.c +26 -3
index 32d5cca30f49..470793ce2617 100644
@@ -297,6 +297,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 {
        struct file_info *files;
        unsigned long file_addr;
+       unsigned long chunkbuf;
        u64 file_size_total;
        efi_file_handle_t *fh = NULL;
        efi_status_t status;
@@ -416,6 +417,24 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
                        goto free_file_total;
                }
 
+               /*
+                * Allocate a bounce buffer below 4GB.
+                *
+                * Some firmware implementations cannot perform file
+                * reads into buffers above 4G and at best corrupt the
+                * buffer, at worst they hang completely.
+                *
+                * Pass chunkbuf to the firmware to perform reads in
+                * chunksize bytes and copy them to the target buffer
+                * 'file_addr'.
+                */
+               status = efi_high_alloc(sys_table_arg, EFI_READ_CHUNK_SIZE,
+                                       0x1000, &chunkbuf, 0xffffffff);
+               if (status != EFI_SUCCESS) {
+                       pr_efi_err(sys_table_arg, "Failed to alloc file chunk buffer\n");
+                       goto free_chunk;
+               }
+
                addr = file_addr;
                for (j = 0; j < nr_files; j++) {
                        unsigned long size;
@@ -430,11 +449,13 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 
                                status = efi_file_read(files[j].handle,
                                                       &chunksize,
-                                                      (void *)addr);
+                                                      (void *)chunkbuf);
                                if (status != EFI_SUCCESS) {
                                        pr_efi_err(sys_table_arg, "Failed to read file\n");
-                                       goto free_file_total;
+                                       goto free_chunk;
                                }
+
+                               memcpy((void *)addr, (void *)chunkbuf, chunksize);
                                addr += chunksize;
                                size -= chunksize;
                        }
@@ -442,6 +463,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
                        efi_file_close(files[j].handle);
                }
 
+               efi_free(sys_table_arg, EFI_READ_CHUNK_SIZE, chunkbuf);
        }
 
        efi_call_early(free_pool, files);
@@ -451,6 +473,8 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
 
        return status;
 
+free_chunk:
+       efi_free(sys_table_arg, EFI_READ_CHUNK_SIZE, chunkbuf);
 free_file_total:
        efi_free(sys_table_arg, file_size_total, file_addr);
 
--

1.9.3

Quoted 2 lines

--
Matt Fleming, Intel Open Source Technology Center

Finally got around to testing the patches here. Sorry for no replies earlier.

Quoted 7 lines

This seemed like it would work, but... it hangs at the memcpy?...

(If I add a printk before memcpy and a printk after memcpy, I never see the second one. I guess that memory location is just cursed, or something.)

Going to test Yinghai's 6aacad3513bf now, just in case.

Err, I meant b524e05df6d4 (the one in mfleming/urgent).

Signature · 1 line
Mantas Mikulėnas <[email protected]>
#13 lore raw
In reply to Mantas Mikulėnas
Quoted 8 lines · Mantas Mikulėnas

Finally got around to testing the patches here. Sorry for no replies earlier.

This seemed like it would work, but... it hangs at the memcpy?...

(If I add a printk before memcpy and a printk after memcpy, I never see the second one. I guess that memory location is just cursed, or something.)

Thanks for testing. Let's go ahead with Yinghai's patch ("x86/efi: Only load initrd above 4g on second try").

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center