Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mm/hmm: A fix and a selftest
@ 2026-05-30  8:54 Dev Jain
  2026-05-30  8:54 ` [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry Dev Jain
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Dev Jain @ 2026-05-30  8:54 UTC (permalink / raw)
  To: akpm, liam, ljs, jgg, leon, david, shuah
  Cc: Dev Jain, vbabka, jannh, pfalcato, balbirs, linux-mm,
	linux-kernel, linux-fsdevel, rppt, surenb, mhocko,
	linux-kselftest, usama.arif, ryan.roberts, anshuman.khandual

Patch 1 fixes a stale warning present from the time when only migration
softleaf entries were supported at the PMD level.

Patch 2 adds some code into hmm-tests.c which exercises the pagemap path
for PMD device-private entries.

---
Applies on mm-unstable (404fb4f38e8f).

Dev Jain (2):
  fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
  selftests/mm/hmm-tests: test pagemap reads of PMD device-private
    entries

 fs/proc/task_mmu.c                     |  1 -
 tools/testing/selftests/mm/hmm-tests.c | 29 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
  2026-05-30  8:54 [PATCH v2 0/2] mm/hmm: A fix and a selftest Dev Jain
@ 2026-05-30  8:54 ` Dev Jain
  2026-05-31 23:39   ` Balbir Singh
  2026-06-01  8:36   ` Lorenzo Stoakes
  2026-05-30  8:54 ` [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries Dev Jain
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 13+ messages in thread
From: Dev Jain @ 2026-05-30  8:54 UTC (permalink / raw)
  To: akpm, liam, ljs, jgg, leon, david, shuah
  Cc: Dev Jain, vbabka, jannh, pfalcato, balbirs, linux-mm,
	linux-kernel, linux-fsdevel, rppt, surenb, mhocko,
	linux-kselftest, usama.arif, ryan.roberts, anshuman.khandual,
	stable

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.

Therefore, remove the stale migration-only assertion.

Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
Cc: stable@vger.kernel.org
Signed-off-by: Dev Jain <dev.jain@arm.com>
---
 fs/proc/task_mmu.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 1e3a15bf46f4e..58938e62154d9 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -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);
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries
  2026-05-30  8:54 [PATCH v2 0/2] mm/hmm: A fix and a selftest Dev Jain
  2026-05-30  8:54 ` [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry Dev Jain
@ 2026-05-30  8:54 ` Dev Jain
  2026-06-01  0:09   ` Balbir Singh
  2026-05-31 19:24 ` [PATCH v2 0/2] mm/hmm: A fix and a selftest Andrew Morton
  2026-06-01  8:33 ` Lorenzo Stoakes
  3 siblings, 1 reply; 13+ messages in thread
From: Dev Jain @ 2026-05-30  8:54 UTC (permalink / raw)
  To: akpm, liam, ljs, jgg, leon, david, shuah
  Cc: Dev Jain, vbabka, jannh, pfalcato, balbirs, linux-mm,
	linux-kernel, linux-fsdevel, rppt, surenb, mhocko,
	linux-kselftest, usama.arif, ryan.roberts, anshuman.khandual

To cover pagemap paths scanning PMD entries, add assertions to check
whether a device-private PMD entry has the correct pagemap information -
the PM_SWAP bit must be on in the pagemap entry. Before that, we must
assert through HMM_DMIRROR_SNAPSHOT snapshot that the leaf entry is
at PMD level and not PTE level.

Signed-off-by: Dev Jain <dev.jain@arm.com>
---
 tools/testing/selftests/mm/hmm-tests.c | 29 ++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
index e1c8a679a4cf3..d09d4a9081de1 100644
--- a/tools/testing/selftests/mm/hmm-tests.c
+++ b/tools/testing/selftests/mm/hmm-tests.c
@@ -2276,8 +2276,11 @@ TEST_F(hmm, migrate_anon_huge_fault)
 	unsigned long npages;
 	unsigned long size;
 	unsigned long i;
+	unsigned char *m;
+	uint64_t entry;
 	void *old_ptr;
 	void *map;
+	int pagemap_fd;
 	int *ptr;
 	int ret;
 
@@ -2318,6 +2321,32 @@ TEST_F(hmm, migrate_anon_huge_fault)
 	for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
 		ASSERT_EQ(ptr[i], i);
 
+	if (!hmm_is_coherent_type(variant->device_number)) {
+		ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT,
+				      buffer, npages);
+		ASSERT_EQ(ret, 0);
+		ASSERT_EQ(buffer->cpages, npages);
+
+		m = buffer->mirror;
+		for (i = 0; i < npages; ++i)
+			ASSERT_EQ(m[i], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL |
+					HMM_DMIRROR_PROT_WRITE |
+					HMM_DMIRROR_PROT_PMD);
+
+		pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
+		ASSERT_GE(pagemap_fd, 0);
+
+		for (i = 0; i < npages; ++i) {
+			entry = pagemap_get_entry(pagemap_fd,
+					(char *)buffer->ptr + i * self->page_size);
+
+			ASSERT_NE(entry & PM_SWAP, 0);
+			ASSERT_EQ(entry & PM_PRESENT, 0);
+		}
+
+		close(pagemap_fd);
+	}
+
 	/* Fault pages back to system memory and check them. */
 	for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i)
 		ASSERT_EQ(ptr[i], i);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/2] mm/hmm: A fix and a selftest
  2026-05-30  8:54 [PATCH v2 0/2] mm/hmm: A fix and a selftest Dev Jain
  2026-05-30  8:54 ` [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry Dev Jain
  2026-05-30  8:54 ` [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries Dev Jain
@ 2026-05-31 19:24 ` Andrew Morton
  2026-05-31 19:49   ` David Hildenbrand (Arm)
  2026-06-01  5:11   ` Dev Jain
  2026-06-01  8:33 ` Lorenzo Stoakes
  3 siblings, 2 replies; 13+ messages in thread
From: Andrew Morton @ 2026-05-31 19:24 UTC (permalink / raw)
  To: Dev Jain
  Cc: liam, ljs, jgg, leon, david, shuah, vbabka, jannh, pfalcato,
	balbirs, linux-mm, linux-kernel, linux-fsdevel, rppt, surenb,
	mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual

On Sat, 30 May 2026 08:54:10 +0000 Dev Jain <dev.jain@arm.com> wrote:

> Patch 1 fixes a stale warning present from the time when only migration
> softleaf entries were supported at the PMD level.
> 
> Patch 2 adds some code into hmm-tests.c which exercises the pagemap path
> for PMD device-private entries.

David, I'll retain your ack on patch 1.

Sashiko has a concern about the selftest:
	https://sashiko.dev/#/patchset/20260530085413.1270139-1-dev.jain@arm.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/2] mm/hmm: A fix and a selftest
  2026-05-31 19:24 ` [PATCH v2 0/2] mm/hmm: A fix and a selftest Andrew Morton
@ 2026-05-31 19:49   ` David Hildenbrand (Arm)
  2026-06-01  5:11   ` Dev Jain
  1 sibling, 0 replies; 13+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-31 19:49 UTC (permalink / raw)
  To: Andrew Morton, Dev Jain
  Cc: liam, ljs, jgg, leon, shuah, vbabka, jannh, pfalcato, balbirs,
	linux-mm, linux-kernel, linux-fsdevel, rppt, surenb, mhocko,
	linux-kselftest, usama.arif, ryan.roberts, anshuman.khandual

On 5/31/26 21:24, Andrew Morton wrote:
> On Sat, 30 May 2026 08:54:10 +0000 Dev Jain <dev.jain@arm.com> wrote:
> 
>> Patch 1 fixes a stale warning present from the time when only migration
>> softleaf entries were supported at the PMD level.
>>
>> Patch 2 adds some code into hmm-tests.c which exercises the pagemap path
>> for PMD device-private entries.
> 
> David, I'll retain your ack on patch 1.

Thanks!

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
  2026-05-30  8:54 ` [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry Dev Jain
@ 2026-05-31 23:39   ` Balbir Singh
  2026-06-01  8:36   ` Lorenzo Stoakes
  1 sibling, 0 replies; 13+ messages in thread
From: Balbir Singh @ 2026-05-31 23:39 UTC (permalink / raw)
  To: Dev Jain, akpm, liam, ljs, jgg, leon, david, shuah
  Cc: vbabka, jannh, pfalcato, linux-mm, linux-kernel, linux-fsdevel,
	rppt, surenb, mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual, stable

On 5/30/26 18:54, Dev Jain wrote:
> 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.
> 
> Therefore, remove the stale migration-only assertion.
> 
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>  fs/proc/task_mmu.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 1e3a15bf46f4e..58938e62154d9 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -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);
>  	}
>  

Thanks!
Reviewed-by: Balbir Singh <balbirs@nvidia.com>

Balbir

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries
  2026-05-30  8:54 ` [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries Dev Jain
@ 2026-06-01  0:09   ` Balbir Singh
  2026-06-01  5:10     ` Dev Jain
  0 siblings, 1 reply; 13+ messages in thread
From: Balbir Singh @ 2026-06-01  0:09 UTC (permalink / raw)
  To: Dev Jain, akpm, liam, ljs, jgg, leon, david, shuah
  Cc: vbabka, jannh, pfalcato, linux-mm, linux-kernel, linux-fsdevel,
	rppt, surenb, mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual

On 5/30/26 18:54, Dev Jain wrote:
> To cover pagemap paths scanning PMD entries, add assertions to check
> whether a device-private PMD entry has the correct pagemap information -
> the PM_SWAP bit must be on in the pagemap entry. Before that, we must
> assert through HMM_DMIRROR_SNAPSHOT snapshot that the leaf entry is
> at PMD level and not PTE level.
> 
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>  tools/testing/selftests/mm/hmm-tests.c | 29 ++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index e1c8a679a4cf3..d09d4a9081de1 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -2276,8 +2276,11 @@ TEST_F(hmm, migrate_anon_huge_fault)
>  	unsigned long npages;
>  	unsigned long size;
>  	unsigned long i;
> +	unsigned char *m;
> +	uint64_t entry;
>  	void *old_ptr;
>  	void *map;
> +	int pagemap_fd;
>  	int *ptr;
>  	int ret;
>  
> @@ -2318,6 +2321,32 @@ TEST_F(hmm, migrate_anon_huge_fault)
>  	for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
>  		ASSERT_EQ(ptr[i], i);
>  
> +	if (!hmm_is_coherent_type(variant->device_number)) {
> +		ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT,
> +				      buffer, npages);
> +		ASSERT_EQ(ret, 0);
> +		ASSERT_EQ(buffer->cpages, npages);
> +
> +		m = buffer->mirror;
> +		for (i = 0; i < npages; ++i)
> +			ASSERT_EQ(m[i], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL |
> +					HMM_DMIRROR_PROT_WRITE |
> +					HMM_DMIRROR_PROT_PMD);

madvise(..., MADV_HUGEPAGE) is not sufficient to guarantee that the allocation
was indeed converted to THP. Might be worth using the kpageflags interface (but that
requires elevated privileges) and then KPF_THP? Otherwise the HMM_DMIRROR_PROT_PMD
can be a miss from time to time. One other option is not to assert, but to check
and inform?

> +
> +		pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
> +		ASSERT_GE(pagemap_fd, 0);
> +
> +		for (i = 0; i < npages; ++i) {
> +			entry = pagemap_get_entry(pagemap_fd,
> +					(char *)buffer->ptr + i * self->page_size);
> +

If this is a THP entry, do we have valid pagemap entries for offset of i * page_size?

> +			ASSERT_NE(entry & PM_SWAP, 0);
> +			ASSERT_EQ(entry & PM_PRESENT, 0);

Nit: You can use PAGEMAP_PRESENT()

> +		}
> +
> +		close(pagemap_fd);
> +	}
> +
>  	/* Fault pages back to system memory and check them. */
>  	for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i)
>  		ASSERT_EQ(ptr[i], i);

Balbir Singh

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries
  2026-06-01  0:09   ` Balbir Singh
