From patchwork Tue Aug 30 06:52:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 74936 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1989114qga; Mon, 29 Aug 2016 23:48:02 -0700 (PDT) X-Received: by 10.98.159.73 with SMTP id g70mr3409325pfe.121.1472539682357; Mon, 29 Aug 2016 23:48:02 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id yi8si43667564pab.224.2016.08.29.23.48.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Aug 2016 23:48:02 -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 1becoe-00072Q-PU; Tue, 30 Aug 2016 06:46:36 +0000 Received: from mail-pf0-x233.google.com ([2607:f8b0:400e:c00::233]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1becoY-0006sJ-DR for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2016 06:46:32 +0000 Received: by mail-pf0-x233.google.com with SMTP id y134so4705091pfg.0 for ; Mon, 29 Aug 2016 23:46:10 -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=WZgojWwcoGs9cgnroDrR/yX9g/jIUuewTlMcAs3BL6zaxhuA67Wrft5IffPfd5k1PJ uHOCaM5sqiQCVDNdItWMTOxzF57+3OOG//+Y71o96izYvTBaIKEQ6iFOKUUOz9bsLqNz pu8dUHj0yH+dLdM6E5bzplxp9dTMhYTPP7DM8= 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=UBNqIjaugf+f7OGT/kg7doM0YyMcV8cxcaNtAUfY/m8NIgmTF6y9McQeC4jERVAFys bl/JF+WESK2bDMIL7bMu6srdmbEHHCbEa9/v7Mkmiqyxs2LlDNXPpa3dzYzylZmrB15C rOtPwaDSekHKZiZ1pW8D11VJHXn1Ig94morglF7D17WRYjFe8s0PnKgpB5wcYJXma8LT rDI2pEprVIHJS/dTEdOBJgXDHPzAhBrhqBIc01WDoIpqBXZ7n4VQf5D/V8yQqLnlxNfj NJU/MhPhBeusUoustY8NIYhaC5uYEuMth+ehIkIUukY0clZBFuE1bvnLjcsQ0mUZ5uDu Zkbw== X-Gm-Message-State: AE9vXwMYLaDCkX9SjsciUwiiaIs8XlarvVcbxPewrBahgbcTGge3gd4pmjEpnHmQkZCwYiQA X-Received: by 10.98.80.29 with SMTP id e29mr3486441pfb.76.1472539569746; Mon, 29 Aug 2016 23:46:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v124sm53842904pfb.14.2016.08.29.23.46.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Aug 2016 23:46:09 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH v25] 2/9] memblock: add memblock_cap_memory_range() Date: Tue, 30 Aug 2016 15:52:39 +0900 Message-Id: <20160830065239.19558-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160830064941.19452-2-takahiro.akashi@linaro.org> References: <20160830064941.19452-2-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160829_234630_560294_698DC361 X-CRM114-Status: GOOD ( 13.37 ) 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:c00:0:0:0:233 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;