From patchwork Tue Aug 9 01:55:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 73504 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp247226qga; Mon, 8 Aug 2016 18:51:15 -0700 (PDT) X-Received: by 10.66.8.163 with SMTP id s3mr69069634paa.142.1470707475162; Mon, 08 Aug 2016 18:51:15 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id c6si39926471pfd.259.2016.08.08.18.51.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Aug 2016 18:51:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org 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 1bWwBI-0002ge-2b; Tue, 09 Aug 2016 01:50:12 +0000 Received: from mail-pa0-x22a.google.com ([2607:f8b0:400e:c03::22a]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bWwBD-0001xA-EJ for linux-arm-kernel@lists.infradead.org; Tue, 09 Aug 2016 01:50:09 +0000 Received: by mail-pa0-x22a.google.com with SMTP id fi15so141699pac.1 for ; Mon, 08 Aug 2016 18:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DkOft1dfGFstS531twXyFf8N33qW3KJbhyTNeSWUpXY=; b=QUm7O5bDA4IoTZI+yKUgp2dGPOdaTsB3qXoHiX8tCpfFVQkAaMDFS4RKaTOx+cPqOV 4MWXctgnJxsGBDyC281/jbpc3758SO9rRfAPzqlLtHtaUl1R9ga88VDIYNaykjIO8Bca RyQCaSiN11WivlXbY/KQyyTSUDBvCE4yJkDAY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DkOft1dfGFstS531twXyFf8N33qW3KJbhyTNeSWUpXY=; b=iaZalWHKpHEU3GHHuSmqrRd5NvXFwY8s/EM2AYdwZpx4D1s+ztRf4hxo58x18YkiyH p4fmB2WhPSrqIa/5eZWbTbL0rI6mb5WiuznlKUSvKwr2W9Y+D8l3rb/2RyT6Z+VdEZre jh4F9IuNgo9Op6M//5oYe9MXfOSAJSrhu88ZyRm/YFz5X+25MGoYSPW89kC/qlMhsUZf nIJj64ezyNULMU3ldM8ITmA5RTyqg5mXxKcm6CzrzNB9pLCSe61mtL+LV6fHJ37fdW1K z3se4I6jpBewUbmwoOcSh/BoD70c6mnxd+mOZ8qFKAf05jBC//0ORT92jRnjbzrRJa7G kw7g== X-Gm-Message-State: AEkoouucCMHhxjMuhvqds+a+iSQpTGMRbBtEO9jDpfLoD8qX8Xr++lWrGsOPz9Ye8Kw6o5eO X-Received: by 10.66.242.166 with SMTP id wr6mr167545661pac.147.1470707384982; Mon, 08 Aug 2016 18:49:44 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v124sm50972600pfb.14.2016.08.08.18.49.43 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 08 Aug 2016 18:49:44 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH v24 2/9] memblock: add memblock_cap_memory_range() Date: Tue, 9 Aug 2016 10:55:26 +0900 Message-Id: <20160809015526.28479-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160809015248.28414-2-takahiro.akashi@linaro.org> References: <20160809015248.28414-2-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160808_185007_577195_91F47A2A X-CRM114-Status: GOOD ( 13.27 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c03:0:0:0:22a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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@arm.com, AKASHI Takahiro , geoff@infradead.org, kexec@lists.infradead.org, linux-mm@kvack.org, james.morse@arm.com, bauerman@linux.vnet.ibm.com, dyoung@redhat.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Crash dump kernel uses only a limited range of memory as System RAM. On arm64 implementation, a new device tree property, "linux,usable-memory-range," is used to notify crash dump kernel of this range.[1] But simply excluding all the other regions, whatever their memory types are, doesn't work, especially, on the systems with ACPI. Since some of such regions will be later mapped as "device memory" by ioremap()/ acpi_os_ioremap(), it can cause errors like unalignment accesses.[2] This issue is akin to the one reported in [3]. So this patch follows Chen's approach, and implements a new function, memblock_cap_memory_range(), which will exclude only the memory regions that are not marked "NOMAP" from memblock.memory. [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/442817.html [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/444165.html [3] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/443356.html Signed-off-by: AKASHI Takahiro --- include/linux/memblock.h | 1 + mm/memblock.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) -- 2.9.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 2925da2..8002f98 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -333,6 +333,7 @@ phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); void memblock_mem_limit_remove_map(phys_addr_t limit); +void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); bool memblock_is_memory(phys_addr_t addr); int memblock_is_map_memory(phys_addr_t addr); int memblock_is_region_memory(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 483197e..3eae109 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1539,6 +1539,34 @@ void __init memblock_mem_limit_remove_map(phys_addr_t limit) (phys_addr_t)ULLONG_MAX); } +void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size) +{ + int start_rgn, end_rgn; + int i, ret; + + if (!size) + return; + + ret = memblock_isolate_range(&memblock.memory, base, size, + &start_rgn, &end_rgn); + if (ret) + return; + + /* remove all the MAP regions */ + for (i = memblock.memory.cnt - 1; i >= end_rgn; i--) + if (!memblock_is_nomap(&memblock.memory.regions[i])) + memblock_remove_region(&memblock.memory, i); + + for (i = start_rgn - 1; i >= 0; i--) + if (!memblock_is_nomap(&memblock.memory.regions[i])) + memblock_remove_region(&memblock.memory, i); + + /* truncate the reserved regions */ + memblock_remove_range(&memblock.reserved, 0, base); + memblock_remove_range(&memblock.reserved, + base + size, (phys_addr_t)ULLONG_MAX); +} + static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr) { unsigned int left = 0, right = type->cnt;