mm: thp: fix split_huge_pte() operation on non-THP aligned address
authorMarek Szyprowski <m.szyprowski@samsung.com>
Tue, 9 Nov 2021 14:34:52 +0000 (15:34 +0100)
committerHoegeun Kwon <hoegeun.kwon@samsung.com>
Mon, 7 Feb 2022 08:01:41 +0000 (17:01 +0900)
When split_huge_pte() has been called on the address, which is not THP
aligned, the pte ptr should also be adjusted to the beginning of the THP
page.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: Idf1ddf95b3f5a5a790fd2b0eb85ac4c22e561a48

arch/arm64/mm/huge_memory.c

index 4dbb11d..402fb11 100644 (file)
@@ -1004,7 +1004,7 @@ void __split_huge_pte(struct vm_area_struct *vma, pmd_t *pmd,
 {
        spinlock_t *ptl;
        struct mmu_notifier_range range;
-       pte_t _pte;
+       pte_t _pte, *hpte;
        bool locked = false;
 
        mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm,
@@ -1051,7 +1051,11 @@ repeat:
                        clear_page_mlock(page);
        } else if (!(pte_devmap(*pte) || is_pte_migration_entry(*pte)))
                goto out;
-       __split_huge_pte_locked(vma, pte, range.start, freeze);
+
+       hpte = pte_offset_map(pmd, range.start);
+       VM_BUG_ON(!pte_present(*hpte) || !pte_cont(*hpte));
+       __split_huge_pte_locked(vma, hpte, range.start, freeze);
+       pte_unmap(hpte);
 out:
        spin_unlock(ptl);
        if (locked && page)