From patchwork Fri Dec 16 16:54:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 9478115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BC90A607EE for ; Fri, 16 Dec 2016 16:57:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB2A5287E7 for ; Fri, 16 Dec 2016 16:57:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F29528811; Fri, 16 Dec 2016 16:57:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3292F287E7 for ; Fri, 16 Dec 2016 16:57:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cHvnA-0006RD-4C; Fri, 16 Dec 2016 16:55:32 +0000 Received: from mail-by2nam01on0084.outbound.protection.outlook.com ([104.47.34.84] helo=NAM01-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cHvn4-0005I2-AL for linux-arm-kernel@lists.infradead.org; Fri, 16 Dec 2016 16:55:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ffNSPDUTeVJhLEU4DXwi7RKuPYqZ/NTo7ry+ccKC4tg=; b=CHBV77fMxUcyA6/M5Un45sIATEkvE7jNfSJCU1ox7C/q3E9mscGOFuSOHvyPhXxcJZ8hiKy4u4qB4vKtr9s8l+hvCwFLz5IsXwloetitITK+O1mYqw0PlOKb+Zxw2GQ7hU5wvaSGqVEhMcmSbM3uykxwb0A5Qxicsa78P4GhLDs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Robert.Richter@cavium.com; Received: from rric.localdomain (92.229.89.225) by BL2PR07MB2340.namprd07.prod.outlook.com (10.167.101.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8; Fri, 16 Dec 2016 16:55:00 +0000 From: Robert Richter To: Russell King , Catalin Marinas , Will Deacon Subject: [PATCH v3] arm64: mm: Fix NOMAP page initialization Date: Fri, 16 Dec 2016 17:54:36 +0100 Message-ID: <20161216165437.21612-1-rrichter@cavium.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [92.229.89.225] X-ClientProxiedBy: VI1PR06CA0037.eurprd06.prod.outlook.com (10.162.116.175) To BL2PR07MB2340.namprd07.prod.outlook.com (10.167.101.18) X-MS-Office365-Filtering-Correlation-Id: 8d296337-9f23-4a13-fb27-08d425d44772 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BL2PR07MB2340; X-Microsoft-Exchange-Diagnostics: 1; BL2PR07MB2340; 3:RlmpjGJpZP5OLH/RHGTeY6AViM+CH/eXF1jOxxYWPEWDBZtUgzTKFbLt8GAzxcFvnBgYnRNWPv5CFp22eI4ahg6eyxzun1OE99Ewd8nr6Ey3OqW0Q8xflaCkF2N58ZLDMO3bjuJuHJgJbpn5jLOa50O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bwO4AbZWfOXsz6wgXFHGA2LmZNIdy0h5Hjex75UVVDmvCnpkioRU+QlnCFYLhOyyjmXmUkhiZFuy3x3bSJeu6Cs54skFPFsod8JLylVQ7sUUa/cS5g+qPXIAh2/wHSMOjMC6oEuTLyeWun4U9mDBuFJhf+pRWkeRQHHOrRFJP7VXcMZ8ax1iPNeia2BuDTdDg6A==; 20:4JAOE6RDi6TSp7Fv8WNtlvPL/KuTmb+D7snYIk5P5k0nNDGzjvPHNSLky6JDgIbeqBHEWqbHIdhb0iohq+hLf+BHkxMC6DiPxdQ1a3YedY7HWhWxGf7qNAc2lhJhat7RQkx1HJucB9J/vioEd0BIqiwwan0O4ICk7ipd71moBYRlp8Xg62JTXyXqGaYzSqoMr0wVQ1PKTf9pL2GwfwtNlXdsScoJWp7T02kL/4aHvnUdcS/UrCYGvPRiq6hmpEnp/Oj0mOidJ4FHRKqL21JjoFj8vyXGk5IV3mifsBHnvBz7Oqh0ws1/lyS2AYjl7nAAb7gmn3kDNyDVf+ALv3BrfmI15dlGm8O45az/aPFGVkXQySKwUrQmuCdesRvfaUS8fT50ts4XGhui8JXLHLdts0NER8LYALcFkptoaAo9s/HuCvawWu/Z2yH1+fpo4GIE95Vw3fyjwaWGsphGsYmfk+lsFym55HF4VrVeQkkepYFjVmPzrI41F1Cw2iYoE+Wb 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)(20161123555025)(20161123564025)(20161123560025)(20161123562025)(6072148); SRVR:BL2PR07MB2340; BCL:0; PCL:0; RULEID:; SRVR:BL2PR07MB2340; X-Microsoft-Exchange-Diagnostics: 1; BL2PR07MB2340; 4:OzK+v93/6KV9p8I3pEs3W35LcaKrt6vmeR6IM520AepB/ZAa7yqpaxKZddkxD4HepG8duZAO5Emcp758yMtHYXhNVWcf5ucGiRQvJc0TR9K5EaqCE5xQTHGk3TYQwNwm7gsHjcDPFNks6W2WkDu4VPA1w+6w2EgVBPS6pNfImkEn2xZLFTHewbrOHae9cN2XWquuuYfncq3vAjk5KMpmzSQTcpg3K6CgoQxvsEnc1lKiKOkN5FvasVmc1YwRi5FpM+/gu9IcAbxaiq24aSBSQlTCjDJ01zAOx5YyfbFF4E+s+uJgiHSnMMBRpTMCBooJntNAfWq3tiv/PAin44v11C69Ql8a/kgDTYom5oKEm1IYMBCFfcrJcs/bSsNBZ/E8MbICw/WpImcyhU1yYgi33kmlIbTULLUY+pOCSbZRXyZqcZ/QIBs5099dpGHPaCr9AlCYCOpDsQK4xwIaUi3Tglmlk61L2Ia+Q4YDhyF3+pLPgO323dpKvaT2dsUtlUjFoJTNpm8w4TFhbJ3ROMeX+bZzPidsTmilr3dp6gKSMzQn5934NAzH7nvHvHfGKRdGAKgTvWTZXvrF4loxiI6+FCzi4gaUciTCqWFm1dMH1jMb1yjZ7S624vQxQU9XTOc9 X-Forefront-PRVS: 01583E185C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(39410400002)(39450400003)(39830400002)(199003)(189002)(6512006)(47776003)(81166006)(305945005)(50466002)(189998001)(6116002)(7416002)(3846002)(101416001)(105586002)(6666003)(68736007)(2906002)(81156014)(4326007)(66066001)(5003940100001)(8676002)(42186005)(1076002)(7736002)(48376002)(92566002)(38730400001)(50226002)(33646002)(6506006)(50986999)(5660300001)(106356001)(36756003)(575784001)(6486002)(5001770100001)(25786008)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR07MB2340; H:rric.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BL2PR07MB2340; 23:5TH4QzFV2amKA3DU6d3OntriPKyVD4KRhRwALtgZV?= =?us-ascii?Q?21CdgSp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K+tHgu78Q?= =?us-ascii?Q?wPwhORwdDne2Wcghyc4TUIuBwogfHGoqsnb7jtTMu0ouDr1enULwbfuBLO6F?= =?us-ascii?Q?u0hgoYb/j4/TKpEjhcckEEq3qgVEQL5R/d248a43apRDj7MFuKDUpcuSzPps?= =?us-ascii?Q?4VYW3wgnTQVwositUzda0Fcr4Qd1ePhUjnWtNBQUoBWKDCkRVCipCHgRhgqZ?= =?us-ascii?Q?pxjdA2ySfI=3D?= X-Microsoft-Exchange-Diagnostics: 1; BL2PR07MB2340; 6:kUJ/HjwoqD/hBYbWn8LF2fu7tqrsOjgw/kBo7/iqytR3Qkf4Fd2YxjrTDB7ho19wwNLTYyQ1hpbV3zEBDz6hU93PeyMdoohLB+mEtl7ZKz0FGh63weXx78AyViqTabNLMCTBjWIITS14A+tSlCrWch2Wn5JMddvGOz+zTfU5D/FnPjAX6ceT4Fg96UWwxU62oBIGzFEG/lCxZoOwYVO0NnntQo2nD50eUGDJIJJkfV8M1yiba9vsZ0ilwS6q6+eVa+Xydhy3NPNy8cuOItBohBJS0x/DV27vYHba0TDD9ARQt66H0dv/aYhpd6eUWwSNSHGr3zd+H/xj4+bt/K86Uc9HeRZ/KxGoeQXRN6dCkRh2Vrj9AXBZ0r2kmE+A+9/5g4bLcXDRxUiLPUmzqEFnAcWVBYaKvjVN/NA/DYZMGzw=; 5:+zYlZNwHYbORcxRnyxzEje62Rsr4Eh2Lhulx2ZdaZ29IeQLAFQNU27TUP2eMR3e4vVq5JFR8vxQgkM7FdX5TMzS09Yukmruxnr+G8YaIpvyRPV0XTQJhXiZgaRoa70Q/F4eIWmRcali3E2ec9K+n8A==; 24:JLn1rYSzNwxVLniOJAr6QFDRL5k4IBjdhBuEBVTkIE8ck/nioX+AI8P8TvvF18/0RugoljgjMPWQ7azkXPsgeceXbiaoj5THeb5D7k5mdjc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BL2PR07MB2340; 7:POSpC6eJv8kzepNeqdB9FDSPZvOaqv/WMDa1jujrQ5VPU5gsRAKsKdFPB7Q6pV0ZmjKEU5VBAWGlgM6QBQ6jwrx5pZXaN6v0oMYV2v5UyKehFlzWk0IzMpl6qlbsG7PfYooAM0/ebrEvpL6+lf2RmF9y7LdZOpEiDl92yazxR2164sSAeErNnZjwcWFb/7Y2mWgxcNyCD+HW1BUmuZO48u/bsLXKu6YHq2hZYv7+Yf+39gu1x84i1o3SiRENfLyOEQnlDN0PzrmfqW84ckTAvMZsm/kSfYF9NKZkjUW+QPRsa7mP4/t+taPIPcTEIsHXY903laCqIlDwOi9NJapCiP0nH+0aocKWlFUoU8bs0B6h80ap0hFD8hEUjITPKtJ6TevBaZfFS6/Xhs2C6Lui+dfmUQJSYXDPMzNanoQCfBhJiV2HeuKKnwbQjKXFsKo/SKJrRz3TUyE0vPgob4wYPg== X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2016 16:55:00.7057 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR07MB2340 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161216_085526_714983_DD57372B X-CRM114-Status: GOOD ( 16.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Yisheng Xie , David Daney , Ard Biesheuvel , linux-kernel@vger.kernel.org, Robert Richter , linux-mm@kvack.org, James Morse , Hanjun Guo , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 all pages of sections with memory including NOMAP ranges 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 valid_section() for arm64. This is the same as for the generic pfn_valid() implementation. v3: * Use valid_section() which is the same as the default pfn_valid() implementation to initialize * Added Ack for arm/ changes. v2: * Use pfn_present() instead of memblock_is_memory() to support also non-memory NOMAP holes Acked-by: Russell King Signed-off-by: Robert Richter --- arch/arm/include/asm/page.h | 1 + arch/arm64/include/asm/page.h | 2 ++ arch/arm64/mm/init.c | 15 +++++++++++++++ include/linux/mmzone.h | 5 ++++- 4 files changed, 22 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..8ff62a7ff634 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -145,11 +145,26 @@ 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); + +/* + * This is the same as the generic pfn_valid() implementation. We use + * valid_section() here to make sure all pages of a section including + * NOMAP pages are initialized with __init_single_page(). + */ +int early_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))); +} +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)