Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4144456pxb; Mon, 8 Feb 2021 08:56:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZ1lj5NIWeLmBEhoehxMtUYAXhPwhLmqrv9fW8LcYdsppR2RBVa5Ry0sDNoStzfj9yMZ+5 X-Received: by 2002:a17:906:d8ae:: with SMTP id qc14mr18046374ejb.129.1612803390689; Mon, 08 Feb 2021 08:56:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612803390; cv=none; d=google.com; s=arc-20160816; b=Ivrtg51wtAGreqmCMWPZdI97R1H7NfBvNmyCx8LOmRhWX3WrkXdZe1+f1z9Sr5fBGW iKKnmXjpAJGo/p1HqSUKhKJwstrMIqMPm/irlb20GZAOK/KNiuGnDz6OGOW+/5yqSBgX 6nnUhrSlEH069N/KIOcYZUE04Bly6l0SlIhSCX7foMiOUs/GO6L8dHcqeqYXMnBC+L3x /p6u1YyoWCkn+iZZpFwbfCW2VxydgNWjmmqgd/Pqr/t60wDg5RKD3xo74LP12H9dkre4 TlbL1LLVnotRpAfUE6e2uQXkP0laIa3VWVag9wLzR6ziYj2q7jJGr49VyLS38edA7vnX VxOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O2OhO83rX4PpJHexoz1WU36jVgAJdF1fcvR8GnYimrc=; b=kNz6Swah/OIJ3D6soE+QwPozGtsE7zKFAOadUmBiDNNuJyq8U51HypoUTrRQxbW+fk kUku78pX/+LGghJqe/9WKybI1BJsxOV/sMbAzYVE6gcJkxlXM3cESfRXkiiYBu6q3IYv 4KMP9Lrx5zQ5Kh7/9ql3EiRirN67iZ8GKABVyVwuTnV9rNkhYMc+fO2aXuyxQiokjpfx pfaJozAJgXyn66DaDbzFpukqHjjHtdfM0skpgBWHJd+dHyxzBc9p9/h+P+njFLBMRbba xoUamqjVJL7VwGs0b5elVfTrKUc5HoX9BKF7VIqGC7eDcoKlfq/lgYPrtrE/pCu+xqtP +vqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XhEg6TV1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr11si3674626ejc.518.2021.02.08.08.56.07; Mon, 08 Feb 2021 08:56:30 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=XhEg6TV1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234638AbhBHQw3 (ORCPT + 99 others); Mon, 8 Feb 2021 11:52:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:60180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233398AbhBHPRa (ORCPT ); Mon, 8 Feb 2021 10:17:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2CCBA64EE1; Mon, 8 Feb 2021 15:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797126; bh=FcRLTV92hDDizMMyrmm6ePyVSC5ysfWszMFF5A0drqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XhEg6TV1ze9f3Ji9bjRuYVd8NTG/oVzyyWDyZIlTtilYHuDQR9vuwvcXk35exINoo NWaWJq2GtEmQ4eln7+Lie1qjNuCAjOpTIop8D7orhbxVahz+k3qKLUSaobV8WUs1OD WUd0/DlgLGWIlzDNYGeooXuLVsQHWtV5c90wT42Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rokudo Yan , Mel Gorman , Vlastimil Babka , Andrew Morton , Linus Torvalds Subject: [PATCH 5.4 52/65] mm, compaction: move high_pfn to the for loop scope Date: Mon, 8 Feb 2021 16:01:24 +0100 Message-Id: <20210208145812.227257840@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145810.230485165@linuxfoundation.org> References: <20210208145810.230485165@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rokudo Yan commit 74e21484e40bb8ce0f9828bbfe1c9fc9b04249c6 upstream. In fast_isolate_freepages, high_pfn will be used if a prefered one (ie PFN >= low_fn) not found. But the high_pfn is not reset before searching an free area, so when it was used as freepage, it may from another free area searched before. As a result move_freelist_head(freelist, freepage) will have unexpected behavior (eg corrupt the MOVABLE freelist) Unable to handle kernel paging request at virtual address dead000000000200 Mem abort info: ESR = 0x96000044 Exception class = DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000044 CM = 0, WnR = 1 [dead000000000200] address between user and kernel address ranges -000|list_cut_before(inline) -000|move_freelist_head(inline) -000|fast_isolate_freepages(inline) -000|isolate_freepages(inline) -000|compaction_alloc(?, ?) -001|unmap_and_move(inline) -001|migrate_pages([NSD:0xFFFFFF80088CBBD0] from = 0xFFFFFF80088CBD88, [NSD:0xFFFFFF80088CBBC8] get_new_p -002|__read_once_size(inline) -002|static_key_count(inline) -002|static_key_false(inline) -002|trace_mm_compaction_migratepages(inline) -002|compact_zone(?, [NSD:0xFFFFFF80088CBCB0] capc = 0x0) -003|kcompactd_do_work(inline) -003|kcompactd([X19] p = 0xFFFFFF93227FBC40) -004|kthread([X20] _create = 0xFFFFFFE1AFB26380) -005|ret_from_fork(asm) The issue was reported on an smart phone product with 6GB ram and 3GB zram as swap device. This patch fixes the issue by reset high_pfn before searching each free area, which ensure freepage and freelist match when call move_freelist_head in fast_isolate_freepages(). Link: http://lkml.kernel.org/r/20190118175136.31341-12-mgorman@techsingularity.net Link: https://lkml.kernel.org/r/20210112094720.1238444-1-wu-yan@tcl.com Fixes: 5a811889de10f1eb ("mm, compaction: use free lists to quickly locate a migration target") Signed-off-by: Rokudo Yan Acked-by: Mel Gorman Acked-by: Vlastimil Babka Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1276,7 +1276,7 @@ fast_isolate_freepages(struct compact_co { unsigned int limit = min(1U, freelist_scan_limit(cc) >> 1); unsigned int nr_scanned = 0; - unsigned long low_pfn, min_pfn, high_pfn = 0, highest = 0; + unsigned long low_pfn, min_pfn, highest = 0; unsigned long nr_isolated = 0; unsigned long distance; struct page *page = NULL; @@ -1321,6 +1321,7 @@ fast_isolate_freepages(struct compact_co struct page *freepage; unsigned long flags; unsigned int order_scanned = 0; + unsigned long high_pfn = 0; if (!area->nr_free) continue;