From patchwork Fri Jun 24 15:06:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12894753 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 83CF6CCA473 for ; Fri, 24 Jun 2022 15:12:58 +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=AM/JYxlOWQa5+NgdC0nhizEZDDwE+ymarypW3OxJ9ag=; b=tShA8W1lt+Jb3j jD76N5ScwMeB4oKR1dVhe5xPmynTyN2bkfEKOihHOi1azZfFU3U7V9sNbbbSauGqmjA3QAdLcwC8A xKHk7L7KmZbEKZrbiaRPMoyOtClJQbRJmmiaunR1ofd3OAd5bIvECYGxCN1QBkxfg55B25MNNShof 653VYUyFX7HI8fRFVrETjZ8eTCpUger4etO4+uhnfRbRvwAjWgh7W/p6UVROCOZjaHCnbY7swZo3S bCGoe8znZdm+qNBnHWXIBSuRdTAaIOwszKUVyFI0mjWS0aM2QFDeTR9IaDY/9P1IILF8iIsWvk9rv L7SCek2dFn2AkSEV99lg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4kyR-002ka1-Ch; Fri, 24 Jun 2022 15:11:55 +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 1o4kuK-002iSo-MC for linux-arm-kernel@lists.infradead.org; Fri, 24 Jun 2022 15:07:42 +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 2365F621DA; Fri, 24 Jun 2022 15:07:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5F96C341C0; Fri, 24 Jun 2022 15:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656083259; bh=fkPCxLjkxw99Z25WhFdlQ1f46LkWg6cY8n9VggShdSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fXgCvolcAuirzZ/Lv/JRRtMxpAOT2HJk8+hmtSi19KTl8u8jlWUpJMVFl1GfcNDBA F86hMfR5r28n3ArH4Cf9LvzFetP76slH0EKLmNSjNahTwYMDlUb/TS/T/RCH2GjAPZ zxw+a3IJQuTvMxlkpozh5glxC059/Z+T8c08wgP9vJKCZ22h9n9Z7CbRGh/gELa47/ uxQMSgpUWFimermh0NTTFDVvyrxIIokhN1mv3ZBsbFHjRKYFq0PDmafsCk1IcWrSE/ q80gRk0BI89Olf/+OZi0j1nLZhAA/RS7d/cU3rTI21JbZbTZAfYKg2kFUOj9zBC687 zsTYxOOAkpnSQ== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual Subject: [PATCH v5 13/21] arm64: head: use relative references to the RELA and RELR tables Date: Fri, 24 Jun 2022 17:06:43 +0200 Message-Id: <20220624150651.1358849-14-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220624150651.1358849-1-ardb@kernel.org> References: <20220624150651.1358849-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2627; h=from:subject; bh=fkPCxLjkxw99Z25WhFdlQ1f46LkWg6cY8n9VggShdSU=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBitdL8M8XXo9wgguFZkrO8v1yr729BvJ/6sQvNs9yr HAmdJBqJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYrXS/AAKCRDDTyI5ktmPJFzlDA CGcAdcYfDYyeoZtRWsDecz7kY5OSHqKeX0e/1q7xiojEN0RdDhVBNzMcu9GescY7akbVpZ45wrNS6i rwtvipcoejw34c17+XUJ7ITnRDiW5O31wXSBwC6J+Y1LABqnyEbtVjJ8z0q6irWRsXlszvBCUXk+BQ OO7okeNWfWaKGHRI6BZMLVQjjWRMA2c9HMMs4uASMrolmG24T01oS2TR3KWDHce2s7/Ceml7oBBjIg pfHevfihywdX/b2bCWK2FVKzFN3fC0y80U8RLetJ8iQUF+coI4IUzMPMmfNqrxVRGnks/1vWne36TA sMH+DdKLOVn6tf1jSl2+/oDSeDuiOaqQ5X54ZSdTbfmXBKppC1y70yd+yp1xfOHgz6tQ8yOAGC2eYf gvTZHxpOI6nw54NauzxFvoQXZTIQVf+YlMgZPcOnepG8mNYi/Q+tgWBVuqhPPYbap6CU8SweQWlpd8 j61TPop0rccdgkbX/3rB84R4VCN5hUYp+fuveYrYQeXic= 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-20220624_080740_850265_95BE261F X-CRM114-Status: GOOD ( 15.35 ) 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 93734c91a29a..f1497f7b4da0 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -757,13 +757,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 @@ -813,10 +810,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 0ce3a7c9f8c4..45131e354e27 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -257,21 +257,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 = .;