From patchwork Wed Nov 18 06:33:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Song Bao Hua (Barry Song)" X-Patchwork-Id: 11913887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11D98C5519F for ; Wed, 18 Nov 2020 06:38:08 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8312224655 for ; Wed, 18 Nov 2020 06:38:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ws/G4GW8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8312224655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hisilicon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=YubUNRnQUu+FxXacYn9Dvt7cQ0pCNnU+HX65XF4JA0Q=; b=Ws/G4GW8hGjkUUdFEzOBN6LPi0 2Raj6Fq21LfEioc7EAL5XYjtwsrnXG058AJGVizc2xpbR5xrQEDC03wDnje4SFjFMhjJLyupDHTeV NvNS17fM64p8bpm+UGVw1fM8oRLAGVsJiYTD2QXD9teey8cdJSJhz/on0Wf18dOKbAIyM2ez9jGNo v4dFHDJ+3/ptIYGjQWNvpK6pusDB5lonp1yjqyQGbKE9arU+VfcyOxm/8fact1iwAk4g+qg1NYZHh v2lrU4SCNnzERrH54+xI2CNDIi+QoGKM0ed0lHSu99Bq/el35qw+Losp5iZyfZZhj6LHjcbPS1IKg /Ml1Zjcw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfH66-0002T9-4q; Wed, 18 Nov 2020 06:37:42 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfH63-0002Sj-C5 for linux-arm-kernel@lists.infradead.org; Wed, 18 Nov 2020 06:37:40 +0000 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CbY5F68njzhc9Z; Wed, 18 Nov 2020 14:37:21 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.202.14) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Wed, 18 Nov 2020 14:37:23 +0800 From: Barry Song To: , , , Subject: [PATCH] arm64: mm: add support for memmap kernel parameters Date: Wed, 18 Nov 2020 19:33:14 +1300 Message-ID: <20201118063314.22940-1-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.126.202.14] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201118_013739_685634_5EC372E6 X-CRM114-Status: GOOD ( 14.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Barry Song , akpm@linux-foundation.org, linuxarm@huawei.com, rppt@kernel.org, anshuman.khandual@arm.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org memmap should be an useful kernel parameter which has been supported by x86, mips and xtensa. This patch adds support for ARM64. At this stage, the below two modes are supported only: memmap=nn[KMG]@ss[KMG] Force usage of a specific region of memory memmap=nn[KMG]$ss[KMG] Region of memory to be reserved is from ss to ss+nn If users set memmap=exactmap before memmap=nn[KMG]@ss[KMG], they will get the exact memory specified by memmap=nn[KMG]@ss[KMG]. For example, on one machine with 4GB memory, "memmap=exactmap memmap=1G@1G" will make kernel use the memory from 1GB to 2GB only. Signed-off-by: Barry Song --- arch/arm64/mm/init.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 095540667f0f..f1c6bfdbc953 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -235,6 +235,65 @@ static int __init early_mem(char *p) } early_param("mem", early_mem); +static int need_remove_real_memblock __initdata; + +static void __init parse_memmap_one(char *p) +{ + char *oldp; + unsigned long start_at, mem_size; + + if (!p) + return; + + if (!strncmp(p, "exactmap", 8)) { + need_remove_real_memblock = 1; + return; + } + + oldp = p; + mem_size = memparse(p, &p); + if (p == oldp) + return; + + switch (*p) { + case '@': + start_at = memparse(p + 1, &p); + /* + * use the exactmap defined by nn[KMG]@ss[KMG], remove + * memblock populated by DT etc. + */ + if (need_remove_real_memblock) { + need_remove_real_memblock = 0; + memblock_remove(0, ULLONG_MAX); + } + memblock_add(start_at, mem_size); + break; + case '$': + start_at = memparse(p + 1, &p); + memblock_reserve(start_at, mem_size); + break; + default: + pr_warn("Unrecognized memmap syntax: %s\n", p); + break; + } +} + +static int __init parse_memmap_opt(char *str) +{ + while (str) { + char *k = strchr(str, ','); + + if (k) + *k++ = 0; + + parse_memmap_one(str); + str = k; + } + + return 0; +} +early_param("memmap", parse_memmap_opt); + static int __init early_init_dt_scan_usablemem(unsigned long node, const char *uname, int depth, void *data) {