Re: [PATCH v2 2/4] x86, boot: PUD VA support for physical mapping (x86_64)

Baoquan He
2016-05-03T10:05:37Z

On 05/02/16 at 02:58pm, Dave Hansen wrote:
> On 05/02/2016 02:41 PM, Thomas Garnier wrote:
> > Minor change that allows early boot physical mapping of PUD level virtual
> > addresses. This change prepares usage of different virtual addresses for
> > KASLR memory randomization. It has no impact on default usage.
> ...
> > diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
> > index 89d9747..6adfbce 100644
> > --- a/arch/x86/mm/init_64.c
> > +++ b/arch/x86/mm/init_64.c
> > @@ -526,10 +526,10 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
> > {
> > unsigned long pages = 0, next;
> > unsigned long last_map_addr = end;
> > - int i = pud_index(addr);
> > + int i = pud_index((unsigned long)__va(addr));
> >
> > for (; i < PTRS_PER_PUD; i++, addr = next) {
> > - pud_t *pud = pud_page + pud_index(addr);
> > + pud_t *pud = pud_page + pud_index((unsigned long)__va(addr));
> > pmd_t *pmd;
> > pgprot_t prot = PAGE_KERNEL;
>
> pud_index() is supposed to take a virtual address. We were passing a
> physical address in here, and it all just worked because PAGE_OFFSET is
> PUD-aligned. Now that you are moving PAGE_OFFSET around a bit and not
> PUD-aligning it, this breaks. Right?

Yes. Acutally here code is tricky since PAGE_OFFSET is PUD-aligned or
. Usually we setup memory mapping with physical addr and the
corresponding virtual addr, here for less parameter we only pass in
physical addr. X86 people need to make it clear about this. Of course
explaining it in patch log is also helpful.

I have a tiny concern about phys_pmd_init(), both phys_pud_init and
phys_pte_init name 2nd parameter as 'addr', phys_pmd_init use 'address'.
If this can be changed to make them look consistent completist would
have a good sleep from now on.

Thanks
Baoquan