Return-Path: Received: from mail-wi0-f170.google.com ([209.85.212.170]:36902 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752921AbbG0IWZ (ORCPT ); Mon, 27 Jul 2015 04:22:25 -0400 Received: by wibud3 with SMTP id ud3so104380143wib.0 for ; Mon, 27 Jul 2015 01:22:24 -0700 (PDT) Received: from ?IPv6:2a01:4240:53f0:43fb::cbb? (b.b.c.0.0.0.0.0.0.0.0.0.0.0.0.0.b.f.3.4.0.f.3.5.0.4.2.4.1.0.a.2.v6.cust.nbox.cz. [2a01:4240:53f0:43fb::cbb]) by smtp.gmail.com with ESMTPSA id k12sm20109283wjw.4.2015.07.27.01.22.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2015 01:22:24 -0700 (PDT) From: "Jiri Slaby" To: Cc: "Catalin Marinas" , "Dave P Martin" Subject: [patch added to the 3.12 stable tree] arm64: mm: Fix freeing of the wrong memmap entries with !SPARSEMEM_VMEMMAP Date: Mon, 27 Jul 2015 10:02:20 +0200 Message-Id: <1437984150-15702-39-git-send-email-jslaby@suse.com> In-Reply-To: <1437984150-15702-1-git-send-email-jslaby@suse.com> References: <1437984150-15702-1-git-send-email-jslaby@suse.com> Sender: stable-owner@vger.kernel.org List-ID: From: Dave P Martin This patch has been added to the 3.12 stable tree. If you have any objections, please let us know. =============== commit b9bcc919931611498e856eae9bf66337330d04cc upstream. The memmap freeing code in free_unused_memmap() computes the end of each memblock by adding the memblock size onto the base. However, if SPARSEMEM is enabled then the value (start) used for the base may already have been rounded downwards to work out which memmap entries to free after the previous memblock. This may cause memmap entries that are in use to get freed. In general, you're not likely to hit this problem unless there are at least 2 memblocks and one of them is not aligned to a sparsemem section boundary. Note that carve-outs can increase the number of memblocks by splitting the regions listed in the device tree. This problem doesn't occur with SPARSEMEM_VMEMMAP, because the vmemmap code deals with freeing the unused regions of the memmap instead of requiring the arch code to do it. This patch gets the memblock base out of the memblock directly when computing the block end address to ensure the correct value is used. Signed-off-by: Dave Martin Signed-off-by: Catalin Marinas Signed-off-by: Jiri Slaby --- arch/arm64/mm/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index de2de5db628d..cfe3ad835d16 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -253,7 +253,7 @@ static void __init free_unused_memmap(void) * memmap entries are valid from the bank end aligned to * MAX_ORDER_NR_PAGES. */ - prev_end = ALIGN(start + __phys_to_pfn(reg->size), + prev_end = ALIGN(__phys_to_pfn(reg->base + reg->size), MAX_ORDER_NR_PAGES); } -- 2.4.6