<div dir="ltr">I`m still reading all the resources, but I found a few more. <div><br></div><div><a href="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/mem.html" target="_blank">http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/mem.html</a><br>
</div><div><br></div><div><br></div><div>I didn`t find a few answers yet, but how a module is loaded ? </div><div>When you do a insmod the kernel take some pages and load all the module's sections to these pages ? </div>
<div>How this work ? Where I can find more information about memory allocation for a new module. </div><div>If I don`t find, I will read the source code for that part, but I try to find a better way to learn. I know that source code is the best and updated, but takes more time too. </div>
<div><br></div><div><br></div><div>And when I do a int inside my module I suppose that my int will be inside that pages that kernel allocated for my new module. Right ?? </div><div>But if I do this inside kernel code ? It's compiler task do allocate this memory in sections ? How the kernel runs ? Like my module is driven by kernel, but how kernel driven it's self ???</div>
<div><br></div><div><br></div><div>Thanks</div><div><br></div><div><br></div><div><br></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><div>--</div>Lucas Tanure <br><a href="tel:%2B55%20%2819%29%20988176559" value="+5519988176559" target="_blank">+55 (19) 988176559</a><br>
</div></div>
<br><br><div class="gmail_quote">On Tue, Aug 5, 2014 at 12:31 AM, Peter Teoh <span dir="ltr"><<a href="mailto:htmldeveloper@gmail.com" target="_blank">htmldeveloper@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">And Q2:<div><br></div><div>Just want to comment that the load address has to be fixed initially, because unlike normal ELF, after loading ELF, there is a relocation tasks done by the linker. In vmlinuz we cannot have relocation, before executing the kernel is the BIOS / uboot / bootloader etc. One possible answer. Others:<br>
</div><div><br></div><div><div><a href="https://groups.google.com/forum/#!topic/comp.os.linux.embedded/0-SAzCqQKFM" target="_blank">https://groups.google.com/forum/#!topic/comp.os.linux.embedded/0-SAzCqQKFM</a><br></div>
</div><div><br></div>
<div>And perhaps some of the links below may help you:</div><div><br></div><div><a href="http://jianggmulab.blogspot.sg/2010_01_01_archive.html" target="_blank">http://jianggmulab.blogspot.sg/2010_01_01_archive.html</a><div>
<br></div><div>
<a href="http://stackoverflow.com/questions/5647279/why-does-the-module-start-from-address-0xbf000000" target="_blank">http://stackoverflow.com/questions/5647279/why-does-the-module-start-from-address-0xbf000000</a><br></div>
<div><br></div>
<div><a href="http://www.arm.linux.org.uk/developer/memory.txt" target="_blank">http://www.arm.linux.org.uk/developer/memory.txt</a><br></div><div><br></div><div><a href="http://en.wikipedia.org/wiki/High_memory" target="_blank">http://en.wikipedia.org/wiki/High_memory</a><br>
</div><div><br></div><div>bottomline: keep googling.</div></div><div><br></div><div>Q6 and 7 makes no sense to me....sorry.</div><div><br></div></div><div class="gmail_extra"><div><div><br><br><div class="gmail_quote">
On Mon, Aug 4, 2014 at 11:22 PM, Lucas Tanure <span dir="ltr"><<a href="mailto:tanure@linux.com" target="_blank">tanure@linux.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks!<br>
<br>
A quick look in all of that show me that there a lot of information<br>
about how kernel manage memory.<br>
But, I will find the answer for question 2, 6 and 7 in it ?<br>
<br>
Thanks!<br>
<div>--<br>
Lucas Tanure<br>
<a href="tel:%2B55%20%2819%29%20988176559" value="+5519988176559" target="_blank">+55 (19) 988176559</a><br>
<br>
<br>
</div><div><div>On Sun, Aug 3, 2014 at 8:58 PM, Peter Teoh <<a href="mailto:htmldeveloper@gmail.com" target="_blank">htmldeveloper@gmail.com</a>> wrote:<br>
> I like your curiosities and interests in Linux<br>
> kernel.<a href="http://virtuallyhyper.com/2013/07/rhcsa-and-rhce-chapter-10-the-kernel/" target="_blank">http://virtuallyhyper.com/2013/07/rhcsa-and-rhce-chapter-10-the-kernel/</a><br>
><br>
> Instead of answering one by one, I think I will just identify the knowledge<br>
> you are lacking:<br>
><br>
> Memory management (from both x86/intel and linux kernel perspective).<br>
><br>
> There are many many resources out there for you in these area, eg:<br>
><br>
> <a href="http://en.wikipedia.org/wiki/Page_table" target="_blank">http://en.wikipedia.org/wiki/Page_table</a><br>
> <a href="http://en.wikipedia.org/wiki/X86-64" target="_blank">http://en.wikipedia.org/wiki/X86-64</a><br>
><br>
> (both boring, but just understand it well enough)<br>
><br>
> <a href="http://wiki.osdev.org/Paging" target="_blank">http://wiki.osdev.org/Paging</a> (good explanation....understand it very very<br>
> well).<br>
><br>
> The ultimate classic ebook:<br>
><br>
> <a href="https://www.kernel.org/doc/gorman/pdf/understand.pdf" target="_blank">https://www.kernel.org/doc/gorman/pdf/understand.pdf</a><br>
><br>
> And this blog site has tons of good info on intel/memory etc:<br>
><br>
> <a href="http://duartes.org/gustavo/blog/post/cpu-rings-privilege-and-protection/" target="_blank">http://duartes.org/gustavo/blog/post/cpu-rings-privilege-and-protection/</a><br>
> <a href="http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory/" target="_blank">http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory/</a><br>
><br>
> <a href="http://virtuallyhyper.com/2013/07/rhcsa-and-rhce-chapter-10-the-kernel/" target="_blank">http://virtuallyhyper.com/2013/07/rhcsa-and-rhce-chapter-10-the-kernel/</a><br>
><br>
> <a href="http://www.cse.psu.edu/~anand/spring01/linux/memory.ppt" target="_blank">http://www.cse.psu.edu/~anand/spring01/linux/memory.ppt</a><br>
><br>
> One more thing:<br>
><br>
> "readelf -S -W vmlinux" shows u the sections and the address where the<br>
> different sections are supposed to be loaded in memory. If u replace the<br>
> vmlinux with the kernel module, eg: ip_tables.ko, then it says:<br>
><br>
> starting at offset 0x328c blah blah....<br>
><br>
> so the loaded address is with respect to ZERO, but then the actual module<br>
> address is:<br>
><br>
> sudo cat /proc/modules |grep ip_table<br>
><br>
> ip_tables 18106 1 iptable_filter, Live 0xf8bf5000<br>
><br>
> So all the output from your readelf, just add 0xf8bf5000 to it and you will<br>
> get the actual virtual address of that section IN MEMORY.<br>
><br>
> Just only in memory. In file, the file offset of the section is different.<br>
> And many parts inside the ELF is also different from memory too: you will<br>
> need to add the virtual load address (above) to the offset as specified<br>
> inside the relocation tables (objdump -r), and for each section there is a<br>
> separate relocation table (all independent from another, meaning that the<br>
> different section CAN BE loaded to different parts in memory).<br>
><br>
> Thanks.<br>
><br>
><br>
> On Sun, Aug 3, 2014 at 11:59 PM, Lucas Tanure <<a href="mailto:tanure@linux.com" target="_blank">tanure@linux.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I'm looking for some site, pdf, book etc, that can answer this questions.<br>
>> For now I have :<br>
>><br>
>> <a href="http://unix.stackexchange.com/questions/5124/what-does-the-virtual-kernel-memory-layout-in-dmesg-imply" target="_blank">http://unix.stackexchange.com/questions/5124/what-does-the-virtual-kernel-memory-layout-in-dmesg-imply</a><br>
>><br>
>><br>
>> I want to understand a few things about the memory and the execution<br>
>> of Linux kernel.<br>
>> Taking from a X86 and grub I have:<br>
>><br>
>> 1) Grub loads kernel and root file system in memory, and the vmlinux<br>
>> has the code to decompress it self, right ? linux<br>
>><br>
>> 2) The address of load kernel is always the same ? And It's at<br>
>> compilation time that is chosen ?<br>
>><br>
>> 2a) The kernel takes places in 3g-4g memory place, and user space from 0<br>
>> to 3gb.<br>
>> But if the pc has only 256mb of memory ?<br>
>> And when pc has 16gb of memory, the user space will be split in two ?<br>
>><br>
>> 2b) And if kernel has soo many modules that needs more than 1gb to run ?<br>
>><br>
>> 2c) How we configure all of that memory configs ? make menuconfig and<br>
>> friends ?<br>
>><br>
>> 3) The function A will call functon B. B is at 0xGGGGGG in .text<br>
>> section, but kernel was loaded in address 0xJJJJJJJJJJ, how A will<br>
>> find B ?<br>
>><br>
>> 4) Please consider this:<br>
>> $ readelf -S -W vmlinux<br>
>> There are 37 section headers, starting at offset 0xe05718:<br>
>><br>
>> Section Headers:<br>
>> [Nr] Name Type Address<br>
>> Off Size ES Flg Lk Inf Al<br>
>> [ 0] NULL<br>
>> 0000000000000000 000000 000000 00 0 0 0<br>
>> [ 1] .text PROGBITS<br>
>> ffffffff81000000 200000 53129a 00 AX 0 0 4096<br>
>> [ 2] .notes NOTE<br>
>> ffffffff8153129c 73129c 0001d8 00 AX 0 0 4<br>
>> [ 3] __ex_table PROGBITS ffffffff81531480<br>
>> 731480 002018 00 A 0 0 8<br>
>> [ 4] .rodata PROGBITS<br>
>> ffffffff81600000 800000 1655ee 00 A 0 0 64<br>
>> [ 5] __bug_table PROGBITS ffffffff817655f0<br>
>> 9655f0 005424 00 A 0 0 1<br>
>> [ 6] .pci_fixup PROGBITS ffffffff8176aa18<br>
>> 96aa18 002f88 00 A 0 0 8<br>
>> [ 7] .tracedata PROGBITS ffffffff8176d9a0<br>
>> 96d9a0 00003c 00 A 0 0 1<br>
>> [ 8] __ksymtab PROGBITS ffffffff8176d9e0<br>
>> 96d9e0 00e710 00 A 0 0 16<br>
>> [ 9] __ksymtab_gpl PROGBITS ffffffff8177c0f0<br>
>> 97c0f0 00a150 00 A 0 0 16<br>
>> [10] __kcrctab PROGBITS ffffffff81786240<br>
>> 986240 007388 00 A 0 0 8<br>
>> [11] __kcrctab_gpl PROGBITS ffffffff8178d5c8<br>
>> 98d5c8 0050a8 00 A 0 0 8<br>
>> [12] __ksymtab_strings PROGBITS ffffffff81792670<br>
>> 992670 01cb42 00 A 0 0 1<br>
>> [13] __init_rodata PROGBITS ffffffff817af1c0<br>
>> 9af1c0 0000e8 00 A 0 0 32<br>
>> [14] __param PROGBITS ffffffff817af2a8<br>
>> 9af2a8 000b00 00 A 0 0 8<br>
>> [15] __modver PROGBITS ffffffff817afda8<br>
>> 9afda8 000258 00 A 0 0 8<br>
>> [16] .data PROGBITS<br>
>> ffffffff81800000 a00000 0e1180 00 WA 0 0 4096<br>
>> [17] .vvar PROGBITS<br>
>> ffffffff818e2000 ae2000 001000 00 WA 0 0 16<br>
>> [18] .data..percpu PROGBITS 0000000000000000<br>
>> c00000 015300 00 WA 0 0 4096<br>
>> [19] .init.text PROGBITS<br>
>> ffffffff818f9000 cf9000 0503ea 00 AX 0 0 16<br>
>> [20] .init.data PROGBITS<br>
>> ffffffff8194a000 d4a000 09e4c8 00 WA 0 0 4096<br>
>> [21] .x86_cpu_dev.init PROGBITS ffffffff819e84c8<br>
>> de84c8 000018 00 A 0 0 8<br>
>> [22] .parainstructions PROGBITS ffffffff819e84e0<br>
>> de84e0 00bd3c 00 A 0 0 8<br>
>> [23] .altinstructions PROGBITS ffffffff819f4220<br>
>> df4220 005f40 00 A 0 0 1<br>
>> [24] .altinstr_replacement PROGBITS ffffffff819fa160<br>
>> dfa160 001a69 00 AX 0 0 1<br>
>> [25] .iommu_table PROGBITS ffffffff819fbbd0<br>
>> dfbbd0 0000f0 00 A 0 0 8<br>
>> [26] .apicdrivers PROGBITS ffffffff819fbcc0<br>
>> dfbcc0 000020 00 WA 0 0 8<br>
>> [27] .exit.text PROGBITS ffffffff819fbce0<br>
>> dfbce0 0009bc 00 AX 0 0 1<br>
>> [28] .smp_locks PROGBITS ffffffff819fd000<br>
>> dfd000 005000 00 A 0 0 4<br>
>> [29] .data_nosave PROGBITS ffffffff81a02000<br>
>> e02000 001000 00 WA 0 0 4<br>
>> [30] .bss NOBITS<br>
>> ffffffff81a03000 e03000 122000 00 WA 0 0 4096<br>
>> [31] .brk NOBITS<br>
>> ffffffff81b25000 e03000 425000 00 WA 0 0 1<br>
>> [32] .comment PROGBITS 0000000000000000<br>
>> e03000 000027 01 MS 0 0 1<br>
>> [33] .debug_frame PROGBITS 0000000000000000<br>
>> e03028 002560 00 0 0 8<br>
>> [34] .shstrtab STRTAB<br>
>> 0000000000000000 e05588 00018a 00 0 0 1<br>
>> [35] .symtab SYMTAB 0000000000000000<br>
>> e06058 1a29f8 18 36 43659 8<br>
>> [36] .strtab STRTAB<br>
>> 0000000000000000 fa8a50 180d92 00 0 0 1<br>
>> Key to Flags:<br>
>> W (write), A (alloc), X (execute), M (merge), S (strings), l (large)<br>
>> I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)<br>
>> O (extra OS processing required) o (OS specific), p (processor specific)<br>
>><br>
>> So the vmlinux is loaded in memory like a dd ?<br>
>><br>
>> 5) In my function A, inside the module that I wrote, a non-initialized<br>
>> variable will take place in non-initialized section that was loaded in<br>
>> memory ?<br>
>> Or my modules has a new sections for it's own use, and my module is<br>
>> loaded my memory like a process, with all his sections?<br>
>> So how another module or kernel code will fin my exported<br>
>> variable/function ?<br>
>><br>
>><br>
>> 6) Let's suppose:<br>
>> I have a int variable, with 17 as content, and the address is 0xGGGGGG.<br>
>> If I stop the linux in this time, read my memory at address 0xGGGGGG I<br>
>> will got 17, right ?<br>
>> 0xGGGGGGG will be bigger than 0xc0000000 always, right ?<br>
>><br>
>><br>
>> 7) Now take int from question and change for:<br>
>> struct mystruct * foo = (struct mystruct* ) kmalloc(sizeof(struct<br>
>> mystruct));<br>
>><br>
>> I will be able to read at address 0xGGGGGG the struct that created,<br>
>> and it address will be greater than 0xc0000000, right ?<br>
>> But for this struct, the memory will be allocated for ever, until I<br>
>> free the pointer, right ?<br>
>><br>
>><br>
>><br>
>> Well, this just a start. I really want to understand how kernel is<br>
>> run, loaded etc. Any help is appreciate, answering my questions, links<br>
>> to read, books to read.<br>
>> Actually, I didn't find any book with that kind of information .<br>
>><br>
>><br>
>> --<br>
>> Lucas Tanure<br>
>> <a href="tel:%2B55%20%2819%29%20988176559" value="+5519988176559" target="_blank">+55 (19) 988176559</a><br>
>><br>
>> --<br>
>> To unsubscribe, send a message with 'unsubscribe linux-mm' in<br>
>> the body to <a href="mailto:majordomo@kvack.org" target="_blank">majordomo@kvack.org</a>. For more info on Linux MM,<br>
>> see: <a href="http://www.linux-mm.org/" target="_blank">http://www.linux-mm.org/</a> .<br>
>> Don't email: <a href=mailto:"<a href="mailto:dont@kvack.org" target="_blank">dont@kvack.org</a>"> <a href="mailto:email@kvack.org" target="_blank">email@kvack.org</a> </a><br>
><br>
><br>
><br>
><br>
> --<br>
> Regards,<br>
> Peter Teoh<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span><font color="#888888">-- <br>Regards,<br>Peter Teoh
</font></span></div>
</blockquote></div><br></div></div>