@ 2026-06-01  5:10     ` Dev Jain
  2026-06-01  8:35       ` Lorenzo Stoakes
  0 siblings, 1 reply; 13+ messages in thread
From: Dev Jain @ 2026-06-01  5:10 UTC (permalink / raw)
  To: Balbir Singh, akpm, liam, ljs, jgg, leon, david, shuah
  Cc: vbabka, jannh, pfalcato, linux-mm, linux-kernel, linux-fsdevel,
	rppt, surenb, mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual



On 01/06/26 5:39 am, Balbir Singh wrote:
> On 5/30/26 18:54, Dev Jain wrote:
>> To cover pagemap paths scanning PMD entries, add assertions to check
>> whether a device-private PMD entry has the correct pagemap information -
>> the PM_SWAP bit must be on in the pagemap entry. Before that, we must
>> assert through HMM_DMIRROR_SNAPSHOT snapshot that the leaf entry is
>> at PMD level and not PTE level.
>>
>> Signed-off-by: Dev Jain <dev.jain@arm.com>
>> ---
>>  tools/testing/selftests/mm/hmm-tests.c | 29 ++++++++++++++++++++++++++
>>  1 file changed, 29 insertions(+)
>>
>> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
>> index e1c8a679a4cf3..d09d4a9081de1 100644
>> --- a/tools/testing/selftests/mm/hmm-tests.c
>> +++ b/tools/testing/selftests/mm/hmm-tests.c
>> @@ -2276,8 +2276,11 @@ TEST_F(hmm, migrate_anon_huge_fault)
>>  	unsigned long npages;
>>  	unsigned long size;
>>  	unsigned long i;
>> +	unsigned char *m;
>> +	uint64_t entry;
>>  	void *old_ptr;
>>  	void *map;
>> +	int pagemap_fd;
>>  	int *ptr;
>>  	int ret;
>>  
>> @@ -2318,6 +2321,32 @@ TEST_F(hmm, migrate_anon_huge_fault)
>>  	for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
>>  		ASSERT_EQ(ptr[i], i);
>>  
>> +	if (!hmm_is_coherent_type(variant->device_number)) {
>> +		ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT,
>> +				      buffer, npages);
>> +		ASSERT_EQ(ret, 0);
>> +		ASSERT_EQ(buffer->cpages, npages);
>> +
>> +		m = buffer->mirror;
>> +		for (i = 0; i < npages; ++i)
>> +			ASSERT_EQ(m[i], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL |
>> +					HMM_DMIRROR_PROT_WRITE |
>> +					HMM_DMIRROR_PROT_PMD);
> 
> madvise(..., MADV_HUGEPAGE) is not sufficient to guarantee that the allocation
> was indeed converted to THP. Might be worth using the kpageflags interface (but that
> requires elevated privileges) and then KPF_THP? Otherwise the HMM_DMIRROR_PROT_PMD
> can be a miss from time to time. One other option is not to assert, but to check
> and inform?

I'll then use the existing check_huge_anon() to assert that a PMD THP got allocated.

> 
>> +
>> +		pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
>> +		ASSERT_GE(pagemap_fd, 0);
>> +
>> +		for (i = 0; i < npages; ++i) {
>> +			entry = pagemap_get_entry(pagemap_fd,
>> +					(char *)buffer->ptr + i * self->page_size);
>> +
> 
> If this is a THP entry, do we have valid pagemap entries for offset of i * page_size?

Yep we do, see the populate_pagemap label in pagemap_pmd_range_thp.

> 
>> +			ASSERT_NE(entry & PM_SWAP, 0);
>> +			ASSERT_EQ(entry & PM_PRESENT, 0);
> 
> Nit: You can use PAGEMAP_PRESENT()

Okay.

> 
>> +		}
>> +
>> +		close(pagemap_fd);
>> +	}
>> +
>>  	/* Fault pages back to system memory and check them. */
>>  	for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i)
>>  		ASSERT_EQ(ptr[i], i);
> 
> Balbir Singh


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/2] mm/hmm: A fix and a selftest
  2026-05-31 19:24 ` [PATCH v2 0/2] mm/hmm: A fix and a selftest Andrew Morton
  2026-05-31 19:49   ` David Hildenbrand (Arm)
