* Re: [PATCH] mm: use softleaf_migration_mkreadable() in change_protection()
2026-12-02 4:59 [PATCH] mm: use softleaf_migration_mkreadable() in change_protection() Chris Down
@ 2026-12-03 3:14 ` Muchun Song
2026-12-03 7:57 ` David Hildenbrand (Arm)
2026-12-03 8:31 ` David Hildenbrand (Arm)
2 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2026-12-03 3:14 UTC (permalink / raw)
To: Chris Down
Cc: Muchun Song, Andrew Morton, Oscar Salvador, David Hildenbrand,
Zi Yan, Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau,
Lorenzo Stoakes, Suren Baghdasaryan, Vlastimil Babka,
Shakeel Butt, Pedro Falcato, Jann Horn, linux-mm, linux-kernel,
Tal Zussman
> On Dec 2, 2026, at 12:59, Chris Down <chris@chrisdown.name> wrote:
>
> change_protection() downgrades a writable migration entry to a readable
> one in change_softleaf_pte(), change_non_present_huge_pmd() and
> hugetlb_change_protection(). Each of them open codes the same choice:
> the new entry is readable exclusive if the folio is anonymous, since a
> writable anon migration entry implies AnonExclusive, and plain readable
> otherwise.
>
> PAGEMAP_SCAN's write-protect path needed the same downgrade, so
> softleaf_migration_mkreadable() was added to leafops.h for it. Let's use
> it in change_protection() too. Each site still handles the soft-dirty
> and uffd bits itself as before. hugetlb_change_protection() only looked
> up the folio for this choice, so its local goes away.
>
> The other places that choose between readable exclusive and readable
> migration entries, such as try_to_migrate_one() and
> __split_huge_pmd_locked(), carry over the exclusive state of the page or
> of the old entry rather than downgrade a writable one, so they are left
> alone.
>
> No functional change intended.
>
> Suggested-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> Signed-off-by: Chris Down <chris@chrisdown.name>
Nive cleanup.
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
THanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: use softleaf_migration_mkreadable() in change_protection()
2026-12-02 4:59 [PATCH] mm: use softleaf_migration_mkreadable() in change_protection() Chris Down
2026-12-03 3:14 ` Muchun Song
@ 2026-12-03 7:57 ` David Hildenbrand (Arm)
2026-12-03 8:31 ` David Hildenbrand (Arm)
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 7:57 UTC (permalink / raw)
To: Chris Down, Andrew Morton
Cc: Muchun Song, Oscar Salvador, Zi Yan, Baolin Wang, Liam R. Howlett,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes, Suren Baghdasaryan,
Vlastimil Babka, Shakeel Butt, Pedro Falcato, Jann Horn, linux-mm,
linux-kernel, Tal Zussman
On 12/2/26 05:59, Chris Down wrote:
> change_protection() downgrades a writable migration entry to a readable
> one in change_softleaf_pte(), change_non_present_huge_pmd() and
> hugetlb_change_protection(). Each of them open codes the same choice:
> the new entry is readable exclusive if the folio is anonymous, since a
> writable anon migration entry implies AnonExclusive, and plain readable
> otherwise.
>
> PAGEMAP_SCAN's write-protect path needed the same downgrade, so
> softleaf_migration_mkreadable() was added to leafops.h for it. Let's use
> it in change_protection() too. Each site still handles the soft-dirty
> and uffd bits itself as before. hugetlb_change_protection() only looked
> up the folio for this choice, so its local goes away.
>
> The other places that choose between readable exclusive and readable
> migration entries, such as try_to_migrate_one() and
> __split_huge_pmd_locked(), carry over the exclusive state of the page or
> of the old entry rather than downgrade a writable one, so they are left
> alone.
>
> No functional change intended.
>
> Suggested-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> Signed-off-by: Chris Down <chris@chrisdown.name>
> ---
> mm/huge_memory.c | 7 +------
> mm/hugetlb.c | 8 +-------
> mm/mprotect.c | 7 +------
> 3 files changed, 3 insertions(+), 19 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 4fc888ddfb69..ce028838bdba 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2704,16 +2704,11 @@ static void change_non_present_huge_pmd(struct mm_struct *mm,
>
> VM_WARN_ON(!pmd_is_valid_softleaf(*pmd));
> if (softleaf_is_migration_write(entry)) {
> - const struct folio *folio = softleaf_to_folio(entry);
> -
> /*
> * A protection check is difficult so
> * just be safe and disable write
> */
> - if (folio_test_anon(folio))
> - entry = make_readable_exclusive_migration_entry(swp_offset(entry));
> - else
> - entry = make_readable_migration_entry(swp_offset(entry));
> + entry = softleaf_migration_mkreadable(entry);
softleaf_migration_mkreadable() looks up the folio again from the pfn ... which
isn't particularly nice. We avoid looking up things again.
But that will all change at some point when we just use the swp_exclusive pte
bit instead.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm: use softleaf_migration_mkreadable() in change_protection()
2026-12-02 4:59 [PATCH] mm: use softleaf_migration_mkreadable() in change_protection() Chris Down
2026-12-03 3:14 ` Muchun Song
2026-12-03 7:57 ` David Hildenbrand (Arm)
@ 2026-12-03 8:31 ` David Hildenbrand (Arm)
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 8:31 UTC (permalink / raw)
To: Chris Down, Andrew Morton
Cc: Muchun Song, Oscar Salvador, Zi Yan, Baolin Wang, Liam R. Howlett,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes, Suren Baghdasaryan,
Vlastimil Babka, Shakeel Butt, Pedro Falcato, Jann Horn, linux-mm,
linux-kernel, Tal Zussman
On 12/2/26 05:59, Chris Down wrote:
> change_protection() downgrades a writable migration entry to a readable
> one in change_softleaf_pte(), change_non_present_huge_pmd() and
> hugetlb_change_protection(). Each of them open codes the same choice:
> the new entry is readable exclusive if the folio is anonymous, since a
> writable anon migration entry implies AnonExclusive, and plain readable
> otherwise.
>
> PAGEMAP_SCAN's write-protect path needed the same downgrade, so
> softleaf_migration_mkreadable() was added to leafops.h for it. Let's use
> it in change_protection() too. Each site still handles the soft-dirty
> and uffd bits itself as before. hugetlb_change_protection() only looked
> up the folio for this choice, so its local goes away.
>
> The other places that choose between readable exclusive and readable
> migration entries, such as try_to_migrate_one() and
> __split_huge_pmd_locked(), carry over the exclusive state of the page or
> of the old entry rather than downgrade a writable one, so they are left
> alone.
>
> No functional change intended.
>
> Suggested-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> Signed-off-by: Chris Down <chris@chrisdown.name>
> ---
> mm/huge_memory.c | 7 +------
> mm/hugetlb.c | 8 +-------
> mm/mprotect.c | 7 +------
> 3 files changed, 3 insertions(+), 19 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 4fc888ddfb69..ce028838bdba 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2704,16 +2704,11 @@ static void change_non_present_huge_pmd(struct mm_struct *mm,
>
> VM_WARN_ON(!pmd_is_valid_softleaf(*pmd));
> if (softleaf_is_migration_write(entry)) {
> - const struct folio *folio = softleaf_to_folio(entry);
> -
> /*
> * A protection check is difficult so
> * just be safe and disable write
> */
> - if (folio_test_anon(folio))
> - entry = make_readable_exclusive_migration_entry(swp_offset(entry));
> - else
> - entry = make_readable_migration_entry(swp_offset(entry));
> + entry = softleaf_migration_mkreadable(entry);
softleaf_migration_mkreadable is not upstream yet, so this change best goes
through Andrew's tree.
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread