Coder Social home page Coder Social logo

0xax / linux-insides Goto Github PK

View Code? Open in Web Editor NEW
29.4K 1.4K 3.3K 20.74 MB

A little bit about a linux kernel

Home Page: http://0xax.gitbooks.io/linux-insides/content/index.html

License: Other

Shell 22.20% Python 50.07% Dockerfile 1.68% Makefile 26.04%
linux-kernel linux-insides linux

linux-insides's Introduction

linux-insides

A book-in-progress about the linux kernel and its insides.

The goal is simple - to share my modest knowledge about the insides of the linux kernel and help people who are interested in linux kernel insides, and other low-level subject matter. Feel free to go through the book Start here

Questions/Suggestions: Feel free about any questions or suggestions by pinging me at twitter @0xAX, adding an issue or just drop me an email.

Generating eBooks and PDFs - documentation

Mailing List

We have a Google Group mailing list for learning the kernel source code. Here are some instructions about how to use it.

Join

Send an email with any subject/content to [email protected]. Then you will receive a confirmation email. Reply it with any content and then you are done.

If you have Google account, you can also open the archive page and click Apply to join group. You will be approved automatically.

Send emails to mailing list

Just send emails to [email protected]. The basic usage is the same as other mailing lists powered by mailman.

Archives

https://groups.google.com/forum/#!forum/kernelhacking

On other languages

Docker

In order to run your own copy of the book with gitbook within a local container:

  1. Enable Docker experimental features with vim or another text editor

     sudo vim /usr/lib/systemd/system/docker.service

    Then add --experimental=true to the end of the ExecStart=/usr/bin/dockerd -H fd:// line and save.

    Eg: ExecStart=/usr/bin/dockerd -H fd:// --experimental=true

    Then, you need to reload and restart the Docker daemon:

     systemctl daemon-reload
     systemctl restart docker.service
  2. Run docker image

    make run
  3. Open your local copy of linux insides book under this url http://localhost:4000 or run make browse

Contributions

Feel free to create issues or pull-requests if you have any problems.

Please read CONTRIBUTING.md before pushing any changes.

linux-kernel

Author

@0xAX

LICENSE

Licensed BY-NC-SA Creative Commons.

linux-insides's People

Contributors

0xax avatar ajouellette avatar akash0x53 avatar andars avatar changuoqiang avatar darkstar avatar dasty avatar douliyang avatar dwillmer avatar epheph avatar h4child avatar hedede avatar hitmoon avatar initbasti avatar ioworker0 avatar lemon1989 avatar michaelaquilina avatar mudongliang avatar nahakiole avatar nanxiao avatar olshevskiy87 avatar proninyaroslav avatar renaudgermain avatar ruthgrace avatar simar7 avatar sjp38 avatar spacewander avatar staroselskii avatar waqar144 avatar warpspeedscp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

linux-insides's Issues

Stack setup numbering

The numbering in Stack Setup under From Bootloader to Kernel is wrong. Instead of 1., 2., 3. it is 1., 1., 1.

Booting from Reset Vactor

I read your post it is really very informative. but i have some doubt.
I am trying to understand booting process.

  1. how cpu know about physical ram and Bios rom?
  2. what is reset vector and how can it save at 0xfffffff0 location beacuse ram is volatile memory.
  3. Bios works in real mode where only 1 mb can access how does cpu access 0xfffffff0( above 1 mb code)?
  4. how bios rom and ram maaped to each other?
  5. what about if system has 1 gb ram then how cpu access 0xfffffff0 ram?

Thanks & Regards
~Sumit Gemini

Capitalisation of sub-directories and other writing guidelines

Is there a special reason for not capitalising all other chapter directories except "interrupts" and "mm" ?

  1. If no reason, then can i submit a pull-request removing the capitalisation of few directories?
  2. Also better to have a writing-guideline.md describing common conventions to follow (and avoid) across all files.

Inlining, binary size

Not sure about this part:

always inlined to reduce size of the Linux kernel image

Isn't it pretty much the other way around. If you inline a function many many times, it would actually increase the size of the resulting binaries, not decrease them.

Add License

Is it possible to add a license that I can agree to before I submit a pull request?

some questions about "Early page tables initialization"

I read head_64.S and find when initialization level 3 (PDPE) entries, the flags are all 0x7, but you said: " where the first entry will be with 0x7 flags and the others with 0x8" , which I can not agreen. The same issue exists for level 2 (PDE) entries initialization. Can you give me a reasonable explanation ?
Thank you !

Spanish translation

I have already started the spanish translation of the first post. It's going a bit slow, since I'm all by myself. I have put links to the original repo and author. However, in other things I've put links
to my email an twitter account, since it will be regarding the translation. I hope that everything is ok.

https://github.com/leolas95/linux-insides

Spanish translation

I didn't know whether to put this here or create a PR, so sorry if this isn't the right place. I would like to see a Spanish translation of the book. I've just started with the first chapter, so I would like to know if it would be ok and no one has a problem with it.

Chinese Edition about this book?

I think this book is very interesting and useful. So I want to translate it to Chinese and publish it in the gitbook as the english version.
In order to ensure my work is not done yet, I ask in the issue.
Thank you all.

Typo

Hi,

you have a typo here:

The tick boradcast framework

Cheers,
Jean

How many kinds of List in Linux Kernel?

I have found two kinds of list in kernel : list_head, and hlist_head. The former is for doubly linked list, and the latter is for hash. Is there any other list structure?

0xffff0000:0xfff0 in protected mode is right?

CS register consists of two parts: the visible segment selector and hidden base address. We know predefined CS base and IP value, so the logical address will be:

0xffff0000:0xfff0

According to protected mode, the logical address should be "0xffff:0xfff0", is it ?

problem in ELF.md file

In linux , there are three kinds of file in elf format:

  • relocation file(object file)
  • execute file
  • shared object file

But in ELF.md file, you always say "elf object file". I don't know your original meaning, but this word will lead us confusion.
Besides, you should add the Linking View and Execution View. This will help to classify those three kinds of file.

What is the size of `struct thread_info` in linux-initialization-4?

In that chapter it says:

thread_info defined as:

struct thread_info {
        struct task_struct      *task;
        struct exec_domain      *exec_domain;
        __u32                   flags; 
        __u32                   status;
        __u32                   cpu;
        int                     saved_preempt_count;
        mm_segment_t            addr_limit;
        struct restart_block    restart_block;
        void __user             *sysenter_return;
        unsigned int            sig_on_uaccess_error:1;
        unsigned int            uaccess_err:1;
};

and occupies 52 bytes.

However, then it says:

The remaining thread_size will be 16 killobytes - 62 bytes = 16332 bytes.

At first I thought it as a typo. But, it seems that the size of thread_info is not less than 56 bytes whatever the size of struct restart_block is, because of memory alignment.
And its size can not be 62 bytes, again because of memory alignment. Its size should be the multiple of 8 bytes.

Suggestions: Assembly Syntax and Boot Sector Disassembly

Hi @0xAX,
thanks for your articles. Please find my two cents below:

  • Although in the "Required Knowledge" section we are starting by saying "Understanding assembly code (AT&T syntax)", most of the assembly code at least in linux-bootstrap-1.md is in Intel syntax. I think you should consider mentioning both Intel and AT&T given that if not more, Intel syntax is at least as commonly used as the AT&T syntax.
  • Here's a quick objdump command that you might consider adding to the article so that a curious reader can dump the compiled boot from boot.nasm, or an existing boot-sector from a running machine after having extracted the first 512 bytes using dd.
nasm -f binary boot.nasm
objdump -D -b binary -mi386 -Maddr16,data16,intel boot

Or,

dd if=/dev/sdaX of=boot bs=512 count=1
objdump -D -b binary -mi386 -Maddr16,data16,intel boot

阅读中遇到个问题,还望解答。

我在阅读https://0xax.gitbooks.io/linux-insides/content/Booting/linux-bootstrap-1.html, 做测试我使用install_gdt中使用的代码如下:

