Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6910423rwb; Mon, 5 Dec 2022 20:57:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf4+a01+K0H89xseCs6p0rzkbEEZorZKlTGU4GLqo81sHwlL7nyrr38suApy8fWVw9Afu8TG X-Received: by 2002:a62:d10b:0:b0:575:ad52:ba94 with SMTP id z11-20020a62d10b000000b00575ad52ba94mr32165501pfg.74.1670302657762; Mon, 05 Dec 2022 20:57:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670302657; cv=none; d=google.com; s=arc-20160816; b=f+iG7VuIr7SZsuBOoTxCUpQjoVO2TZtXlvFGsVJK1pI5RfhET4vnH3qqarnS3W6sUX HmHA/xb22j4PivlDY3cBFMDpLEMWypU0VTrNecCItHMkpyvmGDFsfupxjYIkt/dcZkRI 8jVdBj8TAqD+zk58Xgozq1c0ZnQZhcZJzLsu5J1XcHluGwEAxuw56jK6B2jYpFG93vzG gl0Zikv0ML6Bg30bBw/vda7mxxKvB8r2efrrVlalOpHHs7xgm8/DssFu2JOq3jDArvx+ 4nDFqI2KrEmgCFxfTbGpho/fb9YOSGxueTvHUEymd9Tu3tzXhOjklAScdCgSguJQPgF0 vgQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KjFR/U+EXebWnbm5Gut1egX67f7ZqdL3XwtoMYNuPBk=; b=BBHxazI4eo8rUWikvvCAxcXOZ9ZjU82Al1mwy6bNsQVERk7T8vVZA+ivL9BgsOTHjr tjwxqJ0aCFsW7ZjOpmV+NcuRw+g9TvdvDafCZ5MC9zZeziK6NgT9zIbDJqzKs9BxXO6u JMJtHgmHChsb7p5z9GvzI7VJKqTRWutcOigZ19AMcNX3ym3g2oh35hLLDU0lY+8t/Jbp ixVcpx1Yud8TVAzI9+6JnidmEtO63jEy51sJ5rjbi5/IPOLj7XJo5jXMm6VViXikoApV cLf1ClZU3Jloc6altFMRivK9nnNDI3YgyuableGc+uWC9WXBg9nFRVjfzBcK30eMkzAC uYLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gWamiKgz; 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 g15-20020a056a000b8f00b0056e3c566bfasi16877022pfj.201.2022.12.05.20.57.26; Mon, 05 Dec 2022 20:57:37 -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=gWamiKgz; 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 S232748AbiLFEaC (ORCPT + 80 others); Mon, 5 Dec 2022 23:30:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiLFE34 (ORCPT ); Mon, 5 Dec 2022 23:29:56 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A454BC3A; Mon, 5 Dec 2022 20:29:53 -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 ams.source.kernel.org (Postfix) with ESMTPS id 55C9BB81698; Tue, 6 Dec 2022 04:29:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFEC4C43148; Tue, 6 Dec 2022 04:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670300991; bh=XUnacoeF5yXfIeKrKNdeKKCmSBmbmdDPu8G2Ol5gSpc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gWamiKgz3VX+Yw09lHLA2LxW9F/qImjf7t0OXzmBnx9kch+P3JYNo5Xf9LhM2v0O7 QXwxLpEGrUFQxFBI+iduC/plOWI5cII82rMdiUMJbOeucaFerIDjfE9aZHFZPyVhN1 NaMLY5AdRFj1tkyeHwNsqXOyKmy3C1tZPvBm1qRwmB/pTOR16xXTGvVPdPu68TOgRh Al91UTzbiVmPiLp9tYoIAL8vcMCQRlRpue4+ySyRyQGi6Px0TnikLNZwqwkwxihnWG 99tyEBZx/tI9rLP/nD+3yzA/wz1VraLTPHJPRsggTORzHDiA5QTgvrV+5fLqZpPOmj /f6OywaNZDR8Q== Received: by mail-ed1-f50.google.com with SMTP id e13so18611569edj.7; Mon, 05 Dec 2022 20:29:50 -0800 (PST) X-Gm-Message-State: ANoB5pliq0jUlnlmRJxgu4br8AL/0vR2C7TGWe0JdPgzBNQbD1J7GRr3 td4nhsBbcTww4F/63jfka1UUD1PmpXhnaqoRo4I= X-Received: by 2002:a05:6402:1117:b0:46b:6da7:e8a9 with SMTP id u23-20020a056402111700b0046b6da7e8a9mr28571704edv.401.1670300989129; Mon, 05 Dec 2022 20:29:49 -0800 (PST) MIME-Version: 1.0 References: <20221204174632.3677-1-jszhang@kernel.org> <20221204174632.3677-11-jszhang@kernel.org> In-Reply-To: From: Guo Ren Date: Tue, 6 Dec 2022 12:29:37 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 10/13] riscv: alternative: patch alternatives in the vDSO To: Jisheng Zhang Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Anup Patel , Atish Patra , Heiko Stuebner , Andrew Jones , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" 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 On Mon, Dec 5, 2022 at 11:33 PM Jisheng Zhang wrote: > > On Mon, Dec 05, 2022 at 09:56:37AM +0800, Guo Ren wrote: > > Are there any patches that depend on it? Any existing utilization? My > > first idea is to let __vdso_flush_icache use it, the standard > > implementation is so heavy for user space JIT scenario, maybe vendors > > could give a custom one. > > Hi Guo, > > the 11th patch of swtiching cpu_relax() to riscv_has_extension_likely() > depends on this patch, the gettimeofday implementation calls cpu_relax() > which may use ZIHINTPAUSE extension, so we need to patch vDSO. Oh, I missed that. Thx. Reviewed-by: Guo Ren > > Thanks > > > > > On Mon, Dec 5, 2022 at 1:57 AM Jisheng Zhang wrote: > > > > > > Make it possible to use alternatives in the vDSO, so that better > > > implementations can be used if possible. > > > > > > Signed-off-by: Jisheng Zhang > > > --- > > > 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 af981426fe0f..b6ff7473fb8a 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 9d88375624b5..eaf7ddaba54c 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 > > > @@ -187,6 +189,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 */ > > > @@ -195,6 +218,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 123d05255fcf..1f47bc6566cf 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.37.2 > > > > > > > > > -- > > Best Regards > > Guo Ren -- Best Regards Guo Ren