Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50108C433F5 for ; Wed, 15 Dec 2021 17:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343953AbhLOR2o (ORCPT ); Wed, 15 Dec 2021 12:28:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344102AbhLOR1O (ORCPT ); Wed, 15 Dec 2021 12:27:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48900C06137A; Wed, 15 Dec 2021 09:26:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DD8D6619F2; Wed, 15 Dec 2021 17:26:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3F2FC36AE2; Wed, 15 Dec 2021 17:26:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1639589180; bh=xoLehgCkf7T0Iptmtru5f1UbP/+yuh5g2mtCEMlYPhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DhrdJIPk6NZ/0W8SM7nGGKNQZb0OVkekWCNEBRNKvZZGrchLjErVENt4M7lNbTgQp gQeCfMiO6tMm+oW3EGhpmTUwh49GhG/YM/bh+chDFG/ppvXhVLaO2aAoeDryQQ3kxj ML6Ra8bWR+JZk/mP8XmWdjjlNCrJ8StviqRx8ZWY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Mike Rapoport , Tony Lindgren , Mark-PK Tsai Subject: [PATCH 5.4 15/18] memblock: align freed memory map on pageblock boundaries with SPARSEMEM Date: Wed, 15 Dec 2021 18:21:36 +0100 Message-Id: <20211215172023.327233538@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211215172022.795825673@linuxfoundation.org> References: <20211215172022.795825673@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: Mike Rapoport commit f921f53e089a12a192808ac4319f28727b35dc0f upstream. When CONFIG_SPARSEMEM=y the ranges of the memory map that are freed are not aligned to the pageblock boundaries which breaks assumptions about homogeneity of the memory map throughout core mm code. Make sure that the freed memory map is always aligned on pageblock boundaries regardless of the memory model selection. Signed-off-by: Mike Rapoport Tested-by: Tony Lindgren Link: https://lore.kernel.org/lkml/20210630071211.21011-1-rppt@kernel.org/ [backport upstream modification in mm/memblock.c to arch/arm/mm/init.c] Signed-off-by: Mark-PK Tsai Signed-off-by: Greg Kroah-Hartman --- arch/arm/mm/init.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -371,14 +371,14 @@ static void __init free_unused_memmap(vo */ start = min(start, ALIGN(prev_end, PAGES_PER_SECTION)); -#else +#endif /* * Align down here since many operations in VM subsystem * presume that there are no holes in the memory map inside * a pageblock */ start = round_down(start, pageblock_nr_pages); -#endif + /* * If we had a previous bank, and there is a space * between the current bank and the previous, free it. @@ -396,9 +396,11 @@ static void __init free_unused_memmap(vo } #ifdef CONFIG_SPARSEMEM - if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) + if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) { + prev_end = ALIGN(prev_end, pageblock_nr_pages); free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION)); + } #endif }