linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zi Yan <ziy@nvidia.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Usama Arif <usama.arif@linux.dev>,
	Andrew Morton <akpm@linux-foundation.org>,
	npache@redhat.com, willy@infradead.org, linux-mm@kvack.org,
	matthew.brost@intel.com, joshua.hahnjy@gmail.com,
	hannes@cmpxchg.org, rakie.kim@sk.com, byungchul@sk.com,
	gourry@gourry.net, ying.huang@linux.alibaba.com,
	apopple@nvidia.com, linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH] mm: migrate: transfer large_rmappable flag in folio_migrate_flags()
Date: Wed, 11 Mar 2026 09:38:10 -0400	[thread overview]
Message-ID: <1DA53E52-795E-4057-81F5-E39B85D7CF05@nvidia.com> (raw)
In-Reply-To: <46edc7f1-f97e-4ff3-bf11-a56feb8e33b4@kernel.org>

On 11 Mar 2026, at 9:33, David Hildenbrand (Arm) wrote:

> On 3/11/26 14:23, Usama Arif wrote:
>> folio_migrate_flags() transfers folio state from source to destination
>> during migration, but does not transfer the large_rmappable flag.
>>
>> Migration allocators like alloc_migration_target() and
>> alloc_misplaced_dst_folio() use __folio_alloc() directly without
>> wrapping the result in page_rmappable_folio(), so the destination folio
>> never gets large_rmappable set.
>>
>> This becomes a problem when a folio on the deferred split queue is
>> migrated: the destination folio can be added to the deferred split queue
>> via deferred_split_folio() (which does not check large_rmappable), but
>> when the folio is later freed, folio_unqueue_deferred_split() bails out
>> early because large_rmappable is not set:
>>
>>   if (folio_order(folio) <= 1 || !folio_test_large_rmappable(folio))
>>       return false;
>>
>> This leaves a stale entry on the deferred split queue, leading to
>> use-after-free when the shrinker walks the list.
>>
>> Fix this by transferring large_rmappable in folio_migrate_flags(),
>> consistent with how all other folio flags are handled.
>>
>> Fixes: dafff3f4c850 ("mm: split underused THPs")
>> Signed-off-by: Usama Arif <usama.arif@linux.dev>
>> ---
>>  mm/migrate.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/mm/migrate.c b/mm/migrate.c
>> index 3380021fd3db..ee1c7bc851dd 100644
>> --- a/mm/migrate.c
>> +++ b/mm/migrate.c
>> @@ -846,6 +846,9 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)
>>  	folio_copy_owner(newfolio, folio);
>>  	pgalloc_tag_swap(newfolio, folio);
>>
>> +	if (folio_test_large_rmappable(folio))
>> +		folio_set_large_rmappable(newfolio);
>> +
>>  	mem_cgroup_migrate(folio, newfolio);
>>  }
>>  EXPORT_SYMBOL(folio_migrate_flags);
>
> compaction_alloc_noprof() does the page_rmappable_folio() at the end.
>
> I'd assume that all migration allocation functions must take care of that.
>
> It's a responsibility of the folio allocation code, not folio migration
> code.

I agree. The migration allocation function needs to give a folio or other
types of page matching the original one. Do we want to turn this into
a WARN to make sure newfolio matches folio's large_rmappable state?

--
Best Regards,
Yan, Zi


  reply	other threads:[~2026-03-11 13:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 13:23 Usama Arif
2026-03-11 13:33 ` David Hildenbrand (Arm)
2026-03-11 13:38   ` Zi Yan [this message]
2026-03-11 13:57     ` David Hildenbrand (Arm)
2026-03-11 14:24     ` Usama Arif
2026-03-11 14:28       ` Usama Arif
2026-03-11 14:34       ` David Hildenbrand (Arm)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1DA53E52-795E-4057-81F5-E39B85D7CF05@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=byungchul@sk.com \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew.brost@intel.com \
    --cc=npache@redhat.com \
    --cc=rakie.kim@sk.com \
    --cc=usama.arif@linux.dev \
    --cc=willy@infradead.org \
    --cc=ying.huang@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox