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 3AEA5C04AA5 for ; Thu, 25 Aug 2022 13:20:53 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=euIUmWyAMhbLR09vdTv+WcyyuE2aOSU+wpmz15CEOVY=; b=iNj+Tp+kTYWS94 haLuUeMcohY/EmXH8kuqpgqjTL5dDjVifESMFcFo9RjLWlo3T0lO912nZmdaOQpI1xxhLhJQiHyWG obYLKbNgXpfcFEUgsJmjzyjbUjEWh+xRRTjhxzDEDjBVSoJscatTk50+ZvA9GAVgcUmEc0TZ/AUYP 3hQBOWjuTP+eWoYI9WVbq2PP170SDBGhPOKD0V/nHPZOPz+uC4f98SmP5hkQIEkS0szp3gOVr3bx2 Lioh8Nf19wfMauam7oscDhvai4TEe65knEc50LoI9fzs4OodFhSYQDiNGKzpSfPFxWCONZsQixb8f A5PdbiBD/2Zxlc5L0v3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRCly-00EiUg-Lj; Thu, 25 Aug 2022 13:19:50 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRClu-00Ei4S-4H for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 13:19:48 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D6F6BD6E; Thu, 25 Aug 2022 06:19:43 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.47.11]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0EB653F71A; Thu, 25 Aug 2022 06:19:37 -0700 (PDT) Date: Thu, 25 Aug 2022 14:19:32 +0100 From: Mark Rutland To: Joey Gouly Cc: linux-arm-kernel@lists.infradead.org, nd@arm.com, andre.przywara@arm.com, catalin.marinas@arm.com, vincenzo.frascino@arm.com, will@kernel.org Subject: Re: [PATCH v1 2/3] arm64: alternative: patch alternatives in the vDSO Message-ID: References: <20220825102025.53916-1-joey.gouly@arm.com> <20220825102025.53916-3-joey.gouly@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220825102025.53916-3-joey.gouly@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220825_061946_282922_67AA90A1 X-CRM114-Status: GOOD ( 24.84 ) 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 Thu, Aug 25, 2022 at 11:20:24AM +0100, Joey Gouly wrote: > Make it possible to use alternatives in the vDSO, so that better > implementations can be used if possible. > > Signed-off-by: Joey Gouly > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Vincenzo Frascino > Cc: Mark Rutland > --- > arch/arm64/include/asm/vdso.h | 3 +++ > arch/arm64/kernel/alternative.c | 25 +++++++++++++++++++++++++ > arch/arm64/kernel/vdso.c | 3 --- > arch/arm64/kernel/vdso/vdso.lds.S | 7 +++++++ > 4 files changed, 35 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/vdso.h b/arch/arm64/include/asm/vdso.h > index f99dcb94b438..b4ae32109932 100644 > --- a/arch/arm64/include/asm/vdso.h > +++ b/arch/arm64/include/asm/vdso.h > @@ -26,6 +26,9 @@ > (void *)(vdso_offset_##name - VDSO_LBASE + (unsigned long)(base)); \ > }) > > +extern char vdso_start[], vdso_end[]; > +extern char vdso32_start[], vdso32_end[]; > + > #endif /* !__ASSEMBLY__ */ > > #endif /* __ASM_VDSO_H */ > diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c > index 9bcaa5eacf16..a4036194a5cd 100644 > --- a/arch/arm64/kernel/alternative.c > +++ b/arch/arm64/kernel/alternative.c > @@ -10,11 +10,14 @@ > > #include > #include > +#include > #include > #include > #include > #include > +#include > #include > +#include > #include > > #define __ALT_PTR(a, f) ((void *)&(a)->f + (a)->f) > @@ -192,6 +195,27 @@ static void __nocfi __apply_alternatives(struct alt_region *region, bool is_modu > } > } > > +void apply_alternatives_vdso(unsigned long *feature_mask) > +{ > + struct alt_region region; > + const struct elf64_hdr *hdr; > + const struct elf64_shdr *shdr; > + const struct elf64_shdr *alt; > + > + hdr = (struct elf64_hdr *)vdso_start; > + shdr = (void *)hdr + hdr->e_shoff; > + alt = find_section(hdr, shdr, ".altinstructions"); > + if (!alt) > + return; > + > + region = (struct alt_region){ > + .begin = (void *)hdr + alt->sh_offset, > + .end = (void *)hdr + alt->sh_offset + alt->sh_size, > + }; > + > + __apply_alternatives(®ion, false, feature_mask); > +} > + > /* > * We might be patching the stop_machine state machine, so implement a > * really simple polling protocol here. > @@ -216,6 +240,7 @@ static int __apply_alternatives_multi_stop(void *unused) > > BUG_ON(all_alternatives_applied); > __apply_alternatives(®ion, false, remaining_capabilities); > + apply_alternatives_vdso(remaining_capabilities); Since we didn't patch the vdso in apply_boot_alternatives(), using `remaining_capabilities` means that we could in theory miss alternatives for features which were detected on the boot CPU. Since the VDSO cannot be concurrently executed within the kernel, we could hoist the call to apply_alternatives_vdso() out of __apply_alternatives_multi_stop(), and call it before the stop_machine in apply_alternatives_all(). That would keep __apply_alternatives_multi_stop() simple (and easier to make noinstr-safe), and we could use the same mask logic as apply_alternatives_module(), e.g. void apply_alternatives_vdso(void) { DECLARE_BITMAP(all_capabilities, ARM64_NPATCHABLE); bitmap_fill(all_capabilities, ARM64_NPATCHABLE); struct alt_region region; const struct elf64_hdr *hdr; const struct elf64_shdr *shdr; const struct elf64_shdr *alt; hdr = (struct elf64_hdr *)vdso_start; shdr = (void *)hdr + hdr->e_shoff; alt = find_section(hdr, shdr, ".altinstructions"); if (!alt) return; region = (struct alt_region){ .begin = (void *)hdr + alt->sh_offset, .end = (void *)hdr + alt->sh_offset + alt->sh_size, }; __apply_alternatives(®ion, false, &all_capabilities[0]); } ... does that sound ok to you? Thanks, Mark. > /* Barriers provided by the cache flushing */ > all_alternatives_applied = 1; > } > diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c > index a61fc4f989b3..ac93a2ee9c07 100644 > --- a/arch/arm64/kernel/vdso.c > +++ b/arch/arm64/kernel/vdso.c > @@ -29,9 +29,6 @@ > #include > #include > > -extern char vdso_start[], vdso_end[]; > -extern char vdso32_start[], vdso32_end[]; > - > enum vdso_abi { > VDSO_ABI_AA64, > VDSO_ABI_AA32, > diff --git a/arch/arm64/kernel/vdso/vdso.lds.S b/arch/arm64/kernel/vdso/vdso.lds.S > index e69fb4aaaf3e..6028f1fe2d1c 100644 > --- a/arch/arm64/kernel/vdso/vdso.lds.S > +++ b/arch/arm64/kernel/vdso/vdso.lds.S > @@ -48,6 +48,13 @@ SECTIONS > PROVIDE (_etext = .); > PROVIDE (etext = .); > > + . = ALIGN(4); > + .altinstructions : { > + __alt_instructions = .; > + *(.altinstructions) > + __alt_instructions_end = .; > + } > + > .dynamic : { *(.dynamic) } :text :dynamic > > .rela.dyn : ALIGN(8) { *(.rela .rela*) } > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel