mm: thp: fix wrong cache flush in remove_migration_pmd()
Subsystems (3)
PATCH 1/2 mm: thp: fix wrong cache flush in remove_migration_pmd()
The flush_cache_page() is supposed to be justified only if the page is already placed in process page table, and that is done right after flush_cache_page(). So using this interface is wrong. And there is no need to invalite cache since it was non-present before in remove_migration_pmd(). So just to remove it.
--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/huge_memory.c +2 -1
@@ -3207,7 +3207,6 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new)if (pmd_swp_uffd_wp (*pvmw->pmd)) pmde =pmd_wrprotect (pmd_mkuffd_wp (pmde)); -flush_cache_range (vma, mmun_start, mmun_start +HPAGE_PMD_SIZE );if (PageAnon (new))page_add_anon_rmap (new, vma, mmun_start, true);else
@@ -3215,6 +3214,8 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new)set_pmd_at (mm, mmun_start, pvmw->pmd, pmde);if ((vma->vm_flags &VM_LOCKED ) && !PageDoubleMap (new))mlock_vma_page (new); + +/* No need to invalidate - it was non-present before */ update_mmu_cache_pmd(vma, address, pvmw->pmd); }#endif
Signature · 1 line
2.11.0
PATCH 2/2 mm: fix missing cache flush for all tail pages of THP
The D-cache maintenance inside move_to_new_page() only consider one page, there is still D-cache maintenance issue for tail pages of THP. Fix this by using flush_dcache_folio().
--- mm/migrate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/migrate.c +1 -2
@@ -934,8 +934,7 @@ static int move_to_new_page(struct page *newpage, struct page *page, page->mapping =NULL ;if (likely (!is_zone_device_page (newpage))) -flush_dcache_page (newpage); - +flush_dcache_folio (page_folio (newpage)); } out:return rc;
Signature · 1 line
2.11.0
Zi Yan
reviewerRe: [PATCH 2/2] mm: fix missing cache flush for all tail pages of THP
Quoted 26 lines · Muchun Song
The D-cache maintenance inside
move_to_new_page()only consider one page, there is still D-cache maintenance issue for tail pages of THP. Fix this by usingflush_dcache_folio().Fixes 616b8371539a ("mm: thp: enable thp migration in generic path")Signed-off-by Muchun Song <[email protected]>--- mm/migrate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/migrate.c +1
-2@@ -934,8 +934,7 @@ static int move_to_new_page(struct page *newpage, struct page *page, page->mapping =NULL ;if (likely (!is_zone_device_page (newpage))) -flush_dcache_page (newpage); - +flush_dcache_folio (page_folio (newpage)); } out:return rc;Signature · 1 line
2.11.0
Yes, the entire THP should be flushed. But it is better to use a for loop instead of the folio variant, so that the patch can be ported easily to the stable trees. The for loop can be converted later when the whole function is converted to use folio.
Thanks.
--
Best Regards,
Yan, Zi
Re: [PATCH 2/2] mm: fix missing cache flush for all tail pages of THP
Quoted 20 lines · Zi Yan
Quoted 17 lines · Muchun Song
The D-cache maintenance inside
move_to_new_page()only consider one page, there is still D-cache maintenance issue for tail pages of THP. Fix this by usingflush_dcache_folio().Fixes 616b8371539a ("mm: thp: enable thp migration in generic path")Signed-off-by Muchun Song <[email protected]>--- mm/migrate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/migrate.c +0
-0@@ -934,8 +934,7 @@ static int move_to_new_page(struct page *newpage, struct page *page, page->mapping =NULL ;
Quoted 15 lines
Quoted 9 lines
mm/migrate.c +1
-3if (likely (!is_zone_device_page (newpage))) -flush_dcache_page (newpage); - +flush_dcache_folio (page_folio (newpage)); } out:return rc; --2.11.0
Yes, the entire THP should be flushed. But it is better to use a for loop instead of the folio variant, so that the patch can be ported easily to the stable trees. The for loop can be converted later when the whole function is converted to use folio.
Agree. Will do. Thanks for your review.
Zi Yan
reviewerQuoted 24 lines · Muchun Song
The
flush_cache_page()is supposed to be justified only if the page is already placed in process page table, and that is done right afterflush_cache_page(). So using this interface is wrong. And there is no need to invalite cache since it was non-present before inremove_migration_pmd(). So just to remove it.Signed-off-by Muchun Song <[email protected]>--- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/huge_memory.c +0
-1@@ -3207,7 +3207,6 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new)if (pmd_swp_uffd_wp (*pvmw->pmd)) pmde =pmd_wrprotect (pmd_mkuffd_wp (pmde)); -flush_cache_range (vma, mmun_start, mmun_start +HPAGE_PMD_SIZE );if (PageAnon (new))page_add_anon_rmap (new, vma, mmun_start, true);else
mm/huge_memory.c void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new) · line 3221
Quoted 8 lines
mm/huge_memory.c +2
-0@@ -3215,6 +3214,8 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new)set_pmd_at (mm, mmun_start, pvmw->pmd, pmde);if ((vma->vm_flags &VM_LOCKED ) && !PageDoubleMap (new))mlock_vma_page (new); + +/* No need to invalidate - it was non-present before */ update_mmu_cache_pmd(vma, address, pvmw->pmd); }#endif
LGTM. Thanks. Reviewed-by: Zi Yan <[email protected]>
--
Best Regards,
Yan, Zi