From patchwork Tue May 19 16:26:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11558133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C39C1391 for ; Tue, 19 May 2020 16:27:28 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DF69720756 for ; Tue, 19 May 2020 16:27:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="D0Yuj+pk"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Mhf8scZP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF69720756 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=i7+Q+Yo/mX0leOFJ0rYy8vFz5pxhcV+dPzye42LFKAA=; b=D0Yuj+pky3NYSPidLbmBhQc9iq v7onXXB4hBxDm0/nzxshQ8gfhlRV9Qh4KJfWrQQr45bkMIg/vPnQqbOWf5NsWWsZrK8bVoVALXanQ Ix8KBia2eVCGTE7uCwfvCkR5KJnsH1YvuDWc4iFDKS9XEAxkv8SMBPpv/qdk7kCBzdoJ4AumCLaMK WEgjR3nHct8TCQ5L6isNA4jT5ufDaKDAMk7xx+KPWiI+CmYjdQqCrsvJ+znJ5kyozVdwjsOuxCSRL jEYi0X+FoR4sTvdumVIHzh6GyI/td+smXkEinr6ToWKmAJ8EePKyTG/n38FyK9UAcvTqTqmZE5R2t 4S5Z9nAQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb55L-0004F0-Ba; Tue, 19 May 2020 16:27:19 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb554-000420-G8 for linux-arm-kernel@lists.infradead.org; Tue, 19 May 2020 16:27:04 +0000 Received: from e123331-lin.nice.arm.com (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CD43020823; Tue, 19 May 2020 16:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589905622; bh=s1wJAwkrmgG1XjwsUm3v1xaTI0ARm6WW9gEhCur/Ryw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mhf8scZPUYtvuTAvYm0QeYPePZdh7+Qux7I5nVnoKRYC68hXA3BXA0qAJ9dsc1p9r 9FWz0qdGsTrIN4XttXlX8Ln5odkrizRT2Qrw3dLYhZy5x3dSB1TjRGi2F3wMH4HbX+ eYqJSh29BI3rsCG/YQiRg9kmaUumjQ3a7f2MiwTU= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/5] ARM: decompressor: move headroom variable out of LC0 Date: Tue, 19 May 2020 18:26:41 +0200 Message-Id: <20200519162645.31065-2-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519162645.31065-1-ardb@kernel.org> References: <20200519162645.31065-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200519_092702_555460_6774208D X-CRM114-Status: GOOD ( 11.41 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Geert Uytterhoeven , Nicolas Pitre , Heinrich Schuchardt , Linus Walleij , Russell King , Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Before breaking up LC0 into different pieces, move out the variable that is already place-relative (given that it subtracts 'restart' in the expression) and so its value does not need to be added to the runtime address of the LC0 symbol itself. Signed-off-by: Ard Biesheuvel Reviewed-by: Geert Uytterhoeven Reviewed-by: Nicolas Pitre --- arch/arm/boot/compressed/head.S | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index cabdd8f4a248..42b8d67beab6 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -287,7 +287,7 @@ not_angel: */ mov r0, pc cmp r0, r4 - ldrcc r0, LC0+28 + ldrcc r0, .Lheadroom addcc r0, r0, pc cmpcc r4, r0 orrcc r4, r4, #1 @ remember we skipped cache_on @@ -664,9 +664,11 @@ LC0: .word LC0 @ r1 .word _got_start @ r11 .word _got_end @ ip .word .L_user_stack_end @ sp - .word _end - restart + 16384 + 1024*1024 .size LC0, . - LC0 +.Lheadroom: + .word _end - restart + 16384 + 1024*1024 + .Linflated_image_size_offset: .long (input_data_end - 4) - . From patchwork Tue May 19 16:26:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11558135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F77D60D for ; Tue, 19 May 2020 16:27:38 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7D22A20756 for ; Tue, 19 May 2020 16:27:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GIgqgpcn"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="BaIcUPJO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D22A20756 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0PsT2BbPMJpHw0aaMFLXTlabGj9VIEwcAaDVp60JKF4=; b=GIgqgpcn6nv83KgK2BiFY1dsu0 DmliM6BIoAJ5g7ZUlH33Fg2oSVUkBxcft44Y/ISqBCWbUGLjvPpbM7WBj3DZhEjBPSx4z4mkmr3J+ H5jIZdG5N+5k1qoenbbNI2vOYRd1aKtFTm5zoqO/79bf9EHdSAcxx45uLvIkd4JF8CiDZ/8RhhoIp uipeSX17QXYPD1Y3bL+1YiObGpLRbQSiMKP9NzU9UaRSf0t6wkROYUff7HIwXvadoGeyfM3rdg9Uq dAa1WXkp5aRGCsMy00Dr3+wVLNgIFPIzvGR1WnFMZm3GHsEcpSc8g375jvco/f0wHqP/b3QX6tcLU sNnbsoDQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb55a-0004ST-M0; Tue, 19 May 2020 16:27:34 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb557-000440-4T for linux-arm-kernel@lists.infradead.org; Tue, 19 May 2020 16:27:06 +0000 Received: from e123331-lin.nice.arm.com (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D06A20826; Tue, 19 May 2020 16:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589905624; bh=Rnr1nZVVeFJ8Ie+KrJMA9hzs3cpYXGVP9cLvCfNZ5RE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BaIcUPJO0UwNNr+BifsMlE6U9axBV/4+5mSQRLZxitMW5BasAfLi6BMOcFvXiyeZE lU5+XmKS1kf/lUqb98vJFj17XHoTZi+oxWeqeu6Pwy5vgCQefBJxsIJxCaMCYqdHjx RcwN7Atuv317jS60pgcG16sHDFKsmKEN3Aw/uejU= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/5] ARM: decompressor: split off _edata and stack base into separate object Date: Tue, 19 May 2020 18:26:42 +0200 Message-Id: <20200519162645.31065-3-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519162645.31065-1-ardb@kernel.org> References: <20200519162645.31065-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200519_092705_228234_F25CB644 X-CRM114-Status: GOOD ( 11.47 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Geert Uytterhoeven , Nicolas Pitre , Heinrich Schuchardt , Linus Walleij , Russell King , Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In preparation of moving the handling of the LC0 object to a later stage in the decompressor startup code, move out _edata and the initial value of the stack pointer, which are needed earlier than the remaining contents of LC0. Signed-off-by: Ard Biesheuvel Reviewed-by: Geert Uytterhoeven Reviewed-by: Nicolas Pitre --- arch/arm/boot/compressed/head.S | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 42b8d67beab6..5d712e2c0001 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -293,22 +293,20 @@ not_angel: orrcc r4, r4, #1 @ remember we skipped cache_on blcs cache_on -restart: adr r0, LC0 - ldmia r0, {r1, r2, r3, r6, r11, r12} - ldr sp, [r0, #24] +restart: adr r0, LC1 + ldr sp, [r0] + ldr r6, [r0, #4] + add sp, sp, r0 + add r6, r6, r0 - /* - * We might be running at a different address. We need - * to fix up various pointers. - */ + adr r0, LC0 + ldmia r0, {r1, r2, r3, r11, r12} sub r0, r0, r1 @ calculate the delta offset - add r6, r6, r0 @ _edata get_inflated_image_size r9, r10, lr #ifndef CONFIG_ZBOOT_ROM /* malloc space is above the relocated stack (64k max) */ - add sp, sp, r0 add r10, sp, #0x10000 #else /* @@ -660,12 +658,15 @@ not_relocated: mov r0, #0 LC0: .word LC0 @ r1 .word __bss_start @ r2 .word _end @ r3 - .word _edata @ r6 .word _got_start @ r11 .word _got_end @ ip - .word .L_user_stack_end @ sp .size LC0, . - LC0 + .type LC1, #object +LC1: .word .L_user_stack_end - LC1 @ sp + .word _edata - LC1 @ r6 + .size LC1, . - LC1 + .Lheadroom: .word _end - restart + 16384 + 1024*1024 From patchwork Tue May 19 16:26:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11558137 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E87760D for ; Tue, 19 May 2020 16:27:51 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7BF6C20756 for ; Tue, 19 May 2020 16:27:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nMyXXsxp"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="1oBt2noI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BF6C20756 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=nzVaBOBSGKWg0RgEjEpU29zgtXSecFqWghJbPl3T5fs=; b=nMyXXsxpE68ZJaHx/U77cF8eXw vyDl7/dnTz+T3hCm5DUUPBfNrEYGtZWeAzijalnPD1kPA2L8QOWlJuAQHJBPdsaP0blsim9N1JxAm AGLQSGT75mxgYMLfpTZTmv1U8YHR/1Pxy1Do2vKnjT4/tW52PwPT35jHRiqkmu2RJLYwK9d/nMz+Q g4P0tWWcsWdkn/PHULKhKeJAn5O4u9UnqccKnpZucztTzHH0Wvs6lDAjNxOeXV9ev/M/3Zdmzff/t 0oEBLPkhzs+RWjBn9fqlNFljnnZ7/BoFMTNvVQp0MkrN/+rTKRR/yzPZudnvDVoMEl8qNsrnctBCO ax6PaYfg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb55q-0004g8-CK; Tue, 19 May 2020 16:27:50 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb558-00045l-Sh for linux-arm-kernel@lists.infradead.org; Tue, 19 May 2020 16:27:08 +0000 Received: from e123331-lin.nice.arm.com (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C0249207FB; Tue, 19 May 2020 16:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589905626; bh=C7HgoJDn2kYqnmr2QmhsUs8JI2aan9kSJKl1W84BSOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1oBt2noI2iW40P3wwK0l9PNHZKrkxe+NIZa8eCEdhjgy0nFm8fNmlz3i1YWqaoh3z momG0znFpyDre4CAVNy8I1vwWNBluT/ptuf9gKIaU5KZnmtx1M9muJ1T3wc4bgmdsm oeo3et6vAyCfNgS+qQKm5jyJ1o4t4Cmt8PjWdZ5g= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/5] ARM: decompressor: defer loading of the contents of the LC0 structure Date: Tue, 19 May 2020 18:26:43 +0200 Message-Id: <20200519162645.31065-4-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519162645.31065-1-ardb@kernel.org> References: <20200519162645.31065-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200519_092706_969215_14EC143A X-CRM114-Status: GOOD ( 13.43 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Geert Uytterhoeven , Nicolas Pitre , Heinrich Schuchardt , Linus Walleij , Russell King , Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The remaining contents of LC0 are only used after the point in the decompressor startup code where we enter via 'wont_overwrite'. So move the loading of the LC0 structure after it. This will allow us to jump to wont_overwrite directly from the EFI stub, and execute the decompressor in place at the offset it was loaded by the UEFI firmware. Signed-off-by: Ard Biesheuvel Reviewed-by: Geert Uytterhoeven Reviewed-by: Nicolas Pitre --- arch/arm/boot/compressed/head.S | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 5d712e2c0001..ce442ec5028a 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -299,10 +299,6 @@ restart: adr r0, LC1 add sp, sp, r0 add r6, r6, r0 - adr r0, LC0 - ldmia r0, {r1, r2, r3, r11, r12} - sub r0, r0, r1 @ calculate the delta offset - get_inflated_image_size r9, r10, lr #ifndef CONFIG_ZBOOT_ROM @@ -320,9 +316,6 @@ restart: adr r0, LC1 mov r5, #0 @ init dtb size to 0 #ifdef CONFIG_ARM_APPENDED_DTB /* - * r0 = delta - * r2 = BSS start - * r3 = BSS end * r4 = final kernel address (possibly with LSB set) * r5 = appended dtb size (still unknown) * r6 = _edata @@ -330,8 +323,6 @@ restart: adr r0, LC1 * r8 = atags/device tree pointer * r9 = size of decompressed image * r10 = end of this image, including bss/stack/malloc space if non XIP - * r11 = GOT start - * r12 = GOT end * sp = stack pointer * * if there are device trees (dtb) appended to zImage, advance r10 so that the @@ -379,7 +370,6 @@ restart: adr r0, LC1 /* temporarily relocate the stack past the DTB work space */ add sp, sp, r5 - stmfd sp!, {r0-r3, ip, lr} mov r0, r8 mov r1, r6 mov r2, r5 @@ -398,7 +388,6 @@ restart: adr r0, LC1 mov r2, r5 bleq atags_to_fdt - ldmfd sp!, {r0-r3, ip, lr} sub sp, sp, r5 #endif @@ -535,6 +524,10 @@ dtb_check_done: mov pc, r0 wont_overwrite: + adr r0, LC0 + ldmia r0, {r1, r2, r3, r11, r12} + sub r0, r0, r1 @ calculate the delta offset + /* * If delta is zero, we are running at the address we were linked at. * r0 = delta From patchwork Tue May 19 16:26:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11558139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF25460D for ; Tue, 19 May 2020 16:28:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A0A1020756 for ; Tue, 19 May 2020 16:28:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZfdxyXBw"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="pnzQKbgn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A0A1020756 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=yQ6yfe7cyj0ypvbjZRI0sgpxhvC9xX6baQzamICSdjk=; b=ZfdxyXBwaiAf1mkup0q9QVLXWj cYd6UbNmmaoXU/z/m7co+oq/D4x5kL50SCYmdNhzf+x6paqrimrsh4wxt6aq29C0aCrmf3xY3RZRq lQrVVZY3+tjwZZMbIIdfyA3jFr9MbTQ2bqZ9zEl/9NU5kScce0AjBpK/qTHgBYnmvFqllHhnVBXQE 8JZwk+ozsidtvI1h1QFeM+71LljziWPcC9ut7QA5TVbAnP/UTncL1l2c41ZiHsMEwgKBHTLkXNXIl NKjBJZlldElXzzs/DJ74sIkrmx6SSLQ3GgNjuVmvULlg7K8/taKDFMnOYrfr+Qqoyqc1VazAUngLq 8CSBDMgw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb56B-00050A-NH; Tue, 19 May 2020 16:28:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb55A-00047t-Nn for linux-arm-kernel@lists.infradead.org; Tue, 19 May 2020 16:27:10 +0000 Received: from e123331-lin.nice.arm.com (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BFAB32081A; Tue, 19 May 2020 16:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589905628; bh=s8227r3wr+M1LR2ra2WRSSL45hZ8JOxmjLKJcXVBONI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pnzQKbgnZ9/bKF5J4X9LWpbTecFMM8wwtTOIRVCn/Rbu1Fpk666A/MmM0VfFOO9xU vO4IPV2b8R9D3fg2xGR5LqG2ems8WsHkLY8th0N/88+pzGSoW2anLQFkz5/llAjL2M 0FrJTrk40E4JzkCM66Hbo5BegVSBrGph0StCY/8Q= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 4/5] ARM: decompressor: move GOT into .data for EFI enabled builds Date: Tue, 19 May 2020 18:26:44 +0200 Message-Id: <20200519162645.31065-5-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519162645.31065-1-ardb@kernel.org> References: <20200519162645.31065-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200519_092708_801982_34BB116E X-CRM114-Status: GOOD ( 12.43 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Geert Uytterhoeven , Nicolas Pitre , Heinrich Schuchardt , Linus Walleij , Russell King , Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org We will be running the decompressor in place after a future patch, instead of copying it around first. This means we no longer have to disable and re-enable the MMU and caches either. However, this means we will be loaded with the restricted permissions set by the UEFI firmware, which means that we have to move the GOT table into the data section in order for the contents to be writable by the code itself. Signed-off-by: Ard Biesheuvel Reviewed-by: Nicolas Pitre --- arch/arm/boot/compressed/vmlinux.lds.S | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S index b247f399de71..d0619ec05705 100644 --- a/arch/arm/boot/compressed/vmlinux.lds.S +++ b/arch/arm/boot/compressed/vmlinux.lds.S @@ -63,9 +63,11 @@ SECTIONS _etext = .; .got.plt : { *(.got.plt) } +#ifndef CONFIG_EFI_STUB _got_start = .; .got : { *(.got) } _got_end = .; +#endif /* ensure the zImage file size is always a multiple of 64 bits */ /* (without a dummy byte, ld just ignores the empty section) */ @@ -74,6 +76,9 @@ SECTIONS #ifdef CONFIG_EFI_STUB .data : ALIGN(4096) { __pecoff_data_start = .; + _got_start = .; + *(.got) + _got_end = .; /* * The EFI stub always executes from RAM, and runs strictly before the * decompressor, so we can make an exception for its r/w data, and keep it From patchwork Tue May 19 16:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11558141 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3501E60D for ; Tue, 19 May 2020 16:28:33 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0DDC520826 for ; Tue, 19 May 2020 16:28:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="g10WnDNY"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="NZqtt8Pw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DDC520826 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7IcdW4a1ln3fvFGsURvz2QaId1zdycrtNEH/mLpM2Dc=; b=g10WnDNYrbE2sbUwF29VEX0L/2 NN6oefMa5XtWzbmHnwLvtVwZ9X2Ebb2fyF2jv3AuFC9YYtzzljXY0CEKQ5EU4p5s0hG2xpOVHaETo ZVxV2crelyN7KvNm80TC/kbqwd33jyXjcGqmyOitRMbrh6sm2GNc0Ku5JvS4J7YNUy7wSyMmXLFj9 CPvlCoI1V1ie/kp6zpFXJ+A+I6k7xGAO2Ms5FRZRLKhIzDKjDc8HLe09RqbyqHpN5yZ1UdbjeZ/2f 88hFztboKfss1VCmJyl/sZtuwEhOJqZ1F2qmAopOZqZHduW1ugklXVjGnOB1yc+ATYDqHIccf8yV1 PWO5Gwaw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb56T-0005HD-E0; Tue, 19 May 2020 16:28:29 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jb55E-0004Ad-4Y for linux-arm-kernel@lists.infradead.org; Tue, 19 May 2020 16:27:14 +0000 Received: from e123331-lin.nice.arm.com (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DF4C520829; Tue, 19 May 2020 16:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589905631; bh=ML7xIKOoEGmj8SHYu1fMuw14GUBck0Lag61YRn3ulRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NZqtt8PwB6TkdWgrA2FRdjr5KkG5dGewH7ouN/4ABHG6Mv/8Gf5LYxfqWN7z2Suqa /MC52+qM0/hZLEFKsbYX7v5/pOLXymZYjJm7u05LJ0LzMZmrUQ8edCuKSAE3z3C1ev FtLBBTTG6WqxxuTbRwd0jUKVdZr73YKCbSipBpQs= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 5/5] ARM: decompressor: run decompressor in place if loaded via UEFI Date: Tue, 19 May 2020 18:26:45 +0200 Message-Id: <20200519162645.31065-6-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519162645.31065-1-ardb@kernel.org> References: <20200519162645.31065-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200519_092712_442036_2D7BAEF5 X-CRM114-Status: GOOD ( 20.21 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Geert Uytterhoeven , Nicolas Pitre , Heinrich Schuchardt , Linus Walleij , Russell King , Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The decompressor can load from anywhere in memory, and the only reason the EFI stub code relocates it is to ensure it appears within the first 128 MiB of memory, so that the uncompressed kernel ends up at the right offset in memory. We can short circuit this, and simply jump into the decompressor startup code at the point where it knows where the base of memory lives. This also means there is no need to disable the MMU and caches, create new page tables and re-enable them. Signed-off-by: Ard Biesheuvel Reviewed-by: Nicolas Pitre --- arch/arm/boot/compressed/head.S | 39 ++++++----------- drivers/firmware/efi/libstub/arm32-stub.c | 45 +++----------------- 2 files changed, 20 insertions(+), 64 deletions(-) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index ce442ec5028a..c79db44ba128 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -1430,37 +1430,26 @@ reloc_code_end: #ifdef CONFIG_EFI_STUB ENTRY(efi_enter_kernel) - mov r7, r0 @ preserve image base - mov r4, r1 @ preserve DT pointer + mov r4, r0 @ preserve image base + mov r8, r1 @ preserve DT pointer - mov r0, r4 @ DT start - add r1, r4, r2 @ DT end - bl cache_clean_flush + mrc p15, 0, r0, c1, c0, 0 @ read SCTLR + tst r0, #0x1 @ MMU enabled? + orreq r4, r4, #1 @ set LSB if not - mov r0, r7 @ relocated zImage - ldr r1, =_edata @ size of zImage - add r1, r1, r0 @ end of zImage + mov r0, r8 @ DT start + add r1, r8, r2 @ DT end bl cache_clean_flush - @ The PE/COFF loader might not have cleaned the code we are - @ running beyond the PoU, and so calling cache_off below from - @ inside the PE/COFF loader allocated region is unsafe unless - @ we explicitly clean it to the PoC. - adr r0, call_cache_fn @ region of code we will - adr r1, 0f @ run with MMU off - bl cache_clean_flush - bl cache_off + adr r0, 0f @ switch to our stack + ldr sp, [r0] + add sp, sp, r0 - @ Set parameters for booting zImage according to boot protocol - @ put FDT address in r2, it was returned by efi_entry() - @ r1 is the machine type, and r0 needs to be 0 - mov r0, #0 - mov r1, #0xFFFFFFFF - mov r2, r4 - add r7, r7, #(__efi_start - start) - mov pc, r7 @ no mode switch + mov r5, #0 @ appended DTB size + mov r7, #0xFFFFFFFF @ machine ID + b wont_overwrite ENDPROC(efi_enter_kernel) -0: +0: .long .L_user_stack_end - . #endif .align diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c index 7826553af2ba..0050d811bf20 100644 --- a/drivers/firmware/efi/libstub/arm32-stub.c +++ b/drivers/firmware/efi/libstub/arm32-stub.c @@ -199,14 +199,8 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, unsigned long kernel_base; efi_status_t status; - /* - * Verify that the DRAM base address is compatible with the ARM - * boot protocol, which determines the base of DRAM by masking - * off the low 27 bits of the address at which the zImage is - * loaded. These assumptions are made by the decompressor, - * before any memory map is available. - */ - kernel_base = round_up(dram_base, SZ_128M); + /* use a 16 MiB aligned base for the decompressed kernel */ + kernel_base = round_up(dram_base, SZ_16M) + TEXT_OFFSET; /* * Note that some platforms (notably, the Raspberry Pi 2) put @@ -215,41 +209,14 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, * base of the kernel image is only partially used at the moment. * (Up to 5 pages are used for the swapper page tables) */ - kernel_base += TEXT_OFFSET - 5 * PAGE_SIZE; - - status = reserve_kernel_base(kernel_base, reserve_addr, reserve_size); + status = reserve_kernel_base(kernel_base - 5 * PAGE_SIZE, reserve_addr, + reserve_size); if (status != EFI_SUCCESS) { pr_efi_err("Unable to allocate memory for uncompressed kernel.\n"); return status; } - /* - * Relocate the zImage, so that it appears in the lowest 128 MB - * memory window. - */ - *image_addr = (unsigned long)image->image_base; - *image_size = image->image_size; - status = efi_relocate_kernel(image_addr, *image_size, *image_size, - kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0, 0); - if (status != EFI_SUCCESS) { - pr_efi_err("Failed to relocate kernel.\n"); - efi_free(*reserve_size, *reserve_addr); - *reserve_size = 0; - return status; - } - - /* - * Check to see if we were able to allocate memory low enough - * in memory. The kernel determines the base of DRAM from the - * address at which the zImage is loaded. - */ - if (*image_addr + *image_size > dram_base + ZIMAGE_OFFSET_LIMIT) { - pr_efi_err("Failed to relocate kernel, no low memory available.\n"); - efi_free(*reserve_size, *reserve_addr); - *reserve_size = 0; - efi_free(*image_size, *image_addr); - *image_size = 0; - return EFI_LOAD_ERROR; - } + *image_addr = kernel_base; + *image_size = 0; return EFI_SUCCESS; }