* [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd()
[not found] <20260728194714.3713735-1-gourry@gourry.net>
@ 2026-07-28 19:47 ` Gregory Price
2026-08-06 13:20 ` David Hildenbrand (Arm)
2026-08-06 13:59 ` Lorenzo Stoakes (ARM)
0 siblings, 2 replies; 4+ messages in thread
From: Gregory Price @ 2026-07-28 19:47 UTC (permalink / raw)
To: linux-mm
Cc: damon, linux-kernel, kernel-team, sj, akpm, david, ljs, ziy,
baolin.wang, liam, npache, ryan.roberts, dev.jain, baohua,
lance.yang, usama.arif, vbabka, jannh, matthew.brost,
joshua.hahnjy, rakie.kim, byungchul, gourry, ying.huang, apopple,
stable
madvise_free_huge_pmd() resolves the folio backing a PMD via pmd_folio()
and marks it lazyfree without checking for zone device memory.
The surrounding guards do not cover every zone device case:
- MADV_FREE only operates on anonymous VMAs (DAX mappings are excluded)
- !pmd_present() branch rejects device-private and migration entries
- present zone device PMD (device coherent THP) is not filtered.
Unlike vm_normal_page_pmd(), it performs no special/pfnmap check,
and would be marked lazyfree here.
Bail out when the folio is a zone device folio.
Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
Cc: <stable@vger.kernel.org>
Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
---
mm/huge_memory.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 5bd8d4f59a7b..e0ffdeeb3077 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2338,6 +2338,10 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
}
folio = pmd_folio(orig_pmd);
+
+ if (folio_is_zone_device(folio))
+ goto out;
+
/*
* If other processes are mapping this folio, we couldn't discard
* the folio unless they all do MADV_FREE so let's skip the folio.
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd()
2026-07-28 19:47 ` [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd() Gregory Price
@ 2026-08-06 13:20 ` David Hildenbrand (Arm)
2026-08-06 13:59 ` Lorenzo Stoakes (ARM)
1 sibling, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-08-06 13:20 UTC (permalink / raw)
To: Gregory Price, linux-mm
Cc: damon, linux-kernel, kernel-team, sj, akpm, ljs, ziy, baolin.wang,
liam, npache, ryan.roberts, dev.jain, baohua, lance.yang,
usama.arif, vbabka, jannh, matthew.brost, joshua.hahnjy,
rakie.kim, byungchul, ying.huang, apopple, stable
On 7/28/26 21:47, Gregory Price wrote:
> madvise_free_huge_pmd() resolves the folio backing a PMD via pmd_folio()
> and marks it lazyfree without checking for zone device memory.
>
> The surrounding guards do not cover every zone device case:
> - MADV_FREE only operates on anonymous VMAs (DAX mappings are excluded)
>
> - !pmd_present() branch rejects device-private and migration entries
>
> - present zone device PMD (device coherent THP) is not filtered.
> Unlike vm_normal_page_pmd(), it performs no special/pfnmap check,
> and would be marked lazyfree here.
>
> Bail out when the folio is a zone device folio.
>
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd()
2026-07-28 19:47 ` [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd() Gregory Price
2026-08-06 13:20 ` David Hildenbrand (Arm)
@ 2026-08-06 13:59 ` Lorenzo Stoakes (ARM)
2026-08-06 17:03 ` Gregory Price
1 sibling, 1 reply; 4+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-08-06 13:59 UTC (permalink / raw)
To: Gregory Price
Cc: linux-mm, damon, linux-kernel, kernel-team, sj, akpm, david, ziy,
baolin.wang, liam, npache, ryan.roberts, dev.jain, baohua,
lance.yang, usama.arif, vbabka, jannh, matthew.brost,
joshua.hahnjy, rakie.kim, byungchul, ying.huang, apopple, stable
I kinda wish he had some generalised folio handler like:
struct folio_ops {
int (*handle_empty_entry)(void *priv);
int (*handle_normal_folio)(void *priv, struct folio *folio);
int (*handle_softleaf_pte_entry)(void *priv, const pte_t *ptep);
int (*handle_zone_folio)(void *priv, struct folio *folio);
...
};
Or I don't know an equivalent type of thing, as we keep having these same
patterns emerge in mm that are duplicated in a million places with slight
variations... :)
I wonder if C is expressive enough to get us to something sane though.
On Tue, Jul 28, 2026 at 03:47:12PM -0400, Gregory Price wrote:
> madvise_free_huge_pmd() resolves the folio backing a PMD via pmd_folio()
> and marks it lazyfree without checking for zone device memory.
>
> The surrounding guards do not cover every zone device case:
> - MADV_FREE only operates on anonymous VMAs (DAX mappings are excluded)
>
> - !pmd_present() branch rejects device-private and migration entries
>
> - present zone device PMD (device coherent THP) is not filtered.
> Unlike vm_normal_page_pmd(), it performs no special/pfnmap check,
> and would be marked lazyfree here.
>
> Bail out when the folio is a zone device folio.
>
> Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
Anyway LGTM so:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> mm/huge_memory.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 5bd8d4f59a7b..e0ffdeeb3077 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2338,6 +2338,10 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
> }
>
> folio = pmd_folio(orig_pmd);
> +
> + if (folio_is_zone_device(folio))
> + goto out;
> +
> /*
> * If other processes are mapping this folio, we couldn't discard
> * the folio unless they all do MADV_FREE so let's skip the folio.
> --
> 2.55.0
>
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd()
2026-08-06 13:59 ` Lorenzo Stoakes (ARM)
@ 2026-08-06 17:03 ` Gregory Price
0 siblings, 0 replies; 4+ messages in thread
From: Gregory Price @ 2026-08-06 17:03 UTC (permalink / raw)
To: Lorenzo Stoakes (ARM)
Cc: linux-mm, damon, linux-kernel, kernel-team, sj, akpm, david, ziy,
baolin.wang, liam, npache, ryan.roberts, dev.jain, baohua,
lance.yang, usama.arif, vbabka, jannh, matthew.brost,
joshua.hahnjy, rakie.kim, byungchul, ying.huang, apopple, stable
On Thu, Aug 06, 2026 at 02:59:22PM +0100, Lorenzo Stoakes (ARM) wrote:
> I kinda wish he had some generalised folio handler like:
>
> struct folio_ops {
> int (*handle_empty_entry)(void *priv);
> int (*handle_normal_folio)(void *priv, struct folio *folio);
> int (*handle_softleaf_pte_entry)(void *priv, const pte_t *ptep);
> int (*handle_zone_folio)(void *priv, struct folio *folio);
> ...
> };
>
> Or I don't know an equivalent type of thing, as we keep having these same
> patterns emerge in mm that are duplicated in a million places with slight
> variations... :)
>
> I wonder if C is expressive enough to get us to something sane though.
>
This is functionally folio->pgmap except it's not generalized and it
causes us pain :[
I briefly took a forray into moving pgmap to be node-scope, and that
works decently, but first i'm just trying to clena up what i can for
zone device.
Anyway, i get what you're getting at here, and that would be nice.
> > Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations")
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
>
> Anyway LGTM so:
>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
>
many thanks :]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-06 17:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260728194714.3713735-1-gourry@gourry.net>
2026-07-28 19:47 ` [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd() Gregory Price
2026-08-06 13:20 ` David Hildenbrand (Arm)
2026-08-06 13:59 ` Lorenzo Stoakes (ARM)
2026-08-06 17:03 ` Gregory Price
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox