From: David Hildenbrand <david@redhat.com>
To: Qian Cai <cai@lca.pw>, akpm@linux-foundation.org
Cc: mhocko@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH -mm v2] mm/page_isolation: fix potential warning from user
Date: Mon, 20 Jan 2020 14:38:38 +0100 [thread overview]
Message-ID: <ba3215a2-d616-c636-e70d-99bb8f504292@redhat.com> (raw)
In-Reply-To: <8c56268d-9b8a-f62e-eca9-7707852a2aaf@redhat.com>
On 20.01.20 14:30, David Hildenbrand wrote:
> On 20.01.20 14:19, Qian Cai wrote:
>> It makes sense to call the WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)
>> from start_isolate_page_range(), but should avoid triggering it from
>> userspace, i.e, from is_mem_section_removable() because it could be a
>> DoS if warn_on_panic is set.
>>
>> While at it, simplify the code a bit by removing an unnecessary jump
>> label and a local variable, so set_migratetype_isolate() could really
>> return a bool.
>>
>> Suggested-by: Michal Hocko <mhocko@kernel.org>
>> Signed-off-by: Qian Cai <cai@lca.pw>
>> ---
>>
>> v2: Improve the commit log.
>> Warn for all start_isolate_page_range() users not just offlining.
>>
>> mm/page_alloc.c | 11 ++++-------
>> mm/page_isolation.c | 30 +++++++++++++++++-------------
>> 2 files changed, 21 insertions(+), 20 deletions(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 621716a25639..3c4eb750a199 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,
>> if (is_migrate_cma(migratetype))
>> return NULL;
>>
>> - goto unmovable;
>> + return page;
>> }
>>
>> for (; iter < pageblock_nr_pages; iter++) {
>> @@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,
>> page = pfn_to_page(pfn + iter);
>>
>> if (PageReserved(page))
>> - goto unmovable;
>> + return page;
>>
>> /*
>> * If the zone is movable and we have ruled out all reserved
>> @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,
>> unsigned int skip_pages;
>>
>> if (!hugepage_migration_supported(page_hstate(head)))
>> - goto unmovable;
>> + return page;
>>
>> skip_pages = compound_nr(head) - (page - head);
>> iter += skip_pages - 1;
>> @@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,
>> * is set to both of a memory hole page and a _used_ kernel
>> * page at boot.
>> */
>> - goto unmovable;
>> + return page;
>> }
>> return NULL;
>> -unmovable:
>> - WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE);
>> - return pfn_to_page(pfn + iter);
>> }
>>
>> #ifdef CONFIG_CONTIG_ALLOC
>> diff --git a/mm/page_isolation.c b/mm/page_isolation.c
>> index e70586523ca3..31f5516f5d54 100644
>> --- a/mm/page_isolation.c
>> +++ b/mm/page_isolation.c
>> @@ -15,12 +15,12 @@
>> #define CREATE_TRACE_POINTS
>> #include <trace/events/page_isolation.h>
>>
>> -static int set_migratetype_isolate(struct page *page, int migratetype, int isol_flags)
>> +static bool set_migratetype_isolate(struct page *page, int migratetype,
>> + int isol_flags)
>
> Why this change?
>
>> {
>> - struct page *unmovable = NULL;
>> + struct page *unmovable = ERR_PTR(-EBUSY);
>
> Also, why this change?
>
>> struct zone *zone;
>> unsigned long flags;
>> - int ret = -EBUSY;
>>
>> zone = page_zone(page);
>>
>> @@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_
>> NULL);
>>
>> __mod_zone_freepage_state(zone, -nr_pages, mt);
>> - ret = 0;
>> }
>>
>> out:
>> spin_unlock_irqrestore(&zone->lock, flags);
>> - if (!ret)
>> +
>> + if (!unmovable) {
>> drain_all_pages(zone);
>> - else if ((isol_flags & REPORT_FAILURE) && unmovable)
>> - /*
>> - * printk() with zone->lock held will guarantee to trigger a
>> - * lockdep splat, so defer it here.
>> - */
>> - dump_page(unmovable, "unmovable page");
>> -
>> - return ret;
>> + } else {
>> + WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE);
>> +
>> + if ((isol_flags & REPORT_FAILURE) && !IS_ERR(unmovable))
>> + /*
>
> Why this change? (!IS_ERR)
>
>
> Some things here look unrelated - or I am missing something :)
>
FWIW, I'd prefer this change without any such cleanups (e.g., I don't
like returning a bool from this function and the IS_ERR handling, makes
the function harder to read than before)
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2020-01-20 13:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-20 13:19 Qian Cai
2020-01-20 13:30 ` David Hildenbrand
2020-01-20 13:38 ` Qian Cai
2020-01-20 13:38 ` David Hildenbrand [this message]
2020-01-20 13:56 ` Qian Cai
2020-01-20 14:01 ` David Hildenbrand
2020-01-20 14:11 ` Qian Cai
2020-01-20 14:13 ` David Hildenbrand
2020-01-20 15:43 ` Michal Hocko
2020-01-20 14:07 ` Michal Hocko
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=ba3215a2-d616-c636-e70d-99bb8f504292@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
/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