From: Luiz Capitulino <luizcap@redhat.com>
To: David Hildenbrand <david@redhat.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
yuzhao@google.com
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org,
muchun.song@linux.dev, lcapitulino@gmail.com
Subject: Re: [RFC 2/4] mm: page_owner: use new iteration API
Date: Tue, 11 Feb 2025 11:00:07 -0500 [thread overview]
Message-ID: <4bf1321d-ca18-43d5-9d6a-1b2625be6107@redhat.com> (raw)
In-Reply-To: <40036244-644a-42e0-a5e4-4838a98b1cbc@redhat.com>
On 2025-02-11 10:15, David Hildenbrand wrote:
> On 24.01.25 22:37, Luiz Capitulino wrote:
>> The page_ext_next() function assumes that page extension objects for a
>> page order allocation always reside in the same memory section, which
>> may not be true and could lead to crashes. Use the page_ext_iter API
>> instead.
>>
>> Fixes: e98337d11bbd ("mm/contig_alloc: support __GFP_COMP")
>> Signed-off-by: Luiz Capitulino <luizcap@redhat.com>
>> ---
>
> [...]
>
>> void __folio_copy_owner(struct folio *newfolio, struct folio *old)
>> @@ -364,24 +376,26 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old)
>> int i;
>> struct page_ext *old_ext;
>> struct page_ext *new_ext;
>> + struct page_ext_iter old_iter;
>> + struct page_ext_iter new_iter;
>> struct page_owner *old_page_owner;
>> struct page_owner *new_page_owner;
>> depot_stack_handle_t migrate_handle;
>> - old_ext = page_ext_get(&old->page);
>> + old_ext = page_ext_iter_begin(&old_iter, &old->page);
>> if (unlikely(!old_ext))
>> return;
>> - new_ext = page_ext_get(&newfolio->page);
>> + new_ext = page_ext_iter_begin(&new_iter, &newfolio->page);
>> if (unlikely(!new_ext)) {
>> - page_ext_put(old_ext);
>> + page_ext_iter_end(&old_iter);
>> return;
>> }
>> old_page_owner = get_page_owner(old_ext);
>> new_page_owner = get_page_owner(new_ext);
>> migrate_handle = new_page_owner->handle;
>> - __update_page_owner_handle(new_ext, old_page_owner->handle,
>> + __update_page_owner_handle(&new_iter, old_page_owner->handle,
>> old_page_owner->order, old_page_owner->gfp_mask,
>> old_page_owner->last_migrate_reason,
>> old_page_owner->ts_nsec, old_page_owner->pid,
>> @@ -390,8 +404,13 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old)
>> * Do not proactively clear PAGE_EXT_OWNER{_ALLOCATED} bits as the folio
>> * will be freed after migration. Keep them until then as they may be
>> * useful.
>> + *
>> + * Note that we need to re-grab the page_ext iterator since
>> + * __update_page_owner_handle changed it.
>> */
>> - __update_page_owner_free_handle(new_ext, 0, old_page_owner->order,
>> + page_ext_iter_end(&new_iter);
>> + page_ext_iter_begin(&new_iter, &newfolio->page);
>
> So a page_ext_iter_reset() could be helpful, that wouldn't drop the RCU lock. With that, we could probably also drop the comment.
That's a good suggestion, I'll give it a try.
>
>> + __update_page_owner_free_handle(&new_iter, 0, old_page_owner->order,
>> old_page_owner->free_pid,
>> old_page_owner->free_tgid,
>> old_page_owner->free_ts_nsec);
>> @@ -402,12 +421,12 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old)
>> */
>> for (i = 0; i < (1 << new_page_owner->order); i++) {
>> old_page_owner->handle = migrate_handle;
>> - old_ext = page_ext_next(old_ext);
>> + old_ext = page_ext_iter_next(&old_iter);
>> old_page_owner = get_page_owner(old_ext);
>> }
>> - page_ext_put(new_ext);
>> - page_ext_put(old_ext);
>> + page_ext_iter_end(&new_iter);
>> + page_ext_iter_end(&old_iter);
>
> In general, we should look into implementing the iterator without temporarily dropping the RCU lock I think.
OK.
>
> Nothing jumped at me from a quick glimpse, but yes, this usage is not that easy.
>
next prev parent reply other threads:[~2025-02-11 16:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-24 21:37 [RFC 0/4] mm: page_ext: Fix crash when reserving 1G pages Luiz Capitulino
2025-01-24 21:37 ` [RFC 1/4] mm: page_ext: add an iteration API for page extensions Luiz Capitulino
2025-02-11 15:25 ` David Hildenbrand
2025-02-11 16:07 ` Luiz Capitulino
2025-01-24 21:37 ` [RFC 2/4] mm: page_owner: use new iteration API Luiz Capitulino
2025-02-11 15:15 ` David Hildenbrand
2025-02-11 16:00 ` Luiz Capitulino [this message]
2025-01-24 21:37 ` [RFC 3/4] mm: page_table_check: " Luiz Capitulino
2025-02-11 15:09 ` David Hildenbrand
2025-01-24 21:37 ` [RFC 4/4] mm: page_ext: drop page_ext_next() Luiz Capitulino
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=4bf1321d-ca18-43d5-9d6a-1b2625be6107@redhat.com \
--to=luizcap@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=lcapitulino@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=yuzhao@google.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