@ 2026-06-01  5:11   ` Dev Jain
  1 sibling, 0 replies; 13+ messages in thread
From: Dev Jain @ 2026-06-01  5:11 UTC (permalink / raw)
  To: Andrew Morton
  Cc: liam, ljs, jgg, leon, david, shuah, vbabka, jannh, pfalcato,
	balbirs, linux-mm, linux-kernel, linux-fsdevel, rppt, surenb,
	mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual



On 01/06/26 12:54 am, Andrew Morton wrote:
> On Sat, 30 May 2026 08:54:10 +0000 Dev Jain <dev.jain@arm.com> wrote:
> 
>> Patch 1 fixes a stale warning present from the time when only migration
>> softleaf entries were supported at the PMD level.
>>
>> Patch 2 adds some code into hmm-tests.c which exercises the pagemap path
>> for PMD device-private entries.
> 
> David, I'll retain your ack on patch 1.
> 
> Sashiko has a concern about the selftest:
> 	https://sashiko.dev/#/patchset/20260530085413.1270139-1-dev.jain@arm.com

Same concern as raised by Balbir.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/2] mm/hmm: A fix and a selftest
  2026-05-30  8:54 [PATCH v2 0/2] mm/hmm: A fix and a selftest Dev Jain
                   ` (2 preceding siblings ...)
  2026-05-31 19:24 ` [PATCH v2 0/2] mm/hmm: A fix and a selftest Andrew Morton
@ 2026-06-01  8:33 ` Lorenzo Stoakes
  3 siblings, 0 replies; 13+ messages in thread
From: Lorenzo Stoakes @ 2026-06-01  8:33 UTC (permalink / raw)
  To: Dev Jain
  Cc: akpm, liam, jgg, leon, david, shuah, vbabka, jannh, pfalcato,
	balbirs, linux-mm, linux-kernel, linux-fsdevel, rppt, surenb,
	mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual

On Sat, May 30, 2026 at 08:54:10AM +0000, Dev Jain wrote:
> Patch 1 fixes a stale warning present from the time when only migration
> softleaf entries were supported at the PMD level.
>
> Patch 2 adds some code into hmm-tests.c which exercises the pagemap path
> for PMD device-private entries.

Thanks!

FYI running the HMM tests locally I ran into a nasty issue that I sent a patch
for [0]!

[0]: https://lore.kernel.org/linux-mm/20260601083044.57132-1-ljs@kernel.org/

Cheers, Lorenzo

>
> ---
> Applies on mm-unstable (404fb4f38e8f).
>
> Dev Jain (2):
>   fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
>   selftests/mm/hmm-tests: test pagemap reads of PMD device-private
>     entries
>
>  fs/proc/task_mmu.c                     |  1 -
>  tools/testing/selftests/mm/hmm-tests.c | 29 ++++++++++++++++++++++++++
>  2 files changed, 29 insertions(+), 1 deletion(-)
>
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries
  2026-06-01  5:10     ` Dev Jain
@ 2026-06-01  8:35       ` Lorenzo Stoakes
  2026-06-01  9:14         ` Dev Jain
  0 siblings, 1 reply; 13+ messages in thread
From: Lorenzo Stoakes @ 2026-06-01  8:35 UTC (permalink / raw)
  To: Dev Jain
  Cc: Balbir Singh, akpm, liam, jgg, leon, david, shuah, vbabka, jannh,
	pfalcato, linux-mm, linux-kernel, linux-fsdevel, rppt, surenb,
	mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual

On Mon, Jun 01, 2026 at 10:40:48AM +0530, Dev Jain wrote:
>
>
> On 01/06/26 5:39 am, Balbir Singh wrote:
> > On 5/30/26 18:54, Dev Jain wrote:
> >> To cover pagemap paths scanning PMD entries, add assertions to check
> >> whether a device-private PMD entry has the correct pagemap information -
> >> the PM_SWAP bit must be on in the pagemap entry. Before that, we must
> >> assert through HMM_DMIRROR_SNAPSHOT snapshot that the leaf entry is
> >> at PMD level and not PTE level.
> >>
> >> Signed-off-by: Dev Jain <dev.jain@arm.com>
> >> ---
> >>  tools/testing/selftests/mm/hmm-tests.c | 29 ++++++++++++++++++++++++++
> >>  1 file changed, 29 insertions(+)
> >>
> >> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> >> index e1c8a679a4cf3..d09d4a9081de1 100644
> >> --- a/tools/testing/selftests/mm/hmm-tests.c
> >> +++ b/tools/testing/selftests/mm/hmm-tests.c
> >> @@ -2276,8 +2276,11 @@ TEST_F(hmm, migrate_anon_huge_fault)
> >>  	unsigned long npages;
> >>  	unsigned long size;
> >>  	unsigned long i;
> >> +	unsigned char *m;
> >> +	uint64_t entry;
> >>  	void *old_ptr;
> >>  	void *map;
> >> +	int pagemap_fd;
> >>  	int *ptr;
> >>  	int ret;
> >>
> >> @@ -2318,6 +2321,32 @@ TEST_F(hmm, migrate_anon_huge_fault)
> >>  	for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
> >>  		ASSERT_EQ(ptr[i], i);
> >>
> >> +	if (!hmm_is_coherent_type(variant->device_number)) {
> >> +		ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT,
> >> +				      buffer, npages);
> >> +		ASSERT_EQ(ret, 0);
> >> +		ASSERT_EQ(buffer->cpages, npages);
> >> +
> >> +		m = buffer->mirror;
> >> +		for (i = 0; i < npages; ++i)
> >> +			ASSERT_EQ(m[i], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL |
> >> +					HMM_DMIRROR_PROT_WRITE |
> >> +					HMM_DMIRROR_PROT_PMD);
> >
> > madvise(..., MADV_HUGEPAGE) is not sufficient to guarantee that the allocation
> > was indeed converted to THP. Might be worth using the kpageflags interface (but that
> > requires elevated privileges) and then KPF_THP? Otherwise the HMM_DMIRROR_PROT_PMD
> > can be a miss from time to time. One other option is not to assert, but to check
> > and inform?
>
> I'll then use the existing check_huge_anon() to assert that a PMD THP got allocated.

Would MADV_COLLAPSE work here?

>
> >
> >> +
> >> +		pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
> >> +		ASSERT_GE(pagemap_fd, 0);
> >> +
> >> +		for (i = 0; i < npages; ++i) {
> >> +			entry = pagemap_get_entry(pagemap_fd,
> >> +					(char *)buffer->ptr + i * self->page_size);
> >> +
> >
> > If this is a THP entry, do we have valid pagemap entries for offset of i * page_size?
>
> Yep we do, see the populate_pagemap label in pagemap_pmd_range_thp.
>
> >
> >> +			ASSERT_NE(entry & PM_SWAP, 0);
> >> +			ASSERT_EQ(entry & PM_PRESENT, 0);
> >
> > Nit: You can use PAGEMAP_PRESENT()
>
> Okay.
>
> >
> >> +		}
> >> +
> >> +		close(pagemap_fd);
> >> +	}
> >> +
> >>  	/* Fault pages back to system memory and check them. */
> >>  	for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i)
> >>  		ASSERT_EQ(ptr[i], i);
> >
> > Balbir Singh
>

Cheers, Lorenzo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
  2026-05-30  8:54 ` [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry Dev Jain
  2026-05-31 23:39   ` Balbir Singh
@ 2026-06-01  8:36   ` Lorenzo Stoakes
  1 sibling, 0 replies; 13+ messages in thread
From: Lorenzo Stoakes @ 2026-06-01  8:36 UTC (permalink / raw)
  To: Dev Jain
  Cc: akpm, liam, jgg, leon, david, shuah, vbabka, jannh, pfalcato,
	balbirs, linux-mm, linux-kernel, linux-fsdevel, rppt, surenb,
	mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual, stable

On Sat, May 30, 2026 at 08:54:11AM +0000, Dev Jain wrote:
> 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.
>
> Therefore, remove the stale migration-only assertion.
>
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dev Jain <dev.jain@arm.com>

LGTM so:

Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>

I also verified that I could trigger this locally with your test, so feel free
to add:

Tested-by: Lorenzo Stoakes <ljs@kernel.org>

Cheers, Lorenzo

> ---
>  fs/proc/task_mmu.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 1e3a15bf46f4e..58938e62154d9 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -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);
>  	}
>
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries
  2026-06-01  8:35       ` Lorenzo Stoakes
@ 2026-06-01  9:14         ` Dev Jain
  0 siblings, 0 replies; 13+ messages in thread
From: Dev Jain @ 2026-06-01  9:14 UTC (permalink / raw)
  To: Lorenzo Stoakes
  Cc: Balbir Singh, akpm, liam, jgg, leon, david, shuah, vbabka, jannh,
	pfalcato, linux-mm, linux-kernel, linux-fsdevel, rppt, surenb,
	mhocko, linux-kselftest, usama.arif, ryan.roberts,
	anshuman.khandual



On 01/06/26 2:05 pm, Lorenzo Stoakes wrote:
> On Mon, Jun 01, 2026 at 10:40:48AM +0530, Dev Jain wrote:
>>
>>
>> On 01/06/26 5:39 am, Balbir Singh wrote:
>>> On 5/30/26 18:54, Dev Jain wrote:
>>>> To cover pagemap paths scanning PMD entries, add assertions to check
>>>> whether a device-private PMD entry has the correct pagemap information -
>>>> the PM_SWAP bit must be on in the pagemap entry. Before that, we must
>>>> assert through HMM_DMIRROR_SNAPSHOT snapshot that the leaf entry is
>>>> at PMD level and not PTE level.
>>>>
>>>> Signed-off-by: Dev Jain <dev.jain@arm.com>
>>>> ---
>>>>  tools/testing/selftests/mm/hmm-tests.c | 29 ++++++++++++++++++++++++++
>>>>  1 file changed, 29 insertions(+)
>>>>
>>>> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
>>>> index e1c8a679a4cf3..d09d4a9081de1 100644
>>>> --- a/tools/testing/selftests/mm/hmm-tests.c
>>>> +++ b/tools/testing/selftests/mm/hmm-tests.c
>>>> @@ -2276,8 +2276,11 @@ TEST_F(hmm, migrate_anon_huge_fault)
>>>>  	unsigned long npages;
>>>>  	unsigned long size;
>>>>  	unsigned long i;
>>>> +	unsigned char *m;
>>>> +	uint64_t entry;
>>>>  	void *old_ptr;
>>>>  	void *map;
>>>> +	int pagemap_fd;
>>>>  	int *ptr;
>>>>  	int ret;
>>>>
>>>> @@ -2318,6 +2321,32 @@ TEST_F(hmm, migrate_anon_huge_fault)
>>>>  	for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
>>>>  		ASSERT_EQ(ptr[i], i);
>>>>
>>>> +	if (!hmm_is_coherent_type(variant->device_number)) {
>>>> +		ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT,
>>>> +				      buffer, npages);
>>>> +		ASSERT_EQ(ret, 0);
>>>> +		ASSERT_EQ(buffer->cpages, npages);
>>>> +
>>>> +		m = buffer->mirror;
>>>> +		for (i = 0; i < npages; ++i)
>>>> +			ASSERT_EQ(m[i], HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL |
>>>> +					HMM_DMIRROR_PROT_WRITE |
>>>> +					HMM_DMIRROR_PROT_PMD);
>>>
>>> madvise(..., MADV_HUGEPAGE) is not sufficient to guarantee that the allocation
>>> was indeed converted to THP. Might be worth using the kpageflags interface (but that
>>> requires elevated privileges) and then KPF_THP? Otherwise the HMM_DMIRROR_PROT_PMD
>>> can be a miss from time to time. One other option is not to assert, but to check
>>> and inform?
>>
>> I'll then use the existing check_huge_anon() to assert that a PMD THP got allocated.
> 
> Would MADV_COLLAPSE work here?

