The softleaf changes exposed a BUG in remove_rmap_pmd() where the migration entry was being overridden when the folio is device private. Use scope local entry for creating the device private pmde. Make the pmde writable if the migration entry is writable by moving the check softleaf_is_migration_write() prior to creating the device private entry. Cc: Andrew Morton Cc: David Hildenbrand Cc: Zi Yan Cc: Joshua Hahn Cc: Rakie Kim Cc: Byungchul Park Cc: Gregory Price Cc: Ying Huang Cc: Alistair Popple Cc: Oscar Salvador Cc: Lorenzo Stoakes Cc: Baolin Wang Cc: "Liam R. Howlett" Cc: Nico Pache Cc: Ryan Roberts Cc: Dev Jain Cc: Barry Song Cc: Lyude Paul Cc: Danilo Krummrich Cc: David Airlie Cc: Simona Vetter Cc: Ralph Campbell Cc: Mika Penttilä Cc: Matthew Brost Cc: Francois Dugast Signed-off-by: Balbir Singh --- mm/huge_memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0184cd915f44..e4dadcb9e90b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4850,7 +4850,12 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new) folio_get(folio); pmde = folio_mk_pmd(folio, READ_ONCE(vma->vm_page_prot)); + if (softleaf_is_migration_write(entry)) + pmde = pmd_mkwrite(pmde, vma); + if (folio_is_device_private(folio)) { + swp_entry_t entry; + if (pmd_write(pmde)) entry = make_writable_device_private_entry( page_to_pfn(new)); @@ -4862,8 +4867,6 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new) if (pmd_swp_soft_dirty(*pvmw->pmd)) pmde = pmd_mksoft_dirty(pmde); - if (softleaf_is_migration_write(entry)) - pmde = pmd_mkwrite(pmde, vma); if (pmd_swp_uffd_wp(*pvmw->pmd)) pmde = pmd_mkuffd_wp(pmde); if (!softleaf_is_migration_young(entry)) -- 2.51.1