From patchwork Wed Jun 29 12:51:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 71189 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp2134488qgy; Wed, 29 Jun 2016 05:53:28 -0700 (PDT) X-Received: by 10.66.25.133 with SMTP id c5mr11369248pag.103.1467204807990; Wed, 29 Jun 2016 05:53:27 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ai12si4348557pac.139.2016.06.29.05.53.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jun 2016 05:53:27 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIEym-00061v-3f; Wed, 29 Jun 2016 12:52:32 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bIEyH-0005Wk-Qk for linux-arm-kernel@lists.infradead.org; Wed, 29 Jun 2016 12:52:02 +0000 Received: by mail-wm0-x231.google.com with SMTP id f126so180035816wma.1 for ; Wed, 29 Jun 2016 05:51:41 -0700 (PDT) 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=x5hk451BKn1x/9cHurERqjHdhXaj+IH7bKJqPvYDVaI=; b=Wk8TAwLgP3LUvciv1PleyGysTkD+SPLzJRJ6ZLD4Buic5yjuIg2Uro9qzqe5p1Po2O lePcw241tSPKyBDL+j61yoWRPXXthGFAv9QKtcrY/Tv4cceUi4JKYPKlWGbR5TFf0K1G zeZxysIacslqsVORoZFPcmUK7R2pFmpYZ5mXQ= 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=x5hk451BKn1x/9cHurERqjHdhXaj+IH7bKJqPvYDVaI=; b=ZnFKmicP+BVMZD53neCQRQvIBCFPP2saFXtHO8s2Wz/93uVp6I6CCBe+KGGokrRk7v zqgiunzXGSZeZVOJXCmsWwQ7jfHM+t6LuvITT/anRv+Q2Ny1OAeh+8qhwPj05RNBk5UB l44ZZktJ3dBN8gBl72FQFDhoTQ067N9GL3ge0fLuByW2TSS0rlooEUG/ZfCV2yfnnlBG 0PgX/WJE7TK5xkUuz8jOdZNq6AEdFX458jMPEzWW+qnnGb1U9OpDcH59c59pPEUKzgya UV9V7V59jofe4FQESgS5O+Eag/eedW1oeZfqwV7BxeXTfxJuRUX9nuVHL6DTw8h9cy3C vWQg== X-Gm-Message-State: ALyK8tICqUU6DjulcImVswwPNyYEP7hJO8OsX3XlUv3kb7hl70cuTad2smbl23a+Z+cOgh9a X-Received: by 10.28.156.77 with SMTP id f74mr9139129wme.82.1467204700132; Wed, 29 Jun 2016 05:51:40 -0700 (PDT) Received: from localhost.localdomain ([188.203.148.129]) by smtp.gmail.com with ESMTPSA id bh7sm3592433wjb.22.2016.06.29.05.51.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jun 2016 05:51:39 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, matt@codeblueprint.co.uk Subject: [PATCH 2/5] arm64: efi: always map runtime services code and data regions down to pages Date: Wed, 29 Jun 2016 14:51:27 +0200 Message-Id: <1467204690-10790-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467204690-10790-1-git-send-email-ard.biesheuvel@linaro.org> References: <1467204690-10790-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160629_055202_033991_7DAD51C1 X-CRM114-Status: GOOD ( 14.83 ) 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:231 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 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 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: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org To avoid triggering diagnostics in the MMU code that are finicky about splitting block mappings into more granular mappings, ensure that regions that are likely to appear in the Memory Attributes table as well as the UEFI memory map are always mapped down to pages. This way, we can use apply_to_page_range() instead of create_pgd_mapping() for the second pass, which cannot split or merge block entries, and operates strictly on PTEs. Note that this aligns the arm64 Memory Attributes table handling code with the ARM code, which already uses apply_to_page_range() to set the strict permissions. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/efi.h | 3 +- arch/arm64/kernel/efi.c | 36 +++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) -- 2.7.4 _______________________________________________ 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/efi.h b/arch/arm64/include/asm/efi.h index 622db3c6474e..8b13476cdf96 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -14,8 +14,7 @@ extern void efi_init(void); #endif int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); - -#define efi_set_mapping_permissions efi_create_mapping +int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); #define arch_efi_call_virt_setup() \ ({ \ diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 981604948521..4aef89f37049 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -62,13 +62,47 @@ struct screen_info screen_info __section(.data); int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md) { pteval_t prot_val = create_mapping_protection(md); + bool allow_block_mappings = (md->type != EFI_RUNTIME_SERVICES_CODE && + md->type != EFI_RUNTIME_SERVICES_DATA); create_pgd_mapping(mm, md->phys_addr, md->virt_addr, md->num_pages << EFI_PAGE_SHIFT, - __pgprot(prot_val | PTE_NG), true); + __pgprot(prot_val | PTE_NG), allow_block_mappings); return 0; } +static int __init set_permissions(pte_t *ptep, pgtable_t token, + unsigned long addr, void *data) +{ + efi_memory_desc_t *md = data; + pte_t pte = *ptep; + + if (md->attribute & EFI_MEMORY_RO) + pte = set_pte_bit(pte, __pgprot(PTE_RDONLY)); + if (md->attribute & EFI_MEMORY_XP) + pte = set_pte_bit(pte, __pgprot(PTE_PXN)); + set_pte(ptep, pte); + return 0; +} + +int __init efi_set_mapping_permissions(struct mm_struct *mm, + efi_memory_desc_t *md) +{ + BUG_ON(md->type != EFI_RUNTIME_SERVICES_CODE && + md->type != EFI_RUNTIME_SERVICES_DATA); + + /* + * Calling apply_to_page_range() is only safe on regions that are + * guaranteed to be mapped down to pages. Since we are only called + * for regions that have been mapped using efi_create_mapping() above + * (and this is checked by the generic Memory Attributes table parsing + * routines), there is no need to check that again here. + */ + return apply_to_page_range(mm, md->virt_addr, + md->num_pages << EFI_PAGE_SHIFT, + set_permissions, md); +} + static int __init arm64_dmi_init(void) { /*