From patchwork Mon Feb 1 18:30:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 60962 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp216161lbb; Mon, 1 Feb 2016 10:32:00 -0800 (PST) X-Received: by 10.66.218.40 with SMTP id pd8mr40815104pac.159.1454351520745; Mon, 01 Feb 2016 10:32:00 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id 70si22356360pfi.90.2016.02.01.10.32.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Feb 2016 10:32:00 -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 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 1aQJFV-0004W1-9e; Mon, 01 Feb 2016 18:30:53 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aQJFP-00048X-5m for linux-arm-kernel@lists.infradead.org; Mon, 01 Feb 2016 18:30:48 +0000 Received: by mail-wm0-x229.google.com with SMTP id r129so84100525wmr.0 for ; Mon, 01 Feb 2016 10:30:26 -0800 (PST) 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=kTQvlLXbHGIVLfzTc+SSZVB52lWaBFBjKYf8CQDXE1o=; b=QUW0YGuJvjh7IzYoZm6z6po5pZ20Wsg9M/ai3WIuOqnlHvrPNhGoSemI5FlMhqm0Cu ZXCYq2CtzhjWX5QVg8zYIix8oS0u7U35fh8SA5H2jbXh3OEW8N39JM9PbwwAiGroA0tE Lhe9D57VJfIZ0Lg2lAuk7nrEZVzNlQE1yGYaQ= 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=kTQvlLXbHGIVLfzTc+SSZVB52lWaBFBjKYf8CQDXE1o=; b=HdIOkCpYfZgv0HywmzEIiDiyUEloTL4NndxuCPR0ss7+knmPQxTHsGB4dPUO4rGzLv 2gdC/nfisGeV+A6Rkol9qz+4QA/u324btgXfwguEhI6vCzzaPDN/cw2WDidpvLhBBqqI Y9Ub1ocgCX09B+aeRgAFeXYprUleqpqEXExl0jkdkwgda8FDZzkJI7J1Ph/PElhDeeCZ uaD5Dx5YGD6bsRvd2z1IqPmYoknzGnuHtY88yEn3z10XELizLlVbMpGKV8vR9GRCOfOk akjBQeVLs/35NxTwOfvzFfdORJtPIVmYi7aqPtZD8+nFxZnQNT4l5bQvWQUpavcWtJHP KtZA== X-Gm-Message-State: AG10YOQsmpC6tFcAdBoX6zk7+sXZ4pn2hH7b41KY3P2XpfP6MVkgkc5+2Wrx2hY1mhmEhZkn X-Received: by 10.28.138.69 with SMTP id m66mr14296405wmd.101.1454351425369; Mon, 01 Feb 2016 10:30:25 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id 75sm12740822wmo.22.2016.02.01.10.30.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Feb 2016 10:30:24 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, mark.rutland@arm.com Subject: [PATCH] arm64: move back to generic memblock_enforce_memory_limit() Date: Mon, 1 Feb 2016 19:30:17 +0100 Message-Id: <1454351417-23732-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <20160201180256.GJ15514@e104818-lin.cambridge.arm.com> References: <20160201180256.GJ15514@e104818-lin.cambridge.arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160201_103047_428447_542D117E X-CRM114-Status: GOOD ( 17.56 ) 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 [2a00:1450:400c:c09:0:0:0:229 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Rather than implementing our own elaborate logic to clip the memory ranges in order of preference, use the generic memblock_enforce_memory_limit() as before, and explicitly add back that part of the kernel that needs to be accessible via the linear mapping as well as via the kernel mapping. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/init.c | 59 +++++++--------------------------------------------- 1 file changed, 7 insertions(+), 52 deletions(-) -- 2.5.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index e8e853a1024c..361c91209031 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -160,41 +160,6 @@ static int __init early_mem(char *p) } early_param("mem", early_mem); -/* - * clip_mem_range() - remove memblock memory between @min and @max until - * we meet the limit in 'memory_limit'. - */ -static void __init clip_mem_range(u64 min, u64 max) -{ - u64 mem_size, to_remove; - int i; - -again: - mem_size = memblock_phys_mem_size(); - if (mem_size <= memory_limit || max <= min) - return; - - to_remove = mem_size - memory_limit; - - for (i = memblock.memory.cnt - 1; i >= 0; i--) { - struct memblock_region *r = memblock.memory.regions + i; - u64 start = max(min, r->base); - u64 end = min(max, r->base + r->size); - - if (start >= max || end <= min) - continue; - - if (end > min) { - u64 size = min(to_remove, end - max(start, min)); - - memblock_remove(end - size, size); - } else { - memblock_remove(start, min(max - start, to_remove)); - } - goto again; - } -} - void __init arm64_memblock_init(void) { const s64 linear_region_size = -(s64)PAGE_OFFSET; @@ -215,24 +180,14 @@ void __init arm64_memblock_init(void) if (memblock_end_of_DRAM() > linear_region_size) memblock_remove(0, memblock_end_of_DRAM() - linear_region_size); + /* + * Apply the memory limit if it was set. Since the kernel may be loaded + * high up in memory, add back the kernel region that must be accessible + * via the linear mapping. + */ if (memory_limit != (phys_addr_t)ULLONG_MAX) { - u64 kbase = round_down(__pa(_text), MIN_KIMG_ALIGN); - u64 kend = PAGE_ALIGN(__pa(_end)); - u64 const sz_4g = 0x100000000UL; - - /* - * Clip memory in order of preference: - * - above the kernel and above 4 GB - * - between 4 GB and the start of the kernel (if the kernel - * is loaded high in memory) - * - between the kernel and 4 GB (if the kernel is loaded - * low in memory) - * - below 4 GB - */ - clip_mem_range(max(sz_4g, kend), ULLONG_MAX); - clip_mem_range(sz_4g, kbase); - clip_mem_range(kend, sz_4g); - clip_mem_range(0, min(kbase, sz_4g)); + memblock_enforce_memory_limit(memory_limit); + memblock_add(__pa(__init_begin), (u64)(_end - __init_begin)); } /*