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=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 297D7C4BA24 for ; Thu, 27 Feb 2020 07:45:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE64A24656 for ; Thu, 27 Feb 2020 07:45:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE64A24656 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 16DF36B0006; Thu, 27 Feb 2020 02:45:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F7D06B0007; Thu, 27 Feb 2020 02:45:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F00AB6B0008; Thu, 27 Feb 2020 02:45:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id D52FF6B0006 for ; Thu, 27 Feb 2020 02:45:50 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7D5CF180AD806 for ; Thu, 27 Feb 2020 07:45:50 +0000 (UTC) X-FDA: 76535122860.25.jar16_5009ef4bfeb5c X-HE-Tag: jar16_5009ef4bfeb5c X-Filterd-Recvd-Size: 5049 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 27 Feb 2020 07:45:49 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E8D6EAD5D; Thu, 27 Feb 2020 07:45:47 +0000 (UTC) Subject: Re: [bug report] mm, compaction: capture a page under direct compaction To: Andrew Morton Cc: Dan Carpenter , mgorman@techsingularity.net, linux-mm@kvack.org References: <20200224062949.mhyi2ntdiq4vbptm@kili.mountain> <82147552-be4c-84cc-53d8-f00711859427@suse.cz> <20200226175614.5dfe21b53cad9f8bca084a2b@linux-foundation.org> From: Vlastimil Babka Message-ID: <18b0df3c-0589-d96c-23fa-040798fee187@suse.cz> Date: Thu, 27 Feb 2020 08:45:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200226175614.5dfe21b53cad9f8bca084a2b@linux-foundation.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 2/27/20 2:56 AM, Andrew Morton wrote: > On Wed, 26 Feb 2020 18:04:56 +0100 Vlastimil Babka wrote: > >> On 2/24/20 7:35 AM, Dan Carpenter wrote: >> > Hello Mel Gorman, >> > >> > This is a semi-automatic email about new static checker warnings. >> > >> > The patch 5e1f0f098b46: "mm, compaction: capture a page under direct >> > compaction" from Mar 5, 2019, leads to the following Smatch complaint: >> > >> > mm/compaction.c:2321 compact_zone_order() >> > error: we previously assumed 'capture' could be null (see line 2313) >> > >> >> ----8<---- >> >From fb264bb52576a0582e8a92952cf91e8b61d105c3 Mon Sep 17 00:00:00 2001 >> From: Vlastimil Babka >> Date: Wed, 26 Feb 2020 17:53:54 +0100 >> Subject: [PATCH] mm, compaction: fully assume capture can be NULL in >> compact_zone_order() >> > > Why don't we instead remove the first check for NULL? Remove some dead > code instead of adding some? > Sure, works too. Anyone creating a new caller and trying to pass NULL will crash quickly. ----8<---- >From 3118d9bea8a0fcef294915220f824674fb039ec3 Mon Sep 17 00:00:00 2001 From: Vlastimil Babka Date: Wed, 26 Feb 2020 17:53:54 +0100 Subject: [PATCH] mm, compaction: fully assume capture is not NULL in compact_zone_order() Dan reports: The patch 5e1f0f098b46: "mm, compaction: capture a page under direct compaction" from Mar 5, 2019, leads to the following Smatch complaint: mm/compaction.c:2321 compact_zone_order() error: we previously assumed 'capture' could be null (see line 2313) mm/compaction.c 2288 static enum compact_result compact_zone_order(struct zone *zone, int order, 2289 gfp_t gfp_mask, enum compact_priority prio, 2290 unsigned int alloc_flags, int classzone_idx, 2291 struct page **capture) ^^^^^^^ 2313 if (capture) ^^^^^^^ Check for NULL 2314 current->capture_control = &capc; 2315 2316 ret = compact_zone(&cc, &capc); 2317 2318 VM_BUG_ON(!list_empty(&cc.freepages)); 2319 VM_BUG_ON(!list_empty(&cc.migratepages)); 2320 2321 *capture = capc.page; ^^^^^^^^ Unchecked dereference. 2322 current->capture_control = NULL; 2323 In practice this is not an issue, as the only caller path passes non-NULL capture: __alloc_pages_direct_compact() struct page *page = NULL; try_to_compact_pages(capture = &page); compact_zone_order(capture = capture); So let's remove the unnecessary check, which should also make Smatch happy. Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction") Reported-by: Dan Carpenter Suggested-by: Andrew Morton Signed-off-by: Vlastimil Babka Cc: Mel Gorman --- mm/compaction.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git mm/compaction.c mm/compaction.c index 672d3c78c6ab..35c991fbf983 100644 --- mm/compaction.c +++ mm/compaction.c @@ -2310,8 +2310,7 @@ static enum compact_result compact_zone_order(struct zone *zone, int order, .page = NULL, }; - if (capture) - current->capture_control = &capc; + current->capture_control = &capc; ret = compact_zone(&cc, &capc); @@ -2333,6 +2332,7 @@ int sysctl_extfrag_threshold = 500; * @alloc_flags: The allocation flags of the current allocation * @ac: The context of current allocation * @prio: Determines how hard direct compaction should try to succeed + * @capture: Pointer to free page created by compaction will be stored here * * This is the main entry point for direct page compaction. */ -- 2.25.1