How does Linux not pagefault when jumping to the decompressed bzImage in x86_64?
Harm Smits <[email protected]> Wed, 16 Mar 2022 15:10:04 +0100
| Newsgroups | gmane.linux.newbie |
|---|---|
| Message-ID | <CAO64rh6iYkLMfPnykJJ9VqVK2HUP+=9e9RVd1j5b7OpLAMEfiA@mail.gmail.com> |
Hello! For the past few weeks I have been trying to figure out how Linux boots in its entirety as I found it rather interesting. However, I have now come to a point where I am nothing short of confused. As we can see in the linking script (vmlinux.lds.S), it is offset to a certain address, namely __START_KERNEL. This define resolves to __START_KERNEL_map + __PHYSICAL_START. So the entire 'kernel image' is (from as far as my understanding goes) shifted by __START_KERNEL_map, which holds a value of 0xffffffff80000000. Now, when decompression has finished, it dereferences the first few bytes of bzImage to get the address of `startup_64`, and it jumps to the defined address and resumes execution while still in physical address space. But how can they execute code that is compiled to be run at a completely different address space, without causing page faults? When I attempt to do the same, writing to the descriptor of the temporary GDT causes it to have an access violation at address 0xffffffff8141d0a0 (https://github.com/torvalds/linux/blob/56e337f2cf1326323844927a04e9dbce9a244835/arch/x86/kernel/head64.c#L616) Any help or resources on this would be greatly appreciated. -- Kind regards, Harm Smits