Messages in this thread | | | Date | Sat, 4 Aug 2018 11:23:34 -0700 (PDT) | From | Hugh Dickins <> | Subject | Re: [PATCH 3/7] x86/mm/init: pass unconverted symbol addresses to free_init_pages() |
| |
On Sat, 4 Aug 2018, Linus Torvalds wrote: > 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.
Thanks a lot for writing that up. You shamed me into grepping a little harder than I did yesterday, when all I could find were "- PAGE_OFFSET" conversions (maybe I got lost in 32-bit-land). I had missed __phys_addr_nodebug(), where the __START_KERNEL_map alternative is handled.
Hugh
| |