Messages in this thread | | | From | Linus Torvalds <> | Date | Sat, 4 Aug 2018 10:31:29 -0700 | Subject | Re: [PATCH 3/7] x86/mm/init: pass unconverted symbol addresses to free_init_pages() |
| |
On Fri, Aug 3, 2018 at 5:19 PM Hugh Dickins <hughd@google.com> wrote: > > I thought that virt_to_page() only works on virtual addresses > in the direct map
You're right that virt_to_page() does not work on any _actual_ virtual mappings (ie no user pages, and no vmalloc() pages etc). It does not follow page tables at all.
And on 32-bit, it literally ends up doing (see __phys_addr_nodebug()) a simple
#define __phys_addr_nodebug(x) ((x) - PAGE_OFFSET)
However, on x86-64, we have *two* cases of direct mappings: we have the one at __START_KERNEL_map, and we have the one at PAGE_OFFSET.
And virt_to_page() handles both of those direct mappings.
Annoying? Yes. And it has caused bugs in the past. And I entirely forget why we needed it on x86-64.
[ Goes around and rummages ]
Oh, never mind, looking around reminded me why: we want to map the kernel text in the top 31 bits, so that we can use the faster -mcmodel=kernel because all symbols fit in sign-extended 32 bits.
Maybe there was some other reason too, but I think that's it.
Linus
| |