From patchwork Tue Jan 17 14:27:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13104750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B248C3DA78 for ; Tue, 17 Jan 2023 14:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ajggJQaH4R0M/J5Cx4ojvHFXT00qHrTRH9YkxOAiCJg=; b=ehL/8VYh9+XzZl q7j1/bVlXdKixJoZ9m2hFNZxOIWsTBGyFMI5MTMNpKgz7u4PGCyPANToyNlIm4zxNk0H80LANXy5R t25a7YUjiCYcGOaIoRahXSaTK7HMqyTRuXkUT5ZOxUERUOYpRGmsX7h4aBQKIJyNKV5tf4GRpC3JG ab1V7zzXg98fxINTScmDDRpRTnnCxCeCDOP8PQS5L2KscSatzE4lYGnr7nNcNpQlpg6fZvq9eV17J r+351lhLuvjayElqEQgnVyXTxLvGLaRUeEN0Yp9G2UMfnGZewb68EXt8Smm+cbi6mHO+znsQ35M5q DZXsuvghbzJi6nuvztuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHmwN-00EcK3-P0; Tue, 17 Jan 2023 14:27:55 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHmw5-00EcFb-Mw for linux-arm-kernel@lists.infradead.org; Tue, 17 Jan 2023 14:27:39 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6F0AEB811D3; Tue, 17 Jan 2023 14:27:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88326C433F1; Tue, 17 Jan 2023 14:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673965655; bh=at5daBIYclFSc720o8eNGxPkszsuMCaZodHbMl2VuNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rY985D7b21H1aj4afRocsRRk2Q4pQqgufD50wFCmUF3Je4lCnE7qLfSe45W8cmGNT AQlXr4riVBmzN0Nbzl0Qd/Z1iNicq1aIhHDxX4jEHlPze3JIBpNYS4gVEaOjPROitg zRF1T3t3FTG4Kq8hL2g3SdkibRuoKtwobYiMen9VctciCmTfX+KKjDf2enCDNLQW6f AMV2+EVtuX+fwd+29utn/i9YtJOW5nkfJxLf4iG/5AetQAzfVYPTEwqZS97Cvg1b0q q9xoRrZQof6OfbAfJrAUXDDv9IskiKqS8OGPEKwjO/tOViRoZwAN80/0llkGW1eI1D JEcpCHMb0h4wQ== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Johan Hovold , Maximilian Luz , Nathan Chancellor , Steev Klimaszewski , Shawn Guo Subject: [RFT PATCH 1/2] arm64: efi: Prefer a flat virtual mapping of the runtime services Date: Tue, 17 Jan 2023 15:27:17 +0100 Message-Id: <20230117142718.564299-2-ardb@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230117142718.564299-1-ardb@kernel.org> References: <20230117142718.564299-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1866; i=ardb@kernel.org; h=from:subject; bh=at5daBIYclFSc720o8eNGxPkszsuMCaZodHbMl2VuNQ=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjxrBDVPNsFo47Pm6ql6dwsBM5Nx3PKVwlp6CtTTHY MGa9YoCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY8awQwAKCRDDTyI5ktmPJOsvDA C9kurjZydKeMEvvrS1NhLllsLLPfbNFzceCgAnBptA2ks/revipjbhgGNpfP7sS8SflOLsK2kVVWR+ GHIHFEUC/2z3fWtxnR3IjeXVCxtanHXN9kbMnjB+ZBEq2YTFtsAv1W7tSObAJyR9jsDsDTJ0wlhXua ZBHEfROYAUXse/9/wy3+Vjazcmgs6+NKKE83i/Eoxqj8uKCH72OzkXtZHIVSg9btfPKtsD4KPsszWJ 81DCH2tsncjawLPZmHS3VAV1q7fitP94sCgseih+mRkM4vf5hpTl4lVQYvztnJb81ELe2jcSP61wG/ ofwtEfz4wG/f6t91OlvIASRbfxiT6TlFVUbTAu1TedCqIPnbGnAiT75YKaM4Cvvo6qFPaPaAjuXBEm qUON5PL2N4wBX2a4UUy6U7vWmF6qmC2nq/eUZbXueDtnIEzFKMms4BclZQJ0VBiqwUjhH090JIT3z8 3WvmoxeJrKDGeGhQpBMfyYXRDLPedAiRMY1ZpJ/hGhimk= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230117_062738_053428_3A5A2D00 X-CRM114-Status: GOOD ( 14.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With some systems, we cannot omit the boot time call to SetVirtualAddressMap() even if the kernel VA space is sufficiently large, because some buggy EFI implementations exist that misbehave if SetVirtualAddressMap() is never called. However, this does not mean we must reshuffle the EFI memory map: we can simply invoke SetVirtualAddressMap() with a memory map that places each EFI runtime region at the same virtual address that it takes up in the physical address map. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/efi.h | 2 ++ drivers/firmware/efi/libstub/efi-stub.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index de4ff90785b2c96a..98c4dc4da5a90e8c 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -114,6 +114,8 @@ static inline unsigned long efi_get_kimg_min_align(void) #define EFI_ALLOC_ALIGN SZ_64K #define EFI_ALLOC_LIMIT ((1UL << 48) - 1) +#define EFI_USE_FLAT_VA_MAPPING (VA_BITS_MIN >= 48) + /* * On ARM systems, virtually remapped UEFI runtime services are set up in two * distinct stages: diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 2955c1ac6a36ee00..40869320d601492a 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -44,8 +44,12 @@ #define EFI_RT_VIRTUAL_OFFSET 0 #endif +#ifndef EFI_USE_FLAT_VA_MAPPING +#define EFI_USE_FLAT_VA_MAPPING (EFI_RT_VIRTUAL_OFFSET != 0) +#endif + static u64 virtmap_base = EFI_RT_VIRTUAL_BASE; -static bool flat_va_mapping = (EFI_RT_VIRTUAL_OFFSET != 0); +static bool flat_va_mapping = EFI_USE_FLAT_VA_MAPPING; struct screen_info * __weak alloc_screen_info(void) { From patchwork Tue Jan 17 14:27:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13104746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18C46C63797 for ; Tue, 17 Jan 2023 14:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=m+9TOPcLjTFzxVpGEQRdx0BarEOR8fUI0c6GuXtrOhY=; b=wXW5C+pkUSld2A rnOkcz2sNM8TsEdwkcUESJ+ZyiAcvBlXa0mmy4VROmz1lpGjRSLEJlWgv6bVIyK9RaRGf8G/u8SJF rIt3xagIfXDRlaOKWgHbmFTVTtPA/1V53T2zFzehgQtYDg22R5thRP8+rjnigsv/fEokp5zkf3fVJ 6ETEN5Ej2VeZF93pP91vdROdqcR55r6EbSUw+OR7JW12aG4PJbm0ElsVm0gRgGjzF1WTWClGGfiCG 6FJVFYMFSBAMGO2SZOMZJaZsqhAVNYBcy1IS4rpVH362ZIZEz78PQz+mirfy9cyK/N7xCLjLJBwIn oBMix5PnWX/cpBPNWKlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHmwF-00EcIU-Fz; Tue, 17 Jan 2023 14:27:47 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHmw5-00EcFi-Qg for linux-arm-kernel@lists.infradead.org; Tue, 17 Jan 2023 14:27:39 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 64A3E6147C; Tue, 17 Jan 2023 14:27:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93081C43392; Tue, 17 Jan 2023 14:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673965657; bh=Wrp3SuN2sf33gurMiIx27fDLuT7yPVKXHH1EzZKlC4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qO6UZKm85lxdidHzRIBlEmzabel00R6fT+epRLagkglI9c324eFQl24LKV6Ys7xr2 pxzMg0EXzd4Wh6S+apqPFFDf4RFzXM2/GF5pvorIzQ1aw5OUhMtRqvwcADmASrEpRI LVM4tgZdlnFUf+JAz/uaPVTfXBDbkIO/HVzaPE48oNKVc+JSif3YXg4p/59BDefRWy JZPp3193gnm4ox5QK/omEFu9PGsg3Hfuu+savxQGIHi76hjL4Qs8RWJUzepdWPaBOT d3VvO+3ophnb4v28xgTqzGsUdZli8ADalukiKkL5D16eXgRQWWGuSe2K9J2zdk4OWI XQwXFzv+ffPOw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Johan Hovold , Maximilian Luz , Nathan Chancellor , Steev Klimaszewski , Shawn Guo Subject: [RFT PATCH 2/2] arm64: efi: Force use of SetVirtualAddressMap() on MS Surface Date: Tue, 17 Jan 2023 15:27:18 +0100 Message-Id: <20230117142718.564299-3-ardb@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230117142718.564299-1-ardb@kernel.org> References: <20230117142718.564299-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1374; i=ardb@kernel.org; h=from:subject; bh=Wrp3SuN2sf33gurMiIx27fDLuT7yPVKXHH1EzZKlC4o=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjxrBFK4LKNEyKO1VtL2pr9bayyhVzwVhz3steIhq1 N9crJECJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY8awRQAKCRDDTyI5ktmPJD7wDA CtuOFuG44iYE/4fcehhVRuxvJyzfsCG8MPJP42IX+GpJ4W/3BdRV6nmp4H4y52itZcDQc13yDxrRuk tP/Xjhtt7bcIgdS88R4Uvv1tzjZnmKaAeW/I6xYuRmzPT70ka6hAbWe7cRSsrSLFXpf1MBqZk0uzho 1BKac/OLexVJWMZ4cZL2MqSnbzNQSfIcU367p7NKgbKjuTEPjNOzp+oB05tahotW7FOerYyN1PIw75 u1xtxfHxptcaEBHk2FPs2a9tvrqaoSK93b9cupSeGBPWNcC/RX2mKkZcIRzDNqVkmeogcRmIs4HC7B fpfvFCE8MJETCZuuQ/2KVO5qacEraQGmlTotiIYJnZSPinIOLTbJ8LVcw4hwO1Yepvfh9Wz9fkDASu NC+75IMnH6PP4sOZUDKeqUCIbMyEacKaXtbioSswxJPIg6FPLgevddQ+Rgbnt8YKwrWD/k7rSGDJjx AD56fzaj80Cx9FMZRQPlwglje0ejLXopO7qQkvKS7C/sY= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230117_062737_923089_2536FB56 X-CRM114-Status: GOOD ( 13.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Qualcomm Snapdragon based Surface machines crash in the ResetSystem() EFI runtime service if SetVirtualAddressMap() has not been called prior. Unfortunately, SetVirtualAddressMap() itself crashes at boot time unless the mapping being installed is a 1:1 mapping, as these firmware implementations violate the EFI spec by accessing the new mapping before SetVirtualAddressMap() completes. Now that we have worked around the latter issue by always using a 1:1 map when the size of the VA space permits it, we can safely call SetVirtualAddressMap() in such cases. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c index ff2d18c42ee74979..cc3757fc29bdda24 100644 --- a/drivers/firmware/efi/libstub/arm64.c +++ b/drivers/firmware/efi/libstub/arm64.c @@ -22,7 +22,8 @@ static bool system_needs_vamap(void) * Ampere Altra machines crash in SetTime() if SetVirtualAddressMap() * has not been called prior. */ - if (!type1_family || strcmp(type1_family, "Altra")) + if (!type1_family || + (strcmp(type1_family, "Altra") && strcmp(type1_family, "Surface"))) return false; efi_warn("Working around broken SetVirtualAddressMap()\n");