From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFF6CC2D0DB for ; Mon, 20 Jan 2020 13:38:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 923ED2087E for ; Mon, 20 Jan 2020 13:38:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="Yc8FBZqT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 923ED2087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lca.pw Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 362076B065A; Mon, 20 Jan 2020 08:38:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 313AF6B065B; Mon, 20 Jan 2020 08:38:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 229C16B065C; Mon, 20 Jan 2020 08:38:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id 0CCE56B065A for ; Mon, 20 Jan 2020 08:38:15 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id BE5182472 for ; Mon, 20 Jan 2020 13:38:14 +0000 (UTC) X-FDA: 76398116508.25.desk22_47f30e6d09151 X-HE-Tag: desk22_47f30e6d09151 X-Filterd-Recvd-Size: 7543 Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Jan 2020 13:38:14 +0000 (UTC) Received: by mail-qv1-f68.google.com with SMTP id o18so13970621qvf.1 for ; Mon, 20 Jan 2020 05:38:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VsoGp109ufXvJlVZJZ7+0lYM452uESSHevplYutSYdo=; b=Yc8FBZqTZ49PR5XXHmSJg+sa0E2yA2SnM6T59xCyidB4uZeLSzVy3UCVN/qMge68b1 fjqdT3489T5Z9hCB68ih4OOwJ7kCdrHvSclJqdiHN0Y/83q6BhWQUHxOOR2JZQKib/ol IVT97/PKh0h37qHZrTsQV6nsAf4i2OqGL+rlxPdD/ODZU2JSFurICYGDHrm0NPhB4qo0 XOmN1zU5d3ygI6eneSowmjWlfPkWWHuEdhIc/aOG/ldQrdJZwuJ1zRX+h7e+jW3Bcb4I szkVtjbdL6RtZQ/rzLdjS30XlWuEzg99yvFOAs9wPiGEQMnL+ioVC2Korl/zK2n8Pkdu OyFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VsoGp109ufXvJlVZJZ7+0lYM452uESSHevplYutSYdo=; b=G1iHEPDGgu4bvycMr+xRIxinbjObC2s4Wnh2qJJgC27wc5hPcZO23SqGNJGm8TL0jI RFIed+UniWES3mWj6S3jiCsppjxLvt6AYnmuEHdLOmI0bbozsM9axOCZWB0XDo6SdbJJ PNSAStCc9H8c2OJtxPi4o0yTo0pVqdxzlB0SssA9w7oKsGxmI33nnnOef5GOoimqxmi2 OyCXpxGJx0N5aTQdr3iy7IqYYraCXyoHJvHLWzGBGm8r8gk5AYypSLi+fxxsiUDM0NFL U0mnB9eI/1bBQ2Y/fungHIIOu9xx7XJ3og4rvVdH5kec/BJWwEYmoWfagGZ3kPIOBQgm iIsA== X-Gm-Message-State: APjAAAWGZnEvkV/1iE+j9xLjzrpDN03VyOsAIdwyrzDfA2ENYaYfZ0x0 c786YhtKWvo/7puuwsK0vxtV4x+oyWFGxg== X-Google-Smtp-Source: APXvYqzJWHkLYwbnfPaTEh8dSNBmbk2tJ+IQclnyI2T+yocRWe19nO7fmcyCO3qWekozAS8DWPvdzQ== X-Received: by 2002:a0c:a145:: with SMTP id d63mr21206033qva.120.1579527493658; Mon, 20 Jan 2020 05:38:13 -0800 (PST) Received: from qians-mbp.fios-router.home (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id i90sm17560198qtd.49.2020.01.20.05.38.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jan 2020 05:38:13 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.40.2.2.4\)) Subject: Re: [PATCH -mm v2] mm/page_isolation: fix potential warning from user From: Qian Cai In-Reply-To: <8c56268d-9b8a-f62e-eca9-7707852a2aaf@redhat.com> Date: Mon, 20 Jan 2020 08:38:12 -0500 Cc: Andrew Morton , Michal Hocko , Linux-MM , LKML Content-Transfer-Encoding: quoted-printable Message-Id: <28542D23-FCB7-4342-B77C-65C7B1F162FC@lca.pw> References: <20200120131909.813-1-cai@lca.pw> <8c56268d-9b8a-f62e-eca9-7707852a2aaf@redhat.com> To: David Hildenbrand X-Mailer: Apple Mail (2.3608.40.2.2.4) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > On Jan 20, 2020, at 8:30 AM, David Hildenbrand = wrote: >=20 > On 20.01.20 14:19, Qian Cai wrote: >> It makes sense to call the WARN_ON_ONCE(zone_idx(zone) =3D=3D = 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. >>=20 >> 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. >>=20 >> Suggested-by: Michal Hocko >> Signed-off-by: Qian Cai >> --- >>=20 >> v2: Improve the commit log. >> Warn for all start_isolate_page_range() users not just offlining. >>=20 >> mm/page_alloc.c | 11 ++++------- >> mm/page_isolation.c | 30 +++++++++++++++++------------- >> 2 files changed, 21 insertions(+), 20 deletions(-) >>=20 >> 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; >>=20 >> - goto unmovable; >> + return page; >> } >>=20 >> for (; iter < pageblock_nr_pages; iter++) { >> @@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone = *zone, struct page *page, >> page =3D pfn_to_page(pfn + iter); >>=20 >> if (PageReserved(page)) >> - goto unmovable; >> + return page; >>=20 >> /* >> * 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; >>=20 >> if = (!hugepage_migration_supported(page_hstate(head))) >> - goto unmovable; >> + return page; >>=20 >> skip_pages =3D compound_nr(head) - (page - = head); >> iter +=3D 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) =3D=3D ZONE_MOVABLE); >> - return pfn_to_page(pfn + iter); >> } >>=20 >> #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 >>=20 >> -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) >=20 > Why this change? >=20 >> { >> - struct page *unmovable =3D NULL; >> + struct page *unmovable =3D ERR_PTR(-EBUSY); >=20 > Also, why this change? >=20 >> struct zone *zone; >> unsigned long flags; >> - int ret =3D -EBUSY; >>=20 >> zone =3D page_zone(page); >>=20 >> @@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page = *page, int migratetype, int isol_ >> = NULL); >>=20 >> __mod_zone_freepage_state(zone, -nr_pages, mt); >> - ret =3D 0; >> } >>=20 >> 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) =3D=3D ZONE_MOVABLE); >> + >> + if ((isol_flags & REPORT_FAILURE) && !IS_ERR(unmovable)) >> + /* >=20 > Why this change? (!IS_ERR) >=20 >=20 > Some things here look unrelated - or I am missing something :) The original =E2=80=9Cret=E2=80=9D variable looks ugly to me, so I just = removed that and consolidated with the =E2=80=9Cunmovable=E2=80=9D pointer to always be able to report an = error. Since this cleanup is really small, I did not bother send a separate patch for it.=