• Christophe Leroy's avatar
    powerpc: Fix random segfault when freeing hugetlb range · 542db12a
    Christophe Leroy authored
    The following random segfault is observed from time to time with
    map_hugetlb selftest:
    
    root@localhost:~# ./map_hugetlb 1 19
    524288 kB hugepages
    Mapping 1 Mbytes
    Segmentation fault
    
    [   31.219972] map_hugetlb[365]: segfault (11) at 117 nip 77974f8c lr 779a6834 code 1 in ld-2.23.so[77966000+21000]
    [   31.220192] map_hugetlb[365]: code: 9421ffc0 480318d1 93410028 90010044 9361002c 93810030 93a10034 93c10038
    [   31.220307] map_hugetlb[365]: code: 93e1003c 93210024 8123007c 81430038 <80e90004> 814a0004 7f443a14 813a0004
    [   31.221911] BUG: Bad rss-counter state mm:(ptrval) type:MM_FILEPAGES val:33
    [   31.229362] BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:5
    
    This fault is due to hugetlb_free_pgd_range() freeing page tables
    that are also used by regular pages.
    
    As explain in the comment at the beginning of
    hugetlb_free_pgd_range(), the verification done in free_pgd_range()
    on floor and ceiling is not done here, which means
    hugetlb_free_pte_range() can free outside the expected range.
    
    As the verification cannot be done in hugetlb_free_pgd_range(), it
    must be done in hugetlb_free_pte_range().
    
    Fixes: b250c8c0 ("powerpc/8xx: Manage 512k huge pages as standard pages.")
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
    Reviewed-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/f0cb2a5477cd87d1eaadb128042e20aeb2bc2859.1598860677.git.christophe.leroy@csgroup.eu
    542db12a
hugetlbpage.c 16.9 KB