From patchwork Mon Jan 20 13:19:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 11342179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20DDA13BD for ; Mon, 20 Jan 2020 13:19:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D80F724677 for ; Mon, 20 Jan 2020 13:19:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="G06DXa04" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D80F724677 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 287396B0654; Mon, 20 Jan 2020 08:19:24 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 236E96B0655; Mon, 20 Jan 2020 08:19:24 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 126F86B0656; Mon, 20 Jan 2020 08:19:24 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id F04096B0654 for ; Mon, 20 Jan 2020 08:19:23 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 8E273180AD804 for ; Mon, 20 Jan 2020 13:19:23 +0000 (UTC) X-FDA: 76398069006.08.crow45_34d406ad8d017 X-Spam-Summary: 2,0,0,67f4a06639f898a8,d41d8cd98f00b204,cai@lca.pw,:akpm@linux-foundation.org:mhocko@kernel.org:david@redhat.com::linux-kernel@vger.kernel.org:cai@lca.pw,RULES_HIT:41:69:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1434:1437:1515:1535:1543:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3871:3872:4117:4321:4385:5007:6119:6261:6653:6691:7875:7903:8660:8957:9592:10004:11026:11232:11233:11473:11658:11914:12043:12297:12438:12517:12519:12555:12663:12679:12683:12895:12986:13148:13230:13894:14018:14096:14181:14394:14721:21080:21444:21451:21627:21990:30012:30051:30054:30065,0,RBL:209.85.219.65:@lca.pw:.lbl8.mailshell.net-62.14.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:74,LUA_SUMMARY:none X-HE-Tag: crow45_34d406ad8d017 X-Filterd-Recvd-Size: 6510 Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Jan 2020 13:19:22 +0000 (UTC) Received: by mail-qv1-f65.google.com with SMTP id o18so13946404qvf.1 for ; Mon, 20 Jan 2020 05:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HgJJtE+3yyE+N9S25iMw/ePK2fC497PluXTrflyuZaE=; b=G06DXa046ce21M+FFj1pf7M+SGMVIOvKQ+KNzI/2S3rOacs4u1ls5MIf1HIAx+FNiE I0qr8pAozP1iqZ2XsgbOehQSm/pMzINNxWS0+mJOho4c8xYI0jGBaMo7emeg/gPMz79t 9evp2GdT1tOWeiM55y76vxTZzbHaA5GWZj3iFKLf3tVmrzp3YS8Yw1gJw3aRjbxo0zzJ tEhmdQHGtK0D9F2I17LwpvEYHEYm7+yVycIsG+Ge8q40XddoVwWDt/e6X5YafgYBAp80 uMJwGSlxMcCeWKaJPzFujOlXNjjIk/px3nfH7a0tbdqNtuNSGUrT8A7fM9gnQYMbpRyw VJUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HgJJtE+3yyE+N9S25iMw/ePK2fC497PluXTrflyuZaE=; b=s5j+T+OYOY9ok2NOOqrid9WPDC7LLzNZC/iooRhMA3lJiFJM5KDmayV6dw92Zc51AY 1cSJJZgijYw4dyA4BoAkgfhpHTm7dU0QLo5Ufsh0JnRSezw0QWblTmkXXJkPUe6qTzzy uRMNevaZUr6LyOsNAOgkhk882EUY/YdSGpwrD8inaJIzyCISYkDhfO0rKp8TsTjHgV9N 89EDoxdr/13bMeLAIohHuzOt54mYnjiDXHIn0btZDEHpvqiWYA8KnlD9/nZLlNdBOV3p mNYlMD+hczA3TQOSj0Zh2u8BvJMJd+STheDbclKhsXnwivOt+eVWp/Adz8T403Iynm3z xc1w== X-Gm-Message-State: APjAAAXSJYYOr/lVWH5hKUoNq85I3AqkRvO1r83T9nUHX9jGA7YIVa+P nNYAiVq4auJgGJPtLsG3ZeGpiw== X-Google-Smtp-Source: APXvYqxsRmhPVJuM4MfM26pZXbz3E1qumMVxOSodoqqDohH3qx7zZcC75mmbeG64Yp8Grh8JNuVP1w== X-Received: by 2002:ad4:55ec:: with SMTP id bu12mr20644399qvb.107.1579526362281; Mon, 20 Jan 2020 05:19:22 -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 t73sm15903831qke.71.2020.01.20.05.19.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jan 2020 05:19:21 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: mhocko@kernel.org, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -mm v2] mm/page_isolation: fix potential warning from user Date: Mon, 20 Jan 2020 08:19:09 -0500 Message-Id: <20200120131909.813-1-cai@lca.pw> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) MIME-Version: 1.0 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: 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 Signed-off-by: Qian Cai Acked-by: Michal Hocko --- 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 -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) { - struct page *unmovable = NULL; + struct page *unmovable = ERR_PTR(-EBUSY); 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)) + /* + * printk() with zone->lock held will likely trigger a + * lockdep splat, so defer it here. + */ + dump_page(unmovable, "unmovable page"); + } + + return !!unmovable; } static void unset_migratetype_isolate(struct page *page, unsigned migratetype)