From patchwork Mon Jan 11 13:18:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 59481 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2105513lbb; Mon, 11 Jan 2016 05:21:59 -0800 (PST) X-Received: by 10.98.86.214 with SMTP id h83mr25885141pfj.112.1452518518974; Mon, 11 Jan 2016 05:21:58 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id m10si28611209pfi.250.2016.01.11.05.21.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jan 2016 05:21:58 -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 1aIcP4-0004H1-40; Mon, 11 Jan 2016 13:20:58 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aIcOD-0002io-CA for linux-arm-kernel@lists.infradead.org; Mon, 11 Jan 2016 13:20:06 +0000 Received: by mail-wm0-x233.google.com with SMTP id f206so212495488wmf.0 for ; Mon, 11 Jan 2016 05:19:44 -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=yASYOD5COWpvmVQsL7CawSS5HLaOZ6rG8BkPzkNdKkk=; b=UT6YDlNXPRHGeMHM0qBf34b0TiKBSxw4CmmwPu4iMyFxvO15Oj6yvZ439AWNWpy1Ur PQcbvCBlADrBFITdz29tDV3kpEfuiFKFUbH7HUiF5N5UCtVt9fyrq+V31S2EH6n1a2SB icnIyiGpB3VP/LQjgf1XiAkJmoiyY0jf5hUt8= 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=yASYOD5COWpvmVQsL7CawSS5HLaOZ6rG8BkPzkNdKkk=; b=WztzkRe3rtK0fTkz0uNw5Ip/gi9xI7pRgQEqWSyy1XsCg8fsMfSRRq1yl8UzUECR9r CxnQXNUkY8FGnUT0vS3bpi60GU+LD4YKEca8yJPn9kCNhtLU1aV1nAgYxnicUm6RjFet 8g0XLtnVoszaiddthpxOBhrfNg+3m7qRJ84iKHebidNkpJmY+StTLX3nPDF80Npf0tkq bPnapQttmmbmNvEic+2rhBgqHEUDg3NkSY1B2bUBUZztoeNEN7oCoKFdVQd/3JZstaON /6ZpRPSzurQ9DAIwhacuIyti0BMM6ENbNWi2rm+dfHrW+IbuFTv+3mtJckiGljzie8nd qYwA== X-Gm-Message-State: ALoCoQkuRZy8Silvpt8RfakINubGZgOfnuAOr9kSP+YWWJGVmw2W9J841ne9h5ZQwOjaPNhAZJLe+s6ZZcOU1l0Yji/uJHCBMQ== X-Received: by 10.28.7.72 with SMTP id 69mr2945872wmh.50.1452518383800; Mon, 11 Jan 2016 05:19:43 -0800 (PST) Received: from localhost.localdomain (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by smtp.gmail.com with ESMTPSA id c15sm12766055wmd.19.2016.01.11.05.19.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 05:19:43 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com, will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, leif.lindholm@linaro.org, keescook@chromium.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/21] arm64: decouple early fixmap init from linear mapping Date: Mon, 11 Jan 2016 14:18:57 +0100 Message-Id: <1452518355-4606-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452518355-4606-1-git-send-email-ard.biesheuvel@linaro.org> References: <1452518355-4606-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160111_052005_671940_6326F18A X-CRM114-Status: GOOD ( 13.25 ) 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: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_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 -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: arnd@arndb.de, Ard Biesheuvel , bhupesh.sharma@freescale.com, stuart.yoder@freescale.com, marc.zyngier@arm.com, christoffer.dall@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Since the early fixmap page tables are populated using pages that are part of the static footprint of the kernel, they are covered by the initial kernel mapping, and we can refer to them without using __va/__pa translations, which are tied to the linear mapping. Since the fixmap page tables are disjoint from the kernel mapping up to the top level pgd entry, we can refer to bm_pte[] directly, and there is no need to walk the page tables and perform __pa()/__va() translations at each step. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/mmu.c | 32 ++++++-------------- 1 file changed, 9 insertions(+), 23 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/mmu.c b/arch/arm64/mm/mmu.c index 7711554a94f4..75b5f0dc3bdc 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -570,38 +570,24 @@ void vmemmap_free(unsigned long start, unsigned long end) #endif /* CONFIG_SPARSEMEM_VMEMMAP */ static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss; -#if CONFIG_PGTABLE_LEVELS > 2 static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss; -#endif -#if CONFIG_PGTABLE_LEVELS > 3 static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss; -#endif static inline pud_t * fixmap_pud(unsigned long addr) { - pgd_t *pgd = pgd_offset_k(addr); - - BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd)); - - return pud_offset(pgd, addr); + return (CONFIG_PGTABLE_LEVELS > 3) ? &bm_pud[pud_index(addr)] + : (pud_t *)pgd_offset_k(addr); } -static inline pmd_t * fixmap_pmd(unsigned long addr) +static inline pte_t * fixmap_pmd(unsigned long addr) { - pud_t *pud = fixmap_pud(addr); - - BUG_ON(pud_none(*pud) || pud_bad(*pud)); - - return pmd_offset(pud, addr); + return (CONFIG_PGTABLE_LEVELS > 2) ? &bm_pmd[pmd_index(addr)] + : (pmd_t *)pgd_offset_k(addr); } static inline pte_t * fixmap_pte(unsigned long addr) { - pmd_t *pmd = fixmap_pmd(addr); - - BUG_ON(pmd_none(*pmd) || pmd_bad(*pmd)); - - return pte_offset_kernel(pmd, addr); + return &bm_pte[pte_index(addr)]; } void __init early_fixmap_init(void) @@ -613,14 +599,14 @@ void __init early_fixmap_init(void) pgd = pgd_offset_k(addr); pgd_populate(&init_mm, pgd, bm_pud); - pud = pud_offset(pgd, addr); + pud = fixmap_pud(addr); pud_populate(&init_mm, pud, bm_pmd); - pmd = pmd_offset(pud, addr); + pmd = fixmap_pmd(addr); pmd_populate_kernel(&init_mm, pmd, bm_pte); /* * The boot-ioremap range spans multiple pmds, for which - * we are not preparted: + * we are not prepared: */ BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT) != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));