Re: [PATCH v3 RESEND 2/2] x86/mm/KASLR: Fix the size of vmemmap section

From: Baoquan He
Date: Mon Apr 29 2019 - 04:12:54 EST


On 04/28/19 at 09:54pm, Kirill A. Shutemov wrote:
> > @@ -109,6 +110,14 @@ void __init kernel_randomize_memory(void)
> > if (memory_tb < kaslr_regions[0].size_tb)
> > kaslr_regions[0].size_tb = memory_tb;
> >
> > + /**
>
> Nit: that is weird style for inline comment.

Right, will fix.

Thanks a lot for reviewing.

>
> > + * Calculate how many TB vmemmap region needs, and aligned to
> > + * 1TB boundary.
> > + */
> > + vmemmap_size = (kaslr_regions[0].size_tb << (TB_SHIFT - PAGE_SHIFT)) *
> > + sizeof(struct page);
>
> Hm. Don't we need to take into account alignment requirements for struct
> page here? I'm worried about some exotic debug kernel config where
> sizeof(struct page) doesn't satify __alignof__(struct page).

I know sizeof(struct page) has handled its own struct alignment and
padding. About __alignof__(struct page), will it conflict with below
code to convert pfn < -- > page? Not sure if I got your point.

#elif defined(CONFIG_SPARSEMEM_VMEMMAP)

/* memmap is virtually contiguous. */
#define __pfn_to_page(pfn) (vmemmap + (pfn))
#define __page_to_pfn(page) (unsigned long)((page) - vmemmap)

#elif...


>
> > + kaslr_regions[2].size_tb = DIV_ROUND_UP(vmemmap_size, 1UL << TB_SHIFT);
> > +
> > /* Calculate entropy available between regions */
> > remain_entropy = vaddr_end - vaddr_start;
> > for (i = 0; i < ARRAY_SIZE(kaslr_regions); i++)
> --
> Kirill A. Shutemov