[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiboot ELF segment handling patch

From: Alexander Boettcher
Subject: Re: Multiboot ELF segment handling patch
Date: Thu, 26 Apr 2018 23:55:22 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 24.04.2018 12:42, Daniel Kiper wrote:
> On Mon, Apr 23, 2018 at 08:26:34PM +0200, Alexander Boettcher wrote:
>> On 17.04.2018 21:40, Daniel Kiper wrote
>>>> The overriden memory may contain device memory (vga text mode e.g.), which
>>>> leads to strange boot behaviour.
>>> Have you been able to take a look at memory allocator/relocator code why
>>> this happened?
>> for me it looks like, that either already
>> grub_relocator_alloc_chunk_addr or at latest
>> grub_relocator_prepare_relocs should bail out with an error, if the
>> memory range of the VGA memory (0xa0000 ++) is covered.
> Exactly!
>> What I don't know, respectively didn't found in the code, how and where
>> this information about this VGA text memory area is excluded/reserved
>> from the allocator/reallocator. Maybe you can give me a hint ?
> I have skimmed through the code and I think that you should take
> a look at grub-core/kern/i386/pc/init.c, grub-core/kern/mm.c and
> grub-core/lib/relocator.c. At first sight it looks that
> grub-core/kern/i386/pc/init.c:grub_machine_init() is the
> most interesting thing.
> I hope that helps. If you have further questions drop me a line.
> Thank you for taking a stab at this.

The whole lower 1M physical memory is reserved and not available for use
(done by grub-core/kern/i386/pc/init.c), but effectively ignored by
grub_relocator_alloc_chunk_addr for the non relocatable case during
multiboot segment load.

The adjust_limits call in grub_relocator_alloc_chunk_addr mainly sets
the min_addr to 0 and max_addr to end of physical memory. So
grub_relocator_alloc_chunk_addr will ever find a piece of (higher)
memory, mainly ignoring the target address (which is reserved, e.g.
below 1M).

The showcase code snippet below catches the case now. I don't know
whether it is correct nor do I like it ...

What do you think ?


--- a/grub-core/lib/relocator.c
+++ b/grub-core/lib/relocator.c
@@ -1226,7 +1237,7 @@ adjust_limits (struct grub_relocator *rel,
 grub_relocator_alloc_chunk_addr (struct grub_relocator *rel,
                                 grub_relocator_chunk_t *out,
-                                grub_phys_addr_t target, grub_size_t size)
+                                grub_phys_addr_t target, grub_size_t size, int 
   struct grub_relocator_chunk *chunk;
   grub_phys_addr_t min_addr = 0, max_addr;
@@ -1250,6 +1263,10 @@ grub_relocator_alloc_chunk_addr (struct
grub_relocator *rel,
                (unsigned long long) min_addr, (unsigned long long) max_addr,
                (unsigned long long) target);

+  if (!relocatable &&
+      !malloc_in_range (rel, target, target + size, 1, size, chunk, 0, 1))
+    return grub_error (GRUB_ERR_BUG, "target memory not available");
       /* A trick to improve Linux allocation.  */

Alexander Boettcher
Genode Labs -

Genode Labs GmbH - Amtsgericht Dresden - HRB 28424 - Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth

reply via email to

[Prev in Thread] Current Thread [Next in Thread]