Commit 3592806cfa08b7cca968f793c33f8e9460bab395
Committed by
Linus Torvalds
1 parent
3e1e4a5f3a
Exists in
master
and in
16 other branches
thp: move preallocated PTE page table on move_huge_pmd()
Andrey Wagin reported crash on VM_BUG_ON() in pgtable_pmd_page_dtor() with fallowing backtrace: free_pgd_range+0x2bf/0x410 free_pgtables+0xce/0x120 unmap_region+0xe0/0x120 do_munmap+0x249/0x360 move_vma+0x144/0x270 SyS_mremap+0x3b9/0x510 system_call_fastpath+0x16/0x1b The crash can be reproduce with this test case: #define _GNU_SOURCE #include <sys/mman.h> #include <stdio.h> #include <unistd.h> #define MB (1024 * 1024UL) #define GB (1024 * MB) int main(int argc, char **argv) { char *p; int i; p = mmap((void *) GB, 10 * MB, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); for (i = 0; i < 10 * MB; i += 4096) p[i] = 1; mremap(p, 10 * MB, 10 * MB, MREMAP_FIXED | MREMAP_MAYMOVE, 2 * GB); return 0; } Due to split PMD lock, we now store preallocated PTE tables for THP pages per-PMD table. It means we need to move them to other PMD table if huge PMD moved there. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Reported-by: Andrey Vagin <avagin@openvz.org> Tested-by: Andrey Vagin <avagin@openvz.org> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 11 additions and 1 deletions Side-by-side Diff
mm/huge_memory.c
... | ... | @@ -1481,8 +1481,18 @@ |
1481 | 1481 | pmd = pmdp_get_and_clear(mm, old_addr, old_pmd); |
1482 | 1482 | VM_BUG_ON(!pmd_none(*new_pmd)); |
1483 | 1483 | set_pmd_at(mm, new_addr, new_pmd, pmd_mksoft_dirty(pmd)); |
1484 | - if (new_ptl != old_ptl) | |
1484 | + if (new_ptl != old_ptl) { | |
1485 | + pgtable_t pgtable; | |
1486 | + | |
1487 | + /* | |
1488 | + * Move preallocated PTE page table if new_pmd is on | |
1489 | + * different PMD page table. | |
1490 | + */ | |
1491 | + pgtable = pgtable_trans_huge_withdraw(mm, old_pmd); | |
1492 | + pgtable_trans_huge_deposit(mm, new_pmd, pgtable); | |
1493 | + | |
1485 | 1494 | spin_unlock(new_ptl); |
1495 | + } | |
1486 | 1496 | spin_unlock(old_ptl); |
1487 | 1497 | } |
1488 | 1498 | out: |