* Re: [PATCH 02/13] mm: extract ensure_on_mmlist() helper
[not found] ` <20260427100553.2754667-3-usama.arif@linux.dev>
@ 2026-05-13 13:32 ` David Hildenbrand (Arm)
2026-05-13 17:21 ` Usama Arif
0 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-13 13:32 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, chrisl, kasong, ljs, ziy
Cc: bhe, willy, youngjun.park, hannes, riel, shakeel.butt, alex, kas,
baohua, dev.jain, baolin.wang, npache, Liam.Howlett, ryan.roberts,
Vlastimil Babka, lance.yang, linux-kernel, nphamcs, shikemeng,
kernel-team
On 4/27/26 12:01, Usama Arif wrote:
> When a swap entry is installed in a page table, the mm must be added
> to init_mm.mmlist so that swapoff can find and unuse its swap entries.
> This double-checked locking pattern is currently open-coded in
> try_to_unmap_one() and copy_nonpresent_pte().
>
> Move it into ensure_on_mmlist() in mm/internal.h and convert both
> callers so it can be reused by upcoming PMD-level swap entry code
> paths that also need to register the mm with swapoff.
>
> copy_nonpresent_pte() previously inserted into &src_mm->mmlist rather
> than &init_mm.mmlist, but the insertion point is irrelevant, mmlist
> is a circular list and swapoff walks it entirely from init_mm.mmlist,
> so only membership matters, not position.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
> mm/internal.h | 13 +++++++++++++
> mm/memory.c | 9 +--------
> mm/rmap.c | 7 +------
> 3 files changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/mm/internal.h b/mm/internal.h
> index 5a2ddcf68e0b..7de489689f54 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1952,4 +1952,17 @@ static inline int get_sysctl_max_map_count(void)
> bool may_expand_vm(struct mm_struct *mm, const vma_flags_t *vma_flags,
> unsigned long npages);
>
> +/*
> + * Ensure @mm is on the init_mm.mmlist so swapoff can find it.
> + */
> +static inline void ensure_on_mmlist(struct mm_struct *mm)
> +{
> + if (list_empty(&mm->mmlist)) {
> + spin_lock(&mmlist_lock);
> + if (list_empty(&mm->mmlist))
> + list_add(&mm->mmlist, &init_mm.mmlist);
> + spin_unlock(&mmlist_lock);
> + }
> +}
Instead of talking about the low level detail ("add to mmlist"), maybe we could
just talk about the high-level goal: make sure that the MM can hold swap entries.
mm_prepare_for_swap()
or sth like that?
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 03/13] fs/proc: use softleaf_has_pfn() in pagemap PMD walker
[not found] ` <20260427100553.2754667-4-usama.arif@linux.dev>
@ 2026-05-13 13:35 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-13 13:35 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, chrisl, kasong, ljs, ziy
Cc: bhe, willy, youngjun.park, hannes, riel, shakeel.butt, alex, kas,
baohua, dev.jain, baolin.wang, npache, Liam.Howlett, ryan.roberts,
Vlastimil Babka, lance.yang, linux-kernel, nphamcs, shikemeng,
kernel-team
On 4/27/26 12:01, Usama Arif wrote:
> pagemap_pmd_range_thp() assumes that every non-present PMD is a
> migration entry and unconditionally calls softleaf_to_page(). This
> will crash on any non-present PMD type that does not encode a PFN,
> such as the upcoming PMD-level swap entries.
>
> Guard the page lookup with softleaf_has_pfn(), matching how
> pte_to_pagemap_entry() already handles non-present PTEs.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
Yes, just like pte_to_pagemap_entry() does
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 02/13] mm: extract ensure_on_mmlist() helper
2026-05-13 13:32 ` [PATCH 02/13] mm: extract ensure_on_mmlist() helper David Hildenbrand (Arm)
@ 2026-05-13 17:21 ` Usama Arif
2026-05-13 19:22 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 6+ messages in thread
From: Usama Arif @ 2026-05-13 17:21 UTC (permalink / raw)
To: David Hildenbrand (Arm), Andrew Morton, chrisl, kasong, ljs, ziy
Cc: bhe, willy, youngjun.park, hannes, riel, shakeel.butt, alex, kas,
baohua, dev.jain, baolin.wang, npache, Liam.Howlett, ryan.roberts,
Vlastimil Babka, lance.yang, linux-kernel, nphamcs, shikemeng,
kernel-team
On 13/05/2026 14:32, David Hildenbrand (Arm) wrote:
> On 4/27/26 12:01, Usama Arif wrote:
>> When a swap entry is installed in a page table, the mm must be added
>> to init_mm.mmlist so that swapoff can find and unuse its swap entries.
>> This double-checked locking pattern is currently open-coded in
>> try_to_unmap_one() and copy_nonpresent_pte().
>>
>> Move it into ensure_on_mmlist() in mm/internal.h and convert both
>> callers so it can be reused by upcoming PMD-level swap entry code
>> paths that also need to register the mm with swapoff.
>>
>> copy_nonpresent_pte() previously inserted into &src_mm->mmlist rather
>> than &init_mm.mmlist, but the insertion point is irrelevant, mmlist
>> is a circular list and swapoff walks it entirely from init_mm.mmlist,
>> so only membership matters, not position.
>>
>> Signed-off-by: Usama Arif <usama.arif@linux.dev>
>> ---
>> mm/internal.h | 13 +++++++++++++
>> mm/memory.c | 9 +--------
>> mm/rmap.c | 7 +------
>> 3 files changed, 15 insertions(+), 14 deletions(-)
>>
>> diff --git a/mm/internal.h b/mm/internal.h
>> index 5a2ddcf68e0b..7de489689f54 100644
>> --- a/mm/internal.h
>> +++ b/mm/internal.h
>> @@ -1952,4 +1952,17 @@ static inline int get_sysctl_max_map_count(void)
>> bool may_expand_vm(struct mm_struct *mm, const vma_flags_t *vma_flags,
>> unsigned long npages);
>>
>> +/*
>> + * Ensure @mm is on the init_mm.mmlist so swapoff can find it.
>> + */
>> +static inline void ensure_on_mmlist(struct mm_struct *mm)
>> +{
>> + if (list_empty(&mm->mmlist)) {
>> + spin_lock(&mmlist_lock);
>> + if (list_empty(&mm->mmlist))
>> + list_add(&mm->mmlist, &init_mm.mmlist);
>> + spin_unlock(&mmlist_lock);
>> + }
>> +}
>
> Instead of talking about the low level detail ("add to mmlist"), maybe we could
> just talk about the high-level goal: make sure that the MM can hold swap entries.
>
>
> mm_prepare_for_swap()
>
> or sth like that?
>
Thanks for the review!
Ah so basically rename the function to mm_prepare_for_swap(). I felt like it
makes the function sound more important than it is? But it is a better
name than ensure_on_mmlist(). Maybe mm_prepare_for_swapoff()? As the mmlist
is only used for swapoff.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 02/13] mm: extract ensure_on_mmlist() helper
2026-05-13 17:21 ` Usama Arif
@ 2026-05-13 19:22 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-13 19:22 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, chrisl, kasong, ljs, ziy
Cc: bhe, willy, youngjun.park, hannes, riel, shakeel.butt, alex, kas,
baohua, dev.jain, baolin.wang, npache, Liam.Howlett, ryan.roberts,
Vlastimil Babka, lance.yang, linux-kernel, nphamcs, shikemeng,
kernel-team
On 5/13/26 19:21, Usama Arif wrote:
>
>
> On 13/05/2026 14:32, David Hildenbrand (Arm) wrote:
>> On 4/27/26 12:01, Usama Arif wrote:
>>> When a swap entry is installed in a page table, the mm must be added
>>> to init_mm.mmlist so that swapoff can find and unuse its swap entries.
>>> This double-checked locking pattern is currently open-coded in
>>> try_to_unmap_one() and copy_nonpresent_pte().
>>>
>>> Move it into ensure_on_mmlist() in mm/internal.h and convert both
>>> callers so it can be reused by upcoming PMD-level swap entry code
>>> paths that also need to register the mm with swapoff.
>>>
>>> copy_nonpresent_pte() previously inserted into &src_mm->mmlist rather
>>> than &init_mm.mmlist, but the insertion point is irrelevant, mmlist
>>> is a circular list and swapoff walks it entirely from init_mm.mmlist,
>>> so only membership matters, not position.
>>>
>>> Signed-off-by: Usama Arif <usama.arif@linux.dev>
>>> ---
>>> mm/internal.h | 13 +++++++++++++
>>> mm/memory.c | 9 +--------
>>> mm/rmap.c | 7 +------
>>> 3 files changed, 15 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/mm/internal.h b/mm/internal.h
>>> index 5a2ddcf68e0b..7de489689f54 100644
>>> --- a/mm/internal.h
>>> +++ b/mm/internal.h
>>> @@ -1952,4 +1952,17 @@ static inline int get_sysctl_max_map_count(void)
>>> bool may_expand_vm(struct mm_struct *mm, const vma_flags_t *vma_flags,
>>> unsigned long npages);
>>>
>>> +/*
>>> + * Ensure @mm is on the init_mm.mmlist so swapoff can find it.
>>> + */
>>> +static inline void ensure_on_mmlist(struct mm_struct *mm)
>>> +{
>>> + if (list_empty(&mm->mmlist)) {
>>> + spin_lock(&mmlist_lock);
>>> + if (list_empty(&mm->mmlist))
>>> + list_add(&mm->mmlist, &init_mm.mmlist);
>>> + spin_unlock(&mmlist_lock);
>>> + }
>>> +}
>>
>> Instead of talking about the low level detail ("add to mmlist"), maybe we could
>> just talk about the high-level goal: make sure that the MM can hold swap entries.
>>
>>
>> mm_prepare_for_swap()
>>
>> or sth like that?
>>
>
> Thanks for the review!
Planning on doing more ...
>
> Ah so basically rename the function to mm_prepare_for_swap(). I felt like it
> makes the function sound more important than it is? But it is a better
> name than ensure_on_mmlist(). Maybe mm_prepare_for_swapoff()? As the mmlist
> is only used for swapoff.
Maybe the clearest thing is mm_prepare_for_swap_entries(), because that's what
we're about to establish in these code paths: swap entries.
I wouldn't mention swapoff, but both are better than ensure_on_mmlist ;)
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 01/13] mm: add softleaf_to_pmd() and convert existing callers
[not found] ` <20260427100553.2754667-2-usama.arif@linux.dev>
@ 2026-05-13 19:24 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-13 19:24 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, chrisl, kasong, ljs, ziy
Cc: bhe, willy, youngjun.park, hannes, riel, shakeel.butt, alex, kas,
baohua, dev.jain, baolin.wang, npache, Liam.Howlett, ryan.roberts,
Vlastimil Babka, lance.yang, linux-kernel, nphamcs, shikemeng,
kernel-team
On 4/27/26 12:01, Usama Arif wrote:
> Add softleaf_to_pmd() as the PMD counterpart to softleaf_to_pte(),
> completing the symmetry of the softleaf abstraction for page table
> leaf entries.
>
> The upcoming PMD swap entry support needs to construct PMD entries
> from swap entries. Converting existing swp_entry_to_pmd() callers
> to softleaf_to_pmd() in a prep patch keeps the feature patches
> focused on new functionality rather than mixing refactoring with
> new code.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
> include/linux/leafops.h | 20 ++++++++++++++++++++
> mm/huge_memory.c | 12 ++++++------
> 2 files changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/leafops.h b/include/linux/leafops.h
> index 992cd8bd8ed0..803d312437df 100644
> --- a/include/linux/leafops.h
> +++ b/include/linux/leafops.h
> @@ -108,6 +108,21 @@ static inline softleaf_t softleaf_from_pmd(pmd_t pmd)
> return swp_entry(__swp_type(arch_entry), __swp_offset(arch_entry));
> }
>
> +/**
> + * softleaf_to_pmd() - Obtain a PMD entry from a leaf entry.
> + * @entry: Leaf entry.
> + *
> + * This generates an architecture-specific PMD entry that can be utilised to
> + * encode the metadata the leaf entry encodes.
> + *
> + * Returns: Architecture-specific PMD entry encoding leaf entry.
> + */
> +static inline pmd_t softleaf_to_pmd(softleaf_t entry)
> +{
> + /* Temporary until swp_entry_t eliminated. */
> + return swp_entry_to_pmd(entry);
> +}
> +
Yeah, just what we do for ptes.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 04/13] mm/huge_memory: move softleaf_to_folio() inside migration branch
[not found] ` <20260427100553.2754667-5-usama.arif@linux.dev>
@ 2026-05-13 19:25 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-13 19:25 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, chrisl, kasong, ljs, ziy
Cc: bhe, willy, youngjun.park, hannes, riel, shakeel.butt, alex, kas,
baohua, dev.jain, baolin.wang, npache, Liam.Howlett, ryan.roberts,
Vlastimil Babka, lance.yang, linux-kernel, nphamcs, shikemeng,
kernel-team
On 4/27/26 12:01, Usama Arif wrote:
> change_non_present_huge_pmd() calls softleaf_to_folio() unconditionally
> at the top of the function. softleaf_to_folio() extracts a PFN from
> the entry and converts it to a folio pointer, which is only meaningful
> for migration and device_private entries that encode a real PFN.
>
> A swap entry encodes a swap offset instead, so softleaf_to_folio()
> would produce a bogus pointer and crash on mprotect() when a PMD swap
> entry is present.
>
> Move the call into the migration_write branch where the folio is
> actually used, so the function is safe for any non-present PMD type.
>
> 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 49da0746b8ca..d82a19b5e276 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2619,11 +2619,12 @@ static void change_non_present_huge_pmd(struct mm_struct *mm,
> bool uffd_wp_resolve)
> {
> softleaf_t entry = softleaf_from_pmd(*pmd);
> - const struct folio *folio = softleaf_to_folio(entry);
> pmd_t newpmd;
>
> 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
Right, and the folio is only required on that path
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-05-13 19:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260427100553.2754667-1-usama.arif@linux.dev>
[not found] ` <20260427100553.2754667-3-usama.arif@linux.dev>
2026-05-13 13:32 ` [PATCH 02/13] mm: extract ensure_on_mmlist() helper David Hildenbrand (Arm)
2026-05-13 17:21 ` Usama Arif
2026-05-13 19:22 ` David Hildenbrand (Arm)
[not found] ` <20260427100553.2754667-4-usama.arif@linux.dev>
2026-05-13 13:35 ` [PATCH 03/13] fs/proc: use softleaf_has_pfn() in pagemap PMD walker David Hildenbrand (Arm)
[not found] ` <20260427100553.2754667-2-usama.arif@linux.dev>
2026-05-13 19:24 ` [PATCH 01/13] mm: add softleaf_to_pmd() and convert existing callers David Hildenbrand (Arm)
[not found] ` <20260427100553.2754667-5-usama.arif@linux.dev>
2026-05-13 19:25 ` [PATCH 04/13] mm/huge_memory: move softleaf_to_folio() inside migration branch 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