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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E16DEC433FE for ; Wed, 23 Feb 2022 01:43:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236665AbiBWBn3 (ORCPT ); Tue, 22 Feb 2022 20:43:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236646AbiBWBnT (ORCPT ); Tue, 22 Feb 2022 20:43:19 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7D85506EC for ; Tue, 22 Feb 2022 17:42:52 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id d17so13898727pfl.0 for ; Tue, 22 Feb 2022 17:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=zwBbz/bq064k6HWUopOPQQ33xd8SBnWKxyVQyGTnl5UdREVHJP7U7rarg6Rbx4MJEY /LlmompnRFgBddqV3yrcMHRkZ1XgjT77hGnYmPRmiK7SIvrD4Vch3s7QM3nlzc4jBPQG Dxau7eU01s63zrNj7dT78K1jIhsMDH/h+ROkfwEDe1XVHxawp29OSvp0NAfAjHdSHujy kzod2686NE9Zur+xXABdhziFND67DT3eBW6RPh0fxHtsE6pps2SnHTA9KPiCOrej7PHD hESMrPnkeNEVQLz/eCMpFmWqnmmvV4+/ojlT5fXfo/apl4SdZ2uu/pOuVD05yn9BTGJL pJww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=vOX7XzLH4d5MkPeUCABvI97kSFn63mihDxBleLeJEois3RSb9H5ZmzaWlsqVsOhx+9 82suF+aqHrxvS90wXIuLO9bH3xVPQ/ur3zUIYy/M8kvl9g6ZsGF+H9in4xXd/+j65njJ bPRwOtgfg1GTPt3ZlruZ1XswDQrbtsglZmmPGLsWjFk9U/KoZEouRZqytn8JIqz/KPfM G+2Y7AO9XAPq/T+mxwzc6p5TlKmzZ83biVxTx+UVrNHNV+yM8PgYA340EjX8wkYSd/2+ idpP+xABkmwK52LzFDNJ+GAEKB9ovag9kMK2Ir25sclBpIBgx4VBG2i5nqvlr1wtA81v w1ZA== X-Gm-Message-State: AOAM530jkpF+X94Ytj5PfgHoUfP0ciVoyOL3O+X8ZQTlMsX9a2Zyss2P QMiO9JDedcvRI8iBqxlvGlBmZQ== X-Google-Smtp-Source: ABdhPJwJJUYuSykKTjU6Cuc1f55tmKxp3pv29O0QqN1rqZlo1paLjwV9+OEnvSdoG2dTX2lbqowMew== X-Received: by 2002:a63:eb02:0:b0:370:41e4:6ae6 with SMTP id t2-20020a63eb02000000b0037041e46ae6mr21853093pgh.229.1645580572314; Tue, 22 Feb 2022 17:42:52 -0800 (PST) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id h1sm10706771pgr.7.2022.02.22.17.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 17:42:51 -0800 (PST) Date: Tue, 22 Feb 2022 17:42:51 -0800 (PST) X-Google-Original-Date: Tue, 22 Feb 2022 16:26:12 PST (-0800) Subject: Re: [PATCH V5 16/21] riscv: compat: vdso: Add rv32 VDSO base code implementation In-Reply-To: <20220201150545.1512822-17-guoren@kernel.org> CC: guoren@kernel.org, Arnd Bergmann , anup@brainfault.org, Greg KH , liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org, wangjunqiang@iscas.ac.cn, Christoph Hellwig , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-csky@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-parisc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, guoren@linux.alibaba.com From: Palmer Dabbelt To: guoren@kernel.org Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org On Tue, 01 Feb 2022 07:05:40 PST (-0800), guoren@kernel.org wrote: > From: Guo Ren > > There is no vgettimeofday supported in rv32 that makes simple to > generate rv32 vdso code which only needs riscv64 compiler. Other > architectures need change compiler or -m (machine parameter) to > support vdso32 compiling. If rv32 support vgettimeofday (which > cause C compile) in future, we would add CROSS_COMPILE to support > that makes more requirement on compiler enviornment. IMO this is the wrong way to go, as there's some subtle differences between elf32 and elf64 (the .gnu.hash layout, for example). I'm kind of surprised userspace tolerates this sort of thing at all, but given how easy it is to target rv32 from all toolchains (we don't need libraries here, so just -march should do it) I don't think it's worth chasing around the likely long-tail issues that will arise. > linux-rv64/arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg: > file format elf64-littleriscv > > Disassembly of section .text: > > 0000000000000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 000000000000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 0000000000000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > linux-rv32/arch/riscv/kernel/vdso/vdso.so.dbg: > file format elf32-littleriscv > > Disassembly of section .text: > > 00000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 0000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 00000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > Finally, reuse all *.S from vdso in compat_vdso that makes > implementation clear and readable. > > Signed-off-by: Guo Ren > Signed-off-by: Guo Ren > Cc: Arnd Bergmann > Cc: Palmer Dabbelt > --- > arch/riscv/Makefile | 5 ++ > arch/riscv/include/asm/vdso.h | 9 +++ > arch/riscv/kernel/Makefile | 1 + > arch/riscv/kernel/compat_vdso/.gitignore | 2 + > arch/riscv/kernel/compat_vdso/Makefile | 68 +++++++++++++++++++ > arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +++ > .../kernel/compat_vdso/compat_vdso.lds.S | 3 + > arch/riscv/kernel/compat_vdso/flush_icache.S | 3 + > .../compat_vdso/gen_compat_vdso_offsets.sh | 5 ++ > arch/riscv/kernel/compat_vdso/getcpu.S | 3 + > arch/riscv/kernel/compat_vdso/note.S | 3 + > arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 + > arch/riscv/kernel/vdso/vdso.S | 6 +- > 13 files changed, 118 insertions(+), 1 deletion(-) > create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore > create mode 100644 arch/riscv/kernel/compat_vdso/Makefile > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S > create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S > create mode 100644 arch/riscv/kernel/compat_vdso/note.S > create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > index a02e588c4947..f73d50552e09 100644 > --- a/arch/riscv/Makefile > +++ b/arch/riscv/Makefile > @@ -106,12 +106,17 @@ libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a > PHONY += vdso_install > vdso_install: > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso $@) > > ifeq ($(KBUILD_EXTMOD),) > ifeq ($(CONFIG_MMU),y) > prepare: vdso_prepare > vdso_prepare: prepare0 > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h) > + > endif > endif > > diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h > index bc6f75f3a199..af981426fe0f 100644 > --- a/arch/riscv/include/asm/vdso.h > +++ b/arch/riscv/include/asm/vdso.h > @@ -21,6 +21,15 @@ > > #define VDSO_SYMBOL(base, name) \ > (void __user *)((unsigned long)(base) + __vdso_##name##_offset) > + > +#ifdef CONFIG_COMPAT > +#include > + > +#define COMPAT_VDSO_SYMBOL(base, name) \ > + (void __user *)((unsigned long)(base) + compat__vdso_##name##_offset) > + > +#endif /* CONFIG_COMPAT */ > + > #endif /* !__ASSEMBLY__ */ > > #endif /* CONFIG_MMU */ > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index 954dc7043ad2..88e79f481c21 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -67,3 +67,4 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o > > obj-$(CONFIG_EFI) += efi.o > obj-$(CONFIG_COMPAT) += compat_syscall_table.o > +obj-$(CONFIG_COMPAT) += compat_vdso/ > diff --git a/arch/riscv/kernel/compat_vdso/.gitignore b/arch/riscv/kernel/compat_vdso/.gitignore > new file mode 100644 > index 000000000000..19d83d846c1e > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/.gitignore > @@ -0,0 +1,2 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +compat_vdso.lds > diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile > new file mode 100644 > index 000000000000..7bbbbf94307f > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/Makefile > @@ -0,0 +1,68 @@ > +# SPDX-License-Identifier: GPL-2.0-only > + > +# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before > +# the inclusion of generic Makefile. > +ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT > +include $(srctree)/lib/vdso/Makefile > +# Symbols present in the compat_vdso > +compat_vdso-syms = rt_sigreturn > +compat_vdso-syms += getcpu > +compat_vdso-syms += flush_icache > + > +# Files to link into the compat_vdso > +obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o > + > +ccflags-y := -fno-stack-protector > + > +# Build rules > +targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds > +obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso)) > + > +obj-y += compat_vdso.o > +CPPFLAGS_compat_vdso.lds += -P -C -U$(ARCH) > + > +# Disable profiling and instrumentation for VDSO code > +GCOV_PROFILE := n > +KCOV_INSTRUMENT := n > +KASAN_SANITIZE := n > +UBSAN_SANITIZE := n > + > +# Force dependency > +$(obj)/compat_vdso.o: $(obj)/compat_vdso.so > + > +# link rule for the .so file, .lds has to be first > +$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE > + $(call if_changed,compat_vdsold) > +LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \ > + --build-id=sha1 --hash-style=both --eh-frame-hdr > + > +# strip rule for the .so file > +$(obj)/%.so: OBJCOPYFLAGS := -S > +$(obj)/%.so: $(obj)/%.so.dbg FORCE > + $(call if_changed,objcopy) > + > +# Generate VDSO offsets using helper script > +gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh > +quiet_cmd_compat_vdsosym = VDSOSYM $@ > + cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@ > + > +include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE > + $(call if_changed,compat_vdsosym) > + > +# actual build commands > +# The DSO images are built using a special linker script > +# Make sure only to export the intended __compat_vdso_xxx symbol offsets. > +quiet_cmd_compat_vdsold = VDSOLD $@ > + cmd_compat_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \ > + $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \ > + rm $@.tmp > + > +# install commands for the unstripped file > +quiet_cmd_compat_vdso_install = INSTALL $@ > + cmd_compat_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/compat_vdso/$@ > + > +compat_vdso.so: $(obj)/compat_vdso.so.dbg > + @mkdir -p $(MODLIB)/compat_vdso > + $(call cmd,compat_vdso_install) > + > +compat_vdso_install: compat_vdso.so > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.S b/arch/riscv/kernel/compat_vdso/compat_vdso.S > new file mode 100644 > index 000000000000..fea4a8b0c45d > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.S > @@ -0,0 +1,8 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#define vdso_start compat_vdso_start > +#define vdso_end compat_vdso_end > + > +#define __VDSO_PATH "arch/riscv/kernel/compat_vdso/compat_vdso.so" > + > +#include <../vdso/vdso.S> > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > new file mode 100644 > index 000000000000..02a9ec5dc7f6 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/vdso.lds.S> > diff --git a/arch/riscv/kernel/compat_vdso/flush_icache.S b/arch/riscv/kernel/compat_vdso/flush_icache.S > new file mode 100644 > index 000000000000..88e21a84a974 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/flush_icache.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/flush_icache.S> > diff --git a/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > new file mode 100755 > index 000000000000..8ac070c783b3 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > @@ -0,0 +1,5 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0 > + > +LC_ALL=C > +sed -n -e 's/^[0]\+\(0[0-9a-fA-F]*\) . \(__vdso_[a-zA-Z0-9_]*\)$/\#define compat\2_offset\t0x\1/p' > diff --git a/arch/riscv/kernel/compat_vdso/getcpu.S b/arch/riscv/kernel/compat_vdso/getcpu.S > new file mode 100644 > index 000000000000..946449a15a94 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/getcpu.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/getcpu.S> > diff --git a/arch/riscv/kernel/compat_vdso/note.S b/arch/riscv/kernel/compat_vdso/note.S > new file mode 100644 > index 000000000000..67c50898b8e5 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/note.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/note.S> > diff --git a/arch/riscv/kernel/compat_vdso/rt_sigreturn.S b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > new file mode 100644 > index 000000000000..f4c98f18c053 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/rt_sigreturn.S> > diff --git a/arch/riscv/kernel/vdso/vdso.S b/arch/riscv/kernel/vdso/vdso.S > index df222245be05..83f1c899e8d8 100644 > --- a/arch/riscv/kernel/vdso/vdso.S > +++ b/arch/riscv/kernel/vdso/vdso.S > @@ -7,12 +7,16 @@ > #include > #include > > +#ifndef __VDSO_PATH > +#define __VDSO_PATH "arch/riscv/kernel/vdso/vdso.so" > +#endif > + > __PAGE_ALIGNED_DATA > > .globl vdso_start, vdso_end > .balign PAGE_SIZE > vdso_start: > - .incbin "arch/riscv/kernel/vdso/vdso.so" > + .incbin __VDSO_PATH > .balign PAGE_SIZE > vdso_end: 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 54E65C433F5 for ; Wed, 23 Feb 2022 01:45:03 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Mime-Version:Message-ID:To:From:CC:In-Reply-To: Subject:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References:List-Owner; bh=r0pmHrhEJOWQ4JJ++0wNH3KNiS16codkmUJ1uvwkPAU=; b=XOKxAPcJEo3Ih+soOO9jPzLe2P Gy3WfD+dKpRo9YYomPDDqg+ao3oKsa9aA/MViKDMDnP8ytsTYroz9geZ+PMhChSvMJr3XzPuFTBMR 5vtg4i4YsBChN3cFba7QjFDfYbBcP+mDYuxn4TZbFZaugI1eDtSvcJjGRB2CHx/OLPawZnl75DiA1 V4wT+XpFbOoNH27emQN15/9c5V1mK68rHgA1gU4iqAm0dD+oDys617gImv8aaZxbDxJEO3sd2yf2J GXQDcQdM8gfnX4ijXNhgpDGiz3grAIn2dEfKUWiAvylvJQmFmHfI846NrJwJ2L1MabpHt6OreJx0p MEPyfQzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMgi5-00CAEM-IQ; Wed, 23 Feb 2022 01:44:53 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMgg9-00C9Ai-Li for linux-riscv@lists.infradead.org; Wed, 23 Feb 2022 01:43:01 +0000 Received: by mail-pf1-x436.google.com with SMTP id p8so13854982pfh.8 for ; Tue, 22 Feb 2022 17:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=zwBbz/bq064k6HWUopOPQQ33xd8SBnWKxyVQyGTnl5UdREVHJP7U7rarg6Rbx4MJEY /LlmompnRFgBddqV3yrcMHRkZ1XgjT77hGnYmPRmiK7SIvrD4Vch3s7QM3nlzc4jBPQG Dxau7eU01s63zrNj7dT78K1jIhsMDH/h+ROkfwEDe1XVHxawp29OSvp0NAfAjHdSHujy kzod2686NE9Zur+xXABdhziFND67DT3eBW6RPh0fxHtsE6pps2SnHTA9KPiCOrej7PHD hESMrPnkeNEVQLz/eCMpFmWqnmmvV4+/ojlT5fXfo/apl4SdZ2uu/pOuVD05yn9BTGJL pJww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=Y4SEBonRQ4mrq9gYYPTqH5Pj/IIsK/ZKgvQzOlKNI4HBFTZmWR3FVtchEmHlaOMkvz TrTpPli80s5v/owdCDpbtwYrH6mcMlYn2/6KsRA0FE9W5OVLESEeBFKHyIIRcwY+4mlS AP3cF37CBKCVz04w2CEpITMHqnnE+WEvrgbJl+EM51rFq7HyPoJa4T4H+XXndECa+dfv gS4x/KKuTotIulr5iIkX3ORrHWL3AOqZWs+bRT9bZHE2r87/KmQZ897luoOG4EH3OW89 QPCYh/UEi/08o7Az5ZKjYs3BjMr0izn3pzCwP0MSA4jb/RjmYVYJsVRqEF9D8qaVpXVo g9vw== X-Gm-Message-State: AOAM531ZuMNi5EbHV+ZGoUaOtXtHhbTDQVUy9pBYXm3OKvz0RpseeSLE t6vtS4+aFiY8kwKD8jW/K74bHg== X-Google-Smtp-Source: ABdhPJwJJUYuSykKTjU6Cuc1f55tmKxp3pv29O0QqN1rqZlo1paLjwV9+OEnvSdoG2dTX2lbqowMew== X-Received: by 2002:a63:eb02:0:b0:370:41e4:6ae6 with SMTP id t2-20020a63eb02000000b0037041e46ae6mr21853093pgh.229.1645580572314; Tue, 22 Feb 2022 17:42:52 -0800 (PST) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id h1sm10706771pgr.7.2022.02.22.17.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 17:42:51 -0800 (PST) Date: Tue, 22 Feb 2022 17:42:51 -0800 (PST) X-Google-Original-Date: Tue, 22 Feb 2022 16:26:12 PST (-0800) Subject: Re: [PATCH V5 16/21] riscv: compat: vdso: Add rv32 VDSO base code implementation In-Reply-To: <20220201150545.1512822-17-guoren@kernel.org> CC: guoren@kernel.org, Arnd Bergmann , anup@brainfault.org, Greg KH , liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org, wangjunqiang@iscas.ac.cn, Christoph Hellwig , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-csky@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-parisc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, guoren@linux.alibaba.com From: Palmer Dabbelt To: guoren@kernel.org Message-ID: Mime-Version: 1.0 (MHng) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220222_174253_824518_4D346E1D X-CRM114-Status: GOOD ( 31.03 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Tue, 01 Feb 2022 07:05:40 PST (-0800), guoren@kernel.org wrote: > From: Guo Ren > > There is no vgettimeofday supported in rv32 that makes simple to > generate rv32 vdso code which only needs riscv64 compiler. Other > architectures need change compiler or -m (machine parameter) to > support vdso32 compiling. If rv32 support vgettimeofday (which > cause C compile) in future, we would add CROSS_COMPILE to support > that makes more requirement on compiler enviornment. IMO this is the wrong way to go, as there's some subtle differences between elf32 and elf64 (the .gnu.hash layout, for example). I'm kind of surprised userspace tolerates this sort of thing at all, but given how easy it is to target rv32 from all toolchains (we don't need libraries here, so just -march should do it) I don't think it's worth chasing around the likely long-tail issues that will arise. > linux-rv64/arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg: > file format elf64-littleriscv > > Disassembly of section .text: > > 0000000000000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 000000000000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 0000000000000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > linux-rv32/arch/riscv/kernel/vdso/vdso.so.dbg: > file format elf32-littleriscv > > Disassembly of section .text: > > 00000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 0000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 00000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > Finally, reuse all *.S from vdso in compat_vdso that makes > implementation clear and readable. > > Signed-off-by: Guo Ren > Signed-off-by: Guo Ren > Cc: Arnd Bergmann > Cc: Palmer Dabbelt > --- > arch/riscv/Makefile | 5 ++ > arch/riscv/include/asm/vdso.h | 9 +++ > arch/riscv/kernel/Makefile | 1 + > arch/riscv/kernel/compat_vdso/.gitignore | 2 + > arch/riscv/kernel/compat_vdso/Makefile | 68 +++++++++++++++++++ > arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +++ > .../kernel/compat_vdso/compat_vdso.lds.S | 3 + > arch/riscv/kernel/compat_vdso/flush_icache.S | 3 + > .../compat_vdso/gen_compat_vdso_offsets.sh | 5 ++ > arch/riscv/kernel/compat_vdso/getcpu.S | 3 + > arch/riscv/kernel/compat_vdso/note.S | 3 + > arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 + > arch/riscv/kernel/vdso/vdso.S | 6 +- > 13 files changed, 118 insertions(+), 1 deletion(-) > create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore > create mode 100644 arch/riscv/kernel/compat_vdso/Makefile > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S > create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S > create mode 100644 arch/riscv/kernel/compat_vdso/note.S > create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > index a02e588c4947..f73d50552e09 100644 > --- a/arch/riscv/Makefile > +++ b/arch/riscv/Makefile > @@ -106,12 +106,17 @@ libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a > PHONY += vdso_install > vdso_install: > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso $@) > > ifeq ($(KBUILD_EXTMOD),) > ifeq ($(CONFIG_MMU),y) > prepare: vdso_prepare > vdso_prepare: prepare0 > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h) > + > endif > endif > > diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h > index bc6f75f3a199..af981426fe0f 100644 > --- a/arch/riscv/include/asm/vdso.h > +++ b/arch/riscv/include/asm/vdso.h > @@ -21,6 +21,15 @@ > > #define VDSO_SYMBOL(base, name) \ > (void __user *)((unsigned long)(base) + __vdso_##name##_offset) > + > +#ifdef CONFIG_COMPAT > +#include > + > +#define COMPAT_VDSO_SYMBOL(base, name) \ > + (void __user *)((unsigned long)(base) + compat__vdso_##name##_offset) > + > +#endif /* CONFIG_COMPAT */ > + > #endif /* !__ASSEMBLY__ */ > > #endif /* CONFIG_MMU */ > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index 954dc7043ad2..88e79f481c21 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -67,3 +67,4 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o > > obj-$(CONFIG_EFI) += efi.o > obj-$(CONFIG_COMPAT) += compat_syscall_table.o > +obj-$(CONFIG_COMPAT) += compat_vdso/ > diff --git a/arch/riscv/kernel/compat_vdso/.gitignore b/arch/riscv/kernel/compat_vdso/.gitignore > new file mode 100644 > index 000000000000..19d83d846c1e > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/.gitignore > @@ -0,0 +1,2 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +compat_vdso.lds > diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile > new file mode 100644 > index 000000000000..7bbbbf94307f > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/Makefile > @@ -0,0 +1,68 @@ > +# SPDX-License-Identifier: GPL-2.0-only > + > +# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before > +# the inclusion of generic Makefile. > +ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT > +include $(srctree)/lib/vdso/Makefile > +# Symbols present in the compat_vdso > +compat_vdso-syms = rt_sigreturn > +compat_vdso-syms += getcpu > +compat_vdso-syms += flush_icache > + > +# Files to link into the compat_vdso > +obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o > + > +ccflags-y := -fno-stack-protector > + > +# Build rules > +targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds > +obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso)) > + > +obj-y += compat_vdso.o > +CPPFLAGS_compat_vdso.lds += -P -C -U$(ARCH) > + > +# Disable profiling and instrumentation for VDSO code > +GCOV_PROFILE := n > +KCOV_INSTRUMENT := n > +KASAN_SANITIZE := n > +UBSAN_SANITIZE := n > + > +# Force dependency > +$(obj)/compat_vdso.o: $(obj)/compat_vdso.so > + > +# link rule for the .so file, .lds has to be first > +$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE > + $(call if_changed,compat_vdsold) > +LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \ > + --build-id=sha1 --hash-style=both --eh-frame-hdr > + > +# strip rule for the .so file > +$(obj)/%.so: OBJCOPYFLAGS := -S > +$(obj)/%.so: $(obj)/%.so.dbg FORCE > + $(call if_changed,objcopy) > + > +# Generate VDSO offsets using helper script > +gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh > +quiet_cmd_compat_vdsosym = VDSOSYM $@ > + cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@ > + > +include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE > + $(call if_changed,compat_vdsosym) > + > +# actual build commands > +# The DSO images are built using a special linker script > +# Make sure only to export the intended __compat_vdso_xxx symbol offsets. > +quiet_cmd_compat_vdsold = VDSOLD $@ > + cmd_compat_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \ > + $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \ > + rm $@.tmp > + > +# install commands for the unstripped file > +quiet_cmd_compat_vdso_install = INSTALL $@ > + cmd_compat_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/compat_vdso/$@ > + > +compat_vdso.so: $(obj)/compat_vdso.so.dbg > + @mkdir -p $(MODLIB)/compat_vdso > + $(call cmd,compat_vdso_install) > + > +compat_vdso_install: compat_vdso.so > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.S b/arch/riscv/kernel/compat_vdso/compat_vdso.S > new file mode 100644 > index 000000000000..fea4a8b0c45d > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.S > @@ -0,0 +1,8 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#define vdso_start compat_vdso_start > +#define vdso_end compat_vdso_end > + > +#define __VDSO_PATH "arch/riscv/kernel/compat_vdso/compat_vdso.so" > + > +#include <../vdso/vdso.S> > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > new file mode 100644 > index 000000000000..02a9ec5dc7f6 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/vdso.lds.S> > diff --git a/arch/riscv/kernel/compat_vdso/flush_icache.S b/arch/riscv/kernel/compat_vdso/flush_icache.S > new file mode 100644 > index 000000000000..88e21a84a974 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/flush_icache.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/flush_icache.S> > diff --git a/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > new file mode 100755 > index 000000000000..8ac070c783b3 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > @@ -0,0 +1,5 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0 > + > +LC_ALL=C > +sed -n -e 's/^[0]\+\(0[0-9a-fA-F]*\) . \(__vdso_[a-zA-Z0-9_]*\)$/\#define compat\2_offset\t0x\1/p' > diff --git a/arch/riscv/kernel/compat_vdso/getcpu.S b/arch/riscv/kernel/compat_vdso/getcpu.S > new file mode 100644 > index 000000000000..946449a15a94 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/getcpu.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/getcpu.S> > diff --git a/arch/riscv/kernel/compat_vdso/note.S b/arch/riscv/kernel/compat_vdso/note.S > new file mode 100644 > index 000000000000..67c50898b8e5 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/note.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/note.S> > diff --git a/arch/riscv/kernel/compat_vdso/rt_sigreturn.S b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > new file mode 100644 > index 000000000000..f4c98f18c053 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/rt_sigreturn.S> > diff --git a/arch/riscv/kernel/vdso/vdso.S b/arch/riscv/kernel/vdso/vdso.S > index df222245be05..83f1c899e8d8 100644 > --- a/arch/riscv/kernel/vdso/vdso.S > +++ b/arch/riscv/kernel/vdso/vdso.S > @@ -7,12 +7,16 @@ > #include > #include > > +#ifndef __VDSO_PATH > +#define __VDSO_PATH "arch/riscv/kernel/vdso/vdso.so" > +#endif > + > __PAGE_ALIGNED_DATA > > .globl vdso_start, vdso_end > .balign PAGE_SIZE > vdso_start: > - .incbin "arch/riscv/kernel/vdso/vdso.so" > + .incbin __VDSO_PATH > .balign PAGE_SIZE > vdso_end: _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 BEE0FC433EF for ; Wed, 23 Feb 2022 01:45:51 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4K3Jld6Gcmz3cQY for ; Wed, 23 Feb 2022 12:45:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=dabbelt-com.20210112.gappssmtp.com header.i=@dabbelt-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=zwBbz/bq; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=dabbelt.com (client-ip=2607:f8b0:4864:20::436; helo=mail-pf1-x436.google.com; envelope-from=palmer@dabbelt.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dabbelt-com.20210112.gappssmtp.com header.i=@dabbelt-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=zwBbz/bq; dkim-atps=neutral Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4K3JhJ511qz3bPT for ; Wed, 23 Feb 2022 12:42:55 +1100 (AEDT) Received: by mail-pf1-x436.google.com with SMTP id u16so13854485pfg.12 for ; Tue, 22 Feb 2022 17:42:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=zwBbz/bq064k6HWUopOPQQ33xd8SBnWKxyVQyGTnl5UdREVHJP7U7rarg6Rbx4MJEY /LlmompnRFgBddqV3yrcMHRkZ1XgjT77hGnYmPRmiK7SIvrD4Vch3s7QM3nlzc4jBPQG Dxau7eU01s63zrNj7dT78K1jIhsMDH/h+ROkfwEDe1XVHxawp29OSvp0NAfAjHdSHujy kzod2686NE9Zur+xXABdhziFND67DT3eBW6RPh0fxHtsE6pps2SnHTA9KPiCOrej7PHD hESMrPnkeNEVQLz/eCMpFmWqnmmvV4+/ojlT5fXfo/apl4SdZ2uu/pOuVD05yn9BTGJL pJww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=QtY8VQ3xNHUd0gZqjNM6OpcSIc1wo1RrkAJ+Aa1+leWfnEqeb48f2li1fNrEgrz4OM L3YTcbBGoGaaMGRHCljqMO+ebvdr6RPDD1Wywjq+Y0IH0w7R/mbRJKJ9jS6nmhUHwBM2 OZwQaOlOjhKP9pFAT/DflTyxpgeOyJMB9Lyd4PuW+1WQ2tv8ulp22Z7ZKSX8s5N3gM8h CWVSczMJkQnpyO5fTdQc1Yoria58FBJrEnyiU+C3eeahwnb3Do0kvVBChz/ZylOt2pAA AARJ6RtXftBjOnaT1jzE9E+JbsvEHt3G3bD0u2mQTFk21fifim1CyTLCYF3U+Ii1heE/ BKnw== X-Gm-Message-State: AOAM531jWR4pV4U9aHbwVt4nL5T1LmMcGRjvMr/AZBFgSRxT9ud3QgoX Fys5oXCI9q9zqZ4tjrQ1kfj2Ag== X-Google-Smtp-Source: ABdhPJwJJUYuSykKTjU6Cuc1f55tmKxp3pv29O0QqN1rqZlo1paLjwV9+OEnvSdoG2dTX2lbqowMew== X-Received: by 2002:a63:eb02:0:b0:370:41e4:6ae6 with SMTP id t2-20020a63eb02000000b0037041e46ae6mr21853093pgh.229.1645580572314; Tue, 22 Feb 2022 17:42:52 -0800 (PST) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id h1sm10706771pgr.7.2022.02.22.17.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 17:42:51 -0800 (PST) Date: Tue, 22 Feb 2022 17:42:51 -0800 (PST) X-Google-Original-Date: Tue, 22 Feb 2022 16:26:12 PST (-0800) Subject: Re: [PATCH V5 16/21] riscv: compat: vdso: Add rv32 VDSO base code implementation In-Reply-To: <20220201150545.1512822-17-guoren@kernel.org> From: Palmer Dabbelt To: guoren@kernel.org Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, guoren@linux.alibaba.com, linux-parisc@vger.kernel.org, Arnd Bergmann , Greg KH , drew@beagleboard.org, anup@brainfault.org, wangjunqiang@iscas.ac.cn, x86@kernel.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-mips@vger.kernel.org, guoren@kernel.org, liush@allwinnertech.com, sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christoph Hellwig , linux-arm-kernel@lists.infradead.org, wefu@redhat.com Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, 01 Feb 2022 07:05:40 PST (-0800), guoren@kernel.org wrote: > From: Guo Ren > > There is no vgettimeofday supported in rv32 that makes simple to > generate rv32 vdso code which only needs riscv64 compiler. Other > architectures need change compiler or -m (machine parameter) to > support vdso32 compiling. If rv32 support vgettimeofday (which > cause C compile) in future, we would add CROSS_COMPILE to support > that makes more requirement on compiler enviornment. IMO this is the wrong way to go, as there's some subtle differences between elf32 and elf64 (the .gnu.hash layout, for example). I'm kind of surprised userspace tolerates this sort of thing at all, but given how easy it is to target rv32 from all toolchains (we don't need libraries here, so just -march should do it) I don't think it's worth chasing around the likely long-tail issues that will arise. > linux-rv64/arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg: > file format elf64-littleriscv > > Disassembly of section .text: > > 0000000000000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 000000000000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 0000000000000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > linux-rv32/arch/riscv/kernel/vdso/vdso.so.dbg: > file format elf32-littleriscv > > Disassembly of section .text: > > 00000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 0000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 00000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > Finally, reuse all *.S from vdso in compat_vdso that makes > implementation clear and readable. > > Signed-off-by: Guo Ren > Signed-off-by: Guo Ren > Cc: Arnd Bergmann > Cc: Palmer Dabbelt > --- > arch/riscv/Makefile | 5 ++ > arch/riscv/include/asm/vdso.h | 9 +++ > arch/riscv/kernel/Makefile | 1 + > arch/riscv/kernel/compat_vdso/.gitignore | 2 + > arch/riscv/kernel/compat_vdso/Makefile | 68 +++++++++++++++++++ > arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +++ > .../kernel/compat_vdso/compat_vdso.lds.S | 3 + > arch/riscv/kernel/compat_vdso/flush_icache.S | 3 + > .../compat_vdso/gen_compat_vdso_offsets.sh | 5 ++ > arch/riscv/kernel/compat_vdso/getcpu.S | 3 + > arch/riscv/kernel/compat_vdso/note.S | 3 + > arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 + > arch/riscv/kernel/vdso/vdso.S | 6 +- > 13 files changed, 118 insertions(+), 1 deletion(-) > create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore > create mode 100644 arch/riscv/kernel/compat_vdso/Makefile > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S > create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S > create mode 100644 arch/riscv/kernel/compat_vdso/note.S > create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > index a02e588c4947..f73d50552e09 100644 > --- a/arch/riscv/Makefile > +++ b/arch/riscv/Makefile > @@ -106,12 +106,17 @@ libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a > PHONY += vdso_install > vdso_install: > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso $@) > > ifeq ($(KBUILD_EXTMOD),) > ifeq ($(CONFIG_MMU),y) > prepare: vdso_prepare > vdso_prepare: prepare0 > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h) > + > endif > endif > > diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h > index bc6f75f3a199..af981426fe0f 100644 > --- a/arch/riscv/include/asm/vdso.h > +++ b/arch/riscv/include/asm/vdso.h > @@ -21,6 +21,15 @@ > > #define VDSO_SYMBOL(base, name) \ > (void __user *)((unsigned long)(base) + __vdso_##name##_offset) > + > +#ifdef CONFIG_COMPAT > +#include > + > +#define COMPAT_VDSO_SYMBOL(base, name) \ > + (void __user *)((unsigned long)(base) + compat__vdso_##name##_offset) > + > +#endif /* CONFIG_COMPAT */ > + > #endif /* !__ASSEMBLY__ */ > > #endif /* CONFIG_MMU */ > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index 954dc7043ad2..88e79f481c21 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -67,3 +67,4 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o > > obj-$(CONFIG_EFI) += efi.o > obj-$(CONFIG_COMPAT) += compat_syscall_table.o > +obj-$(CONFIG_COMPAT) += compat_vdso/ > diff --git a/arch/riscv/kernel/compat_vdso/.gitignore b/arch/riscv/kernel/compat_vdso/.gitignore > new file mode 100644 > index 000000000000..19d83d846c1e > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/.gitignore > @@ -0,0 +1,2 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +compat_vdso.lds > diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile > new file mode 100644 > index 000000000000..7bbbbf94307f > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/Makefile > @@ -0,0 +1,68 @@ > +# SPDX-License-Identifier: GPL-2.0-only > + > +# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before > +# the inclusion of generic Makefile. > +ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT > +include $(srctree)/lib/vdso/Makefile > +# Symbols present in the compat_vdso > +compat_vdso-syms = rt_sigreturn > +compat_vdso-syms += getcpu > +compat_vdso-syms += flush_icache > + > +# Files to link into the compat_vdso > +obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o > + > +ccflags-y := -fno-stack-protector > + > +# Build rules > +targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds > +obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso)) > + > +obj-y += compat_vdso.o > +CPPFLAGS_compat_vdso.lds += -P -C -U$(ARCH) > + > +# Disable profiling and instrumentation for VDSO code > +GCOV_PROFILE := n > +KCOV_INSTRUMENT := n > +KASAN_SANITIZE := n > +UBSAN_SANITIZE := n > + > +# Force dependency > +$(obj)/compat_vdso.o: $(obj)/compat_vdso.so > + > +# link rule for the .so file, .lds has to be first > +$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE > + $(call if_changed,compat_vdsold) > +LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \ > + --build-id=sha1 --hash-style=both --eh-frame-hdr > + > +# strip rule for the .so file > +$(obj)/%.so: OBJCOPYFLAGS := -S > +$(obj)/%.so: $(obj)/%.so.dbg FORCE > + $(call if_changed,objcopy) > + > +# Generate VDSO offsets using helper script > +gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh > +quiet_cmd_compat_vdsosym = VDSOSYM $@ > + cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@ > + > +include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE > + $(call if_changed,compat_vdsosym) > + > +# actual build commands > +# The DSO images are built using a special linker script > +# Make sure only to export the intended __compat_vdso_xxx symbol offsets. > +quiet_cmd_compat_vdsold = VDSOLD $@ > + cmd_compat_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \ > + $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \ > + rm $@.tmp > + > +# install commands for the unstripped file > +quiet_cmd_compat_vdso_install = INSTALL $@ > + cmd_compat_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/compat_vdso/$@ > + > +compat_vdso.so: $(obj)/compat_vdso.so.dbg > + @mkdir -p $(MODLIB)/compat_vdso > + $(call cmd,compat_vdso_install) > + > +compat_vdso_install: compat_vdso.so > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.S b/arch/riscv/kernel/compat_vdso/compat_vdso.S > new file mode 100644 > index 000000000000..fea4a8b0c45d > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.S > @@ -0,0 +1,8 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#define vdso_start compat_vdso_start > +#define vdso_end compat_vdso_end > + > +#define __VDSO_PATH "arch/riscv/kernel/compat_vdso/compat_vdso.so" > + > +#include <../vdso/vdso.S> > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > new file mode 100644 > index 000000000000..02a9ec5dc7f6 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/vdso.lds.S> > diff --git a/arch/riscv/kernel/compat_vdso/flush_icache.S b/arch/riscv/kernel/compat_vdso/flush_icache.S > new file mode 100644 > index 000000000000..88e21a84a974 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/flush_icache.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/flush_icache.S> > diff --git a/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > new file mode 100755 > index 000000000000..8ac070c783b3 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > @@ -0,0 +1,5 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0 > + > +LC_ALL=C > +sed -n -e 's/^[0]\+\(0[0-9a-fA-F]*\) . \(__vdso_[a-zA-Z0-9_]*\)$/\#define compat\2_offset\t0x\1/p' > diff --git a/arch/riscv/kernel/compat_vdso/getcpu.S b/arch/riscv/kernel/compat_vdso/getcpu.S > new file mode 100644 > index 000000000000..946449a15a94 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/getcpu.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/getcpu.S> > diff --git a/arch/riscv/kernel/compat_vdso/note.S b/arch/riscv/kernel/compat_vdso/note.S > new file mode 100644 > index 000000000000..67c50898b8e5 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/note.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/note.S> > diff --git a/arch/riscv/kernel/compat_vdso/rt_sigreturn.S b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > new file mode 100644 > index 000000000000..f4c98f18c053 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/rt_sigreturn.S> > diff --git a/arch/riscv/kernel/vdso/vdso.S b/arch/riscv/kernel/vdso/vdso.S > index df222245be05..83f1c899e8d8 100644 > --- a/arch/riscv/kernel/vdso/vdso.S > +++ b/arch/riscv/kernel/vdso/vdso.S > @@ -7,12 +7,16 @@ > #include > #include > > +#ifndef __VDSO_PATH > +#define __VDSO_PATH "arch/riscv/kernel/vdso/vdso.so" > +#endif > + > __PAGE_ALIGNED_DATA > > .globl vdso_start, vdso_end > .balign PAGE_SIZE > vdso_start: > - .incbin "arch/riscv/kernel/vdso/vdso.so" > + .incbin __VDSO_PATH > .balign PAGE_SIZE > vdso_end: 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 9FFABC433EF for ; Wed, 23 Feb 2022 01:48:05 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Mime-Version:Message-ID:To:From:CC:In-Reply-To: Subject:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References:List-Owner; bh=YDZ6zHxqS4VDflVGO/j3vgb7LX/ap4FChTwHDzXm/NU=; b=oXZJgzbp81p0ZFfaT2XDb/i+37 bNhqjHCTGGkU+L4NXcZ8h49pPUx+dvsH51C1KSkIMAgjmavX8R63m5fzn4c0C7zjfzlDIVz9iCt2V S+ybJ5SapuW2K1uvJLRsy8uhiOUX0Nc5xMnjagyNKgP3BGVasyfOOjrTrYlSlcU1/wz0hoqCWRJCC ocEiW0gK6Fi7mWj4ttR2R4xw4eOf5Lca/pH7XgYS4aEz2gT36660vnE8ZQ7A3ohi+W5ZmGHgbkEHC wpPcgQH9uW7nUhfnUMfCAuG0d09rxb9td0HY+268kFSeSoKIU7itqtZDg5yADcAD+5MnCDik3JZpO zui109Sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMgjk-00CAwM-1C; Wed, 23 Feb 2022 01:46:36 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMgg9-00C9Ah-Kz for linux-arm-kernel@lists.infradead.org; Wed, 23 Feb 2022 01:42:56 +0000 Received: by mail-pf1-x434.google.com with SMTP id i6so13847238pfc.9 for ; Tue, 22 Feb 2022 17:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=zwBbz/bq064k6HWUopOPQQ33xd8SBnWKxyVQyGTnl5UdREVHJP7U7rarg6Rbx4MJEY /LlmompnRFgBddqV3yrcMHRkZ1XgjT77hGnYmPRmiK7SIvrD4Vch3s7QM3nlzc4jBPQG Dxau7eU01s63zrNj7dT78K1jIhsMDH/h+ROkfwEDe1XVHxawp29OSvp0NAfAjHdSHujy kzod2686NE9Zur+xXABdhziFND67DT3eBW6RPh0fxHtsE6pps2SnHTA9KPiCOrej7PHD hESMrPnkeNEVQLz/eCMpFmWqnmmvV4+/ojlT5fXfo/apl4SdZ2uu/pOuVD05yn9BTGJL pJww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=atTO77+TkxhABJlr8wI/qCGUOeZZg0UG4WdQx8Uydms=; b=JvRXFN346vmcex3mW6MEBiucP+jgdpERJd8OSeMQAS9XKA+b+oTidmRJeQ7uEIfYyQ +CGlj7DB1TzQI7mQui8ves0OheTZYHeeZ3L87T+xDEDd818xMW4JJj7GU4ETjETeU1Ix f0dGPiZ9fv9K7Le/Vv3NYzFLvnLq+VMv5AMwTuui85v4kO4njJ76tRhQU4rLkf9rs7O8 +zBqApEvfS4cBznsrMR3mF3TObcB5wj6XQH1kVzAcgo+JtTYq1fyuBX5gTtG62BmHWzI 8jHqqnTMCoQxVEcs3Gl4em2jEyMY8yQhlCjcoKW6R4YEqO1OLLmLPxXYQAkyIa25fiW4 bFTg== X-Gm-Message-State: AOAM532xyyf0dFPq6WxtlBkOg5eWjSoqaTgCFIIcQNwXsgkLQuy2jWPU UxwbJA3tdUFG5RgfqE9uJSOa3g== X-Google-Smtp-Source: ABdhPJwJJUYuSykKTjU6Cuc1f55tmKxp3pv29O0QqN1rqZlo1paLjwV9+OEnvSdoG2dTX2lbqowMew== X-Received: by 2002:a63:eb02:0:b0:370:41e4:6ae6 with SMTP id t2-20020a63eb02000000b0037041e46ae6mr21853093pgh.229.1645580572314; Tue, 22 Feb 2022 17:42:52 -0800 (PST) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id h1sm10706771pgr.7.2022.02.22.17.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 17:42:51 -0800 (PST) Date: Tue, 22 Feb 2022 17:42:51 -0800 (PST) X-Google-Original-Date: Tue, 22 Feb 2022 16:26:12 PST (-0800) Subject: Re: [PATCH V5 16/21] riscv: compat: vdso: Add rv32 VDSO base code implementation In-Reply-To: <20220201150545.1512822-17-guoren@kernel.org> CC: guoren@kernel.org, Arnd Bergmann , anup@brainfault.org, Greg KH , liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org, wangjunqiang@iscas.ac.cn, Christoph Hellwig , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-csky@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-parisc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, guoren@linux.alibaba.com From: Palmer Dabbelt To: guoren@kernel.org Message-ID: Mime-Version: 1.0 (MHng) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220222_174253_761103_70D65227 X-CRM114-Status: GOOD ( 32.65 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 01 Feb 2022 07:05:40 PST (-0800), guoren@kernel.org wrote: > From: Guo Ren > > There is no vgettimeofday supported in rv32 that makes simple to > generate rv32 vdso code which only needs riscv64 compiler. Other > architectures need change compiler or -m (machine parameter) to > support vdso32 compiling. If rv32 support vgettimeofday (which > cause C compile) in future, we would add CROSS_COMPILE to support > that makes more requirement on compiler enviornment. IMO this is the wrong way to go, as there's some subtle differences between elf32 and elf64 (the .gnu.hash layout, for example). I'm kind of surprised userspace tolerates this sort of thing at all, but given how easy it is to target rv32 from all toolchains (we don't need libraries here, so just -march should do it) I don't think it's worth chasing around the likely long-tail issues that will arise. > linux-rv64/arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg: > file format elf64-littleriscv > > Disassembly of section .text: > > 0000000000000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 000000000000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 0000000000000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > linux-rv32/arch/riscv/kernel/vdso/vdso.so.dbg: > file format elf32-littleriscv > > Disassembly of section .text: > > 00000800 <__vdso_rt_sigreturn>: > 800: 08b00893 li a7,139 > 804: 00000073 ecall > 808: 0000 unimp > ... > > 0000080c <__vdso_getcpu>: > 80c: 0a800893 li a7,168 > 810: 00000073 ecall > 814: 8082 ret > ... > > 00000818 <__vdso_flush_icache>: > 818: 10300893 li a7,259 > 81c: 00000073 ecall > 820: 8082 ret > > Finally, reuse all *.S from vdso in compat_vdso that makes > implementation clear and readable. > > Signed-off-by: Guo Ren > Signed-off-by: Guo Ren > Cc: Arnd Bergmann > Cc: Palmer Dabbelt > --- > arch/riscv/Makefile | 5 ++ > arch/riscv/include/asm/vdso.h | 9 +++ > arch/riscv/kernel/Makefile | 1 + > arch/riscv/kernel/compat_vdso/.gitignore | 2 + > arch/riscv/kernel/compat_vdso/Makefile | 68 +++++++++++++++++++ > arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +++ > .../kernel/compat_vdso/compat_vdso.lds.S | 3 + > arch/riscv/kernel/compat_vdso/flush_icache.S | 3 + > .../compat_vdso/gen_compat_vdso_offsets.sh | 5 ++ > arch/riscv/kernel/compat_vdso/getcpu.S | 3 + > arch/riscv/kernel/compat_vdso/note.S | 3 + > arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 + > arch/riscv/kernel/vdso/vdso.S | 6 +- > 13 files changed, 118 insertions(+), 1 deletion(-) > create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore > create mode 100644 arch/riscv/kernel/compat_vdso/Makefile > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S > create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S > create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S > create mode 100644 arch/riscv/kernel/compat_vdso/note.S > create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > index a02e588c4947..f73d50552e09 100644 > --- a/arch/riscv/Makefile > +++ b/arch/riscv/Makefile > @@ -106,12 +106,17 @@ libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a > PHONY += vdso_install > vdso_install: > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@ > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso $@) > > ifeq ($(KBUILD_EXTMOD),) > ifeq ($(CONFIG_MMU),y) > prepare: vdso_prepare > vdso_prepare: prepare0 > $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h > + $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ > + $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h) > + > endif > endif > > diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h > index bc6f75f3a199..af981426fe0f 100644 > --- a/arch/riscv/include/asm/vdso.h > +++ b/arch/riscv/include/asm/vdso.h > @@ -21,6 +21,15 @@ > > #define VDSO_SYMBOL(base, name) \ > (void __user *)((unsigned long)(base) + __vdso_##name##_offset) > + > +#ifdef CONFIG_COMPAT > +#include > + > +#define COMPAT_VDSO_SYMBOL(base, name) \ > + (void __user *)((unsigned long)(base) + compat__vdso_##name##_offset) > + > +#endif /* CONFIG_COMPAT */ > + > #endif /* !__ASSEMBLY__ */ > > #endif /* CONFIG_MMU */ > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index 954dc7043ad2..88e79f481c21 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -67,3 +67,4 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o > > obj-$(CONFIG_EFI) += efi.o > obj-$(CONFIG_COMPAT) += compat_syscall_table.o > +obj-$(CONFIG_COMPAT) += compat_vdso/ > diff --git a/arch/riscv/kernel/compat_vdso/.gitignore b/arch/riscv/kernel/compat_vdso/.gitignore > new file mode 100644 > index 000000000000..19d83d846c1e > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/.gitignore > @@ -0,0 +1,2 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +compat_vdso.lds > diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile > new file mode 100644 > index 000000000000..7bbbbf94307f > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/Makefile > @@ -0,0 +1,68 @@ > +# SPDX-License-Identifier: GPL-2.0-only > + > +# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before > +# the inclusion of generic Makefile. > +ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT > +include $(srctree)/lib/vdso/Makefile > +# Symbols present in the compat_vdso > +compat_vdso-syms = rt_sigreturn > +compat_vdso-syms += getcpu > +compat_vdso-syms += flush_icache > + > +# Files to link into the compat_vdso > +obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o > + > +ccflags-y := -fno-stack-protector > + > +# Build rules > +targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds > +obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso)) > + > +obj-y += compat_vdso.o > +CPPFLAGS_compat_vdso.lds += -P -C -U$(ARCH) > + > +# Disable profiling and instrumentation for VDSO code > +GCOV_PROFILE := n > +KCOV_INSTRUMENT := n > +KASAN_SANITIZE := n > +UBSAN_SANITIZE := n > + > +# Force dependency > +$(obj)/compat_vdso.o: $(obj)/compat_vdso.so > + > +# link rule for the .so file, .lds has to be first > +$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE > + $(call if_changed,compat_vdsold) > +LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \ > + --build-id=sha1 --hash-style=both --eh-frame-hdr > + > +# strip rule for the .so file > +$(obj)/%.so: OBJCOPYFLAGS := -S > +$(obj)/%.so: $(obj)/%.so.dbg FORCE > + $(call if_changed,objcopy) > + > +# Generate VDSO offsets using helper script > +gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh > +quiet_cmd_compat_vdsosym = VDSOSYM $@ > + cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@ > + > +include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE > + $(call if_changed,compat_vdsosym) > + > +# actual build commands > +# The DSO images are built using a special linker script > +# Make sure only to export the intended __compat_vdso_xxx symbol offsets. > +quiet_cmd_compat_vdsold = VDSOLD $@ > + cmd_compat_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \ > + $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \ > + rm $@.tmp > + > +# install commands for the unstripped file > +quiet_cmd_compat_vdso_install = INSTALL $@ > + cmd_compat_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/compat_vdso/$@ > + > +compat_vdso.so: $(obj)/compat_vdso.so.dbg > + @mkdir -p $(MODLIB)/compat_vdso > + $(call cmd,compat_vdso_install) > + > +compat_vdso_install: compat_vdso.so > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.S b/arch/riscv/kernel/compat_vdso/compat_vdso.S > new file mode 100644 > index 000000000000..fea4a8b0c45d > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.S > @@ -0,0 +1,8 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#define vdso_start compat_vdso_start > +#define vdso_end compat_vdso_end > + > +#define __VDSO_PATH "arch/riscv/kernel/compat_vdso/compat_vdso.so" > + > +#include <../vdso/vdso.S> > diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > new file mode 100644 > index 000000000000..02a9ec5dc7f6 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/vdso.lds.S> > diff --git a/arch/riscv/kernel/compat_vdso/flush_icache.S b/arch/riscv/kernel/compat_vdso/flush_icache.S > new file mode 100644 > index 000000000000..88e21a84a974 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/flush_icache.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/flush_icache.S> > diff --git a/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > new file mode 100755 > index 000000000000..8ac070c783b3 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh > @@ -0,0 +1,5 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0 > + > +LC_ALL=C > +sed -n -e 's/^[0]\+\(0[0-9a-fA-F]*\) . \(__vdso_[a-zA-Z0-9_]*\)$/\#define compat\2_offset\t0x\1/p' > diff --git a/arch/riscv/kernel/compat_vdso/getcpu.S b/arch/riscv/kernel/compat_vdso/getcpu.S > new file mode 100644 > index 000000000000..946449a15a94 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/getcpu.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/getcpu.S> > diff --git a/arch/riscv/kernel/compat_vdso/note.S b/arch/riscv/kernel/compat_vdso/note.S > new file mode 100644 > index 000000000000..67c50898b8e5 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/note.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/note.S> > diff --git a/arch/riscv/kernel/compat_vdso/rt_sigreturn.S b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > new file mode 100644 > index 000000000000..f4c98f18c053 > --- /dev/null > +++ b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S > @@ -0,0 +1,3 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#include <../vdso/rt_sigreturn.S> > diff --git a/arch/riscv/kernel/vdso/vdso.S b/arch/riscv/kernel/vdso/vdso.S > index df222245be05..83f1c899e8d8 100644 > --- a/arch/riscv/kernel/vdso/vdso.S > +++ b/arch/riscv/kernel/vdso/vdso.S > @@ -7,12 +7,16 @@ > #include > #include > > +#ifndef __VDSO_PATH > +#define __VDSO_PATH "arch/riscv/kernel/vdso/vdso.so" > +#endif > + > __PAGE_ALIGNED_DATA > > .globl vdso_start, vdso_end > .balign PAGE_SIZE > vdso_start: > - .incbin "arch/riscv/kernel/vdso/vdso.so" > + .incbin __VDSO_PATH > .balign PAGE_SIZE > vdso_end: _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel