Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4185412pxb; Mon, 8 Feb 2021 09:54:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxh07Y0CDGOKS5d6lszORqa4oiOTPhY1IcvbOK/OBL8p9w2PvdIAsv/bAKkTJik372xL38M X-Received: by 2002:a17:906:6b1b:: with SMTP id q27mr3212066ejr.508.1612806841794; Mon, 08 Feb 2021 09:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612806841; cv=none; d=google.com; s=arc-20160816; b=iAFgBt2I0lVQTlKK8ap9KbQwpQI8GHzONJxDqlxa23U71RK+Jf2gepzdZadNoq5u5m in4Xj9oM1oFdE9Oii2vmeE27gbmFsQZHo4YNHbWXyN730Qglt0TUmceughc5PTxFP4dR uDCKeb3V1+wkWZS12ib2zaQJrufh07eORfn41JJm3hrUe23jTq8ORuZCdEumGHO2xD0w 99tcFIky7t5+hLlPkRXdPNoOgvkL4H+9c3W+IypgCC7pMIrkrZWnH+PDv9nuEacuTuKI t7HyQpoUn2pgs8dH6inJrByt9VHC+IwJe8Xk/7/pdjYahNiPtawW8lJEdA4nqmx8iZBL O9FA== 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=8VVlPYUTrA/e/V/9uenVFxTDsnRiQuS0I3tMBtEz5uE=; b=faiMAgrlwIK2ZvfQ8ZjZZJuEg5PJmixDUyQwffdi6YumjPqh2UQzusfCPyBx6QYRm7 LacB1mxD+YGTBJYeGV9JSetehZzkGUUWehT7kJdcBZ8YwqUDQiFpAZMWvAHtCXC8bnJG NOy/OhpjOcG7Tqmz10lMOPQPR9jPctiGs5OlXDW7byb9TL6AMw6r7WCdD5uZMegoJ724 dyWYwlrkNuNpYtnxjQ5NKen6eXpSYoZmEjnHl+HEau8x0bhG1KHLsW1UDAKhnof3joMI BIt5tatTvCPlCsM4uq+83Bctcv8d9kY93uYY/tS1pSNgqE2b+HZfeFYsajCVKKD87Tiu 8U6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aUMzv6lx; 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 k11si11496549ejr.403.2021.02.08.09.53.34; Mon, 08 Feb 2021 09:54:01 -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=aUMzv6lx; 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 S234282AbhBHRw2 (ORCPT + 99 others); Mon, 8 Feb 2021 12:52:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:37210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233967AbhBHPck (ORCPT ); Mon, 8 Feb 2021 10:32:40 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6C6A64ED1; Mon, 8 Feb 2021 15:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797482; bh=KF6IruUkSfV1vancijK4inQAZPt5T+WJYyncJvY99pk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aUMzv6lxXPk/BGZHWqNbtGFzNISCgjsDnex3JLBdwjopXwYugf8RQhC9uNHdKvaPR erwGkzJA4sAJNSX4KVYKpoQCxu4vfqAMbw3I2Wm+UdQ7mECZhMIgN4gG44W3C1pje8 HmE1ufqXk3rHIWtmv74ARDGlsrhlRyLMqZTSczIo= 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.10 102/120] mm, compaction: move high_pfn to the for loop scope Date: Mon, 8 Feb 2021 16:01:29 +0100 Message-Id: <20210208145822.443206228@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145818.395353822@linuxfoundation.org> References: <20210208145818.395353822@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 @@ -1302,7 +1302,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; @@ -1347,6 +1347,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;