Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753647AbcLISLY (ORCPT ); Fri, 9 Dec 2016 13:11:24 -0500 Received: from mail-bl2nam02on0064.outbound.protection.outlook.com ([104.47.38.64]:56179 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753451AbcLISLV (ORCPT ); Fri, 9 Dec 2016 13:11:21 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Robert.Richter@cavium.com; From: Robert Richter To: Russell King , Catalin Marinas , Will Deacon CC: Ard Biesheuvel , David Daney , Mark Rutland , Hanjun Guo , James Morse , Yisheng Xie , Robert Richter , , , Subject: [PATCH] arm64: mm: Fix NOMAP page initialization Date: Fri, 9 Dec 2016 19:10:41 +0100 Message-ID: <1481307042-29773-1-git-send-email-rrichter@cavium.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [92.229.93.144] X-ClientProxiedBy: AM4PR0701CA0019.eurprd07.prod.outlook.com (10.165.102.29) To BY2PR07MB2342.namprd07.prod.outlook.com (10.166.114.144) X-MS-Office365-Filtering-Correlation-Id: d346bf84-3c61-4399-ba02-08d4205ec55f X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BY2PR07MB2342; X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB2342;3:JBdQYg5GfH5CFpjc6VHZgI0E8Zs1Onj/iHL/DKj4Vn8y9TNya6ROFKuVyoJAHPgSDtK075jgsQ9SLp/xjf3k+p2jVxhaYa7e9SWTtI4VXi1t6cxxGUcU2Cbh79a0yCeiyAHOW3K6Tf3xdl7bCa22YK1F0qAYP+bGcaXjvLzyDgaOBHFhYfvHH+YyTg+I2piV63UiE6CHRI1S+I98RpGoetmM/5/FBXLwhUO+afYJ4YiIZ66YgXUckJov+qJpUVCNlec+WGgKxD7rs9XmUbHWRw== X-Microsoft-Exchange-Di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y9vJAgA+xVrrVdtE;20:VE1pS1oJDCSIXkXspYxZYOTnIyKj0GZPUR7rd+xbctzy8UHzJDrXaBDFh+CbaCs3Fjsh83dq6/k082bcZLPeyU/K4VS206iJOyPTCf8qW6n2KFLWtOeWNfAqyFUzmwitIImTyJSLSdOC0jFSRUbI8ut8P6dNJDLSBI9S9h0VXyY8qxW6RFr0aei8XANWlQDx0Zn9MbD1eWDaBuUb5wU4iZYfdLxDK8kJNK3w+jN19vgRg0C4s9Qt0CTw8vaR2hqM3vM34E3cv7qx97acxeO1lf95VFilU85hxQMksuZSGbDdwT0U+kncZxj5BcrfmZklcXjbOLOWIHzwBdSebpg3rXfpJqHPLSQ/0N2vCLfzeJXPviTil5L6q3muR5hT02sU0MkNAifvUKNIVucoAIDJ6NlZHiuHMJTClHk5xffg81n5N4UXXulf/34ZHSISAQDc4um8iXNJ8IWM6QZCFvy+UQ8JNAS3BorVLqAVLUzz/tGhelyxjDy7T6Fe9l/6yqtp X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(20558992708506); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123564025)(20161123555025)(20161123562025)(20161123560025)(6072148);SRVR:BY2PR07MB2342;BCL:0;PCL:0;RULEID:;SRVR:BY2PR07MB2342; X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB2342;4:6VpGh6UDVoPw6Wsj5CQc4b/mTdxdr0cURlJV1tj6bIwS/DIADPWs4mL6gwB989sQwL+8fPYQZrcnDXxeRlCU315/ABJtViuNpreies4hepYtVaDu5UDc/9GZ/2BtD+jYgaguwVIp2GTqsTkxUAcJvZIXw9W9QQb/l1qkTAiHbYG/ALVUriN5uc8ug4sq6vzqnw8MzwVSdVYvy8/qVonk/O+/MoOnIWCc0muwz7Xv6IuHbdksAiSbhmB4jEhD29lkzXk4Kugo+yiym+2dw9TGEv4QUdJUmwBTOFIOEf99SH1y2bGUPSM+LTUJrgGInnPeWBKZNPjv5W6mtocki3pGE5/zTysuXF47ql6nha1ikGXLAtodo0A8oZeIsUCNUHn2VjJpD/kn4ZfVzHtUsFYrZ3WLGiOWSFVOncPJ5TCCTXc+YE7PG5RDE4ZIKafflwUDww2GerqEdprp9T7FLXD+XnKnOpH8O2QTBeTEiHO1r178Rsh8xh3jjbs7/CYfZNkC1oyjhZfTcKHhNdnhMIFGbSPVgcdBGcNmgrEsqEGMZLAQI+LF2urNuXdI+xOO2CaYrSsN36lxIl1W2v+4aCWv4lSktcohghTTacWszq8IwspkoY8S/7kRqrr2kl6u31pm X-Forefront-PRVS: 015114592F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(7916002)(39850400002)(39410400002)(39840400002)(39450400003)(199003)(189002)(5001770100001)(38730400001)(33646002)(101416001)(50986999)(36756003)(6512006)(92566002)(5003940100001)(6666003)(6506006)(305945005)(3846002)(6486002)(7736002)(48376002)(97736004)(50466002)(6116002)(189998001)(8676002)(50226002)(68736007)(7416002)(81156014)(42186005)(105586002)(5660300001)(81166006)(47776003)(66066001)(4326007)(2906002)(575784001)(106356001);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR07MB2342;H:rric.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR07MB2342;23:ZTZ/YT7ZoZJl2WS3H9lsHJOboio1bKzlmC+q7Ke0h?= =?us-ascii?Q?SIrKUjt1ka83NLLFCJsbRDVLsQpOd9rqUX0PQ1VpsZ7f1eTSK9wd+nYnfmPL?= =?us-ascii?Q?B7czb+JtaUle6xUHvBh0U/kh0Xk2FbsueXuXgT/TcT4a1NWgbjP/xnOWG4sH?= =?us-ascii?Q?AL6w8u1iSiS/xqTbkk76hYIq9Bvw3dTwrpFiNOJC5+cMPIxgUXApJBBzOMXp?= =?us-ascii?Q?ce5diphl+PR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UrAgteteowX7sLXvGe51k3mI3VfMQyiaiUt9VvvU7QqtDjQudEskbMRAVqjTQjlQ7Oah5nXVQY1CghvqBTv7lE5Sg8TPARB4D12dCjCRwXq+n8X6s4btx8Kj956UJ0s7sAlPHcVtndVK4PX2v/komlhvXpOhNqbN6VKxofCzV+dHofEthfZkcbcJQe149KRd7CeKjMBntB5Ag== X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2016 18:11:14.9850 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR07MB2342 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4048 Lines: 125 On ThunderX systems with certain memory configurations we see the following BUG_ON(): kernel BUG at mm/page_alloc.c:1848! This happens for some configs with 64k page size enabled. The BUG_ON() checks if start and end page of a memmap range belongs to the same zone. The BUG_ON() check fails if a memory zone contains NOMAP regions. In this case the node information of those pages is not initialized. This causes an inconsistency of the page links with wrong zone and node information for that pages. NOMAP pages from node 1 still point to the mem zone from node 0 and have the wrong nid assigned. The reason for the mis-configuration is a change in pfn_valid() which reports pages marked NOMAP as invalid: 68709f45385a arm64: only consider memblocks with NOMAP cleared for linear mapping This causes pages marked as nomap being no longer reassigned to the new zone in memmap_init_zone() by calling __init_single_pfn(). Fixing this by implementing an arm64 specific early_pfn_valid(). This causes the whole mem range including NOMAP memory to be initialized by __init_single_page() and ensures consistency of page links to zone, node and section. The HAVE_ARCH_PFN_VALID config option now requires an explicit definiton of early_pfn_valid() in the same way as pfn_valid(). This allows a customized implementation of early_pfn_valid() which redirects to memblock_is_memory() for arm64. Signed-off-by: Robert Richter --- arch/arm/include/asm/page.h | 1 + arch/arm64/include/asm/page.h | 2 ++ arch/arm64/mm/init.c | 12 ++++++++++++ include/linux/mmzone.h | 5 ++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h index 4355f0ec44d6..79761bd55f94 100644 --- a/arch/arm/include/asm/page.h +++ b/arch/arm/include/asm/page.h @@ -158,6 +158,7 @@ typedef struct page *pgtable_t; #ifdef CONFIG_HAVE_ARCH_PFN_VALID extern int pfn_valid(unsigned long); +#define early_pfn_valid(pfn) pfn_valid(pfn) #endif #include diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h index 8472c6def5ef..17ceb7435ded 100644 --- a/arch/arm64/include/asm/page.h +++ b/arch/arm64/include/asm/page.h @@ -49,6 +49,8 @@ typedef struct page *pgtable_t; #ifdef CONFIG_HAVE_ARCH_PFN_VALID extern int pfn_valid(unsigned long); +extern int early_pfn_valid(unsigned long); +#define early_pfn_valid early_pfn_valid #endif #include diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 212c4d1e2f26..fbc136533472 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -145,11 +145,23 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) #endif /* CONFIG_NUMA */ #ifdef CONFIG_HAVE_ARCH_PFN_VALID + int pfn_valid(unsigned long pfn) { return memblock_is_map_memory(pfn << PAGE_SHIFT); } EXPORT_SYMBOL(pfn_valid); + +/* + * We use memblock_is_memory() here to make sure all pages including + * NOMAP ranges are initialized with __init_single_page(). + */ +int early_pfn_valid(unsigned long pfn) +{ + return memblock_is_memory(pfn << PAGE_SHIFT); +} +EXPORT_SYMBOL(early_pfn_valid); + #endif #ifndef CONFIG_SPARSEMEM diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 0f088f3a2fed..bedcf8a95881 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1170,12 +1170,16 @@ static inline struct mem_section *__pfn_to_section(unsigned long pfn) } #ifndef CONFIG_HAVE_ARCH_PFN_VALID + static inline int pfn_valid(unsigned long pfn) { if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) return 0; return valid_section(__nr_to_section(pfn_to_section_nr(pfn))); } + +#define early_pfn_valid(pfn) pfn_valid(pfn) + #endif static inline int pfn_present(unsigned long pfn) @@ -1200,7 +1204,6 @@ static inline int pfn_present(unsigned long pfn) #define pfn_to_nid(pfn) (0) #endif -#define early_pfn_valid(pfn) pfn_valid(pfn) void sparse_init(void); #else #define sparse_init() do {} while (0) -- 2.1.4