From patchwork Wed Nov 30 18:21:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 9454699 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 E96DE60235 for ; Wed, 30 Nov 2016 18:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D58682848F for ; Wed, 30 Nov 2016 18:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5BF428493; Wed, 30 Nov 2016 18:24:28 +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 C0EC02848F for ; Wed, 30 Nov 2016 18:24:27 +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 1cC9WS-0008Js-2i; Wed, 30 Nov 2016 18:22:24 +0000 Received: from mail-by2nam01on0070.outbound.protection.outlook.com ([104.47.34.70] helo=NAM01-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cC9WO-0008Dm-91 for linux-arm-kernel@lists.infradead.org; Wed, 30 Nov 2016 18:22:21 +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=6hBnxHKUkMAgiChgK8UyAiNfOd/kIoGVvSAGxA2nYnc=; b=QRzdLQJiW+bruorRzphXcHdt6fH711/+cYxnIaQTUHs3tPLysgaEU4frw3aaJcr2EkHaP9ZOvAPOUnfDNpUl9nXlOahcUD9qYhRSUmzDvrD9/jkTWJtnPpkVSVm3/mcknuoG6BTH3AiD3mk2yy6tke/RAF+XXStxU9TlMRfbk64= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Robert.Richter@cavium.com; Received: from rric.localdomain (92.229.81.164) by BY2PR07MB2342.namprd07.prod.outlook.com (10.166.114.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.734.8; Wed, 30 Nov 2016 18:21:55 +0000 From: Robert Richter To: Catalin Marinas , Will Deacon Subject: [PATCH v2] arm64: mm: Fix memmap to be initialized for the entire section Date: Wed, 30 Nov 2016 19:21:31 +0100 Message-ID: <1480530091-1092-1-git-send-email-rrichter@cavium.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-Originating-IP: [92.229.81.164] X-ClientProxiedBy: VI1PR0501CA0014.eurprd05.prod.outlook.com (10.172.9.152) To BY2PR07MB2342.namprd07.prod.outlook.com (10.166.114.144) X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2342; 2:nKiTLNc3ryKIfOpChhcBEtxj1L9EsD4kx1Phh/N3oo5KonZbVPcAUsTyjBQVLUeOrnNH0MEoGVCiLaQpcPeBe+d9VsM09WNWmnOiA3RjLvvmwl5sbuZ1OQ8vgFsNVauk89yFPfCvBSwBKnqSSWOfbZo5L2Utf4YBYtUhG8W6Ed4=; 3:9FCbHN0qZxOXSkPb0Kxs2a6PaLwgi4SW9f17aAFFZb8GxHUy6/MmLHNHKspGc1n2ocfFAe6nD851rttSsSV7+vT3xH1a1ww0DCJfab6gMSCmFRLCpB+Dd7Wz5MaFOQOmD9FHAXSZPAm1wRLiUA3yyUEr5XhduR2P2kLAtGccCUk=; 25:hzBe9X5eJ4dPbZ//MQub2Lh3QznEgR987WHss+wGE5lJ1t4WTkvSWkT6i4+JJCos8uw+3m10jX1IVCLB5PdG6g7c391syQ17941nmLQdFTXH638KR6DqN7DDTVd+QVxVJ++AYyzBYC+vojPSWUoFpFlQ/2Rvl/CNieDw5+hjUZiog8ZCVYyqXIwRTJx+bzaXu76eFM+M4RHP6CLx18lT3v5wc3hP4XkRqT1pJplfI53K9OOoTI1CQ86prAQdf3jZFHEyxZlK2Y9TyPhceYEcoa3HBV0ynFEXItzF4CcbopQdPLEvtmFa+EL1OXcCBnhLXZDo/rzL2+3ZYEC1ZatdunaHkOU9NYBRwEpQefc7U/Tyu7acq+M9NacrG5s8euWQD21QTtvpIrzMQVfieR3K3Nw3rFuK+9vaR72wHeBQz/k43240+4z/LT8zJHeQ4Vx+3sdv894XsVhF14ejVYsEtw== X-MS-Office365-Filtering-Correlation-Id: ecbed00f-d0d8-4fa5-bd96-08d4194dc51e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BY2PR07MB2342; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2342; 31:s8Xlcr3gMfC+KpkCWVbmJW2eCxh2/ElBAE3KEJnPqZ2UPYaMIANJP7H7izNrxxTtcC5+PtE1PdVEDA0JGtOLoQi3HKYE6DGHHYStKezDkhybFANamPQKSGO2cf7h/iY5Cci+rbCd86eLTHbcQsXphJ0uL7XJTODDUYD0r0crW1wmd315CW0hEpOk5SRX/mzAIqSrqdxdR4eDtA53FBJSTZ/9HwW63D0IAQqH3iKsFtfLNzcFWO6kpp1ph+ETDA/mD/HRutCruBFcOOemZ9t6wg==; 20:TF3ioDj+nN292jtyWDvEKpY+ZcNCkjhpdvI4y92rLZrtw72Bn7IP39Cx94fnIsfs2u9bx/gC7IpKGplJsUC5wPlMIs7JVkwAcXL7Zcy3Cd0/+dru0fLMCyr5py0dNMhcSz0T/QrbVl4OSZFgprWRLVHwOGQ+vdAPPwEvMqB+RqSnq0PMxEiI+Gu3/1JyCX9VKx5hHnDnE9n06/ORB2dr+SWMWo4C9wGIi5toWEImaIr4l0mGJkmVBarqufRGatPNwEyWfWD+ToWobjPiybnfC48GZEgpASdUyJbf3JWlhpa3/k1GdpHFGh7ar4Ztng8IOO1DSI16P17hFKsfmC+G9EYudlV8tV3GJolnN0RyseJw0wpineNZ87iV2n7ssBwtoZBoogsjja2PwAkNQljiwWOgS9fSe/aAgtGmOeNL152X7FY5VLeXFUr914RkEQouoWqeSLWYXoX7Vl8lcdwYy2wpgRBNWGAQPp3XOaaoXLTT9F6wbky+Yi6tOgw8s21c 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)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(6072148); SRVR:BY2PR07MB2342; BCL:0; PCL:0; RULEID:; SRVR:BY2PR07MB2342; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2342; 4:9sqCfhSzlnCczMHM8jPIyk26+klf6hs/pQ09DvnO9IBmNmH+fyzICtIOYo/OVnWvBJha6vfrQcXFrXGGM9pz4wQf+7BlTth6By6Rs3lXtywjOwmnWiu3QzlWSxy5RvitrJ4LkSUTPPefkLBOb9PDg9LmNYuFOWgzUVKjSUxAEmdr/sEnids+2NYWKU2QRFUB0bGpqOX5te5VOalmKAPPhTqlRbiRyHo3FEeeWqucv3auMopkXOZ4NwlbfAxYKfcspHFJqwn52/sbLmSKw954GnUqJDviuKxdEYvTAA7ChqJXjJC/iRGoESaSmQkeFhrF70NyqL7Ejbm/VX9Hj4OREcboypWUtCCCGImYpWLhjTOUyfwV5Osgnk9XJK6shkamMU+3ER6gThl1qHV8rdORjguhJKX4t132N2YM+TCPifjFYHYGGzmesWvhIm+jhzpGbVq80ZMdifjqeTIonu+NujsB1axv0iG3jRpFWC6R2USGNbifKGd5ybWQoTfoodgjsx4eFoW/SH4117CSIroDV7nTCWWOjjtOzXdoLkFARUC9nMimGkFjvyHCeG0ASpjXCJy61qW685XpkaNGu2hc2GBLUKnPby7vq3bli3xf7Naar1ZI4Z5MH7ZR9j+6JET0 X-Forefront-PRVS: 0142F22657 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(979002)(6009001)(7916002)(199003)(189002)(38730400001)(5660300001)(33646002)(5003940100001)(47776003)(3846002)(39450400002)(6116002)(6486002)(6666003)(66066001)(2906002)(4326007)(39410400001)(733004)(101416001)(68736007)(50226002)(7846002)(189998001)(50986999)(7736002)(81156014)(81166006)(106356001)(5001770100001)(97736004)(575784001)(105586002)(8676002)(92566002)(48376002)(36756003)(305945005)(42186005)(50466002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR07MB2342; 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; BY2PR07MB2342; 23:xSLVt5HClii9uwd2w/V1GYiGOOHcm7cNba+lytPLT?= =?us-ascii?Q?CVtd7atD8rt8ab/X+HZOLy9ozT+147ZVGmE+cFjhf0aIqD7dICybuLYciku8?= =?us-ascii?Q?hNCa9dz7ZY2ehgV4LRwNWKELst+WY7O3anQYJlrL2Ht9F4/yGxEjqKBrxvGq?= =?us-ascii?Q?s9NTQHqLQKUMydiVvnD/LLpdzMWfxjQyl0X5NMMFlQupeBxbLjZUG5F39OTB?= =?us-ascii?Q?H0es+HqgRO8g5lzKBLc2VevNx6qq9gGPuJGeaUrNilUSs7Rf5po9ru5C/0VE?= =?us-ascii?Q?sRwlBUcrzhYrk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oft-Exchange-Diagnostics: 1; BY2PR07MB2342; 6:L52tHsxoxfmCD8MiOTgGiR2lms0G0DkTnTV0j2FiHO+T86Lc4O49PRG5msZ5+a97GnVuLcDtW0eloa1UCPBVDryfekJznXjo+72FcbfPp/dADORx7opeP49ZSpBgVCvWdiV9/XwEH3amy8DgukbmBnuRXfwNScHC1dym+SlVNZGXvU6y1G6ap7084brDOYks4uRMPtDQ9EKs/hJNl3ilBgHcf/KUgg4zT1eAM+4xVNvnayUQj7FCMRkkETQbyluWD5mGmr+mnO754UxfNy5IAZud2e9e6tkvYZ/1IeN8L0f8Cvv0rh6jhB9cHsQqEViT8RyIl2hNFtN3ziD5SQr/VNb91xPbnqg7GbewuNfx9CY=; 5:h0MEn4nAQF+UZvq/dZlIwJR+ajN1GNZv5qzhsismjJ1EIq4VzbyW6JncAPPw/cBVf8KCvGylLh2uWl9BY7Dwx3iBPog8uCdw29UpBEb6uVteE7wv8pvR68dMiuRklZd/IuttIm7Yy2kh3HDBjhE2WA==; 24:I1Xe3HNQfKxdMOSWx2wE2Oz0bt0ArTh94+o6uP0ILUYbMdSu+52144g58qF1HCsIz6P+vUzraqX64eoVTQBWGCpzfPJFqfBYq8o/jw7vdIs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2342; 7:4ATdOER1laVv0ndMm29mk9o580LrY43Sx+XcyczCY1hkFEGtTX2oUUKphIpmHfSSQfxThuI+tWgxOy0tH+GDtPBizlNPfpClSsA9XYejqBbxGvLSNXp4iQT8oILz72gbenk7QzEjktOBIXxPRFZiY18peMgLWNNdkdohJGdJvdxk2u512hDz7os1wbLuZ5553BRBXj2FoTkvrypdPQFdgf/cRTKLIUBRsQZ8vJoZe9nl0Gv/SwGRhgipWonb6SKfjf4buNyTFC0VAJq3h7qLobEL8Q5Vy8OBWrLJHdHTJe99uy1ApZd8vkZAaUUl/SmpmFwATwuh1hI7LF2BnbKBWC9+2WirAPoj5dS0GS+a4QA= X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2016 18:21:55.3696 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR07MB2342 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161130_102220_381591_99B661B6 X-CRM114-Status: GOOD ( 17.31 ) 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 , David Daney , Ard Biesheuvel , linux-kernel@vger.kernel.org, Robert Richter , 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 long reassigned to the new zone in memmap_init_zone() by calling __init_single_pfn(). Fixing this by restoring the old behavior of pfn_valid() to use memblock_is_memory(). Also changing users of pfn_valid() in arm64 code to use memblock_is_map_memory() where necessary. This only affects code in ioremap.c. The code in mmu.c still can use the new version of pfn_valid(). As a consequence, pfn_valid() can not be used to check if a physical page is RAM. It just checks if there is an underlying memmap with a valid struct page. Moreover, for performance reasons the whole memmap (with pageblock_nr_pages number of pages) has valid pfns (SPARSEMEM config). The memory range is extended to fit the alignment of the memmap. Thus, pfn_valid() may return true for pfns that do not map to physical memory. Those pages are simply not reported to the mm, they are not marked reserved nor added to the list of free pages. Other functions such a page_is_ram() or memblock_is_map_ memory() must be used to check for memory and if the page can be mapped with the linear mapping. Since NOMAP mem ranges may need to be mapped with different mem attributes (e.g. read-only or non-caching) we can not use linear mapping here. The use of memblock_is_memory() in pfn_valid() may not break this behaviour. Since commit: e7cd190385d1 arm64: mark reserved memblock regions explicitly in iomem NOMAP mem resources are no longer marked as system RAM (IORESOURCE_ SYSTEM_RAM). Now page_is_ram() and region_intersects() (see memremap()) do not detect NOMAP mem as system ram and NOMAP mem is not added to the linear mapping as system RAM is. v2: * Added Ack * updated description to reflect the discussion Acked-by: Ard Biesheuvel Signed-off-by: Robert Richter Acked-by: Will Deacon --- arch/arm64/mm/init.c | 2 +- arch/arm64/mm/ioremap.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 212c4d1e2f26..166911f4a2e6 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -147,7 +147,7 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid(unsigned long pfn) { - return memblock_is_map_memory(pfn << PAGE_SHIFT); + return memblock_is_memory(pfn << PAGE_SHIFT); } EXPORT_SYMBOL(pfn_valid); #endif diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index 01e88c8bcab0..c17c220b0c48 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -55,7 +56,7 @@ static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size, /* * Don't allow RAM to be mapped. */ - if (WARN_ON(pfn_valid(__phys_to_pfn(phys_addr)))) + if (WARN_ON(memblock_is_map_memory(phys_addr))) return NULL; area = get_vm_area_caller(size, VM_IOREMAP, caller); @@ -96,7 +97,7 @@ EXPORT_SYMBOL(__iounmap); void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size) { /* For normal memory we already have a cacheable mapping. */ - if (pfn_valid(__phys_to_pfn(phys_addr))) + if (memblock_is_map_memory(phys_addr)) return (void __iomem *)__phys_to_virt(phys_addr); return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),