void install_gdt() {
static const u64 boot_gdt[] attribute((aligned(16))) = {
0
};
static const struct gdt_ptr gdtptr = {
.len = sizeof(boot_gdt),
.ptr = (u32)boot_gdt
};
asm volatile ("lgdtl %0" : : "m"(gdtptr));
}
连接脚本如下:
SECTIONS
{
. = 0;
.text16 : {
(.text16)
}
c32_begin = .;
.text32 : {
*(.text32)
}
. = ALIGN(16);
.rodata : {
*(.rodata
)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
/DISCARD/ : {
*(.MIPS.options)
*(.options)
*(.pdr)
*(.reginfo)
*(.comment)
*(.note)
}
}

我的问题是 生成的代码 访问的是地址是从0x0开始链接的(这个当然是这么的因为 . = 0;指定了), 但是我看linux的kernel 也是这么的 不晓得它是怎么让链接出来的地址能够和内存对应。

linux的链接接本https://github.com/torvalds/linux/blob/097f70b3c4d84ffccca15195bdfde3a37c0a7c0f/arch/x86/boot/setup.ld

"segement" typo?

Hi,
In the 3rd part of Kernel Booting Process, the word "segement" is used several times (for example on 9707a44#diff-bd7a5d6000784eb76eabb976454db43bR364). As this word occurs several times, I wonder whether this is "segment" with a typo or a technical word which was not defined. If it is a typo, could you please fix it?
Thanks

Chinese Edition Problems

I am sorry about Chinese Edition for linux-insides is misoperated to delete by one administrator in my organization.
Now the link in README for Chinese Edition is broken. I was contacting with Github Help to solve this problem and tried to persuade Github to restore my organization.
Apologies!
If github can't restore my organization, I will redirect the link to another repository.
@0xAX

the reset vector

you are saying the reset vector is

FFFF0000h:FFF0h

then add it as its segmented address

0xffff0000 + 0xfff0
'0xfffffff0'

according to your definition, to get linear address from segmented address, we need to multiple by 16 or left shit 4 and then add the offset right ? should it be

FFFFF000h:FFF0h

in real mode as explained in the
wiki page http://en.wikipedia.org/wiki/Reset_vector

Impact of cgroups constraints on memory

Regarding "Linux kernel memory management" -- I'd love to hear more about what impact there is to enabling cgroups-constraints on memory.

Empirically, I've seen that memory allocations made from within a cgroup-memory-constrained process appear to steal cycles to evict cache pages in the foreground (in order to make room for my allocation). This has a devastating impact on worst case latency for memory allocations.

About the minus 64 when setting the irq_stack_ptr

Hi,

In this chapter https://github.com/0xAX/linux-insides/blob/master/interrupts/interrupts-1.md , and more precisely, this snippet:

    per_cpu(irq_stack_ptr, cpu) =
            per_cpu(irq_stack_union.irq_stack, cpu) +
            IRQ_STACK_SIZE - 64;

I don't understand why the minus 64.

You say it's because of the stack canary, but the canary is at the bottom of the irq_stack_union, not the top. Also, you say it's because the canary is 64 bits long, but here we are reserving 64 bytes, not bits. Did I misunderstand something? Maybe this part needs clarification.

And thanks for the good work :)

Inconsistency with kernel setup offset

In linux-bootstrap-1, you say the offset of the actual kernel setup code is 0x200. But later in the document, you say state.cs = segment + 0x20 not 0x200. Also you write cs = 0x1020 where it seems like it should be cs = 0x10200. Do I have something wrong or were you just missing a digit?

Typo in 'syscall-1.md'

The current version reads
A system call is just an userspace request of a kernel service.
however proper grammar would read
A system call is just a userspace request of a kernel service.

Networking

I think it would be interesting for some description of the internals of how networking is handled in the kernel.

Get someone to proof read linkers.md

This is an interesting subject but the grammatical errors are too much.
Examples of grammatical errors:

  • The nm util allows us to see the list of symbols from the given object file. Look on the its output, it consists from the
  • Here we are interesting only in the two callq operations.

There are probably more but I just can't keep reading after things like this.

a sentence need to be explained

Here we can see the jump instruction opcode - 0xe9 to the address _start - ( . + 2),
 and we can see that the reset section is 16 bytes and starts at 0xfffffff0

This is one sentence from Booting/linux-bootstrap-1.md which I can't understand. Can someone explain it for me?

CS base, IP value, how logical address?

We know predefined CS base and IP value:

which is:

IP              0xfff0
CS selector     0xf000
CS base        0xffff0000

so our logical address will be:
0x0ffff000:0xfff0

How so?

New formatting paramenters suggestion

I would like to suggest some new formatting parameters:

  • Fit lines in 80 chars width (now is infinite long lines).
  • Beware of trailing whitespaces.

I've tried in this branch, but i've used automatic formatting and seems to be broken (bad backquotes handling).

Maybe some manual inspection or another autoformatting method would work.

Advice needed

Hey, I was going through your post, they are really good. I want to hack android os, for that I read some kernel development books and build some small drivers and modules. but still I didn't have much confidence in it, so please guide me how to hack kernel drivers from the start.

Typo in SysCall/syscall-1.md

Should the line 302 in linux-insides/SysCall/syscall-1.md be:

asmlinkage long sys_write(unsigned int fd, const char __user * buf, size_t count);

rather than:

asmlinkage long sys_write(unsigned int fd, const char __user * filename, size_t count);

codes

I need someone to help me remove codes that are put into my phones and computer...please

'__START_KERNEL' in ELF.h is not suitable

The following content is from Theory/ELF.h, but this part is not much related to the theme : ELF.
And they have already been in the linux initialization - linux-initialization-1.md.
I suggest we delete it.

We can read from the Documentation/x86/x86_64/mm.txt:
ffffffff80000000 - ffffffffa0000000 (=512 MB)  kernel text mapping, from phys 0
We can then look this address up in the vmlinux ELF object with:
        ......
        ......
__START_KERNEL_map is the value from the documentation - ffffffff80000000 and 
__PHYSICAL_START is 0x1000000. 
That's why address of the startup_64 is ffffffff81000000.

Help about Ctrl-Z and Ctrl-Y(urgent)

Unix systems support a large number of special characters that receive special processing by the OS. One such character is the “suspend” character (ctrl-Z by default), that causes a SIGTSTP signal to be sent to the application process. The default action for the signal is to suspend execution of the process. The system responds to the suspend character (by sending the signal) as soon as possible after it is typed in. In older Unix systems there was another special character known as the “delayed suspend” character (ctrl-Y by default) that had the same effect as the suspend character, except that the signal is sent when the application process consumes the character, rather than right away. (That this feature is no longer supported is perhaps some indication of how useful it was ...) The suspend and the delayed-suspend characters have the effect, when they are processed, of deleting all characters currently waiting to be read by the user application that arrived before them. Explain, how both special characters are implemented?

Heading has typo

"Impplementation of the gettimeofday system call"

Change that to "Implementation of the gettimeofday system call"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.