So MADV_COLLAPSE requires at least one page to be faulted in (or precisely,
HPAGE_PMD_NR - khugepaged_max_ptes_none). So I rejected that, but now I
noticed that we are initializing the buffer first.

So yes I will use this, thanks.

> 
>>
>>>
>>>> +
>>>> +		pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
>>>> +		ASSERT_GE(pagemap_fd, 0);
>>>> +
>>>> +		for (i = 0; i < npages; ++i) {
>>>> +			entry = pagemap_get_entry(pagemap_fd,
>>>> +					(char *)buffer->ptr + i * self->page_size);
>>>> +
>>>
>>> If this is a THP entry, do we have valid pagemap entries for offset of i * page_size?
>>
>> Yep we do, see the populate_pagemap label in pagemap_pmd_range_thp.
>>
>>>
>>>> +			ASSERT_NE(entry & PM_SWAP, 0);
>>>> +			ASSERT_EQ(entry & PM_PRESENT, 0);
>>>
>>> Nit: You can use PAGEMAP_PRESENT()
>>
>> Okay.
>>
>>>
>>>> +		}
>>>> +
>>>> +		close(pagemap_fd);
>>>> +	}
>>>> +
>>>>  	/* Fault pages back to system memory and check them. */
>>>>  	for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i)
>>>>  		ASSERT_EQ(ptr[i], i);
>>>
>>> Balbir Singh
>>
> 
> Cheers, Lorenzo


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-06-01  9:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-30  8:54 [PATCH v2 0/2] mm/hmm: A fix and a selftest Dev Jain
2026-05-30  8:54 ` [PATCH v2 1/2] fs/proc/task_mmu: do not warn on seeing non-migration pmd entry Dev Jain
2026-05-31 23:39   ` Balbir Singh
2026-06-01  8:36   ` Lorenzo Stoakes
2026-05-30  8:54 ` [PATCH v2 2/2] selftests/mm/hmm-tests: test pagemap reads of PMD device-private entries Dev Jain
2026-06-01  0:09   ` Balbir Singh
2026-06-01  5:10     ` Dev Jain
2026-06-01  8:35       ` Lorenzo Stoakes
2026-06-01  9:14         ` Dev Jain
2026-05-31 19:24 ` [PATCH v2 0/2] mm/hmm: A fix and a selftest Andrew Morton
2026-05-31 19:49   ` David Hildenbrand (Arm)
2026-06-01  5:11   ` Dev Jain
2026-06-01  8:33 ` Lorenzo Stoakes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox