The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 0/3] mm: handle device-private PMDs in walk callbacks
@ 2026-07-08 12:20 Usama Arif
  2026-07-08 12:20 ` [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios Usama Arif
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Usama Arif @ 2026-07-08 12:20 UTC (permalink / raw)
  To: Andrew Morton, apopple, balbirs, baohua, baolin.wang, byungchul,
	david, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang, liam,
	linux-kernel, linux-mm, ljs, matthew.brost, npache, rakie.kim,
	ryan.roberts, usama.arif, vbabka, ying.huang, ziy, shakeel.butt,
	hannes

I have followed Joshua's suggestion in [1] for v2. The patches look different
but acheive the same goal, so I have kept the Reviewed-by tags from v1.
Joshua, Zi and Balbir please let me know if this wasn't ok!

Since commit 368076f52ebe ("mm/huge_memory: add device-private THP support
to PMD operations") a PMD may hold a device-private swap entry whenever
an HMM-based GPU driver migrates an anonymous THP folio to device memory
via migrate_vma_pages().

pmd_trans_huge_lock() succeeds for such PMDs (pmd_is_huge() returns true
for any non-present, non-none huge PMD), so several MM walk callbacks
that used to assume present THP or migration entry are now reachable with
a device-private PMD. The results range from a VM_BUG_ON() firing on debug
kernels, to an oops on a bogus vmemmap dereference, to silently isolating
an unrelated live folio from LRU in the aliasing case.

[1] https://lore.kernel.org/all/20260707191917.3213033-1-joshua.hahnjy@gmail.com/

v1 -> v2: https://lore.kernel.org/all/20260707135255.292870-1-usama.arif@linux.dev/
- Patch 1 now gates queue_folios_pmd() on !pmd_present() instead of
  checking only pmd_is_device_private_entry(). This matches the PTE path,
  keeps migration entries counted in qp->nr_failed, and skips other
  non-present PMDs such as device-private entries before calling
  pmd_folio(). (Joshua)
- Patches 2 and 3 now fold device-private PMD handling into the existing
  !pmd_present() VM_BUG_ON() condition instead of using a separate early
  pmd_is_device_private_entry() check. (Joshua)
- cc stable (Zi)
 
Usama Arif (3):
  mm/mempolicy: skip non-present PMDs when queueing folios
  mm/madvise: skip device-private PMDs in cold and pageout walks
  mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd

 mm/huge_memory.c | 3 ++-
 mm/madvise.c     | 3 ++-
 mm/mempolicy.c   | 8 +++++---
 3 files changed, 9 insertions(+), 5 deletions(-)

-- 
2.53.0-Meta


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

* [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios
  2026-07-08 12:20 [PATCH v2 0/3] mm: handle device-private PMDs in walk callbacks Usama Arif
@ 2026-07-08 12:20 ` Usama Arif
  2026-07-08 13:05   ` David Hildenbrand (Arm)
  2026-07-08 15:27   ` Zi Yan
  2026-07-08 12:20 ` [PATCH v2 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks Usama Arif
  2026-07-08 12:20 ` [PATCH v2 3/3] mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd Usama Arif
  2 siblings, 2 replies; 8+ messages in thread
From: Usama Arif @ 2026-07-08 12:20 UTC (permalink / raw)
  To: Andrew Morton, apopple, balbirs, baohua, baolin.wang, byungchul,
	david, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang, liam,
	linux-kernel, linux-mm, ljs, matthew.brost, npache, rakie.kim,
	ryan.roberts, usama.arif, vbabka, ying.huang, ziy, shakeel.butt,
	hannes
  Cc: sashiko-bot, stable

queue_folios_pmd() is called under pmd_trans_huge_lock(), whose
pmd_is_huge() check returns true for any non-present, non-none PMD
softleaf. Passing such a PMD to pmd_folio() treats the softleaf encoding
as a hardware PFN and can return a bogus folio pointer.

Mirror queue_folios_pte_range(): handle non-present entries before
looking up a folio. Keep migration entries counted as failures, but skip
other non-present PMDs such as device-private entries.

