On Thu, Jun 20, 2019 at 02:42:55PM +0000, Dave Hansen wrote: > On 6/20/19 4:22 AM, Kirill A. Shutemov wrote: > > The commit relaxes KASLR alignment requirements and it can lead to > > mismatch bentween 'i' and 'p4d_index(vaddr)' inside the loop in > > phys_p4d_init(). The mismatch in its turn leads to clearing wrong p4d > > entry and eventually to the oops. > > Just curious, but what does it relax the requirement to and from? > > I'm just not clearly spotting the actual bug.
Before the commit PAGE_OFFSET is always aligned to P4D_SIZE if we boot in 5-level paging mode. But now only PUD_SIZE alignment is guaranteed. For phys_p4d_init() it means that paddr_next after the first iteration can belong to the same p4d entry. In the case I was able to reproduce the vaddr on the first iteration is 0xff4228027fe00000 and paddr is 0x33fe00000. On the second iteration vaddr becomes 0xff42287f40000000 and paddr is 0x8000000000. The vaddr in both cases bolong to the same p4d entry. It screws up 'i' count: we miss the last entry in the page table completely. And it confuses the branch under 'paddr >= paddr_end' condition: the p4d entry can be cleared where must not to. The patch makes phys_p4d_init() work like __kernel_physical_mapping_init() which deals with phys-virt mismatch already. I hope this explanation makes any sense :P -- Kirill A. Shutemov