Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9756004rwl; Wed, 11 Jan 2023 09:31:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXudEO+eC/f2eyNBnDQMXBy3ueDlUZhaDKsKOeH5MD7N5S+N15HO90rd6dr0NFX0drQMTDoM X-Received: by 2002:a17:906:4cd2:b0:7c0:e5c6:2a74 with SMTP id q18-20020a1709064cd200b007c0e5c62a74mr58490645ejt.34.1673458271007; Wed, 11 Jan 2023 09:31:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673458270; cv=none; d=google.com; s=arc-20160816; b=SFOSmtDM3YJaFGrrN8v5KSZ4vVdRDKUZalI9aIZGZwezhNukTH7gkZGgWF7gCUXe0Q DlG5RguefG1FyinmzWEMDGzrGvr7WzlYawMh32FhRCZ/JekyH1cNM7i5NuqPewv8p88m 76MvrcMnrCHRtxE4mfN5KiYSwYRxUCKRZ4yLifLLDgpBRL2U+fy+wJvGcf1ikklNp9pd Icn0h7SgSptJ5ZdkbCRTt/zu8kqwA5IBj33p7MfpWBn4BFJNBOrdST6MbuJkM7ZebAG0 RNU8Hl6zLsVfbf9J4OiornYjA9N1RIaIBM7a+RVFMs0kLCcnGZSepudhJBTzf+LgsYMU gGuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PM5/lbGagSaTFa1SErGsZkyNa1MUdgZOCEoZvU3cS1Q=; b=iehtd1fj9i8T58aYBHugWz1NwclTH2QJ4hlIriJ34UUrFI3hlcOfPjFltr0GdDWF1N I6mLyAkM79GJuKYKa2elUI8Cbg7d7VWFl5S8p32L2CSgMezzGuOXRydf9DmE3d5Qs0qy uOM0BbZtRwLZzF86QnqszJzulVX4NMf/voOvdxSBgNi3gjgaF5G+IeTHwPzCHhyJjcj3 mMKVezrOUMtDX//eRkyOLGQJJXHatU6ogQ3ttUBSxf55gbVlY/8DAuzkRNv1wls0Fuv6 9gFcitJyDbymFyZ/zCM9P7F1KowXFW5MI6x+91G7m4CnnH8IwenwsatjdPHMsxwFdjiI qeCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="MA/U+XhE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xf10-20020a17090731ca00b0084d42589be6si9468228ejb.787.2023.01.11.09.30.58; Wed, 11 Jan 2023 09:31:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="MA/U+XhE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239578AbjAKRVv (ORCPT + 51 others); Wed, 11 Jan 2023 12:21:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238487AbjAKRVR (ORCPT ); Wed, 11 Jan 2023 12:21:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52D66164B7; Wed, 11 Jan 2023 09:21:17 -0800 (PST) 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 E2D0661D7C; Wed, 11 Jan 2023 17:21:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8A27C433EF; Wed, 11 Jan 2023 17:21:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673457676; bh=ANC1L0wfy1/P0+f7TDcL1iJdITEJZEnzKGu3tEgjcsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MA/U+XhExNf+fuYB7IqjgrugfJkHiRS6aw7i1XlatIvpnKCSUmj6NEGFRa4rsthPS jibd7VDhON/0KD0gFuDXjtZan8MrILnJmpnAMuTh/rSWgJ2AcKE2tI5sdgCc8moT4f v+3yvhyOXIMQR4tICFtxQGH9Np12dsL6SmUJWfMuMNMaaO5MMLP5udx1IxRU9ThKBf kCmQZl6al1ZA/R2wcVbu3pn/iTeARnAWCG5fwRdKcTnf+ZYfroqVygo63+ZuDF6vdK NWtOvwlG31jA98tq69Wcz8B1VGGA5UZ4PvA1m90xxAt+F6KG312mh/yMMoWvJRlYfR Nt6rC9358gCXA== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , Heiko Stuebner Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Guo Ren , Andrew Jones Subject: [PATCH v3 10/13] riscv: alternative: patch alternatives in the vDSO Date: Thu, 12 Jan 2023 01:10:24 +0800 Message-Id: <20230111171027.2392-11-jszhang@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230111171027.2392-1-jszhang@kernel.org> References: <20230111171027.2392-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make it possible to use alternatives in the vDSO, so that better implementations can be used if possible. Signed-off-by: Jisheng Zhang Reviewed-by: Guo Ren Reviewed-by: Andrew Jones --- arch/riscv/include/asm/vdso.h | 4 ++++ arch/riscv/kernel/alternative.c | 25 +++++++++++++++++++++++++ arch/riscv/kernel/vdso.c | 5 ----- arch/riscv/kernel/vdso/vdso.lds.S | 7 +++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h index a7644f46d0e5..f891478829a5 100644 --- a/arch/riscv/include/asm/vdso.h +++ b/arch/riscv/include/asm/vdso.h @@ -28,8 +28,12 @@ #define COMPAT_VDSO_SYMBOL(base, name) \ (void __user *)((unsigned long)(base) + compat__vdso_##name##_offset) +extern char compat_vdso_start[], compat_vdso_end[]; + #endif /* CONFIG_COMPAT */ +extern char vdso_start[], vdso_end[]; + #endif /* !__ASSEMBLY__ */ #endif /* CONFIG_MMU */ diff --git a/arch/riscv/kernel/alternative.c b/arch/riscv/kernel/alternative.c index 3d4f1f32c7f6..a883a309139f 100644 --- a/arch/riscv/kernel/alternative.c +++ b/arch/riscv/kernel/alternative.c @@ -11,7 +11,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -160,6 +162,27 @@ static void __init_or_module _apply_alternatives(struct alt_entry *begin, stage); } +static void __init apply_vdso_alternatives(void) +{ + const struct elf64_hdr *hdr; + const struct elf64_shdr *shdr; + const struct elf64_shdr *alt; + struct alt_entry *begin, *end; + + hdr = (struct elf64_hdr *)vdso_start; + shdr = (void *)hdr + hdr->e_shoff; + alt = find_section(hdr, shdr, ".alternative"); + if (!alt) + return; + + begin = (void *)hdr + alt->sh_offset, + end = (void *)hdr + alt->sh_offset + alt->sh_size, + + _apply_alternatives((struct alt_entry *)begin, + (struct alt_entry *)end, + RISCV_ALTERNATIVES_BOOT); +} + void __init apply_boot_alternatives(void) { /* If called on non-boot cpu things could go wrong */ @@ -168,6 +191,8 @@ void __init apply_boot_alternatives(void) _apply_alternatives((struct alt_entry *)__alt_start, (struct alt_entry *)__alt_end, RISCV_ALTERNATIVES_BOOT); + + apply_vdso_alternatives(); } /* diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c index e410275918ac..4e631c098f4d 100644 --- a/arch/riscv/kernel/vdso.c +++ b/arch/riscv/kernel/vdso.c @@ -22,11 +22,6 @@ struct vdso_data { }; #endif -extern char vdso_start[], vdso_end[]; -#ifdef CONFIG_COMPAT -extern char compat_vdso_start[], compat_vdso_end[]; -#endif - enum vvar_pages { VVAR_DATA_PAGE_OFFSET, VVAR_TIMENS_PAGE_OFFSET, diff --git a/arch/riscv/kernel/vdso/vdso.lds.S b/arch/riscv/kernel/vdso/vdso.lds.S index 150b1a572e61..4a0606633290 100644 --- a/arch/riscv/kernel/vdso/vdso.lds.S +++ b/arch/riscv/kernel/vdso/vdso.lds.S @@ -40,6 +40,13 @@ SECTIONS . = 0x800; .text : { *(.text .text.*) } :text + . = ALIGN(4); + .alternative : { + __alt_start = .; + *(.alternative) + __alt_end = .; + } + .data : { *(.got.plt) *(.got) *(.data .data.* .gnu.linkonce.d.*) -- 2.38.1