mm/huge_memory: fix override of entry in remove_migration_pmd
Subsystems (2)
PATCH 1/1 mm/huge_memory: fix override of entry in remove_migration_pmd
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.
--- mm/huge_memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
mm/huge_memory.c +5 -2
@@ -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))
Signature · 1 line
2.51.1
Quoted 33 lines · Balbir Singh
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 <[email protected]>Cc David Hildenbrand <[email protected]>Cc Zi Yan <[email protected]>Cc Joshua Hahn <[email protected]>Cc Rakie Kim <[email protected]>Cc Byungchul Park <[email protected]>Cc Gregory Price <[email protected]>Cc Ying Huang <[email protected]>Cc Alistair Popple <[email protected]>Cc Oscar Salvador <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Baolin Wang <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Nico Pache <[email protected]>Cc Ryan Roberts <[email protected]>Cc Dev Jain <[email protected]>Cc Barry Song <[email protected]>Cc Lyude Paul <[email protected]>Cc Danilo Krummrich <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>Cc Ralph Campbell <[email protected]>Cc Mika Penttilä <[email protected]>Cc Matthew Brost <[email protected]>Cc Francois Dugast <[email protected]>
Quoted 1 line
Signed-off-by Balbir Singh <[email protected]>
THe logic LGTM but we don't want to have a bisect hazard here by having the bug introduced earlier then resolved here.
I think better would be to do the fix up in the original series as a fix-patch, then maybe point at this one as a conflict resolution for my series?
In any case, LGTM so:
Quoted 33 lines
--- mm/huge_memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +5
-3@@ -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
David Hildenbrand (Red Hat)
maintainerQuoted 34 lines · Lorenzo Stoakes
Quoted 33 lines · Balbir Singh
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 <[email protected]>Cc David Hildenbrand <[email protected]>Cc Zi Yan <[email protected]>Cc Joshua Hahn <[email protected]>Cc Rakie Kim <[email protected]>Cc Byungchul Park <[email protected]>Cc Gregory Price <[email protected]>Cc Ying Huang <[email protected]>Cc Alistair Popple <[email protected]>Cc Oscar Salvador <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Baolin Wang <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Nico Pache <[email protected]>Cc Ryan Roberts <[email protected]>Cc Dev Jain <[email protected]>Cc Barry Song <[email protected]>Cc Lyude Paul <[email protected]>Cc Danilo Krummrich <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>Cc Ralph Campbell <[email protected]>Cc Mika Penttilä <[email protected]>Cc Matthew Brost <[email protected]>Cc Francois Dugast <[email protected]>
Quoted 4 lines
Quoted 1 line
Signed-off-by Balbir Singh <[email protected]>THe logic LGTM but we don't want to have a bisect hazard here by having the bug introduced earlier then resolved here.
Exactly.
Signature · 3 lines
Cheers David
Quoted 35 lines · David Hildenbrand (Red Hat)
Quoted 34 lines · Lorenzo Stoakes
Quoted 33 lines · Balbir Singh
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 <[email protected]>Cc David Hildenbrand <[email protected]>Cc Zi Yan <[email protected]>Cc Joshua Hahn <[email protected]>Cc Rakie Kim <[email protected]>Cc Byungchul Park <[email protected]>Cc Gregory Price <[email protected]>Cc Ying Huang <[email protected]>Cc Alistair Popple <[email protected]>Cc Oscar Salvador <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Baolin Wang <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Nico Pache <[email protected]>Cc Ryan Roberts <[email protected]>Cc Dev Jain <[email protected]>Cc Barry Song <[email protected]>Cc Lyude Paul <[email protected]>Cc Danilo Krummrich <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>Cc Ralph Campbell <[email protected]>Cc Mika Penttilä <[email protected]>Cc Matthew Brost <[email protected]>Cc Francois Dugast <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Balbir Singh <[email protected]>THe logic LGTM but we don't want to have a bisect hazard here by having the bug introduced earlier then resolved here.
Exactly.
The hazard is a VM_WARN_ON() that checks for is_migration_entry() in the call to softleaf_is_migration_young(). I am happy to go down that path, let me send out the fixups, it felt weird to break the rebase, but I am sure Andrew has a better way of dealing with this stuff.
Balbir
Andrew Morton
maintainerQuoted 10 lines · On Fri, 14 Nov 2025 07:55:29 +1100 Balbir Singh <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines
THe logic LGTM but we don't want to have a bisect hazard here by having the bug introduced earlier then resolved here.
Exactly.
The hazard is a
VM_WARN_ON()that checks foris_migration_entry()in the call tosoftleaf_is_migration_young(). I am happy to go down that path, let me send out the fixups, it felt weird to break the rebase, but I am sure Andrew has a better way of dealing with this stuff.
Yes, please tell us which patch introduced the issue then send a fix for that patch. We can figure out the softleaf changes later. (Which this patch provides anyway).
Also, confusing that the changelog says "The softleaf changes exposed a BUG in remove_rmap_pmd()" but it's remove_migration_pmd() that gets altered. Please expand and clarify?
Quoted 13 lines · Andrew Morton
Quoted 10 lines · On Fri, 14 Nov 2025 07:55:29 +1100 Balbir Singh <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines
THe logic LGTM but we don't want to have a bisect hazard here by having the bug introduced earlier then resolved here.
Exactly.
The hazard is a
VM_WARN_ON()that checks foris_migration_entry()in the call tosoftleaf_is_migration_young(). I am happy to go down that path, let me send out the fixups, it felt weird to break the rebase, but I am sure Andrew has a better way of dealing with this stuff.
Quoted 7 lines
Yes, please tell us which patch introduced the issue then send a fix for that patch. We can figure out the softleaf changes later. (Which this patch provides anyway).
Also, confusing that the changelog says "The softleaf changes exposed a BUG in
remove_rmap_pmd()" but it'sremove_migration_pmd()that gets altered. Please expand and clarify?
Sorry, it's remove_migration_pmd() that is effected. I've updated the changelog and sent out the patches. I've sent the fix to the original patch and the fixup along with it, hopefully I got it right :)
Balbir