From patchwork Tue Nov 17 08:53:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 56714 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1804361lbb; Tue, 17 Nov 2015 00:56:01 -0800 (PST) X-Received: by 10.66.254.39 with SMTP id af7mr61218434pad.43.1447750561067; Tue, 17 Nov 2015 00:56:01 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id xl1si56750743pbc.220.2015.11.17.00.56.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Nov 2015 00:56:01 -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 1Zyc1c-0004TF-QQ; Tue, 17 Nov 2015 08:54:04 +0000 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zyc1Z-000488-4i for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2015 08:54:02 +0000 Received: by wmdw130 with SMTP id w130so144870930wmd.0 for ; Tue, 17 Nov 2015 00:53:39 -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; bh=JUxYRehgcmAmuQRybjAKrEcdwOJK7HGgze/zzIMxqv8=; b=xwFBtN7wPkpFGa9DQqTswtjo2aal/A/ynGc4JFCO+k6KJsRblooCld+7P56gDt7KgO DslSowNZtWws9kzqKFKFA64d/99/PoWwfrRRkXholgNHgVYbTdBT3vQ+4hx/XQ3fJlzU oeRUNnbNlos/0Vv131hhVCVnbSrmKpsZdSQjA8oc6UpUuG3uQtDFHmUOzc8jkTbBnsl1 1RkphN9EXBFUFkBpg21YS4EcNDJKg87O1kqWmPTa6hAgI49N9RorD8RiBQSMV3Fuu8cx 57h9czj7++nucECtKKAJvIxlg4ugl4zmpegrLthkDoYPWH4The/dK2zim3rpACvtCW4F N88w== 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; bh=JUxYRehgcmAmuQRybjAKrEcdwOJK7HGgze/zzIMxqv8=; b=Ko3IcrBGII5kxXCKZvKKF8TIPbySZBoZnVQXnj8vjnVP9RlQsjrcu4mg5zTG8d3P9t bmnIKTiA7oMv1wtEaVXfe5oFPWO114UMhTI+ww0TjsXj3PIChE1AG2CEHr/n/R6x0pVx HOygWr7i7Z/A/Y8tZ4/utDJKz5vdJWCtlVkpDzSvfqbZKxG332rAp50BPUX1ieiZ90CY Ihd5Y2KvBHqnGQpfKjedylu5udzCAcsV2PFOr9TwMcyvy9ayVhPxFdk5ANo8K9StCZr8 8+K81As8TMR8QTSQhJukLDa5i14/j6qfybieyiCM8suSOoEPOgxMjdhHTY5eXtHKuCcA 4wcw== X-Gm-Message-State: ALoCoQnRtJLk11grIEjoHjyeD2uoeN+lyhMHjBH3FPfr5RTJO80Vq0GhJQ44u7dxLHR9AWmV8R6j X-Received: by 10.28.221.134 with SMTP id u128mr1300604wmg.94.1447750419169; Tue, 17 Nov 2015 00:53:39 -0800 (PST) Received: from ards-macbook-pro.lan (2-237-3-18.ip236.fastwebnet.it. [2.237.3.18]) by smtp.gmail.com with ESMTPSA id lf10sm38750816wjb.23.2015.11.17.00.53.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 00:53:38 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, leif.lindholm@linaro.org Subject: [RFC PATCH] arm64: use non-global mappings for UEFI runtime regions Date: Tue, 17 Nov 2015 09:53:31 +0100 Message-Id: <1447750411-6424-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151117_005401_338986_61E5CFB1 X-CRM114-Status: GOOD ( 15.03 ) 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:230 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: Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org As pointed out by Russell King in response to the proposed ARM version of this code, the sequence to switch between the UEFI runtime mapping and current's actual userland mapping (and vice versa) is potentially unsafe, since it leaves a time window between the switch to the new page tables and the TLB flush where speculative accesses may hit on stale global TLB entries. So instead, use non-global mappings, and perform the switch via the ordinary ASID-aware context switch routines. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/mmu_context.h | 2 +- arch/arm64/kernel/efi.c | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) -- 1.9.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel Reviewed-by: Mark Rutland Acked-by: Will Deacon diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index c0e87898ba96..24165784b803 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -101,7 +101,7 @@ static inline void cpu_set_default_tcr_t0sz(void) #define destroy_context(mm) do { } while(0) void check_and_switch_context(struct mm_struct *mm, unsigned int cpu); -#define init_new_context(tsk,mm) ({ atomic64_set(&mm->context.id, 0); 0; }) +#define init_new_context(tsk,mm) ({ atomic64_set(&(mm)->context.id, 0); 0; }) /* * This is called when "tsk" is about to enter lazy TLB mode. diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index de46b50f4cdf..fc5508e0df57 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -224,6 +224,8 @@ static bool __init efi_virtmap_init(void) { efi_memory_desc_t *md; + init_new_context(NULL, &efi_mm); + for_each_efi_memory_desc(&memmap, md) { u64 paddr, npages, size; pgprot_t prot; @@ -254,7 +256,8 @@ static bool __init efi_virtmap_init(void) else prot = PAGE_KERNEL; - create_pgd_mapping(&efi_mm, paddr, md->virt_addr, size, prot); + create_pgd_mapping(&efi_mm, paddr, md->virt_addr, size, + __pgprot(pgprot_val(prot) | PTE_NG)); } return true; } @@ -329,14 +332,7 @@ core_initcall(arm64_dmi_init); static void efi_set_pgd(struct mm_struct *mm) { - if (mm == &init_mm) - cpu_set_reserved_ttbr0(); - else - cpu_switch_mm(mm->pgd, mm); - - local_flush_tlb_all(); - if (icache_is_aivivt()) - __local_flush_icache_all(); + switch_mm(NULL, mm, NULL); } void efi_virtmap_load(void)