Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/migrate_device.c: copy pte dirty bit to page

migrate_vma_setup() has a fast path in migrate_vma_collect_pmd() that
installs migration entries directly if it can lock the migrating page.
When removing a dirty pte the dirty bit is supposed to be carried over to
the underlying page to prevent it being lost.

Currently migrate_vma_*() can only be used for private anonymous mappings.
That means loss of the dirty bit usually doesn't result in data loss
because these pages are typically not file-backed. However pages may be
backed by swap storage which can result in data loss if an attempt is made
to migrate a dirty page that doesn't yet have the PageDirty flag set.

In this case migration will fail due to unexpected references but the
dirty pte bit will be lost. If the page is subsequently reclaimed data
won't be written back to swap storage as it is considered uptodate,
resulting in data loss if the page is subsequently accessed.

Prevent this by copying the dirty bit to the page when removing the pte to
match what try_to_migrate_one() does.

Link: https://lkml.kernel.org/r/dd48e4882ce859c295c1a77612f66d198b0403f9.1662078528.git-series.apopple@nvidia.com
Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages")
Signed-off-by: Alistair Popple <apopple@nvidia.com>
Acked-by: Peter Xu <peterx@redhat.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Reported-by: "Huang, Ying" <ying.huang@intel.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Alex Sierra <alex.sierra@amd.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: huang ying <huang.ying.caritas@gmail.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Karol Herbst <kherbst@redhat.com>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Alistair Popple and committed by
Andrew Morton
fd35ca3d a3589e1d

+7 -2
+7 -2
mm/migrate_device.c
··· 7 7 #include <linux/export.h> 8 8 #include <linux/memremap.h> 9 9 #include <linux/migrate.h> 10 + #include <linux/mm.h> 10 11 #include <linux/mm_inline.h> 11 12 #include <linux/mmu_notifier.h> 12 13 #include <linux/oom.h> ··· 197 196 flush_cache_page(vma, addr, pte_pfn(*ptep)); 198 197 anon_exclusive = PageAnon(page) && PageAnonExclusive(page); 199 198 if (anon_exclusive) { 200 - ptep_clear_flush(vma, addr, ptep); 199 + pte = ptep_clear_flush(vma, addr, ptep); 201 200 202 201 if (page_try_share_anon_rmap(page)) { 203 202 set_pte_at(mm, addr, ptep, pte); ··· 207 206 goto next; 208 207 } 209 208 } else { 210 - ptep_get_and_clear(mm, addr, ptep); 209 + pte = ptep_get_and_clear(mm, addr, ptep); 211 210 } 212 211 213 212 migrate->cpages++; 213 + 214 + /* Set the dirty flag on the folio now the pte is gone. */ 215 + if (pte_dirty(pte)) 216 + folio_mark_dirty(page_folio(page)); 214 217 215 218 /* Setup special migration page table entry */ 216 219 if (mpfn & MIGRATE_PFN_WRITE)