2
votes

In x86 arch, linux kernel 2.6.x, 32bit system

I understand that virtual address 0xC0000000 ~ 0xFFFFFFFF

is reserved for kernel.

and this virtual address can be translated to physical address by

subtracting 0xC0000000.

however, I think even the result is same, MMU will translate

the kernel virtual address(such as 0xC0851000) to physical address by walking through page table.

such as

CR3 -> page directory -> page table -> PFN.

am I correct or wrong?, please correct me if I'm wrong.

I need to develop hardware based kernel monitor in x86, linux 32bit system.

so I need to know this problem

please help.

2
"and this virtual address can be translated to physical address by subtracting 0xC0000000" --- no, no, no. The MMU translates some address to some other physical address. Contiguous virtual addresses are not necessarily contiguous physical addresses, nor in any particular address range. Only addresses within the same 4k page (or 2M with huge pages) are really guaranteed to are contiguous with each other.Damon
are you sure about this? because I have seen a lot of articles which describes unlike user space virtual memory and highmem area, kernel virtual address(0xC0000000 ~ 0xFFFFFFFF) is linearly mapped to physical memory... (that is why __va, __pa are simple)daehee
It is of course possible to do such a thing, for simplicity, and Linux may even do that on some architectures. But you have no guarantee that this is the case, and no guarantee that it won't change tomorrow. In general, logical addresses are translated to physical in an "obscure" way (obscure to you, not to the OS), with no clear 1:1 relationship and no clear rules about being at a particular address (no rules that you know about) or contiguous with an address in any other page.Damon
thank you, It seems your right!daehee

2 Answers

3
votes

For kernel logical addresses, you are correct. Kernel virtual addresses, like memory allocated by vmalloc, do not necessarily have a one-to-one mapping to physical addresses that characterize the logical address space, however.

Just bear in mind that kernel logical addresses aren't always translated to physical by subtracting an offset (that's true in x86 but not, say, AVR32).

0
votes

"and this virtual address can be translated to physical address by

subtracting 0xC0000000"

since page tables for the kernel virtual addresses are configured that way, people have come up with a shortcut you mentioned.