Skip to content

Commit 8a8683a

Browse files
yhuang-inteltorvalds
authored andcommitted
mm: fix possible PMD dirty bit lost in set_pmd_migration_entry()
In set_pmd_migration_entry(), pmdp_invalidate() is used to change PMD atomically. But the PMD is read before that with an ordinary memory reading. If the THP (transparent huge page) is written between the PMD reading and pmdp_invalidate(), the PMD dirty bit may be lost, and cause data corruption. The race window is quite small, but still possible in theory, so need to be fixed. The race is fixed via using the return value of pmdp_invalidate() to get the original content of PMD, which is a read/modify/write atomic operation. So no THP writing can occur in between. The race has been introduced when the THP migration support is added in the commit 616b837 ("mm: thp: enable thp migration in generic path"). But this fix depends on the commit d52605d ("mm: do not lose dirty and accessed bits in pmdp_invalidate()"). So it's easy to be backported after v4.16. But the race window is really small, so it may be fine not to backport the fix at all. Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: "Huang, Ying" <[email protected]> Reviewed-by: Zi Yan <[email protected]> Reviewed-by: William Kucharski <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Cc: <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Andrea Arcangeli <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8b272b3 commit 8a8683a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

mm/huge_memory.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -3043,8 +3043,7 @@ void set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
30433043
return;
30443044

30453045
flush_cache_range(vma, address, address + HPAGE_PMD_SIZE);
3046-
pmdval = *pvmw->pmd;
3047-
pmdp_invalidate(vma, address, pvmw->pmd);
3046+
pmdval = pmdp_invalidate(vma, address, pvmw->pmd);
30483047
if (pmd_dirty(pmdval))
30493048
set_page_dirty(page);
30503049
entry = make_migration_entry(page, pmd_write(pmdval));

0 commit comments

Comments
 (0)