From patchwork Fri Feb 26 16:57:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 63085 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp821701lbc; Fri, 26 Feb 2016 08:59:09 -0800 (PST) X-Received: by 10.98.14.67 with SMTP id w64mr3562078pfi.154.1456505948981; Fri, 26 Feb 2016 08:59:08 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id us7si4667228pac.204.2016.02.26.08.59.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Feb 2016 08:59:08 -0800 (PST) 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; 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; 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 1aZLiP-0002rV-VW; Fri, 26 Feb 2016 16:58:05 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aZLi1-0002eC-6h for linux-arm-kernel@lists.infradead.org; Fri, 26 Feb 2016 16:57:41 +0000 Received: by mail-wm0-x235.google.com with SMTP id g62so80258185wme.0 for ; Fri, 26 Feb 2016 08:57:20 -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=EVq5zZuT3oiZjAcc8kMeZQmnxJLCDjADi+kGjwd9gHA=; b=Ofj2a0X8/TYT5B41BZljuUTXFpIuxTgUDuU3xYfw9NGcTOi5mqxA8+TMBfqLiejDqv t4bjhQe3eEqgXV7Hl68aV+c5i2ZQMlZJXheS0/fOBNyPsS14f2y7YcODBvpvfXiVRbW4 6LaWWb8oN69mPbyEYZjtEQWfGWlTL3sGpSGXE= 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=EVq5zZuT3oiZjAcc8kMeZQmnxJLCDjADi+kGjwd9gHA=; b=foNKR1rnao6DJ42PPQdtls4ZiqVbWbJC9vvQb06poOPcmuS7BZCeXSCviizUSmKxUp 9p4451ARYEv3D/bX6uI27A8KG6EqnroqKkFfLH6l7+TPRzwB9YBwxW0JNWVH99ju/WIK FSZN587t8sggb9O7etDBM0IbJEeyynERLDHNjtwn55S3xb0tW08gZC4jbE1JP9sFyEGg GPzO5hz9eZWkdwHpcNzklQyMCHgafZjLBA7bnEBYRJ0UfKn1u9WMTdWfHcsobdWx7EgQ VgV36brSlUiZL40Nfgwj60VLVTR0LHufb1NoIyy2Gi4lvCneW7B3Bs7uhiSwtUehED0p Jk5Q== X-Gm-Message-State: AD7BkJJpYbTDRunozSvpfhk5DzCutTAmVb0xzrmjFARzXSESxnG/1jnzcx3MQ6kroJBVRB/4 X-Received: by 10.194.91.205 with SMTP id cg13mr2636286wjb.166.1456505839412; Fri, 26 Feb 2016 08:57:19 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id p125sm3632550wmd.16.2016.02.26.08.57.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Feb 2016 08:57:18 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com Subject: [PATCH v2 1/2] arm64: vmemmap: use virtual projection of linear region Date: Fri, 26 Feb 2016 17:57:13 +0100 Message-Id: <1456505834-8638-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456505834-8638-1-git-send-email-ard.biesheuvel@linaro.org> References: <1456505834-8638-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160226_085741_438935_ED61CF62 X-CRM114-Status: GOOD ( 16.17 ) 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:235 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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 Commit dd006da21646 ("arm64: mm: increase VA range of identity map") made some changes to the memory mapping code to allow physical memory to reside at an offset that exceeds the size of the virtual mapping. However, since the size of the vmemmap area is proportional to the size of the VA area, but it is populated relative to the physical space, we may end up with the struct page array being mapped outside of the vmemmap region. For instance, on my Seattle A0 box, I can see the following output in the dmesg log. vmemmap : 0xffffffbdc0000000 - 0xffffffbfc0000000 ( 8 GB maximum) 0xffffffbfc0000000 - 0xffffffbfd0000000 ( 256 MB actual) We can fix this by deciding that the vmemmap region is not a projection of the physical space, but of the virtual space above PAGE_OFFSET, i.e., the linear region. This way, we are guaranteed that the vmemmap region is of sufficient size, and we can even reduce the size by half. Signed-off-by: Ard Biesheuvel --- v2: simplify the expression for vmemmap, forward compatible with the patch that changes the type of memstart_addr to s64 arch/arm64/include/asm/pgtable.h | 7 ++++--- arch/arm64/mm/init.c | 4 ++-- 2 files changed, 6 insertions(+), 5 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/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 16438dd8916a..43abcbc30813 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -34,18 +34,19 @@ /* * VMALLOC and SPARSEMEM_VMEMMAP ranges. * - * VMEMAP_SIZE: allows the whole VA space to be covered by a struct page array + * VMEMAP_SIZE: allows the whole linear region to be covered by a struct page array * (rounded up to PUD_SIZE). * VMALLOC_START: beginning of the kernel vmalloc space * VMALLOC_END: extends to the available space below vmmemmap, PCI I/O space, * fixed mappings and modules */ -#define VMEMMAP_SIZE ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE) +#define VMEMMAP_SIZE ALIGN((1UL << (VA_BITS - PAGE_SHIFT - 1)) * sizeof(struct page), PUD_SIZE) #define VMALLOC_START (MODULES_END) #define VMALLOC_END (PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - SZ_64K) -#define vmemmap ((struct page *)(VMALLOC_END + SZ_64K)) +#define VMEMMAP_START (VMALLOC_END + SZ_64K) +#define vmemmap ((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT)) #define FIRST_USER_ADDRESS 0UL diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index e1f425fe5a81..4ea7efc28e65 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -380,8 +380,8 @@ void __init mem_init(void) MLK_ROUNDUP(_text, _etext), MLK_ROUNDUP(_sdata, _edata), #ifdef CONFIG_SPARSEMEM_VMEMMAP - MLG((unsigned long)vmemmap, - (unsigned long)vmemmap + VMEMMAP_SIZE), + MLG(VMEMMAP_START, + VMEMMAP_START + VMEMMAP_SIZE), MLM((unsigned long)phys_to_page(memblock_start_of_DRAM()), (unsigned long)virt_to_page(high_memory)), #endif