Received: by 10.223.185.116 with SMTP id b49csp1022418wrg; Wed, 21 Feb 2018 10:43:25 -0800 (PST) X-Google-Smtp-Source: AH8x224OckoB8ockCVjwZW14O7t3pWyuIXqfYu6QpHc98FRawSlSa0zw9kpj5lARdzSrRgnTqF1w X-Received: by 2002:a17:902:3084:: with SMTP id v4-v6mr4060591plb.131.1519238605206; Wed, 21 Feb 2018 10:43:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238605; cv=none; d=google.com; s=arc-20160816; b=KEn7qSf9OMGNij/sulCGz7lX9GvrBV1nWOjIvLkj+KEcwlfI2rVJeRFS7uOQOv1Hje xYqbx8nqgwQVBc4lrYvMjIowR3jMLf0KbsZ/XFDt1S5zbbGhc6RUhw/sdk0ZiVQBSvnv sSoL9vrEE2PzCfSu3Qk58PGMZK8g5N+J/zUhcrTkdqbcyvSr6m90bASpPamcd1QbVUi9 L7SOzqQgqbXtK9dK3eN2i9lY6QmQ7RXEGV9bCN03CJPZnkR607e5qSWJRnMgh0UsuXVU AvKcFI10lTEWxS7qqeUl6eR7u3NRBpG4JcmYbyxRkkgAl+lKKjzTj06GVfsZSyh44bXP DaEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Hs52wqfv9Kgdd2p7lNInWpTjfyaQaz4Wg0iusXZveSU=; b=jvhY6IxUEliDhq4OBbq+6DG8JSUia+SIuq1OPTGzkr1dPya8mKB1bPgdL/PWFST6vY CWrG2nRyPfZ3XGg/ec2uVFHCsBDdXQs4YSeeI8VWslcIl1c2bHnu+IPDMvf70ne06ZLa 0RxaQnnNMl9hXkn60oaaCdh9I6NNFvLuOdQVQyYoSQHWHTE+U42amQoRcI8ix1JCYvA/ /LHNCQfQGQqJzjDhmUuHrP0SkKSLi3kppl3nySAv+dCcSn2WqSgIW8+cO/SSkfme7dC5 3Vf2MJo1p67DNQ4L/dWJvae3RM9zK4oJYHA91IANwU/M/DtloxEfeqLRq1rfkygN3aKP oRVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6-v6si12522311plt.467.2018.02.21.10.43.10; Wed, 21 Feb 2018 10:43:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936711AbeBUN2S (ORCPT + 99 others); Wed, 21 Feb 2018 08:28:18 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44488 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936294AbeBUNLL (ORCPT ); Wed, 21 Feb 2018 08:11:11 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E12D51242; Wed, 21 Feb 2018 13:10:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Malaterre , Marcin Nowakowski , Ralf Baechle , linux-mips@linux-mips.org, Mathieu Malaterre , James Hogan Subject: [PATCH 4.15 114/163] MIPS: Fix incorrect mem=X@Y handling Date: Wed, 21 Feb 2018 13:49:03 +0100 Message-Id: <20180221124536.453895962@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marcin Nowakowski commit 67a3ba25aa955198196f40b76b329b3ab9ad415a upstream. Commit 73fbc1eba7ff ("MIPS: fix mem=X@Y commandline processing") added a fix to ensure that the memory range between PHYS_OFFSET and low memory address specified by mem= cmdline argument is not later processed by free_all_bootmem. This change was incorrect for systems where the commandline specifies more than 1 mem argument, as it will cause all memory between PHYS_OFFSET and each of the memory offsets to be marked as reserved, which results in parts of the RAM marked as reserved (Creator CI20's u-boot has a default commandline argument 'mem=256M@0x0 mem=768M@0x30000000'). Change the behaviour to ensure that only the range between PHYS_OFFSET and the lowest start address of the memories is marked as protected. This change also ensures that the range is marked protected even if it's only defined through the devicetree and not only via commandline arguments. Reported-by: Mathieu Malaterre Signed-off-by: Marcin Nowakowski Fixes: 73fbc1eba7ff ("MIPS: fix mem=X@Y commandline processing") Cc: Ralf Baechle Cc: linux-mips@linux-mips.org Cc: # v4.11+ Tested-by: Mathieu Malaterre Patchwork: https://patchwork.linux-mips.org/patch/18562/ Signed-off-by: James Hogan Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/setup.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -375,6 +375,7 @@ static void __init bootmem_init(void) unsigned long reserved_end; unsigned long mapstart = ~0UL; unsigned long bootmap_size; + phys_addr_t ramstart = (phys_addr_t)ULLONG_MAX; bool bootmap_valid = false; int i; @@ -395,7 +396,8 @@ static void __init bootmem_init(void) max_low_pfn = 0; /* - * Find the highest page frame number we have available. + * Find the highest page frame number we have available + * and the lowest used RAM address */ for (i = 0; i < boot_mem_map.nr_map; i++) { unsigned long start, end; @@ -407,6 +409,8 @@ static void __init bootmem_init(void) end = PFN_DOWN(boot_mem_map.map[i].addr + boot_mem_map.map[i].size); + ramstart = min(ramstart, boot_mem_map.map[i].addr); + #ifndef CONFIG_HIGHMEM /* * Skip highmem here so we get an accurate max_low_pfn if low @@ -436,6 +440,13 @@ static void __init bootmem_init(void) mapstart = max(reserved_end, start); } + /* + * Reserve any memory between the start of RAM and PHYS_OFFSET + */ + if (ramstart > PHYS_OFFSET) + add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET, + BOOT_MEM_RESERVED); + if (min_low_pfn >= max_low_pfn) panic("Incorrect memory mapping !!!"); if (min_low_pfn > ARCH_PFN_OFFSET) { @@ -664,9 +675,6 @@ static int __init early_parse_mem(char * add_memory_region(start, size, BOOT_MEM_RAM); - if (start && start > PHYS_OFFSET) - add_memory_region(PHYS_OFFSET, start - PHYS_OFFSET, - BOOT_MEM_RESERVED); return 0; } early_param("mem", early_parse_mem);