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: 9304917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F0090601C0 for ; Tue, 30 Aug 2016 06:48:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD19128A79 for ; Tue, 30 Aug 2016 06:48:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1EBF28AE7; Tue, 30 Aug 2016 06:48:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE69E28A79 for ; Tue, 30 Aug 2016 06:48:27 +0000 (UTC) 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-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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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;