Skip to contentSkip to conversation

Grub UEFI memory allocation patch

PATCH Bernon, Rémi 2 participants 5 messages Apr 3, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

I was trying for a few days to enable EFI boot on my laptop, and i've encountered some issues with Grub2.

My motherboard is one of the modern Intel chipset motherboard, that come with UEFI v2, and when i tried to boot using grub 1.98, compiled with efi support, there was some memory allocation error message at the kernel loading time, saying "cannot allocate protected mode page" or something like that.

So, i looked into the grub source code, and found that it tries to allocate memory at a hard coded memory address (0X10000), that was already in use, for my computer.

I've also found parts of the code in loader/i386/linux.c that were looking for free pages in the memory map, which is already done by the EFI memory allocation function.
Actually, i've managed to make it working, by letting EFI find free memory pages and allocate them, but i dont really know how important this 0x10000 address is.

My fix works for me, but I think it may be connected to the fact I've also build a relocatable kernel. I don't know enough about "kernel loading" and bootloaders to determine if my fix will work well in all situations or not, so maybe someone can tell me that.

Actually, i've still have an issue at shutdown time : the kernel (or grub ?) crashes with an error message "Bad RIP value" and a full stack trace with an EFI call, just when it is expected to power down. So, i need to poweroff or reboot it manually, using the power switch. I anyone have an idea from where the error comes, i'm interested.

Rémi

include/grub/efi/efi.h +13 -0
index 5852a47..996b545 100644
@@ -37,9 +37,22 @@ void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle,
 					   grub_efi_uint32_t attributes);
 int EXPORT_FUNC(grub_efi_set_text_mode) (int on);
 void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds);
+
+void *
+EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages,
+                                          grub_efi_memory_type_t memtype);
+void *
+EXPORT_FUNC(grub_efi_allocate_pages_before) (grub_efi_physical_address_t address,
+		 			     grub_efi_uintn_t pages,
+                                             grub_efi_memory_type_t memtype);
 void *
 EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address,
 				      grub_efi_uintn_t pages);
+void *
+EXPORT_FUNC(grub_efi_typed_allocate_pages) (grub_efi_physical_address_t address,
+					    grub_efi_uintn_t pages,
+					    grub_efi_allocate_type_t type,
+	                                    grub_efi_memory_type_t memtype);
 void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,
 				       grub_efi_uintn_t pages);
 int
kern/efi/mm.c +39 -13

79 lines not on this page · raw message

loader/i386/efi/linux.c +9 -102

148 lines not on this page · raw message

#1 lore raw
Quoted 8 lines · Bernon

I've also found parts of the code in loader/i386/linux.c that were looking for free pages in the memory map, which is already done by the EFI memory allocation function.
Actually, i've managed to make it working, by letting EFI find free memory pages and allocate them, but i dont really know how important this 0x10000 address is.

It is important and we have an experimental stuff in my newreloc branch to workaround the problem. It was already explained on the list

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#2 lore raw

Actually, I've read the answer you made to someone who had the same memory issue as I had, and I tried the newreloc branch, but it doesn't even build when targeting efi platform. The "loader/i386/efi/linux.c" file is missing in this branch.

I will look for explanation about this part of code, in the mailing list archives, however, as i said, the fix works fine for me. The only error i have noticed, occurs on shutdown, and also occurs when i boot using elilo.

Regards,
Rémi Bernon

#3 lore raw
Quoted 6 lines · Bernon

Actually, I've read the answer you made to someone who had the same memory issue as I had, and I tried the newreloc branch, but it doesn't even build when targeting efi platform. The "loader/i386/efi/linux.c" file is missing in this branch.

It was a mismerge. I've fixed it. Recently I was working on making this branch mergeable into experimental and for this it needed some restructure. I recommend trying r2130 of newreloc

Quoted 2 lines

I will look for explanation about this part of code, in the mailing list archives, however, as i said, the fix works fine for me.

Even if it does it needs a special support from kernel and doesn't allow to handle e.g. FreeBSD so when it will be mergeable (probably next week) your fix will be obsolete

Quoted 14 lines

The only
error i have noticed, occurs on shutdown, and also occurs when i boot using elilo.

Regards,
Rémi Bernon

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#4 lore raw

That's fine. I suspected that this required a specific kernel configuration, as you have confirmed. I will try again the newreloc branch.
Thanks.

Regards,
Rémi Bernon

2010/4/3 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:

Quoted 43 lines
Quoted 6 lines · Bernon

Actually, I've read the answer you made to someone who had the same memory issue as I had, and I tried the newreloc branch, but it doesn't even build when targeting efi platform. The "loader/i386/efi/linux.c" file is missing in this branch.

It was a mismerge. I've fixed it. Recently I was working on making this branch mergeable into experimental and for this it needed some restructure. I recommend trying r2130 of newreloc

Quoted 2 lines

I will look for explanation  about this part of code, in the mailing list archives, however, as i said, the fix works fine for me.

Even if it does it needs a special support from kernel and doesn't allow to handle e.g. FreeBSD so when it will be mergeable (probably next week) your fix will be obsolete

Quoted 4 lines

 The only
error i have noticed, occurs on shutdown, and also occurs when i boot using elilo.

Quoted 10 lines

Regards,
Rémi Bernon

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel