fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
Subsystems (8)
PATCH 1/1 fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
pagemap_pmd_range_thp() warns if a non-present PMD is not a migration entry. This became false once device-private entries at the PMD level were added.
One can hit the warning by patching hmm-tests.c with the following:
tools/testing/selftests/mm/hmm-tests.c +35 -0
@@ -209,6 +209,37 @@ static int hmm_dmirror_cmd(int fd,return 0 ; } +static int hmm_read_self_pagemap (void *addr,unsigned long npages, +unsigned long page_size) +{ +const size_t entry_size =sizeof (uint64_t ); +const off_t offset = ((uintptr_t )addr / page_size) * entry_size; +uint64_t *entries; +ssize_t nread; +int fd; + + entries =malloc (npages * entry_size); +if (!entries) +return -ENOMEM ; + + fd =open ("/proc/self/pagemap" ,O_RDONLY ); +if (fd <0 ) { +free (entries); +return -errno; + } + + nread =pread (fd, entries, npages * entry_size, offset); +close (fd); +free (entries); + +if (nread <0 ) +return -errno; +if ((size_t )nread != npages * entry_size) +return -EIO ; + +return 0 ; +} +static void hmm_buffer_free (struct hmm_buffer *buffer) {if (buffer ==NULL )
@@ -2314,6 +2345,10 @@ TEST_F(hmm, migrate_anon_huge_fault)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); +/* Exercise pagemap on a PMD device-private entry. */ + ret =hmm_read_self_pagemap (buffer->ptr, npages, self->page_size); +ASSERT_EQ (ret,0 ); +/* Check what the device read. */ for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i);
Therefore, remove the stale migration-only assertion.
---
Applies on mm-unstable (404fb4f38e8f).
fs/proc/task_mmu.c | 1 - 1 file changed, 1 deletion(-)
fs/proc/task_mmu.c +0 -1
@@ -2129,7 +2129,6 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_SOFT_DIRTY ;if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ; -VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); page =softleaf_to_page (entry); }
Signature · 1 line
2.43.0
Lorenzo Stoakes
maintainerQuoted 49 lines · Dev Jain
pagemap_pmd_range_thp()warns if a non-present PMD is not a migration entry. This became false once device-private entries at the PMD level were added.One can hit the warning by patching
hmm-tests.cwith the following:tools/testing/selftests/mm/hmm-tests.c +31
-0@@ -209,6 +209,37 @@ static int hmm_dmirror_cmd(int fd,return 0 ; } +static int hmm_read_self_pagemap (void *addr,unsigned long npages, +unsigned long page_size) +{ +const size_t entry_size =sizeof (uint64_t ); +const off_t offset = ((uintptr_t )addr / page_size) * entry_size; +uint64_t *entries; +ssize_t nread; +int fd; + + entries =malloc (npages * entry_size); +if (!entries) +return -ENOMEM ; + + fd =open ("/proc/self/pagemap" ,O_RDONLY ); +if (fd <0 ) { +free (entries); +return -errno; + } + + nread =pread (fd, entries, npages * entry_size, offset); +close (fd); +free (entries); + +if (nread <0 ) +return -errno; +if ((size_t )nread != npages * entry_size) +return -EIO ; + +return 0 ; +} +static void hmm_buffer_free (struct hmm_buffer *buffer) {if (buffer ==NULL )
tools/testing/selftests/mm/hmm-tests.c TEST_F(hmm, migrate_anon_huge_fault) · line 2354
Quoted 10 lines
tools/testing/selftests/mm/hmm-tests.c +4
-0@@ -2314,6 +2345,10 @@ TEST_F(hmm, migrate_anon_huge_fault)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); +/* Exercise pagemap on a PMD device-private entry. */ + ret =hmm_read_self_pagemap (buffer->ptr, npages, self->page_size); +ASSERT_EQ (ret,0 ); +/* Check what the device read. */ for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i);
Thanks for this!
though, hmm it really feels like you maybe want to add this as a test and make this a series :)
Andrew is usually fine with adding tests as part of a fix I believe!
Quoted 7 lines
Therefore, remove the stale migration-only assertion.
Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Dev Jain <[email protected]>
The logic does seem sense, it does seem like something of an oversight here and I can repro the assert (though I have to fix something else first on my system, patch incoming for that...!)
Quoted 20 lines
---
Applies on mm-unstable (404fb4f38e8f).fs/proc/task_mmu.c | 1 - 1 file changed, 1 deletion(-)fs/proc/task_mmu.c +0
-2@@ -2129,7 +2129,6 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_SOFT_DIRTY ;if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ; -VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); page =softleaf_to_page (entry); } --
Quoted 2 lines
2.43.0
Cheers, Lorenzo
Andrew Morton
maintainerQuoted 10 lines · On Fri, 29 May 2026 17:45:24 +0100 Lorenzo Stoakes <[email protected]> wrote:
tools/testing/selftests/mm/hmm-tests.c TEST_F(hmm, migrate_anon_huge_fault) · line 2354
Quoted 7 lines
tools/testing/selftests/mm/hmm-tests.c +4
-0+/* Exercise pagemap on a PMD device-private entry. */ + ret =hmm_read_self_pagemap (buffer->ptr, npages, self->page_size); +ASSERT_EQ (ret,0 ); +/* Check what the device read. */ for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i);Thanks for this!
Quoted 2 lines
though, hmm it really feels like you maybe want to add this as a test and make this a series :)
yes please!
Quoted 79 lines · Dev Jain
pagemap_pmd_range_thp()warns if a non-present PMD is not a migration entry. This became false once device-private entries at the PMD level were added.One can hit the warning by patching
hmm-tests.cwith the following:tools/testing/selftests/mm/hmm-tests.c +35
-0@@ -209,6 +209,37 @@ static int hmm_dmirror_cmd(int fd,return 0 ; } +static int hmm_read_self_pagemap (void *addr,unsigned long npages, +unsigned long page_size) +{ +const size_t entry_size =sizeof (uint64_t ); +const off_t offset = ((uintptr_t )addr / page_size) * entry_size; +uint64_t *entries; +ssize_t nread; +int fd; + + entries =malloc (npages * entry_size); +if (!entries) +return -ENOMEM ; + + fd =open ("/proc/self/pagemap" ,O_RDONLY ); +if (fd <0 ) { +free (entries); +return -errno; + } + + nread =pread (fd, entries, npages * entry_size, offset); +close (fd); +free (entries); + +if (nread <0 ) +return -errno; +if ((size_t )nread != npages * entry_size) +return -EIO ; + +return 0 ; +} +static void hmm_buffer_free (struct hmm_buffer *buffer) {if (buffer ==NULL )@@ -2314,6 +2345,10 @@ TEST_F(hmm, migrate_anon_huge_fault)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); +/* Exercise pagemap on a PMD device-private entry. */ + ret =hmm_read_self_pagemap (buffer->ptr, npages, self->page_size); +ASSERT_EQ (ret,0 ); +/* Check what the device read. */ for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i);Therefore, remove the stale migration-only assertion.
Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Dev Jain <[email protected]>---
Applies on mm-unstable (404fb4f38e8f).fs/proc/task_mmu.c | 1 - 1 file changed, 1 deletion(-)fs/proc/task_mmu.c +0
-0
fs/proc/task_mmu.c static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, · line 2134
Quoted 7 lines
fs/proc/task_mmu.c +0
-1@@ -2129,7 +2129,6 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_SOFT_DIRTY ;if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ; -VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); page =softleaf_to_page (entry); }
The whole thp_migration_supported() guard is a bit shaky, right?
I guess device-private entries currently imply thp_migration_supported(), but that thp_migration_supported() check is really questionable and should likely just go away (else if -> else).
Staring at pte_to_pagemap_entry(), likely we'd also want
if (softleaf_has_pfn(entry))
page = softleaf_to_page(entry);
to prepare for PMD swap entries.
Anyhow, both are unrelated (can you send patches to clean it up?)
Signature · 3 lines
Cheers, David
Quoted 75 lines · David Hildenbrand (Arm)
Quoted 74 lines · Dev Jain
pagemap_pmd_range_thp()warns if a non-present PMD is not a migration entry. This became false once device-private entries at the PMD level were added.One can hit the warning by patching
hmm-tests.cwith the following:tools/testing/selftests/mm/hmm-tests.c +35
-0@@ -209,6 +209,37 @@ static int hmm_dmirror_cmd(int fd,return 0 ; } +static int hmm_read_self_pagemap (void *addr,unsigned long npages, +unsigned long page_size) +{ +const size_t entry_size =sizeof (uint64_t ); +const off_t offset = ((uintptr_t )addr / page_size) * entry_size; +uint64_t *entries; +ssize_t nread; +int fd; + + entries =malloc (npages * entry_size); +if (!entries) +return -ENOMEM ; + + fd =open ("/proc/self/pagemap" ,O_RDONLY ); +if (fd <0 ) { +free (entries); +return -errno; + } + + nread =pread (fd, entries, npages * entry_size, offset); +close (fd); +free (entries); + +if (nread <0 ) +return -errno; +if ((size_t )nread != npages * entry_size) +return -EIO ; + +return 0 ; +} +static void hmm_buffer_free (struct hmm_buffer *buffer) {if (buffer ==NULL )@@ -2314,6 +2345,10 @@ TEST_F(hmm, migrate_anon_huge_fault)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); +/* Exercise pagemap on a PMD device-private entry. */ + ret =hmm_read_self_pagemap (buffer->ptr, npages, self->page_size); +ASSERT_EQ (ret,0 ); +/* Check what the device read. */ for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i);Therefore, remove the stale migration-only assertion.
Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Dev Jain <[email protected]>---
Applies on mm-unstable (404fb4f38e8f).fs/proc/task_mmu.c | 1 - 1 file changed, 1 deletion(-)
Quoted 14 lines
fs/proc/task_mmu.c static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, · line 2134
Quoted 12 lines
fs/proc/task_mmu.c +0
-1@@ -2129,7 +2129,6 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_SOFT_DIRTY ;if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ; -VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); page =softleaf_to_page (entry); }The whole
thp_migration_supported()guard is a bit shaky, right?
I think if you remove this, then you will trigger a WARN_ON in softleaf_to_page(), for the case of !CONFIG_ARCH_ENABLE_THP_MIGRATION.
Quoted 11 lines
I guess device-private entries currently imply
thp_migration_supported(), but thatthp_migration_supported()check is really questionable and should likely just go away (else if -> else).Staring at
pte_to_pagemap_entry(), likely we'd also wantif (
softleaf_has_pfn(entry))page = softleaf_to_page(entry);to prepare for PMD swap entries.
Correct, and this is done in
https://lore.kernel.org/all/[email protected]/
I think in addition to that, Usama can also remove the thp_migration_supported() check.
Quoted 6 lines
Anyhow, both are unrelated (can you send patches to clean it up?)
David Hildenbrand (Arm)
maintainerQuoted 93 lines · Dev Jain
Quoted 75 lines · David Hildenbrand (Arm)
Quoted 74 lines · Dev Jain
pagemap_pmd_range_thp()warns if a non-present PMD is not a migration entry. This became false once device-private entries at the PMD level were added.One can hit the warning by patching
hmm-tests.cwith the following:tools/testing/selftests/mm/hmm-tests.c +35
-0@@ -209,6 +209,37 @@ static int hmm_dmirror_cmd(int fd,return 0 ; } +static int hmm_read_self_pagemap (void *addr,unsigned long npages, +unsigned long page_size) +{ +const size_t entry_size =sizeof (uint64_t ); +const off_t offset = ((uintptr_t )addr / page_size) * entry_size; +uint64_t *entries; +ssize_t nread; +int fd; + + entries =malloc (npages * entry_size); +if (!entries) +return -ENOMEM ; + + fd =open ("/proc/self/pagemap" ,O_RDONLY ); +if (fd <0 ) { +free (entries); +return -errno; + } + + nread =pread (fd, entries, npages * entry_size, offset); +close (fd); +free (entries); + +if (nread <0 ) +return -errno; +if ((size_t )nread != npages * entry_size) +return -EIO ; + +return 0 ; +} +static void hmm_buffer_free (struct hmm_buffer *buffer) {if (buffer ==NULL )@@ -2314,6 +2345,10 @@ TEST_F(hmm, migrate_anon_huge_fault)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); +/* Exercise pagemap on a PMD device-private entry. */ + ret =hmm_read_self_pagemap (buffer->ptr, npages, self->page_size); +ASSERT_EQ (ret,0 ); +/* Check what the device read. */ for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i);Therefore, remove the stale migration-only assertion.
Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Dev Jain <[email protected]>---
Applies on mm-unstable (404fb4f38e8f).fs/proc/task_mmu.c | 1 - 1 file changed, 1 deletion(-)Quoted 14 lines
fs/proc/task_mmu.c static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, · line 2134
Quoted 12 lines
fs/proc/task_mmu.c +0
-1@@ -2129,7 +2129,6 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_SOFT_DIRTY ;if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ; -VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); page =softleaf_to_page (entry); }The whole
thp_migration_supported()guard is a bit shaky, right?
Quoted 2 lines
I think if you remove this, then you will trigger a
WARN_ONinsoftleaf_to_page(), for the case of !CONFIG_ARCH_ENABLE_THP_MIGRATION.
Right, what I noted below.
Right now it's all a bit hacked on top of initial migration entry support.
Quoted 10 lines
Quoted 10 lines
I guess device-private entries currently imply
thp_migration_supported(), but thatthp_migration_supported()check is really questionable and should likely just go away (else if -> else).Staring at
pte_to_pagemap_entry(), likely we'd also wantif (
softleaf_has_pfn(entry))page = softleaf_to_page(entry);
Quoted 6 lines
Quoted 1 line
to prepare for PMD swap entries.
Correct, and this is done in
https://lore.kernel.org/all/[email protected]/I think in addition to that, Usama can also remove the
thp_migration_supported()check.
Yes, that one should go away.
Signature · 3 lines
Cheers, David
Quoted 6 lines · David Hildenbrand (Arm)
The whole
thp_migration_supported()guard is a bit shaky, right?I guess device-private entries currently imply
thp_migration_supported(), but thatthp_migration_supported()check is really questionable and should likely just go away (else if -> else).
Quoted 6 lines
Staring at
pte_to_pagemap_entry(), likely we'd also wantif (
softleaf_has_pfn(entry))page = softleaf_to_page(entry);to prepare for PMD swap entries.
Yes, that is what I was doing for non-present PMDs when implementing the new API [1].
[1] https://lore.kernel.org/linux-mm/[email protected]/
Signature · 2 lines
Oscar Salvador SUSE Labs
Quoted 61 lines · Dev Jain
pagemap_pmd_range_thp()warns if a non-present PMD is not a migration entry. This became false once device-private entries at the PMD level were added.One can hit the warning by patching
hmm-tests.cwith the following:tools/testing/selftests/mm/hmm-tests.c +35
-0@@ -209,6 +209,37 @@ static int hmm_dmirror_cmd(int fd,return 0 ; } +static int hmm_read_self_pagemap (void *addr,unsigned long npages, +unsigned long page_size) +{ +const size_t entry_size =sizeof (uint64_t ); +const off_t offset = ((uintptr_t )addr / page_size) * entry_size; +uint64_t *entries; +ssize_t nread; +int fd; + + entries =malloc (npages * entry_size); +if (!entries) +return -ENOMEM ; + + fd =open ("/proc/self/pagemap" ,O_RDONLY ); +if (fd <0 ) { +free (entries); +return -errno; + } + + nread =pread (fd, entries, npages * entry_size, offset); +close (fd); +free (entries); + +if (nread <0 ) +return -errno; +if ((size_t )nread != npages * entry_size) +return -EIO ; + +return 0 ; +} +static void hmm_buffer_free (struct hmm_buffer *buffer) {if (buffer ==NULL )@@ -2314,6 +2345,10 @@ TEST_F(hmm, migrate_anon_huge_fault)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); +/* Exercise pagemap on a PMD device-private entry. */ + ret =hmm_read_self_pagemap (buffer->ptr, npages, self->page_size); +ASSERT_EQ (ret,0 ); +/* Check what the device read. */ for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i);
Quoted 5 lines
Therefore, remove the stale migration-only assertion.
Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Dev Jain <[email protected]>
LGTM,
Signature · 2 lines
Oscar Salvador SUSE Labs