From patchwork Mon Nov 23 09:06:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 57117 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1315757lbb; Mon, 23 Nov 2015 01:09:23 -0800 (PST) X-Received: by 10.66.240.97 with SMTP id vz1mr34655401pac.29.1448269762922; Mon, 23 Nov 2015 01:09:22 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id i9si18495121pbq.207.2015.11.23.01.09.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Nov 2015 01:09:22 -0800 (PST) Received-SPF: pass (google.com: 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; spf=pass (google.com: 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; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a0n5y-0003QQ-Qb; Mon, 23 Nov 2015 09:07:34 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a0n5d-0003Fh-Fg for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2015 09:07:16 +0000 Received: by wmvv187 with SMTP id v187so150194639wmv.1 for ; Mon, 23 Nov 2015 01:06:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=51JTTeEcxBfnuaSrbLLwNP7Ux48aexHAY//UCEx52cw=; b=i9tkcoRPdZiHK9mJWM6QwunQkipQ/1/h/YqBMF6fHnT92hOtMNXpqutv+M4oA+8+pl JG7cByGZ2KBbo65rGuQugFPjt2p8Tojb48PncihNquVOJ3pk5qVrU9qTh6Ig5mhkv+HK AL4G7+oRgo+vxKtivKDeidbTIpTZvKQjcVHsXMraxlEt9ey3kStRcm0FP0Gm7jBNanwT RbqiP5iIjRgfJ6y+2xab4Aeg/KvLfPO/+vhopGvQkjfofE9VX1IE1S8MO9TFawCw37v5 DGqHkKvN+5CbPPpOVDcp5iturKjTk+jSIFSVDF0SaIvlUNqU9uiGeneW4FzgYZi1bc/f 3T8w== 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=51JTTeEcxBfnuaSrbLLwNP7Ux48aexHAY//UCEx52cw=; b=Wipty3v7oDtu9PrXUy/5zfPQA0Lnl0YJlzqd9/+uz+fQyWKpeGWHp68L3RwEGFDef5 Sr6mTKp9HtbwQx9CNc1g4nxcPoKLM3W++zsEXSxNEmoWpKn4o6M5uQqQ5U6hwAhhUtUg O6xOq2NJ7CY+0r0/OHbDv5S4a419Q8ny+QF5fTegQ8VeWy2xabyUs7TZhRfXYjDWTQhi d87zdks9yRt74w6qr1BpFKn7ODYK5uT8rkd5JupupvKdJGOyVbrNRCnnT+hU4RNnCzXE 7EcCslxM3tXW6E3SjOKmHjJHl5iqQ7MC/2rjlSAUomBNiMxVuCWoqv+xMILb8KKhQ880 WLiQ== X-Gm-Message-State: ALoCoQk9NCjM58LR5LR3/sVxSn1UpuFihL+72Kj1egJTvI7z+gdoN07ak9ELvZYCCvBWseIGwh3m X-Received: by 10.28.68.139 with SMTP id r133mr18498157wma.66.1448269611783; Mon, 23 Nov 2015 01:06:51 -0800 (PST) Received: from localhost.localdomain ([2.44.140.166]) by smtp.gmail.com with ESMTPSA id h189sm12241754wme.1.2015.11.23.01.06.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Nov 2015 01:06:51 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, linux-efi@vger.kernel.org, leif.lindholm@linaro.org, matt@codeblueprint.co.uk Subject: [PATCH v3 01/13] mm/memblock: add MEMBLOCK_NOMAP attribute to memblock memory table Date: Mon, 23 Nov 2015 10:06:21 +0100 Message-Id: <1448269593-20758-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448269593-20758-1-git-send-email-ard.biesheuvel@linaro.org> References: <1448269593-20758-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151123_010713_842622_78F660A8 X-CRM114-Status: GOOD ( 15.26 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:236 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: kuleshovmail@gmail.com, Ard Biesheuvel , roy.franz@linaro.org, linux-mm@kvack.org, ryan.harkin@linaro.org, msalter@redhat.com, grant.likely@linaro.org, akpm@linux-foundation.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org This introduces the MEMBLOCK_NOMAP attribute and the required plumbing to make it usable as an indicator that some parts of normal memory should not be covered by the kernel direct mapping. It is up to the arch to actually honor the attribute when laying out this mapping, but the memblock code itself is modified to disregard these regions for allocations and other general use. Signed-off-by: Ard Biesheuvel --- include/linux/memblock.h | 8 ++++++ mm/memblock.c | 28 ++++++++++++++++++++ 2 files changed, 36 insertions(+) -- 1.9.1 _______________________________________________ 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 24daf8fc4d7c..fec66f86eeff 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -25,6 +25,7 @@ enum { MEMBLOCK_NONE = 0x0, /* No special request */ MEMBLOCK_HOTPLUG = 0x1, /* hotpluggable region */ MEMBLOCK_MIRROR = 0x2, /* mirrored region */ + MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ }; struct memblock_region { @@ -82,6 +83,7 @@ bool memblock_overlaps_region(struct memblock_type *type, int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size); int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); +int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); ulong choose_memblock_flags(void); /* Low level functions */ @@ -184,6 +186,11 @@ static inline bool memblock_is_mirror(struct memblock_region *m) return m->flags & MEMBLOCK_MIRROR; } +static inline bool memblock_is_nomap(struct memblock_region *m) +{ + return m->flags & MEMBLOCK_NOMAP; +} + #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, unsigned long *end_pfn); @@ -319,6 +326,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); int 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); int memblock_is_reserved(phys_addr_t addr); bool memblock_is_region_reserved(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index d300f1329814..07ff069fef25 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -822,6 +822,17 @@ int __init_memblock memblock_mark_mirror(phys_addr_t base, phys_addr_t size) return memblock_setclr_flag(base, size, 1, MEMBLOCK_MIRROR); } +/** + * memblock_mark_nomap - Mark a memory region with flag MEMBLOCK_NOMAP. + * @base: the base phys addr of the region + * @size: the size of the region + * + * Return 0 on success, -errno on failure. + */ +int __init_memblock memblock_mark_nomap(phys_addr_t base, phys_addr_t size) +{ + return memblock_setclr_flag(base, size, 1, MEMBLOCK_NOMAP); +} /** * __next_reserved_mem_region - next function for for_each_reserved_region() @@ -913,6 +924,10 @@ void __init_memblock __next_mem_range(u64 *idx, int nid, ulong flags, if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(m)) continue; + /* skip nomap memory unless we were asked for it explicitly */ + if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m)) + continue; + if (!type_b) { if (out_start) *out_start = m_start; @@ -1022,6 +1037,10 @@ void __init_memblock __next_mem_range_rev(u64 *idx, int nid, ulong flags, if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(m)) continue; + /* skip nomap memory unless we were asked for it explicitly */ + if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m)) + continue; + if (!type_b) { if (out_start) *out_start = m_start; @@ -1519,6 +1538,15 @@ int __init_memblock memblock_is_memory(phys_addr_t addr) return memblock_search(&memblock.memory, addr) != -1; } +int __init_memblock memblock_is_map_memory(phys_addr_t addr) +{ + int i = memblock_search(&memblock.memory, addr); + + if (i == -1) + return false; + return !memblock_is_nomap(&memblock.memory.regions[i]); +} + #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP int __init_memblock memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, unsigned long *end_pfn)