Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1137765ybt; Tue, 7 Jul 2020 08:34:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4eITVDWzam8O70wF89uRsccHVAqfotI/K0aUFZknbbuiqp5kBCstcpuwd6Bv0wo1mvkNO X-Received: by 2002:a05:6402:1a54:: with SMTP id bf20mr61428450edb.69.1594136089359; Tue, 07 Jul 2020 08:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594136089; cv=none; d=google.com; s=arc-20160816; b=DVxgbQiMXfMDG4jigrhRJ3ELwOYWWU8Tbu6aOdXZjypgsP0b6q1a+NXcr1fV4FwnWu xK2PN2yC5BkiGEu0uGoSeWa5K4376c4FMg7Idx/Qan/VLJ288323T8aeicp51wuppTXV QeTNB4imS9bFdyR9YCyPnEsTk+XcOQ3juwnx+FmauwxKRg7+/+6Xhgd76AUWv+jUG7r5 5sCAz3Vwd3HuqKTMIHPp21OY3AG0N/UoD4kd9FOButLKLrCuyNO3l7mvw6/eHXrinhIb Ms+h2pYrjXX5rPhmpqClclri5dos24y2CvL9JXN9PtW4ATuC6utNNwHc3X9/qlsuGU2y DYWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tbLeifwCW+CuN6zd2JCjxvUueUVN4SWkyTTnk8X6DVs=; b=jx8o4z9BNO/Of9D1xyAViYNZJ5pMW7EE8eQQ9+/ZZ1eZEdr93JyXepg6m1QLByWQNu Lz3vPxWIuHCv8o3pVYeTUHpQMRR92GK3tUGOQgye65SjDaxFGJNRqUesr5ymY7LatKqP ot4bBsLJEtDBDlWN39Z7SGw+wbS08VCXIhXTPU17FxMI12+RIGXOF0Oz1YSTT2xGk7Z6 Azg4dMrMmIrhJQXc8sjb/ZFMWbDb9EMOyXQq0b9itW1G9NQuWvR4vUqkVcIwa4BvBKJz j3AfWaR2kW2xmeuvYrereasjbp+rE9Rn9LI4ev9cBlYTpgy65hJ9k/Z8/m1hjDqeeOOK 28Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QIfuaEVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn9si11013189edb.344.2020.07.07.08.34.25; Tue, 07 Jul 2020 08:34:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QIfuaEVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729799AbgGGPWL (ORCPT + 99 others); Tue, 7 Jul 2020 11:22:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:34438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729791AbgGGPWF (ORCPT ); Tue, 7 Jul 2020 11:22:05 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 31B39206E2; Tue, 7 Jul 2020 15:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135324; bh=pOz1h0Kui2vd4TQTtCN/LUp1rK8LonyhxFM4eNU/vBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QIfuaEVJrJJ0FU73iXlHgr1gZ8D9Kl57Psqfy7QOt/cIL42LLZXKn63mbKvVBEAaC XCvEZ/wS2JdxgPecYxcWG0tPPOac+dD6pubRUuBFy2hBRuKv+3KWE3QaPyJb5oYQHk SWCdoZVFANRNOy6m26o8so6qARrohC23/XzaX+GI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Andrew Morton , Vlastimil Babka , Mel Gorman , Linus Torvalds Subject: [PATCH 5.4 61/65] mm, compaction: fully assume capture is not NULL in compact_zone_order() Date: Tue, 7 Jul 2020 17:17:40 +0200 Message-Id: <20200707145755.418273739@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145752.417212219@linuxfoundation.org> References: <20200707145752.417212219@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vlastimil Babka commit 6467552ca64c4ddd2b83ed73192107d7145f533b upstream. 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 Signed-off-by: Andrew Morton Reviewed-by: Andrew Morton Acked-by: Mel Gorman Link: http://lkml.kernel.org/r/18b0df3c-0589-d96c-23fa-040798fee187@suse.cz Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/compaction.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2310,8 +2310,7 @@ static enum compact_result compact_zone_ .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. */