Skip to contentSkip to conversation

boot in EFI mode (x86_64) fails on some systems

bug #36532 [email protected] 2 participants 7 messages Jun 27, 2012 – Jul 2, 2012 9 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 959D45574D89AF41A9DADF6F446A2E9A2AE507A772@AUSX7MCPS310.AMER.DELL.COM

A message that is not in the archive (sent off-list or not yet received): 959D45574D89AF41A9DADF6F446A2E9A2AE55A707B@AUSX7MCPS310.AMER.DELL.COM

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 959D45574D89AF41A9DADF6F446A2E9A2AE5668374@AUSX7MCPS310.AMER.DELL.COM

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 959D45574D89AF41A9DADF6F446A2E9A2AE56AEA8E@AUSX7MCPS310.AMER.DELL.COM

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 12 lines

Well, this works, too (on top of HEAD from 7 june).

--- ../../grub/grub-core/loader/i386/linux.c 2012-05-31
12:59:19.000000000 -0400
+++ grub-core/loader/i386/linux.c 2012-06-12 20:47:51.455718055 -0400

(quoted diff) +0 -0
@@ -139,7 +139,7 @@ find_efi_mmap_size (void)
 
   /* Increase the size a bit for safety, because GRUB allocates more

on
later, and EFI itself may allocate more. */

Review

Quoted 5 lines
(quoted diff) +1 -1
-  mmap_size += (1 << 12);
+  mmap_size += (3 << 12);
 
   mmap_size = page_align (mmap_size);
   return mmap_size;

Vladimir,

The 2.00rc1 version of grub2 still doesn't fix the efi memory map buffer size I've been working on (though I can see you are now allocating the efi memory map buffer very shortly before you are calling grub_efi_finish_boot_services()).

Increasing the mmap_size in find_efi_mmap_size()--as in the patch immediately above this text--does fix the problem. Even adding (2 << 12) (instead of (1 << 12)) to the mmap_size will work on the system I'm testing with.

As is, though, 2.00rc1 fails to boot, with the error message "memory map buffer is too small".

Thanks,
Stuart

#10 lore raw
Quoted 15 lines · On 27.06.2012 21:59, [email protected] wrote:
Quoted 15 lines

Well, this works, too (on top of HEAD from 7 june).

--- ../../grub/grub-core/loader/i386/linux.c 2012-05-31
12:59:19.000000000 -0400
+++ grub-core/loader/i386/linux.c 2012-06-12 20:47:51.455718055 -0400

(quoted diff) +0 -0
@@ -139,7 +139,7 @@ find_efi_mmap_size (void)
 
   /* Increase the size a bit for safety, because GRUB allocates more

on
later, and EFI itself may allocate more. */

(quoted diff) +1 -1
-  mmap_size += (1 << 12);
+  mmap_size += (3 << 12);
Quoted 9 lines
Quoted 2 lines
   mmap_size = page_align (mmap_size);
   return mmap_size;

Vladimir,

The 2.00rc1 version of grub2 still doesn't fix the efi memory map buffer size I've been working on (though I can see you are now allocating the efi memory map buffer very shortly before you are calling grub_efi_finish_boot_services()).

Increasing the mmap_size in find_efi_mmap_size()--as in the patch immediately above this text--does fix the problem. Even adding (2 << 12) (instead of (1 << 12)) to the mmap_size will work on the system I'm testing with.

I've changed it to 3. Thanks. It's annoying that even such simple operations as we have between find_efi_mmap and finish drastically increase memory map size.

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

-----Original Message-----
From: [email protected] [mailto:grub- [email protected]] On Behalf Of Vladimir 'f- coder/phcoder' Serbinenko
Sent: Wednesday, June 27, 2012 3:51 PM
To: Hayes, Stuart
Cc: [email protected]; [email protected]; Dominguez, Jared
Subject: Re: [bug #36532] boot in EFI mode (x86_64) fails on some systems

Quoted 7 lines · On 27.06.2012 21:59, [email protected] wrote:
Quoted 7 lines

Well, this works, too (on top of HEAD from 7 june).

--- ../../grub/grub-core/loader/i386/linux.c 2012-05-31
12:59:19.000000000 -0400
+++ grub-core/loader/i386/linux.c 2012-06-12 20:47:51.455718055

-0400

Quoted 3 lines

Review find_efi_mmap_size (void) · line 140

Quoted 3 lines
(quoted diff) +0 -0
@@ -139,7 +139,7 @@ find_efi_mmap_size (void)
 
   /* Increase the size a bit for safety, because GRUB allocates

more

Quoted 11 lines

Review

Quoted 7 lines

on
later, and EFI itself may allocate more. */

(quoted diff) +1 -1
-  mmap_size += (1 << 12);
+  mmap_size += (3 << 12);
 
   mmap_size = page_align (mmap_size);
   return mmap_size;

Vladimir,

The 2.00rc1 version of grub2 still doesn't fix the efi memory map

buffer size I've been working on (though I can see you are now allocating the efi memory map buffer very shortly before you are calling grub_efi_finish_boot_services()).

Quoted 2 lines

Increasing the mmap_size in find_efi_mmap_size()--as in the patch

immediately above this text--does fix the problem. Even adding (2 <<
12) (instead of (1 << 12)) to the mmap_size will work on the system I'm testing with.

Quoted 1 line
Quoted 7 lines

I've changed it to 3. Thanks. It's annoying that even such simple operations as we have between find_efi_mmap and finish drastically increase memory map size.

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

Thanks! I completely agree that it is annoying.

#12 lore raw
In reply to Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 19 lines
Quoted 11 lines
Quoted 4 lines

Vladimir,

The 2.00rc1 version of grub2 still doesn't fix the efi memory map

buffer size I've been working on (though I can see you are now allocating the efi memory map buffer very shortly before you are calling grub_efi_finish_boot_services()).

Quoted 2 lines

Increasing the mmap_size in find_efi_mmap_size()--as in the patch

immediately above this text--does fix the problem. Even adding (2 <<
12) (instead of (1 << 12)) to the mmap_size will work on the system

I'm

Quoted 7 lines

testing with.

Quoted 1 line

I've changed it to 3. Thanks. It's annoying that even such simple operations as we have between find_efi_mmap and finish drastically increase memory map size.

Quoted 6 lines
Quoted 3 lines

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

Thanks! I completely agree that it is annoying.

FYI, while grub-2.00 works on my system now, someone else here at Dell has tested it and found that it still doesn't work. (I verified that they were indeed using version 2.00, and saw the error myself).

I have no idea how or why the memory map size is growing that much. As I get time, I'll try to figure that out...

#13 lore raw
In reply to Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

Vladimir,

The 2.00rc1 version of grub2 still doesn't fix the efi memory map

buffer size I've been working on (though I can see you are now allocating the efi memory map buffer very shortly before you are calling grub_efi_finish_boot_services()).

Quoted 2 lines

Increasing the mmap_size in find_efi_mmap_size()--as in the patch

immediately above this text--does fix the problem. Even adding (2

<<

Quoted 9 lines
Quoted 1 line

12) (instead of (1 << 12)) to the mmap_size will work on the system

I'm

Quoted 7 lines

testing with.

Quoted 1 line

I've changed it to 3. Thanks. It's annoying that even such simple operations as we have between find_efi_mmap and finish drastically increase memory map size.

Quoted 6 lines
Quoted 3 lines

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

Thanks! I completely agree that it is annoying.

Quoted 6 lines

FYI, while grub-2.00 works on my system now, someone else here at Dell has tested it and found that it still doesn't work. (I verified that they were indeed using version 2.00, and saw the error myself).

I have no idea how or why the memory map size is growing that much. As I get time, I'll try to figure that out...

FYI again:

I've found the problem. The memory map is not growing wildly... it is more of a firmware "quirk." The firmware is thinking it needs a larger buffer than it actually needs. So calls to GetMemoryMap with a buffer that is smaller than (say) 52368 bytes will return EFI_BUFFER_TOO_SMALL and say that the buffer needs to be 52368 bytes, but then when you call it with a buffer that's 52368 bytes, it will put the memory map into the buffer and tell you that the memory map is in fact only (say) 24576 bytes.

Unfortunately, right now, find_efi_mmap_size() will then return 24576 bytes (plus 3 pages, aligned to a page size), which isn't enough, but not because the memory map size is growing...

I'll send in a patch for grub that will make it immune to this quirk... it should be pretty low risk (I'm thinking modify find_efi_mmap_size() to use the value of mmap_size that was passed to grub_efi_get_memory_map(), rather than the value of mmap_size that was returned from that function.) With that, I don't believe it would even need to add 3 pages to the memory map size (I watched the memory map size, and it is not growing significantly).

Stuart

#14 lore raw
Quoted 33 lines · On 29.06.2012 22:49, [email protected] wrote:
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

Vladimir,

The 2.00rc1 version of grub2 still doesn't fix the efi memory map

buffer size I've been working on (though I can see you are now allocating the efi memory map buffer very shortly before you are calling grub_efi_finish_boot_services()).

Quoted 2 lines

Increasing the mmap_size in find_efi_mmap_size()--as in the patch

immediately above this text--does fix the problem. Even adding (2

<<

Quoted 9 lines
Quoted 1 line

12) (instead of (1 << 12)) to the mmap_size will work on the system

I'm

Quoted 7 lines

testing with.

Quoted 1 line

I've changed it to 3. Thanks. It's annoying that even such simple operations as we have between find_efi_mmap and finish drastically increase memory map size.

Quoted 6 lines
Quoted 3 lines

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

Thanks! I completely agree that it is annoying.

Quoted 6 lines

FYI, while grub-2.00 works on my system now, someone else here at Dell has tested it and found that it still doesn't work. (I verified that they were indeed using version 2.00, and saw the error myself).

I have no idea how or why the memory map size is growing that much. As I get time, I'll try to figure that out...

Quoted 8 lines

FYI again:

I've found the problem. The memory map is not growing wildly... it is more of a firmware "quirk." The firmware is thinking it needs a larger buffer than it actually needs. So calls to GetMemoryMap with a buffer that is smaller than (say) 52368 bytes will return EFI_BUFFER_TOO_SMALL and say that the buffer needs to be 52368 bytes, but then when you call it with a buffer that's 52368 bytes, it will put the memory map into the buffer and tell you that the memory map is in fact only (say) 24576 bytes.

Unfortunately, right now, find_efi_mmap_size() will then return 24576 bytes (plus 3 pages, aligned to a page size), which isn't enough, but not because the memory map size is growing...

I'll send in a patch for grub that will make it immune to this quirk... it should be pretty low risk (I'm thinking modify find_efi_mmap_size() to use the value of mmap_size that was passed to grub_efi_get_memory_map(), rather than the value of mmap_size that was returned from that function.) With that, I don't believe it would even need to add 3 pages to the memory map size (I watched the memory map size, and it is not growing significantly).

What about this:
=== modified file 'grub-core/loader/i386/linux.c'

loader/i386/linux.c +5 -2
@@ -118,12 +118,13 @@ find_efi_mmap_size (void)
       int ret;
       grub_efi_memory_descriptor_t *mmap;
       grub_efi_uintn_t desc_size;
+      grub_efi_uintn_t cur_mmap_size = mmap_size;
 
-      mmap = grub_malloc (mmap_size);
+      mmap = grub_malloc (cur_mmap_size);
       if (! mmap)
 	return 0;
 
-      ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size, 0);
+      ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0);
       grub_free (mmap);
 
       if (ret < 0)
@@ -134,6 +135,8 @@ find_efi_mmap_size (void)
       else if (ret > 0)
 	break;
 
+      if (mmap_size < cur_mmap_size)
+	mmap_size = cur_mmap_size;
       mmap_size += (1 << 12);
     }
 

It will take the largest size returned which should be safe.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#15 lore raw
Quoted 94 lines · On 29.06.2012 22:49, [email protected] wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Vladimir,

The 2.00rc1 version of grub2 still doesn't fix the efi memory map

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

buffer size I've been working on (though I can see you are now allocating the efi memory map buffer very shortly before you are calling grub_efi_finish_boot_services()).

Quoted 2 lines

Increasing the mmap_size in find_efi_mmap_size()--as in the patch

immediately above this text--does fix the problem. Even adding (2

<<

Quoted 1 line
Quoted 1 line

12) (instead of (1 << 12)) to the mmap_size will work on the

system

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

I'm

Quoted 10 lines

testing with.

Quoted 1 line

I've changed it to 3. Thanks. It's annoying that even such simple operations as we have between find_efi_mmap and finish drastically increase memory map size.

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

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Thanks! I completely agree that it is annoying.

FYI, while grub-2.00 works on my system now, someone else here at Dell has tested it and found that it still doesn't work. (I

verified

Quoted 8 lines
Quoted 4 lines

that they were indeed using version 2.00, and saw the error myself).

I have no idea how or why the memory map size is growing that much. As I get time, I'll try to figure that out...

FYI again:

I've found the problem. The memory map is not growing wildly... it

is more of a firmware "quirk." The firmware is thinking it needs a larger buffer than it actually needs. So calls to GetMemoryMap with a buffer that is smaller than (say) 52368 bytes will return EFI_BUFFER_TOO_SMALL and say that the buffer needs to be 52368 bytes, but then when you call it with a buffer that's 52368 bytes, it will put the memory map into the buffer and tell you that the memory map is in fact only (say) 24576 bytes.

Quoted 2 lines

Unfortunately, right now, find_efi_mmap_size() will then return 24576

bytes (plus 3 pages, aligned to a page size), which isn't enough, but not because the memory map size is growing...

Quoted 2 lines

I'll send in a patch for grub that will make it immune to this

quirk... it should be pretty low risk (I'm thinking modify find_efi_mmap_size() to use the value of mmap_size that was passed to grub_efi_get_memory_map(), rather than the value of mmap_size that was returned from that function.) With that, I don't believe it would even need to add 3 pages to the memory map size (I watched the memory map size, and it is not growing significantly).

Quoted 1 line

What about this:
=== modified file 'grub-core/loader/i386/linux.c'

loader/i386/linux.c +6 -2
@@ -118,12 +118,13 @@ find_efi_mmap_size (void)
       int ret;
       grub_efi_memory_descriptor_t *mmap;
       grub_efi_uintn_t desc_size;
+      grub_efi_uintn_t cur_mmap_size = mmap_size;
 
-      mmap = grub_malloc (mmap_size);
+      mmap = grub_malloc (cur_mmap_size);
       if (! mmap)
 	return 0;
 
-      ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size,
 0);
+      ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0,
+ &desc_size, 0);
       grub_free (mmap);
 
       if (ret < 0)
@@ -134,6 +135,8 @@ find_efi_mmap_size (void)
       else if (ret > 0)
 	break;
 
+      if (mmap_size < cur_mmap_size)
+	mmap_size = cur_mmap_size;
       mmap_size += (1 << 12);
     }
 
Quoted 5 lines

It will take the largest size returned which should be safe.

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

That works great. Tested on a couple systems, including the one on which grub-2.00 failed.

Thanks!
Stuart