My interest is not completely ingenuous, I hit an issue with memory corruption 
last week when PXE booting tboot. That's with  arather large (200MiB) initrd so 
I was wondering if it's somehow related (your patch does not fix my issue, 
though).
We found and fixed my issue (or at least the symptom I'm seeing), but I have a 
feeling the root cause is something like this.

Jan


> On 13 Jun 2016, at 17:38, Ahmed, Safayet (GE Global Research, US) 
> <safayet.ah...@ge.com> wrote:
> 
> Thanks for testing this so quickly, Jan.
> 
> I am aware of the code from the patch you mention. However, just moving 
> modules above the memory occupied by TBoot is not always enough for a 
> successful launch (especially when your kernel is large or you have a whole 
> bunch of modules).
> 
> Safayet
> 
> -----Original Message-----
> From: Jan Schermer [mailto:j...@schermer.cz] 
> Sent: Monday, June 13, 2016 11:32 AM
> To: Ahmed, Safayet (GE Global Research, US)
> Cc: tboot-devel@lists.sourceforge.net
> Subject: EXT: Re: [tboot-devel] Loading multiboot(2) images
> 
> I just wonder how it relates to this patch?
> https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceforge.net_p_tboot_mailman_message_28249969_&d=CwIFAg&c=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI&r=lDSLRzn8YUPmwjLuy9Ek9Dy-T15T3uK505eKqf1EFfg&m=0M9z_fwbfXh2WiB5AcWfW3ePsEIv1JkglOMQpbHgvK8&s=y-rxEOzbQBAUMjBfGgzT-DLHdCAibJzcGhO5ovi0-f8&e=
>  
> 
> For what it's worth, I tested this patch on my system, boots fine using PXE 
> GRUB2 multiboot.
> 
> Jan
> 
> 
> 
>> On 13 Jun 2016, at 16:52, Ahmed, Safayet (GE Global Research, US) 
>> <safayet.ah...@ge.com> wrote:
>> 
>> We have been experimenting with measured launch of environments other than 
>> Linux and Xen, such as the RTS hypervisor and some real-time operating 
>> systems. 
>> 
>> We have seen a recurring issue in some cases with the way TBoot launches 
>> multiboot/multiboot2 environments. Namely, when loading the ELF image, TBoot 
>> overwrites the kernel ELF image and modules.
>> 
>> Developers at RTS have made changes to "tboot/common/loader.c" and 
>> "tboot/common/elf.c" that addresses this issue:
>> When the follow-on kernel is a multiboot or multiboot2 kernel, move the 
>> modules to the top of memory as reported in the E820 map. Then, after 
>> loading the kernel ELF binary into its final location in memory, move the 
>> modules to a location just above the kernel.
>> 
>> The patches for these changes are below.
>> 
>> thanks,
>> 
>> Safayet
>> 
>> Signed-off-by: Raphael Baum  <r.b...@real-time-systems.com>
>> Signed-off-by: Safayet Ahmed <safayet.ah...@ge.com>
>> 
>> diff -r 6531a0eaf369 tboot/common/elf.c
>> --- a/tboot/common/elf.c    Wed May 18 10:13:24 2016 -0700
>> +++ b/tboot/common/elf.c    Mon Jun 13 10:19:02 2016 -0400
>> @@ -146,7 +146,5 @@
>> }
>> 
>> -#if 0
>> -static bool get_elf_image_range(const elf_header_t *elf, void **start,
>> -                                void **end)
>> +bool get_elf_image_range(const elf_header_t *elf, void **start, void 
>> +**end)
>> {
>>    uint32_t u_start, u_end;
>> @@ -189,5 +187,4 @@
>>    }
>> }
>> -#endif
>> 
>> bool expand_elf_image(const void *image, void **entry_point) diff -r 
>> 6531a0eaf369 tboot/common/loader.c
>> --- a/tboot/common/loader.c    Wed May 18 10:13:24 2016 -0700
>> +++ b/tboot/common/loader.c    Mon Jun 13 10:19:02 2016 -0400
>> @@ -4,4 +4,5 @@
>> *
>> * Copyright (c) 2006-2013, Intel Corporation
>> + * Copyright (c) 2016 Real-Time Systems GmbH
>> * All rights reserved.
>> *
>> @@ -65,5 +66,5 @@
>> /* multiboot struct saved so that post_launch() can use it (in 
>> tboot.c) */ extern loader_ctx *g_ldr_ctx;
>> -
>> +extern bool get_elf_image_range(const elf_header_t *elf, void 
>> +**start, void **end);
>> extern bool is_elf_image(const void *image, size_t size); extern bool 
>> expand_elf_image(const elf_header_t *elf, void **entry_point); @@ 
>> -770,4 +771,96 @@ }
>> 
>> +/*
>> + * Move all mbi components/modules/mbi to end of memory  */ static 
>> +bool move_modules_to_high_memory(loader_ctx *lctx) {
>> +    uint64_t max_ram_base = 0,
>> +             max_ram_size = 0;
>> +    uint32_t memRequired = 0;
>> +
>> +    uint32_t module_count = get_module_count(lctx);
>> +
>> +    for ( unsigned int i = 0; i < module_count; i++ )
>> +    {
>> +        module_t *m = get_module(lctx,i);
>> +        memRequired += PAGE_UP(m->mod_end - m->mod_start);
>> +    }
>> +
>> +    get_highest_sized_ram(memRequired, 0x100000000ULL, &max_ram_base, 
>> &max_ram_size);
>> +    if(!max_ram_base || !max_ram_size)
>> +    {
>> +        printk(TBOOT_INFO"ERROR No suitable memory area found for image 
>> relocation!\n");
>> +    printk(TBOOT_INFO"required 0x%X\n", memRequired);
>> +        return false;
>> +    }
>> +
>> +    printk(TBOOT_INFO"highest suitable area @ 0x%llX (size 
>> + 0x%llX)\n", max_ram_base, max_ram_size);
>> +
>> +    unsigned long target_addr =  PAGE_DOWN(max_ram_base + 
>> + max_ram_size);
>> +
>> +    for ( unsigned int i = 0; i < module_count; i++ )
>> +    {
>> +        unsigned long base, size;
>> +        module_t *m = get_module(lctx,i);
>> +        base = m->mod_start;
>> +        size = m->mod_end - m->mod_start;
>> +        printk(TBOOT_INFO"moving module %u (%lu bytes) from 0x%08X ", 
>> + i, size, (uint32_t)base);
>> +
>> +        //calculate target addresses
>> +        target_addr = PAGE_DOWN(target_addr - size);
>> +        printk(TBOOT_INFO"to 0x%08X\n", (uint32_t)target_addr);
>> +
>> +        memcpy((void *)target_addr, (void *)base, size);
>> +        m->mod_start = target_addr;
>> +        m->mod_end = target_addr + size;
>> +    }
>> +
>> +    return true;
>> +}
>> +
>> +/*
>> + * Move any mbi components/modules/mbi that just above the kernel  */ 
>> +static bool move_modules_above_elf_kernel(loader_ctx *lctx, 
>> +elf_header_t *kernel_image) {
>> +    if (LOADER_CTX_BAD(lctx))
>> +        return false;
>> +
>> +    /* get end address of loaded elf image */
>> +    void *elf_start=NULL, *elf_end=NULL;
>> +    if ( !get_elf_image_range(kernel_image, &elf_start, &elf_end) )
>> +    {
>> +        printk(TBOOT_INFO"ERROR: failed tget elf image range\n");
>> +    }
>> +
>> +    printk(TBOOT_INFO"ELF kernel top is at 0x%X\n", 
>> + (uint32_t)elf_end);
>> +
>> +    /* keep modules page aligned */
>> +    uint32_t target_addr = PAGE_UP((uint32_t)elf_end);
>> +
>> +    uint32_t module_count = get_module_count(lctx);
>> +
>> +    for ( unsigned int i = 0; i < module_count; i++ )
>> +    {
>> +        unsigned long base, size;
>> +        module_t *m = get_module(lctx,i);
>> +        base = m->mod_start;
>> +        size = m->mod_end - m->mod_start;
>> +        printk(TBOOT_INFO"moving module %u (%lu bytes) from 0x%08X ", 
>> + i, size, (uint32_t)base);
>> +
>> +        //calculate target addresses
>> +        printk(TBOOT_INFO"to 0x%08X\n", (uint32_t)target_addr);
>> +
>> +        memcpy((void *)target_addr, (void *)base, size);
>> +        m->mod_start = target_addr;
>> +        m->mod_end = target_addr + size;
>> +
>> +        target_addr = PAGE_UP(target_addr + size);
>> +    }
>> +
>> +    return true;
>> +}
>> +
>> static void fixup_modules(loader_ctx *lctx, size_t offset) { @@ 
>> -1245,4 +1338,9 @@
>>        /* fix for GRUB2, which may load modules into memory before tboot */
>>        move_modules(g_ldr_ctx);
>> +
>> +        /* move modules out of the way (to top og memory below 4G) */
>> +        printk(TBOOT_INFO"move modules to high memory\n");
>> +        if(!move_modules_to_high_memory(g_ldr_ctx))
>> +            return false;
>>    }
>>    else {
>> @@ -1263,4 +1361,9 @@
>>                               &kernel_entry_point) )
>>            return false;
>> +
>> +        /* move modules on top of expanded kernel */
>> +        if(!move_modules_above_elf_kernel(g_ldr_ctx, (elf_header_t 
>> *)kernel_image))
>> +            return false;
>> +
>>        printk(TBOOT_INFO"transfering control to kernel @%p...\n", 
>>               kernel_entry_point);
>> 
>> ----------------------------------------------------------------------
>> -------- What NetFlow Analyzer can do for you? Monitors network 
>> bandwidth and traffic patterns at an interface-level. Reveals which 
>> users, apps, and protocols are consuming the most bandwidth. Provides 
>> multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make 
>> informed decisions using capacity planning reports. 
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__ad.doubleclick.ne
>> t_ddm_clk_305295220-3B132659582-3Be&d=CwIFAg&c=IV_clAzoPDE253xZdHuilRg
>> ztyh_RiV3wUrLrDQYWSI&r=lDSLRzn8YUPmwjLuy9Ek9Dy-T15T3uK505eKqf1EFfg&m=0
>> M9z_fwbfXh2WiB5AcWfW3ePsEIv1JkglOMQpbHgvK8&s=scsOwVjiA7m7VhkaHYc_poWfP
>> MxJ575XkWR3-fJ3DWA&e= _______________________________________________
>> tboot-devel mailing list
>> tboot-devel@lists.sourceforge.net
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.sourceforge
>> .net_lists_listinfo_tboot-2Ddevel&d=CwIFAg&c=IV_clAzoPDE253xZdHuilRgzt
>> yh_RiV3wUrLrDQYWSI&r=lDSLRzn8YUPmwjLuy9Ek9Dy-T15T3uK505eKqf1EFfg&m=0M9
>> z_fwbfXh2WiB5AcWfW3ePsEIv1JkglOMQpbHgvK8&s=H4OvP3USeX0sDYNBb7H3PFMvpjs
>> XH5brWBHA8c8VLqE&e=
> 


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
tboot-devel mailing list
tboot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tboot-devel

Reply via email to