From nobody Tue Sep 16 02:19:42 2025 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 795E3C61DB3 for ; Mon, 9 Jan 2023 08:09:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233305AbjAIIJq (ORCPT ); Mon, 9 Jan 2023 03:09:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbjAIIJm (ORCPT ); Mon, 9 Jan 2023 03:09:42 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B62A0BA6 for ; Mon, 9 Jan 2023 00:09:40 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30989Pl9026641; Mon, 9 Jan 2023 09:09:25 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Sven Schnelle , Willy Tarreau Subject: [PATCH 1/4] nolibc: add support for s390 Date: Mon, 9 Jan 2023 09:09:07 +0100 Message-Id: <20230109080910.26594-2-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109080910.26594-1-w@1wt.eu> References: <20230109080910.26594-1-w@1wt.eu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Sven Schnelle Use arch-x86_64 as a template. Not really different, but we have our own mmap syscall which takes a structure instead of discrete arguments. Signed-off-by: Sven Schnelle Acked-by: Heiko Carstens Signed-off-by: Willy Tarreau --- tools/include/nolibc/arch-s390.h | 222 +++++++++++++++++++++++++++++++ tools/include/nolibc/arch.h | 2 + tools/include/nolibc/sys.h | 2 + 3 files changed, 226 insertions(+) create mode 100644 tools/include/nolibc/arch-s390.h diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h new file mode 100644 index 000000000000..76bc8fdaf922 --- /dev/null +++ b/tools/include/nolibc/arch-s390.h @@ -0,0 +1,222 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * s390 specific definitions for NOLIBC + */ + +#ifndef _NOLIBC_ARCH_S390_H +#define _NOLIBC_ARCH_S390_H +#include + +/* O_* macros for fcntl/open are architecture-specific */ +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 +#define O_CREAT 0x40 +#define O_EXCL 0x80 +#define O_NOCTTY 0x100 +#define O_TRUNC 0x200 +#define O_APPEND 0x400 +#define O_NONBLOCK 0x800 +#define O_DIRECTORY 0x10000 + +/* The struct returned by the stat() syscall, equivalent to stat64(). The + * syscall returns 116 bytes and stops in the middle of __unused. + */ + +struct sys_stat_struct { + unsigned long st_dev; + unsigned long st_ino; + unsigned long st_nlink; + unsigned int st_mode; + unsigned int st_uid; + unsigned int st_gid; + unsigned int __pad1; + unsigned long st_rdev; + unsigned long st_size; + unsigned long st_atime; + unsigned long st_atime_nsec; + unsigned long st_mtime; + unsigned long st_mtime_nsec; + unsigned long st_ctime; + unsigned long st_ctime_nsec; + unsigned long st_blksize; + long st_blocks; + unsigned long __unused[3]; +}; + +/* Syscalls for s390: + * - registers are 64-bit + * - syscall number is passed in r1 + * - arguments are in r2-r7 + * - the system call is performed by calling the svc instruction + * - syscall return value is in r2 + * - r1 and r2 are clobbered, others are preserved. + * + * Link s390 ABI: https://github.com/IBM/s390x-abi + * + */ + +#define my_syscall0(num) \ +({ \ + register long _num __asm__ ("1") =3D (num); \ + register long _rc __asm__ ("2"); \ + \ + __asm__ volatile ( \ + "svc 0\n" \ + : "=3Dd"(_rc) \ + : "d"(_num) \ + : "memory", "cc" \ + ); \ + _rc; \ +}) + +#define my_syscall1(num, arg1) \ +({ \ + register long _num __asm__ ("1") =3D (num); \ + register long _arg1 __asm__ ("2") =3D (long)(arg1); \ + \ + __asm__ volatile ( \ + "svc 0\n" \ + : "+d"(_arg1) \ + : "d"(_num) \ + : "memory", "cc" \ + ); \ + _arg1; \ +}) + +#define my_syscall2(num, arg1, arg2) \ +({ \ + register long _num __asm__ ("1") =3D (num); \ + register long _arg1 __asm__ ("2") =3D (long)(arg1); \ + register long _arg2 __asm__ ("3") =3D (long)(arg2); \ + \ + __asm__ volatile ( \ + "svc 0\n" \ + : "+d"(_arg1) \ + : "d"(_arg2), "d"(_num) \ + : "memory", "cc" \ + ); \ + _arg1; \ +}) + +#define my_syscall3(num, arg1, arg2, arg3) \ +({ \ + register long _num __asm__ ("1") =3D (num); \ + register long _arg1 __asm__ ("2") =3D (long)(arg1); \ + register long _arg2 __asm__ ("3") =3D (long)(arg2); \ + register long _arg3 __asm__ ("4") =3D (long)(arg3); \ + \ + __asm__ volatile ( \ + "svc 0\n" \ + : "+d"(_arg1) \ + : "d"(_arg2), "d"(_arg3), "d"(_num) \ + : "memory", "cc" \ + ); \ + _arg1; \ +}) + +#define my_syscall4(num, arg1, arg2, arg3, arg4) \ +({ \ + register long _num __asm__ ("1") =3D (num); \ + register long _arg1 __asm__ ("2") =3D (long)(arg1); \ + register long _arg2 __asm__ ("3") =3D (long)(arg2); \ + register long _arg3 __asm__ ("4") =3D (long)(arg3); \ + register long _arg4 __asm__ ("5") =3D (long)(arg4); \ + \ + __asm__ volatile ( \ + "svc 0\n" \ + : "+d"(_arg1) \ + : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_num) \ + : "memory", "cc" \ + ); \ + _arg1; \ +}) + +#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ +({ \ + register long _num __asm__ ("1") =3D (num); \ + register long _arg1 __asm__ ("2") =3D (long)(arg1); \ + register long _arg2 __asm__ ("3") =3D (long)(arg2); \ + register long _arg3 __asm__ ("4") =3D (long)(arg3); \ + register long _arg4 __asm__ ("5") =3D (long)(arg4); \ + register long _arg5 __asm__ ("6") =3D (long)(arg5); \ + \ + __asm__ volatile ( \ + "svc 0\n" \ + : "+d"(_arg1) \ + : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \ + "d"(_num) \ + : "memory", "cc" \ + ); \ + _arg1; \ +}) + +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ +({ \ + register long _num __asm__ ("1") =3D (num); \ + register long _arg1 __asm__ ("2") =3D (long)(arg1); \ + register long _arg2 __asm__ ("3") =3D (long)(arg2); \ + register long _arg3 __asm__ ("4") =3D (long)(arg3); \ + register long _arg4 __asm__ ("5") =3D (long)(arg4); \ + register long _arg5 __asm__ ("6") =3D (long)(arg5); \ + register long _arg6 __asm__ ("7") =3D (long)(arg6); \ + \ + __asm__ volatile ( \ + "svc 0\n" \ + : "+d"(_arg1) \ + : "d"(_arg2), "d"(_arg3), "d"(_arg4), "d"(_arg5), \ + "d"(_arg6), "d"(_num) \ + : "memory", "cc" \ + ); \ + _arg1; \ +}) + +/* startup code */ +__asm__ (".section .text\n" + ".weak _start\n" + "_start:\n" + "lg %r2,0(%r15)\n" /* argument count */ + "la %r3,8(%r15)\n" /* argument pointers */ + + "xgr %r0,%r0\n" /* r0 will be our NULL value */ + /* search for envp */ + "lgr %r4,%r3\n" /* start at argv */ + "0:\n" + "clg %r0,0(%r4)\n" /* entry zero? */ + "la %r4,8(%r4)\n" /* advance pointer */ + "jnz 0b\n" /* no -> test next pointer */ + /* yes -> r4 now contains start of envp */ + + "aghi %r15,-160\n" /* allocate new stackframe */ + "xc 0(8,%r15),0(%r15)\n" /* clear backchain */ + "brasl %r14,main\n" /* ret value of main is arg to exit */ + "lghi %r1,1\n" /* __NR_exit */ + "svc 0\n" + ""); + +struct s390_mmap_arg_struct { + unsigned long addr; + unsigned long len; + unsigned long prot; + unsigned long flags; + unsigned long fd; + unsigned long offset; +}; + +static __attribute__((unused)) +void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, + off_t offset) +{ + struct s390_mmap_arg_struct args =3D { + .addr =3D (unsigned long)addr, + .len =3D (unsigned long)length, + .prot =3D prot, + .flags =3D flags, + .fd =3D fd, + .offset =3D (unsigned long)offset + }; + + return (void *)my_syscall1(__NR_mmap, &args); +} +#define sys_mmap sys_mmap +#endif // _NOLIBC_ARCH_S390_H diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h index 4c6992321b0d..78b067a4fa47 100644 --- a/tools/include/nolibc/arch.h +++ b/tools/include/nolibc/arch.h @@ -27,6 +27,8 @@ #include "arch-mips.h" #elif defined(__riscv) #include "arch-riscv.h" +#elif defined(__s390x__) +#include "arch-s390.h" #endif =20 #endif /* _NOLIBC_ARCH_H */ diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 78473d34e27c..a42d7c405bdc 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -686,6 +686,7 @@ int mknod(const char *path, mode_t mode, dev_t dev) #define MAP_FAILED ((void *)-1) #endif =20 +#ifndef sys_mmap static __attribute__((unused)) void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) @@ -707,6 +708,7 @@ void *sys_mmap(void *addr, size_t length, int prot, int= flags, int fd, return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset); #endif } +#endif =20 static __attribute__((unused)) void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t o= ffset) --=20 2.17.5 From nobody Tue Sep 16 02:19:42 2025 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 36657C54EBD for ; Mon, 9 Jan 2023 08:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236299AbjAIIKC (ORCPT ); Mon, 9 Jan 2023 03:10:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233986AbjAIIJt (ORCPT ); Mon, 9 Jan 2023 03:09:49 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 139AE5FBA for ; Mon, 9 Jan 2023 00:09:47 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30989Phd026642; Mon, 9 Jan 2023 09:09:25 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Sven Schnelle , Willy Tarreau Subject: [PATCH 2/4] selftests/nolibc: add s390 support Date: Mon, 9 Jan 2023 09:09:08 +0100 Message-Id: <20230109080910.26594-3-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109080910.26594-1-w@1wt.eu> References: <20230109080910.26594-1-w@1wt.eu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Sven Schnelle Signed-off-by: Sven Schnelle Acked-by: Heiko Carstens Signed-off-by: Willy Tarreau --- tools/testing/selftests/nolibc/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 22f1e1d73fa8..2bf613ee363d 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -19,6 +19,7 @@ IMAGE_arm64 =3D arch/arm64/boot/Image IMAGE_arm =3D arch/arm/boot/zImage IMAGE_mips =3D vmlinuz IMAGE_riscv =3D arch/riscv/boot/Image +IMAGE_s390 =3D arch/s390/boot/bzImage IMAGE =3D $(IMAGE_$(ARCH)) IMAGE_NAME =3D $(notdir $(IMAGE)) =20 @@ -29,6 +30,7 @@ DEFCONFIG_arm64 =3D defconfig DEFCONFIG_arm =3D multi_v7_defconfig DEFCONFIG_mips =3D malta_defconfig DEFCONFIG_riscv =3D defconfig +DEFCONFIG_s390 =3D defconfig DEFCONFIG =3D $(DEFCONFIG_$(ARCH)) =20 # optional tests to run (default =3D all) @@ -41,6 +43,7 @@ QEMU_ARCH_arm64 =3D aarch64 QEMU_ARCH_arm =3D arm QEMU_ARCH_mips =3D mipsel # works with malta_defconfig QEMU_ARCH_riscv =3D riscv64 +QEMU_ARCH_s390 =3D s390x QEMU_ARCH =3D $(QEMU_ARCH_$(ARCH)) =20 # QEMU_ARGS : some arch-specific args to pass to qemu @@ -50,6 +53,7 @@ QEMU_ARGS_arm64 =3D -M virt -cpu cortex-a53 -append "pa= nic=3D-1 $(TEST:%=3DNOLIBC_TE QEMU_ARGS_arm =3D -M virt -append "panic=3D-1 $(TEST:%=3DNOLIBC_TEST= =3D%)" QEMU_ARGS_mips =3D -M malta -append "panic=3D-1 $(TEST:%=3DNOLIBC_TEST= =3D%)" QEMU_ARGS_riscv =3D -M virt -append "console=3DttyS0 panic=3D-1 $(TEST:%= =3DNOLIBC_TEST=3D%)" +QEMU_ARGS_s390 =3D -M s390-ccw-virtio -m 1G -append "console=3DttyS0 pa= nic=3D-1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS =3D $(QEMU_ARGS_$(ARCH)) =20 # OUTPUT is only set when run from the main makefile, otherwise @@ -62,7 +66,8 @@ else Q=3D@ endif =20 -CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables +CFLAGS_s390 =3D -m64 +CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables $(CFLAGS_$(ARC= H)) LDFLAGS :=3D -s =20 help: --=20 2.17.5 From nobody Tue Sep 16 02:19:42 2025 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 82AFCC5479D for ; Mon, 9 Jan 2023 08:11:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236573AbjAIIKj (ORCPT ); Mon, 9 Jan 2023 03:10:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236574AbjAIIKR (ORCPT ); Mon, 9 Jan 2023 03:10:17 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C92B513F10 for ; Mon, 9 Jan 2023 00:10:02 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30989Qe6026643; Mon, 9 Jan 2023 09:09:26 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Sven Schnelle , Willy Tarreau Subject: [PATCH 3/4] rcutorture: add support for s390 Date: Mon, 9 Jan 2023 09:09:09 +0100 Message-Id: <20230109080910.26594-4-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109080910.26594-1-w@1wt.eu> References: <20230109080910.26594-1-w@1wt.eu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Sven Schnelle Add the required values to identify_qemu() and identify_bootimage(). Signed-off-by: Sven Schnelle Acked-by: Heiko Carstens Signed-off-by: Willy Tarreau --- tools/testing/selftests/rcutorture/bin/functions.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/rcutorture/bin/functions.sh b/tools/te= sting/selftests/rcutorture/bin/functions.sh index 66d0414d8e4b..b52d5069563c 100644 --- a/tools/testing/selftests/rcutorture/bin/functions.sh +++ b/tools/testing/selftests/rcutorture/bin/functions.sh @@ -159,6 +159,9 @@ identify_boot_image () { qemu-system-aarch64) echo arch/arm64/boot/Image ;; + qemu-system-s390x) + echo arch/s390/boot/bzImage + ;; *) echo vmlinux ;; @@ -184,6 +187,9 @@ identify_qemu () { elif echo $u | grep -q aarch64 then echo qemu-system-aarch64 + elif echo $u | grep -q 'IBM S/390' + then + echo qemu-system-s390x elif uname -a | grep -q ppc64 then echo qemu-system-ppc64 --=20 2.17.5 From nobody Tue Sep 16 02:19:42 2025 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 207DCC54EBD for ; Mon, 9 Jan 2023 08:11:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236374AbjAIILK (ORCPT ); Mon, 9 Jan 2023 03:11:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236623AbjAIIK0 (ORCPT ); Mon, 9 Jan 2023 03:10:26 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6426B13F3A for ; Mon, 9 Jan 2023 00:10:05 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30989Q1r026646; Mon, 9 Jan 2023 09:09:26 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Sven Schnelle , Willy Tarreau Subject: [PATCH 4/4] rcutorture: build initrd for rcutorture with nolibc Date: Mon, 9 Jan 2023 09:09:10 +0100 Message-Id: <20230109080910.26594-5-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109080910.26594-1-w@1wt.eu> References: <20230109080910.26594-1-w@1wt.eu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Sven Schnelle This reduces the size of init from ~600KB to ~1KB. Signed-off-by: Sven Schnelle Acked-by: Heiko Carstens Signed-off-by: Willy Tarreau --- tools/testing/selftests/rcutorture/bin/mkinitrd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/rcutorture/bin/mkinitrd.sh b/tools/tes= ting/selftests/rcutorture/bin/mkinitrd.sh index 70d62fd0d31d..71f0dfbb2a6d 100755 --- a/tools/testing/selftests/rcutorture/bin/mkinitrd.sh +++ b/tools/testing/selftests/rcutorture/bin/mkinitrd.sh @@ -64,7 +64,7 @@ ___EOF___ # build using nolibc on supported archs (smaller executable) and fall # back to regular glibc on other ones. if echo -e "#if __x86_64__||__i386__||__i486__||__i586__||__i686__" \ - "||__ARM_EABI__||__aarch64__\nyes\n#endif" \ + "||__ARM_EABI__||__aarch64__||__s390x__\nyes\n#endif" \ | ${CROSS_COMPILE}gcc -E -nostdlib -xc - \ | grep -q '^yes'; then # architecture supported by nolibc --=20 2.17.5