From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E18CC388F9 for ; Sat, 31 Oct 2020 09:43:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D24FF20885 for ; Sat, 31 Oct 2020 09:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604137434; bh=VvBOXLme6FI5EZGrCkCjihO7J3QUI6NE5sFXDTpUC3o=; h=From:To:Cc:Subject:Date:List-ID:From; b=kD0umZGt7e37Ef7pcER7D5zn5MOukgBLLfAnNL8enGZdQHhfpaPXsaAhD3tNFde5T SDa9f8+WsIJ/8Myk+ic+PeUX6HGs3XV7KQ8QbjB2pbvJMWQaC+KoEkzl30gb69Xncz JvpaO4zupLyuP+NtKqmE34fbIBZ7QSVankGoL670= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbgJaJnx (ORCPT ); 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