Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1923119pxx; Sat, 31 Oct 2020 02:46:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+A9kGmeUZkwmyU4LPbPXEk+izkvfwiKfu+emH2LvF2dsRk/CGbUOqAk7TJHYBAuo5/QGu X-Received: by 2002:a17:906:8398:: with SMTP id p24mr6598157ejx.401.1604137604019; Sat, 31 Oct 2020 02:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604137604; cv=none; d=google.com; s=arc-20160816; b=Nl/GsJRVvHIaAHTd+5ogjlHM+rYPRTi2kRYvwAgUGiAvU8hU3hImKiuOOHn0WQXaTg C9jibuEjoolV9hfGN41eYpM0kv7r7mtDQsNdvEPXqibt7epl3jd7hu+21lBa159ZwaMl N29PclQNHohpK8hVQRvJHgdIGqHiPZPA+106XNEm/kExRW41GTSjF3YmSC90+t7u0xl5 AX6Z92+yhsfQHiTy7GGl3omg/6LKzR9SQfn0b3lQ3lMhy12My8IGb5BW5ulk7UOEyJ20 ppWZk3Ur1M9SpOuJD+0G1zlgRwfqP1mBrWza2t0+G5Rx138pfbbwo4EoT7sw9PmfTaXD 5XmA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=FtJsFBZndccuKKW8eT/CAL+gK4OCy8zoNb64tIa0f/E=; b=KcA43Qdf4B/zc9/pEoc2X3x8Y6YHMssr8Ep3wZlWb+Gg0+SW+AywvPBKBw4DT82NhT w/jBcS8D1CMT+sRPVfAkuwWSkNyMeVAWiZxurwGb8OH4/tsUW1dv0l7/Ev0RhjazZe70 VPdC2htpSl+NhtJqEVClxEy/e6VQeUsM+c3TbGyNKSSHSpOrTRwcpZnb8AB7/5Z1dbXX Ivo0l7eXTH/JREQ5FvewdBGBGVSJOhucAZfpUrB7SY5REOIxWU4br16AzpR9TeItBZiI GXOlG6CZZQW36HyIfv1aQIKnevE/jhQgMKnL5PleHUf/rAVLcYUIgqbVLUg7FKwUHBbg 9EQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n84ti3TO; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y10si6849756edm.401.2020.10.31.02.46.20; Sat, 31 Oct 2020 02:46:44 -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=n84ti3TO; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgJaJnx (ORCPT + 99 others); Sat, 31 Oct 2020 05:43:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:46858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbgJaJnw (ORCPT ); Sat, 31 Oct 2020 05:43:52 -0400 Received: from aquarius.haifa.ibm.com (nesher1.haifa.il.ibm.com [195.110.40.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 772EA2076D; Sat, 31 Oct 2020 09:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604137432; bh=VvBOXLme6FI5EZGrCkCjihO7J3QUI6NE5sFXDTpUC3o=; h=From:To:Cc:Subject:Date:From; b=n84ti3TOZIKzO0erhtdpxXSJDOhPJHvQ36pCBg85BhjJR1JcDj+PjWvqcz+dZjtY7 IqeuwDi21FroqQ8rU2xVO/YIKB5aHdxcKl2sPSxkSVu/OESGH51S0VQflI/TOoxrBP HP+Zbr/m+KC8W7qkJjD2OheKd5ZjDzIK1Teyfn8g= From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org, linux-xtensa@linux-xtensa.org Cc: Ard Biesheuvel , Chris Zankel , Florian Fainelli , Linus Walleij , Max Filippov , Mike Rapoport , Mike Rapoport , Russell King , linux-kernel@vger.kernel.org Subject: [PATCH] ARM, xtensa: highmem: avoid clobbering non-page aligned memory reservations Date: Sat, 31 Oct 2020 11:43:45 +0200 Message-Id: <20201031094345.6984-1-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel free_highpages() iterates over the free memblock regions in high memory, and marks each page as available for the memory management system. Until commit cddb5ddf2b76 ("arm, xtensa: simplify initialization of high memory pages") it rounded beginning of each region upwards and end of each region downwards. However, after that commit free_highmem() rounds the beginning and end of each region downwards, and we may end up freeing a page that is memblock_reserve()d, resulting in memory corruption. Restore the original rounding of the region boundaries to avoid freeing reserved pages. Fixes: cddb5ddf2b76 ("arm, xtensa: simplify initialization of high memory pages") Link: https://lore.kernel.org/r/20201029110334.4118-1-ardb@kernel.org/ Signed-off-by: Ard Biesheuvel Co-developed-by: Mike Rapoport Signed-off-by: Mike Rapoport --- Max, Russell, Please let me know how do you prefer to take it upstream. If needed this can go via memblock tree. v2: fix words order in the commit message arch/arm/mm/init.c | 4 ++-- arch/xtensa/mm/init.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index d57112a276f5..c23dbf8bebee 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -354,8 +354,8 @@ static void __init free_highpages(void) /* set highmem page free */ for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &range_start, &range_end, NULL) { - unsigned long start = PHYS_PFN(range_start); - unsigned long end = PHYS_PFN(range_end); + unsigned long start = PFN_UP(range_start); + unsigned long end = PFN_DOWN(range_end); /* Ignore complete lowmem entries */ if (end <= max_low) diff --git a/arch/xtensa/mm/init.c b/arch/xtensa/mm/init.c index c6fc83efee0c..8731b7ad9308 100644 --- a/arch/xtensa/mm/init.c +++ b/arch/xtensa/mm/init.c @@ -89,8 +89,8 @@ static void __init free_highpages(void) /* set highmem page free */ for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &range_start, &range_end, NULL) { - unsigned long start = PHYS_PFN(range_start); - unsigned long end = PHYS_PFN(range_end); + unsigned long start = PFN_UP(range_start); + unsigned long end = PFN_DOWN(range_end); /* Ignore complete lowmem entries */ if (end <= max_low) -- 2.28.0