Potential trigger: an HMM-based GPU driver migrates an anonymous THP
folio to device memory via migrate_vma_pages(), leaving a device-private
PMD. Userspace then calls mbind(), migrate_pages() or
set_mempolicy_home_node() on that range.

Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=6
Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
Cc: <stable@vger.kernel.org>
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
 mm/mempolicy.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 914f81863db5..4785b55c02da 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -654,12 +654,14 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk)
 {
 	struct folio *folio;
 	struct queue_pages *qp = walk->private;
+	pmd_t pmdval = *pmd;
 
-	if (unlikely(pmd_is_migration_entry(*pmd))) {
-		qp->nr_failed++;
+	if (unlikely(!pmd_present(pmdval))) {
+		if (pmd_is_migration_entry(pmdval))
+			qp->nr_failed++;
 		return;
 	}
-	folio = pmd_folio(*pmd);
+	folio = pmd_folio(pmdval);
 	if (is_huge_zero_folio(folio)) {
 		walk->action = ACTION_CONTINUE;
 		return;
-- 
2.53.0-Meta


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

* [PATCH v2 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks
  2026-07-08 12:20 [PATCH v2 0/3] mm: handle device-private PMDs in walk callbacks Usama Arif
  2026-07-08 12:20 ` [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios Usama Arif
@ 2026-07-08 12:20 ` Usama Arif
  2026-07-08 13:10   ` David Hildenbrand (Arm)
  2026-07-08 12:20 ` [PATCH v2 3/3] mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd Usama Arif
  2 siblings, 1 reply; 8+ messages in thread
From: Usama Arif @ 2026-07-08 12:20 UTC (permalink / raw)
  To: Andrew Morton, apopple, balbirs, baohua, baolin.wang, byungchul,
	david, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang, liam,
	linux-kernel, linux-mm, ljs, matthew.brost, npache, rakie.kim,
	ryan.roberts, usama.arif, vbabka, ying.huang, ziy, shakeel.butt,
	hannes
  Cc: sashiko-bot, stable

madvise_cold_or_pageout_pte_range() takes pmd_trans_huge_lock(), whose
pmd_is_huge() check returns true for a device-private PMD. The subsequent
!pmd_present() branch has a VM_BUG_ON() asserting migration is the only
allowed non-present case; a device-private PMD trips it.

Allow device-private PMDs in that non-present assertion and continue to
huge_unlock before calling pmd_folio(). This keeps the assertion for
unexpected PMD softleafs while skipping device-private PMDs like other
non-present PMDs in this path.

Potential trigger: an HMM-based GPU driver races with
madvise(MADV_COLD)/MADV_PAGEOUT: pmd_trans_huge(*pmd) reads true, then
migrate_vma_pages() flips the PMD to a device-private entry before the
PMD lock is acquired.

Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=6
Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
Cc: <stable@vger.kernel.org>
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Balbir Singh <balbirs@nvidia.com>
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
 mm/madvise.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 9292f60b19aa..1065b5a84ea7 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -389,7 +389,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 
 		if (unlikely(!pmd_present(orig_pmd))) {
 			VM_BUG_ON(thp_migration_supported() &&
-					!pmd_is_migration_entry(orig_pmd));
+					!pmd_is_migration_entry(orig_pmd) &&
+					!pmd_is_device_private_entry(orig_pmd));
 			goto huge_unlock;
 		}
 
-- 
2.53.0-Meta


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

* [PATCH v2 3/3] mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd
  2026-07-08 12:20 [PATCH v2 0/3] mm: handle device-private PMDs in walk callbacks Usama Arif
  2026-07-08 12:20 ` [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios Usama Arif
  2026-07-08 12:20 ` [PATCH v2 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks Usama Arif
@ 2026-07-08 12:20 ` Usama Arif
  2026-07-08 13:11   ` David Hildenbrand (Arm)
  2 siblings, 1 reply; 8+ messages in thread
From: Usama Arif @ 2026-07-08 12:20 UTC (permalink / raw)
  To: Andrew Morton, apopple, balbirs, baohua, baolin.wang, byungchul,
	david, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang, liam,
	linux-kernel, linux-mm, ljs, matthew.brost, npache, rakie.kim,
	ryan.roberts, usama.arif, vbabka, ying.huang, ziy, shakeel.butt,
	hannes
  Cc: stable

madvise_free_pte_range() checks pmd_trans_huge(*pmd) unlocked, then
madvise_free_huge_pmd() takes pmd_trans_huge_lock(). pmd_is_huge()
returns true for a device-private PMD, so orig_pmd can be device-private
and enter the !pmd_present() branch.

Allow device-private PMDs in that non-present assertion and continue to
out before calling pmd_folio(). This keeps the assertion for unexpected
PMD softleafs while skipping device-private PMDs like other non-present
PMDs in this path.

Potential trigger: an HMM-based GPU driver races with madvise(MADV_FREE):
migrate_vma_pages() flips the PMD to a device-private entry between the
caller's pmd_trans_huge() check and the callee's pmd_trans_huge_lock().

Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
Cc: <stable@vger.kernel.org>
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Balbir Singh <balbirs@nvidia.com>
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
 mm/huge_memory.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index c0892cc533a9..ddbdc83b4cae 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2298,7 +2298,8 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 
 	if (unlikely(!pmd_present(orig_pmd))) {
 		VM_BUG_ON(thp_migration_supported() &&
-				  !pmd_is_migration_entry(orig_pmd));
+				  !pmd_is_migration_entry(orig_pmd) &&
+				  !pmd_is_device_private_entry(orig_pmd));
 		goto out;
 	}
 
-- 
2.53.0-Meta


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

* Re: [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios
  2026-07-08 12:20 ` [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios Usama Arif
@ 2026-07-08 13:05   ` David Hildenbrand (Arm)
  2026-07-08 15:27   ` Zi Yan
  1 sibling, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-08 13:05 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, apopple, balbirs, baohua, baolin.wang,
	byungchul, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang,
	liam, linux-kernel, linux-mm, ljs, matthew.brost, npache,
	rakie.kim, ryan.roberts, vbabka, ying.huang, ziy, shakeel.butt,
	hannes
  Cc: sashiko-bot, stable

On 7/8/26 14:20, Usama Arif wrote:
> queue_folios_pmd() is called under pmd_trans_huge_lock(), whose
> pmd_is_huge() check returns true for any non-present, non-none PMD
> softleaf. Passing such a PMD to pmd_folio() treats the softleaf encoding
> as a hardware PFN and can return a bogus folio pointer.
> 
> Mirror queue_folios_pte_range(): handle non-present entries before
> looking up a folio. Keep migration entries counted as failures, but skip
> other non-present PMDs such as device-private entries.
> 
> Potential trigger: an HMM-based GPU driver migrates an anonymous THP
> folio to device memory via migrate_vma_pages(), leaving a device-private
> PMD. Userspace then calls mbind(), migrate_pages() or
> set_mempolicy_home_node() on that range.
> 
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=6
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

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

* Re: [PATCH v2 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks
  2026-07-08 12:20 ` [PATCH v2 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks Usama Arif
@ 2026-07-08 13:10   ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-08 13:10 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, apopple, balbirs, baohua, baolin.wang,
	byungchul, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang,
	liam, linux-kernel, linux-mm, ljs, matthew.brost, npache,
	rakie.kim, ryan.roberts, vbabka, ying.huang, ziy, shakeel.butt,
	hannes
  Cc: sashiko-bot, stable

On 7/8/26 14:20, Usama Arif wrote:
> madvise_cold_or_pageout_pte_range() takes pmd_trans_huge_lock(), whose
> pmd_is_huge() check returns true for a device-private PMD. The subsequent
> !pmd_present() branch has a VM_BUG_ON() asserting migration is the only
> allowed non-present case; a device-private PMD trips it.
> 
> Allow device-private PMDs in that non-present assertion and continue to
> huge_unlock before calling pmd_folio(). This keeps the assertion for
> unexpected PMD softleafs while skipping device-private PMDs like other
> non-present PMDs in this path.
> 
> Potential trigger: an HMM-based GPU driver races with
> madvise(MADV_COLD)/MADV_PAGEOUT: pmd_trans_huge(*pmd) reads true, then
> migrate_vma_pages() flips the PMD to a device-private entry before the
> PMD lock is acquired.
> 
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=6
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Balbir Singh <balbirs@nvidia.com>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
>  mm/madvise.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 9292f60b19aa..1065b5a84ea7 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -389,7 +389,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
>  
>  		if (unlikely(!pmd_present(orig_pmd))) {
>  			VM_BUG_ON(thp_migration_supported() &&
> -					!pmd_is_migration_entry(orig_pmd));
> +					!pmd_is_migration_entry(orig_pmd) &&
> +					!pmd_is_device_private_entry(orig_pmd));

thp_migration_supported() is just effectively CONFIG_TRANSPARENT_HUGEPAGE &&
CONFIG_ARCH_HAS_PMD_SOFTLEAVES.

pmd_is_migration_entry() -> softleaf_is_migration(softleaf_from_pmd(pmd)) ==
false without CONFIG_ARCH_HAS_PMD_SOFTLEAVES. ... and
CONFIG_ARCH_HAS_PMD_SOFTLEAVES is only selected if TRANSPARENT_HUGEPAGE.

While at it, can you drop the thp_migration_supported() check and turn the
VM_BUG_ON into a VM_WARN_ON_ONCE() ?

-- 
Cheers,

David

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

* Re: [PATCH v2 3/3] mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd
  2026-07-08 12:20 ` [PATCH v2 3/3] mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd Usama Arif
@ 2026-07-08 13:11   ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-08 13:11 UTC (permalink / raw)
  To: Usama Arif, Andrew Morton, apopple, balbirs, baohua, baolin.wang,
	byungchul, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang,
	liam, linux-kernel, linux-mm, ljs, matthew.brost, npache,
	rakie.kim, ryan.roberts, vbabka, ying.huang, ziy, shakeel.butt,
	hannes
  Cc: stable

On 7/8/26 14:20, Usama Arif wrote:
> madvise_free_pte_range() checks pmd_trans_huge(*pmd) unlocked, then
> madvise_free_huge_pmd() takes pmd_trans_huge_lock(). pmd_is_huge()
> returns true for a device-private PMD, so orig_pmd can be device-private
> and enter the !pmd_present() branch.
> 
> Allow device-private PMDs in that non-present assertion and continue to
> out before calling pmd_folio(). This keeps the assertion for unexpected
> PMD softleafs while skipping device-private PMDs like other non-present
> PMDs in this path.
> 
> Potential trigger: an HMM-based GPU driver races with madvise(MADV_FREE):
> migrate_vma_pages() flips the PMD to a device-private entry between the
> caller's pmd_trans_huge() check and the callee's pmd_trans_huge_lock().
> 
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Balbir Singh <balbirs@nvidia.com>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
>  mm/huge_memory.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index c0892cc533a9..ddbdc83b4cae 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2298,7 +2298,8 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
>  
>  	if (unlikely(!pmd_present(orig_pmd))) {
>  		VM_BUG_ON(thp_migration_supported() &&
> -				  !pmd_is_migration_entry(orig_pmd));
> +				  !pmd_is_migration_entry(orig_pmd) &&
> +				  !pmd_is_device_private_entry(orig_pmd));

Same comment as to #2.

-- 
Cheers,

David

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

* Re: [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios
  2026-07-08 12:20 ` [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios Usama Arif
  2026-07-08 13:05   ` David Hildenbrand (Arm)
@ 2026-07-08 15:27   ` Zi Yan
  1 sibling, 0 replies; 8+ messages in thread
From: Zi Yan @ 2026-07-08 15:27 UTC (permalink / raw)
  To: Usama Arif
  Cc: Andrew Morton, apopple, balbirs, baohua, baolin.wang, byungchul,
	david, dev.jain, gourry, jannh, joshua.hahnjy, lance.yang, liam,
	linux-kernel, linux-mm, ljs, matthew.brost, npache, rakie.kim,
	ryan.roberts, vbabka, ying.huang, shakeel.butt, hannes,
	sashiko-bot, stable

On 8 Jul 2026, at 8:20, Usama Arif wrote:

> queue_folios_pmd() is called under pmd_trans_huge_lock(), whose
> pmd_is_huge() check returns true for any non-present, non-none PMD
> softleaf. Passing such a PMD to pmd_folio() treats the softleaf encoding
> as a hardware PFN and can return a bogus folio pointer.
>
> Mirror queue_folios_pte_range(): handle non-present entries before
> looking up a folio. Keep migration entries counted as failures, but skip
> other non-present PMDs such as device-private entries.
>
> Potential trigger: an HMM-based GPU driver migrates an anonymous THP
> folio to device memory via migrate_vma_pages(), leaving a device-private
> PMD. Userspace then calls mbind(), migrate_pages() or
> set_mempolicy_home_node() on that range.
>
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=6
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
>  mm/mempolicy.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 914f81863db5..4785b55c02da 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -654,12 +654,14 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk)
>  {
>  	struct folio *folio;
>  	struct queue_pages *qp = walk->private;
> +	pmd_t pmdval = *pmd;

Use pmdp_get() instead?

>
> -	if (unlikely(pmd_is_migration_entry(*pmd))) {
> -		qp->nr_failed++;
> +	if (unlikely(!pmd_present(pmdval))) {
> +		if (pmd_is_migration_entry(pmdval))
> +			qp->nr_failed++;
>  		return;
>  	}
> -	folio = pmd_folio(*pmd);
> +	folio = pmd_folio(pmdval);
>  	if (is_huge_zero_folio(folio)) {
>  		walk->action = ACTION_CONTINUE;
>  		return;
> -- 
> 2.53.0-Meta

Otherwise, LGTM.

Reviewed-by: Zi Yan <ziy@nvidia.com>


Best Regards,
Yan, Zi

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

end of thread, other threads:[~2026-07-08 15:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 12:20 [PATCH v2 0/3] mm: handle device-private PMDs in walk callbacks Usama Arif
2026-07-08 12:20 ` [PATCH v2 1/3] mm/mempolicy: skip non-present PMDs when queueing folios Usama Arif
2026-07-08 13:05   ` David Hildenbrand (Arm)
2026-07-08 15:27   ` Zi Yan
2026-07-08 12:20 ` [PATCH v2 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks Usama Arif
2026-07-08 13:10   ` David Hildenbrand (Arm)
2026-07-08 12:20 ` [PATCH v2 3/3] mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd Usama Arif
2026-07-08 13:11   ` David Hildenbrand (Arm)

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