From mboxrd@z Thu Jan 1 00:00:00 1970 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 08B7CC4167B for ; Mon, 27 Nov 2023 12:54:21 +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: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Pcqk/m/47WNg/+GJ+5+AFpOKEPv9cilJmxIKR9g5Ars=; b=n6HGppeU27j2Z4 Z69Jb8idtRulmt1SqH12cNviZeoS8DK4Ko6CB1zqsJK9WAP4mnBfeNLgWB5wdrgAfgzdt8NAbWH/E nxPKrbCaZP8rklncC+YFyVErMUm3dwgKw71vyhGPxHxoGcwuG8orpx6XjVUF957DCE6b1AoFS+tBs bTUpcmI99JegtoD6I561UihF8agedJQrkw1Q1Gx+gOjXBq0gzYw55YJOQXzkOfzrtp+qZZTMkDx40 l87fVkQqMpKXM3CkBjPqelOON0ADKT4xU5miInw/edf3iG734Fww2KCPsdzKjfaKCRHobqq6Z0rlJ L5AhtvwPQ0B5KWHHNyNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7b7Y-002Udy-2v; Mon, 27 Nov 2023 12:53:52 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7b7V-002UdL-24 for linux-arm-kernel@lists.infradead.org; Mon, 27 Nov 2023 12:53:51 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EC2B561180; Mon, 27 Nov 2023 12:53:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88199C433C8; Mon, 27 Nov 2023 12:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701089628; bh=8wDYVbGQ4uQY62BAql1gWi8M8ifhDbG8g7GkY8y442o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=itRwyZ8hY+8D21MU6AU3x9v64I31J45acEyIjc515SvhyPLWpnyGdpxdHjZ2jKe1+ aX8siDzzmNn5qn4A1xd40cANub7RCg+ugVRiahDZzAk4fCBZk+0brvdECoRgoRhkSC P4Detk/1zfTZ3zqr8IkIJd3X9rK1TI/ZlkMnSkP8NynYvnk4iIX9rkQZCmoWlAeHdH bEY4XgTn7K4kwOUP9YzJq6vE9TCSBKAmVyMxwQ2LEU0zXfsF64M0bYfvAUmjH79hH7 HbAH20bXB7hBv2hEppZBlQ0603+B8JbynjnyQz59y00SX/YOFE1+eW1pxb59OREe7Z lt68ACMXCtJtg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r7b7S-00Gmkv-KJ; Mon, 27 Nov 2023 12:53:46 +0000 Date: Mon, 27 Nov 2023 12:53:46 +0000 Message-ID: <86edgbcq79.wl-maz@kernel.org> From: Marc Zyngier To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: Re: [PATCH v5 15/39] arm64: idreg-override: Prepare for place relative reloc patching In-Reply-To: <20231124101840.944737-56-ardb@google.com> References: <20231124101840.944737-41-ardb@google.com> <20231124101840.944737-56-ardb@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: ardb@google.com, linux-arm-kernel@lists.infradead.org, ardb@kernel.org, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ryan.roberts@arm.com, anshuman.khandual@arm.com, keescook@chromium.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231127_045349_759883_ECDF20C3 X-CRM114-Status: GOOD ( 32.37 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 24 Nov 2023 10:18:55 +0000, Ard Biesheuvel wrote: > > From: Ard Biesheuvel > > The ID reg override handling code uses a rather elaborate data structure > that relies on statically initialized absolute address values in pointer > fields. This means that this code cannot run until relocation fixups > have been applied, and this is unfortunate, because it means we cannot > discover overrides for KASLR or LVA/LPA without creating the kernel > mapping and performing the relocations first. > > This can be solved by switching to place-relative relocations, which can > be applied by the linker at build time. This means some additional > arithmetic is required when dereferencing these pointers, as we can no > longer dereference the pointer members directly. > > So let's implement this for idreg-override.c in a preliminary way, i.e., > convert all the references in code to use a special accessor that > produces the correct absolute value at runtime. > > To preserve the strong type checking for the static initializers, use > union types for representing the hybrid quantities. > > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/kernel/idreg-override.c | 98 +++++++++++++------- > 1 file changed, 65 insertions(+), 33 deletions(-) > > diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c > index 536bc33859bc..4e32a44560bf 100644 > --- a/arch/arm64/kernel/idreg-override.c > +++ b/arch/arm64/kernel/idreg-override.c > @@ -21,14 +21,32 @@ > > static u64 __boot_status __initdata; > > +// temporary __prel64 related definitions > +// to be removed when this code is moved under pi/ > + > +#define __prel64_initconst __initconst > + > +typedef void *prel64_t; > + > +static void *prel64_to_pointer(const prel64_t *p) > +{ > + return *p; > +} > + Having played with this series a bit to see how the E2H0 override support would fit in, I found that this cast to a void* could hide stupid bugs that should normally be caught at compile time. Having hacked on it a bit, I came up with this (partial patch on top of the full series): diff --git a/arch/arm64/kernel/pi/idreg-override.c b/arch/arm64/kernel/pi/idreg-override.c index 84647ebb87ee..d60322477e44 100644 --- a/arch/arm64/kernel/pi/idreg-override.c +++ b/arch/arm64/kernel/pi/idreg-override.c @@ -246,12 +246,12 @@ static void __init match_options(const char *cmdline) int i; for (i = 0; i < ARRAY_SIZE(regs); i++) { - const struct ftr_set_desc *reg = prel64_to_pointer(®s[i].reg_prel); + const struct ftr_set_desc *reg = prel64_pointer(regs[i].reg); struct arm64_ftr_override *override; int len = strlen(reg->name); int f; - override = prel64_to_pointer(®->override_prel); + override = prel64_pointer(reg->override); // set opt[] to '.' memcpy(opt, reg->name, len); diff --git a/arch/arm64/kernel/pi/pi.h b/arch/arm64/kernel/pi/pi.h index 04a1f576baee..9d922322999b 100644 --- a/arch/arm64/kernel/pi/pi.h +++ b/arch/arm64/kernel/pi/pi.h @@ -15,6 +15,8 @@ static inline void *prel64_to_pointer(const prel64_t *offset) return (void *)offset + *offset; } +#define prel64_pointer(__d) (typeof(__d))prel64_to_pointer(&__d##_prel) + extern bool dynamic_scs_is_enabled; extern pgd_t init_idmap_pg_dir[]; which preserves the type-checking, at the expense of the implicit *_prel field access. Not sure if that's something you have considered, but I thought I'd raise it here. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel