From patchwork Mon Apr 11 09:48:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12808889 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 65E8EC433F5 for ; Mon, 11 Apr 2022 10:02:45 +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=mrP9CXWRDT87dnZPEVUPgL82VjqUeK0UYxf4gZEvfnA=; b=urm5XYLcprnVTq +8skirid061womCqL/CFXoa1JYwR/fd/g00j9KVMwtXjqZHARSWn20I6ZPx75tMt8pggA4a4ckpXF +j+Nn/Lt3ZHOo7eDqsQfcVYzrIRSBA/L9sYT8qKEM+LdvrIP5Crt2LYKbHlTO4a+jd5SorFhVKhUv zz9RFBEeU1u/2ihV/TqrTumq1UKAQOBcyGg0tCnMc8PP1d8us9oxbZbu2+SEDCsyIAcXPpYicYC6w lnWVLtWux/y/xHnKQr+woqTTL6saJIwUb/xPG06re3tVL3NZdcJvlurZET+2pai+gNEEjHT+GiqGn TIBIdbwBOwIv6iAg+ntw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndqrH-0088Im-Js; Mon, 11 Apr 2022 10:01:20 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndqfa-0082Nk-GS for linux-arm-kernel@lists.infradead.org; Mon, 11 Apr 2022 09:49:16 +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 1426A6115F; Mon, 11 Apr 2022 09:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E61F4C385A6; Mon, 11 Apr 2022 09:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649670553; bh=9AVu6mHMPoK5oK6gxu8iTn6r/yGLVCYbNn1BWuZoPiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ciI3qJjxsec5kGKKsw1xjchaR3pY2jznjRb0fUmRRRVJLvHEViho+WNqu7pb+lCaA 3J/pJAZW9lwBMVQ4xC986ITcDWc4R4owMezkl95lgSv2Ps5DL5xmGgyAIByGKznpBr K+sOw3AyEKOPSkdczlUAVGcTb1mLUuRwwboRHtKYzpn1XkVp3ahv4jnJ+mq+tCUPdb WJYzWAZdeOrm8VaLEnd/zlizdLFVz7M7IW4oBouP9kdfBOuaFQV00DPOSKv1pCAHlc E1RzM425RmqknXPw6/dxu5nnZy1NfNdrym0+4oPu5hYTLt3+4zrKJhR2jHnpFbt28G OXjSOlNFwcQpw== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown Subject: [PATCH v3 13/30] arm64: head: use relative references to the RELA and RELR tables Date: Mon, 11 Apr 2022 11:48:07 +0200 Message-Id: <20220411094824.4176877-14-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220411094824.4176877-1-ardb@kernel.org> References: <20220411094824.4176877-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2627; h=from:subject; bh=9AVu6mHMPoK5oK6gxu8iTn6r/yGLVCYbNn1BWuZoPiE=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBiU/lKS9UO+vDmp3VZscy4lffXl6hh9vn47/4m4jxm q5vW/eCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYlP5SgAKCRDDTyI5ktmPJIVnDA CimfPlPaFYAo0iN/LnxYQG3BmsRvLvSt+6H64/MD/ykF0PW0CNiJLyg21qrZrsR/pDUS4syQDslo9+ 2AirEU10zMRc3A2SokvJB1tmiC6Zk0qK5IWTndiNHZ4J3WwMEzOmv6iexGjbYqkoO/Lg7pwU1VuUrZ 4oNrCWHNzXuAbeEh6UAGCZpctR4TRTEEH7YDsWoCiHzlREa9JQALq7oBFMnEeyDwyW01PPzKBsp2xj ymn0357ZnrArJNJ1tHgklE6CLlqxD7xfNezf/dK3TRiaZptv04i3y+3Id0Sm43PklmsuoQd4nUYRbZ qxmRWewzl+tI3RGekm3JXiBFA1IlGVk3bGzGDDmkiTYz3eNdPeAph4edjM/5kRjIm+RkOt4JMpveWZ dXBB+xtVz4/l74osHnxBfPE70Tfi0q9jRHxlEAYEvY8OkYIXF5TJ3dUn4zv3SbB9tO0AeiydDSQYg9 i0TUtic+ZMIM3fUKJgVi9HBXyyiY6NFpusIHoNI5dKCgs= 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-20220411_024914_720854_1BE1CB70 X-CRM114-Status: GOOD ( 15.69 ) 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 Formerly, we had to access the RELA and RELR tables via the kernel mapping that was being relocated, and so deriving the start and end addresses using ADRP/ADD references was not possible, as the relocation code runs from the ID map. Now that we map the entire kernel image via the ID map, we can simplify this, and just load the entries via the ID map as well. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 13 ++++--------- arch/arm64/kernel/vmlinux.lds.S | 12 ++++-------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 4ef12bcdfe6a..2c491cac4871 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -755,13 +755,10 @@ SYM_FUNC_START_LOCAL(__relocate_kernel) * Iterate over each entry in the relocation table, and apply the * relocations in place. */ - ldr w9, =__rela_offset // offset to reloc table - ldr w10, =__rela_size // size of reloc table - + adr_l x9, __rela_start + adr_l x10, __rela_end mov_q x11, KIMAGE_VADDR // default virtual offset add x11, x11, x23 // actual virtual offset - add x9, x9, x11 // __va(.rela) - add x10, x9, x10 // __va(.rela) + sizeof(.rela) 0: cmp x9, x10 b.hs 1f @@ -811,10 +808,8 @@ SYM_FUNC_START_LOCAL(__relocate_kernel) * __relocate_kernel is called twice with non-zero displacements (i.e. * if there is both a physical misalignment and a KASLR displacement). */ - ldr w9, =__relr_offset // offset to reloc table - ldr w10, =__relr_size // size of reloc table - add x9, x9, x11 // __va(.relr) - add x10, x9, x10 // __va(.relr) + sizeof(.relr) + adr_l x9, __relr_start + adr_l x10, __relr_end sub x15, x23, x24 // delta from previous offset cbz x15, 7f // nothing to do if unchanged diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 7030b5a57d23..21ca72e7ad22 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -253,21 +253,17 @@ SECTIONS HYPERVISOR_RELOC_SECTION .rela.dyn : ALIGN(8) { + __rela_start = .; *(.rela .rela*) + __rela_end = .; } - __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); - __rela_size = SIZEOF(.rela.dyn); - -#ifdef CONFIG_RELR .relr.dyn : ALIGN(8) { + __relr_start = .; *(.relr.dyn) + __relr_end = .; } - __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); - __relr_size = SIZEOF(.relr.dyn); -#endif - . = ALIGN(SEGMENT_ALIGN); __initdata_end = .; __init_end = .;