From patchwork Tue May 31 15:14:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 68947 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2013988qge; Tue, 31 May 2016 08:16:37 -0700 (PDT) X-Received: by 10.66.174.109 with SMTP id br13mr55444425pac.42.1464707797017; Tue, 31 May 2016 08:16:37 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id f72si42091190pfd.211.2016.05.31.08.16.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 May 2016 08:16:37 -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; 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 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 1b7lOC-0005vj-Tk; Tue, 31 May 2016 15:15:28 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7lNi-0004a8-Bb for linux-arm-kernel@lists.infradead.org; Tue, 31 May 2016 15:14:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2BA4354C; Tue, 31 May 2016 08:15:09 -0700 (PDT) Received: from e104818-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 531283F246; Tue, 31 May 2016 08:14:39 -0700 (PDT) From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] arm64: efi: Ensure efi_create_mapping() does not map overlapping regions Date: Tue, 31 May 2016 16:14:31 +0100 Message-Id: <1464707672-21882-3-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464707672-21882-1-git-send-email-catalin.marinas@arm.com> References: <1464707672-21882-1-git-send-email-catalin.marinas@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160531_081458_482318_9AE4F539 X-CRM114-Status: GOOD ( 12.53 ) X-Spam-Score: -8.3 (--------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-8.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.101.70 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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: Matt Fleming , Mark Rutland , linux-efi@vger.kernel.org, Will Deacon , Jeremy Linton MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Since the EFI page size is 4KB, it is possible for a !4KB page kernel to align an EFI runtime map boundaries in a way that they can overlap within the same page. This requires the current create_pgd_mapping() code to be able to split existing larger mappings when an overlapping region needs to be mapped. With this patch, efi_create_mapping() scans the EFI memory map for overlapping regions and trims the length of the current map to avoid a large block mapping and subsequent split. Signed-off-by: Catalin Marinas --- arch/arm64/kernel/efi.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) _______________________________________________ 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/kernel/efi.c b/arch/arm64/kernel/efi.c index 78f52488f9ff..0d5753c31c7f 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -62,10 +62,26 @@ 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); + phys_addr_t length = md->num_pages << EFI_PAGE_SHIFT; + efi_memory_desc_t *next = md; - create_pgd_mapping(mm, md->phys_addr, md->virt_addr, - md->num_pages << EFI_PAGE_SHIFT, - __pgprot(prot_val | PTE_NG)); + /* + * Search for the next EFI runtime map and check for any overlap with + * the current map when aligned to PAGE_SIZE. In such case, defer + * mapping the end of the current range until the next + * efi_create_mapping() call. + */ + for_each_efi_memory_desc_continue(next) { + if (!(next->attribute & EFI_MEMORY_RUNTIME)) + continue; + if (next->phys_addr < PAGE_ALIGN(md->phys_addr + length)) + length -= (md->phys_addr + length) & ~PAGE_MASK; + break; + } + + if (length) + create_pgd_mapping(mm, md->phys_addr, md->virt_addr, length, + __pgprot(prot_val | PTE_NG)); return 0; }