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 45157C433EF for ; Wed, 22 Jun 2022 15:28:57 +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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MmENE+rtLA8oGfSGqPDJFWa10BZeawPOtGwVs/VoU6k=; b=xXD9NpTMACKkkG ijtpFpF2gHMRDMphEC8Jl0UpAYZbO+26wY8wWVDJTEwNXvi0J/UIWg5IkRXCG0jYeQHW8V265biYP rrWNJMwYtBeKdQbw0HXgo26xkbb1/z/lupewO85pPSDFaIlKiEFAqcffju/zvNB7RVJFjx91wUdSk td4WsoEJgcYlkkYP97N2UG6oKi3werdL7TqvklYu5DxVXvt6U8OakLJOptU5qZqCZDUZ6SayrXbNr Wm0tkh8rdBJBzBC54loqX4sThhq7RSmAatamRlwZaY2fm1slFxrf3Q11dimaZ9YMkWNvfx9mmKjxx /UXDyb2NpiYvW8Zlrgpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o42Gr-00BBgS-0S; Wed, 22 Jun 2022 15:27:57 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o42Gm-00BBeN-LM for linux-arm-kernel@lists.infradead.org; Wed, 22 Jun 2022 15:27:54 +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 C709BB81F98 for ; Wed, 22 Jun 2022 15:27:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80A6CC34114 for ; Wed, 22 Jun 2022 15:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655911667; bh=8WWnzSXr7yc70VyqhcEd1Zvu1vipglbAyAiy133LHCc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=j5rSOgZCjBwUkZ9TJ5wmBrbyook8PCjQcTPIFbH/7OL+1+pU4GQkuWvmSKHPCLG7A eZMgbTZcha9B+jEOHyl4lHZKXl99GQVmhwvYApTEyG3sV15JoTE5SLBj1lJyMwPGxC DM9GgR1rzGLzLhbEBhVSQrZC0RiXjR+gE/KTJho2kv6PJWntOYrxi3sqffTSknJZOK xyPiO39gT4jkV4d/nSJBA4PSx/qVIQZAAmeaTTJyEfQpeQGIfPWrUM7fZfuHuhmgEr NLlni0p/hc+SJyrMhOLO+ZmX4J+58ftQWPhaydUPEJj73yAQOgNUlf8PisIdBAeikf 8T1H7xSUZBrJA== Received: by mail-oi1-f174.google.com with SMTP id h65so21152769oia.11 for ; Wed, 22 Jun 2022 08:27:47 -0700 (PDT) X-Gm-Message-State: AJIora91CykKGAgghHKP4glck+IqDpC4G4sl6SncHPTxwi0vcl414l5Q RioBzXluj+eQkheq4mfZNy/ZRxhCsLdZxbJYiH4= X-Google-Smtp-Source: AGRyM1tCjKpHUPkmeY3xtZPtUEYAjAyPDnysoonS/dDVd7xZNExJcizsfsR4Z1ceWoGPQbLWhBvwS0aX5xqXgbNfrKs= X-Received: by 2002:a05:6808:300e:b0:32c:425e:df34 with SMTP id ay14-20020a056808300e00b0032c425edf34mr2247328oib.126.1655911666567; Wed, 22 Jun 2022 08:27:46 -0700 (PDT) MIME-Version: 1.0 References: <20220427102255.1336386-1-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Wed, 22 Jun 2022 17:27:35 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] arm64: entry: simplify trampoline data page To: Mark Rutland Cc: Linux ARM , Will Deacon , Catalin Marinas , James Morse X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220622_082753_033572_B1E72906 X-CRM114-Status: GOOD ( 42.60 ) 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 Wed, 22 Jun 2022 at 17:05, Mark Rutland wrote: > > On Wed, Jun 22, 2022 at 04:41:41PM +0200, Ard Biesheuvel wrote: > > On Wed, 27 Apr 2022 at 12:23, Ard Biesheuvel wrote: > > > > > > Get rid of some clunky open coded arithmetic on section addresses, by > > > emitting the trampoline data variables into a separate, dedicated r/o > > > data section, and putting it at the next page boundary. This way, we can > > > access the literals via single LDR instruction. > > > > > > While at it, get rid of other, implicit literals, and use ADRP/ADD or > > > MOVZ/MOVK sequences, as appropriate. Note that the latter are only > > > supported for CONFIG_RELOCATABLE=n (which is usually the case if > > > CONFIG_RANDOMIZE_BASE=n), so update the CPP conditionals to reflect > > > this. > > > > > > Cc: James Morse > > > Signed-off-by: Ard Biesheuvel > > > > Ping, in case this one slipped behind the desk. > > Sorry for the delay. THis has been on my queue of things to look at with a > bunch of other stuff, and I've had some difficulty prioritizing all that. > Yeah, no worries. > > > > > --- > > > arch/arm64/include/asm/fixmap.h | 4 +- > > > arch/arm64/kernel/entry.S | 45 ++++++-------------- > > > arch/arm64/kernel/vmlinux.lds.S | 3 +- > > > arch/arm64/mm/mmu.c | 10 ++--- > > > 4 files changed, 22 insertions(+), 40 deletions(-) > > > > > > diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h > > > index daff882883f9..71ed5fdf718b 100644 > > > --- a/arch/arm64/include/asm/fixmap.h > > > +++ b/arch/arm64/include/asm/fixmap.h > > > @@ -62,10 +62,12 @@ enum fixed_addresses { > > > #endif /* CONFIG_ACPI_APEI_GHES */ > > > > > > #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 > > > +#ifdef CONFIG_RELOCATABLE > > > + FIX_ENTRY_TRAMP_TEXT4, /* one extra slot for the data page */ > > > +#endif > > > FIX_ENTRY_TRAMP_TEXT3, > > > FIX_ENTRY_TRAMP_TEXT2, > > > FIX_ENTRY_TRAMP_TEXT1, > > > - FIX_ENTRY_TRAMP_DATA, > > > #define TRAMP_VALIAS (__fix_to_virt(FIX_ENTRY_TRAMP_TEXT1)) > > > #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ > > > __end_of_permanent_fixed_addresses, > > > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S > > > index ede028dee81b..aed2b41e05aa 100644 > > > --- a/arch/arm64/kernel/entry.S > > > +++ b/arch/arm64/kernel/entry.S > > > @@ -636,18 +636,20 @@ alternative_else_nop_endif > > > */ > > > .endm > > > > > > - .macro tramp_data_page dst > > > - adr_l \dst, .entry.tramp.text > > > - sub \dst, \dst, PAGE_SIZE > > > - .endm > > > - > > > - .macro tramp_data_read_var dst, var > > > -#ifdef CONFIG_RANDOMIZE_BASE > > > - tramp_data_page \dst > > > - add \dst, \dst, #:lo12:__entry_tramp_data_\var > > > - ldr \dst, [\dst] > > > + .macro tramp_data_read_var dst, var > > > +#ifdef CONFIG_RELOCATABLE > > > + ldr \dst, .L__tramp_data_\var > > > + .ifndef .L__tramp_data_\var > > > + .pushsection ".entry.tramp.rodata", "a", %progbits > > > + .align 3 > > > +.L__tramp_data_\var: > > > + .quad \var > > > + .popsection > > > + .endif > > > #else > > > - ldr \dst, =\var > > > + movz \dst, :abs_g2_s:\var > > > + movk \dst, :abs_g1_nc:\var > > > + movk \dst, :abs_g0_nc:\var > > > #endif > > > .endm > > Given the lack of a g3 reloc, I assumme `var` is always an address, and we're > assuming it's always in the upper 48-bits? I think it'd be worth a comment as > to why this is safe, or just use a g3 reloc since then it's always good per > inspection. > Upper 47 bits, yes. This is because since the 52-bit VA address space overhaul, the kernel, fixmap and anything else we may want to address statically here will always be in the upper 47-bit addressable part of the address space. The abs_g2_s relocation sign extends that into the bits above. I opted for as few instructions as required, as these sequences are emitted into the vector table. > I'm a bit confused that we've put the var into the literal; I thought the idea > here was that it was secret and needed to be placed in a page not mapped during > userspace. Is the assumption there that it's pointless for !RELOCATABLE kernels > since it can be known anyway, have I misunderstood, or something else? > Basically, yes. !RELOCATABLE implies !RANDOMIZE_BASE, and so the kernel will be running from a known address anyway. So if you are using KPTI without KASLR, there is no need to use a literal load here. > Otherwise this all looks good superficially; I just haven't had the time to > page it all in. > > Mark. > > > > > > > @@ -695,7 +697,7 @@ alternative_else_nop_endif > > > msr vbar_el1, x30 > > > isb > > > .else > > > - ldr x30, =vectors > > > + adr_l x30, vectors > > > .endif // \kpti == 1 > > > > > > .if \bhb == BHB_MITIGATION_FW > > > @@ -764,24 +766,7 @@ SYM_CODE_END(tramp_exit_native) > > > SYM_CODE_START(tramp_exit_compat) > > > tramp_exit 32 > > > SYM_CODE_END(tramp_exit_compat) > > > - > > > - .ltorg > > > .popsection // .entry.tramp.text > > > -#ifdef CONFIG_RANDOMIZE_BASE > > > - .pushsection ".rodata", "a" > > > - .align PAGE_SHIFT > > > -SYM_DATA_START(__entry_tramp_data_start) > > > -__entry_tramp_data_vectors: > > > - .quad vectors > > > -#ifdef CONFIG_ARM_SDE_INTERFACE > > > -__entry_tramp_data___sdei_asm_handler: > > > - .quad __sdei_asm_handler > > > -#endif /* CONFIG_ARM_SDE_INTERFACE */ > > > -__entry_tramp_data_this_cpu_vector: > > > - .quad this_cpu_vector > > > -SYM_DATA_END(__entry_tramp_data_start) > > > - .popsection // .rodata > > > -#endif /* CONFIG_RANDOMIZE_BASE */ > > > #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ > > > > > > /* > > > @@ -932,7 +917,6 @@ NOKPROBE(call_on_irq_stack) > > > * This clobbers x4, __sdei_handler() will restore this from firmware's > > > * copy. > > > */ > > > -.ltorg > > > .pushsection ".entry.tramp.text", "ax" > > > SYM_CODE_START(__sdei_asm_entry_trampoline) > > > mrs x4, ttbr1_el1 > > > @@ -967,7 +951,6 @@ SYM_CODE_START(__sdei_asm_exit_trampoline) > > > 1: sdei_handler_exit exit_mode=x2 > > > SYM_CODE_END(__sdei_asm_exit_trampoline) > > > NOKPROBE(__sdei_asm_exit_trampoline) > > > - .ltorg > > > .popsection // .entry.tramp.text > > > #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ > > > > > > diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S > > > index edaf0faf766f..17e554be9198 100644 > > > --- a/arch/arm64/kernel/vmlinux.lds.S > > > +++ b/arch/arm64/kernel/vmlinux.lds.S > > > @@ -117,7 +117,8 @@ jiffies = jiffies_64; > > > __entry_tramp_text_start = .; \ > > > *(.entry.tramp.text) \ > > > . = ALIGN(PAGE_SIZE); \ > > > - __entry_tramp_text_end = .; > > > + __entry_tramp_text_end = .; \ > > > + *(.entry.tramp.rodata) > > > #else > > > #define TRAMP_TEXT > > > #endif > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > > index 626ec32873c6..be4d6c3f5692 100644 > > > --- a/arch/arm64/mm/mmu.c > > > +++ b/arch/arm64/mm/mmu.c > > > @@ -665,13 +665,9 @@ static int __init map_entry_trampoline(void) > > > __set_fixmap(FIX_ENTRY_TRAMP_TEXT1 - i, > > > pa_start + i * PAGE_SIZE, prot); > > > > > > - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { > > > - extern char __entry_tramp_data_start[]; > > > - > > > - __set_fixmap(FIX_ENTRY_TRAMP_DATA, > > > - __pa_symbol(__entry_tramp_data_start), > > > - PAGE_KERNEL_RO); > > > - } > > > + if (IS_ENABLED(CONFIG_RELOCATABLE)) > > > + __set_fixmap(FIX_ENTRY_TRAMP_TEXT1 - i, > > > + pa_start + i * PAGE_SIZE, PAGE_KERNEL_RO); > > > > > > return 0; > > > } > > > -- > > > 2.30.2 > > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel