From patchwork Sat Apr 15 21:28:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 674299 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 C8820C77B70 for ; Sat, 15 Apr 2023 21:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbjDOV2x (ORCPT ); Sat, 15 Apr 2023 17:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbjDOV2w (ORCPT ); Sat, 15 Apr 2023 17:28:52 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60F2326BB; Sat, 15 Apr 2023 14:28:50 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1681594128; bh=CZhCYpNg6uTpr8ZWTgKMWLkEe3rYuevwpfUwwonzaWk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PcywB2y0z0iNDHNCs9VywljvSdQG2Nf16KN2ym/OCk8ABkmfoXUrSyYL1Z20J2x0W UuHvT+4bIO6HElmv37TvJLz7TOXcsI3smT6QL7WBhOGvn8SdFhOgSU6B7sJZyA6SVH mPRDfe4sL8wngoEIoUcMgaOgHZukj82JcUwELmeE= Date: Sat, 15 Apr 2023 23:28:47 +0200 Subject: [PATCH 1/2] tools/nolibc: s390: provide custom implementation for sys_fork MIME-Version: 1.0 Message-Id: <20230415-nolibc-fork-v1-1-9747c73651c5@weissschuh.net> References: <20230415-nolibc-fork-v1-0-9747c73651c5@weissschuh.net> In-Reply-To: <20230415-nolibc-fork-v1-0-9747c73651c5@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1681594127; l=1606; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=CZhCYpNg6uTpr8ZWTgKMWLkEe3rYuevwpfUwwonzaWk=; b=hD1G6hgf9pqOmGf4Ntf0OGWFeXHPFB9vAqPAyQNtEqtgOf52tpnC/4SnTJ8toLNxHPC4OitDO xW6fgOK8tnlA2shaegJnpmX4hiVvWwcnQKooqvRjqsZJ/DCFR+RsLnw X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org On s390 the first two arguments to the clone() syscall are swapped, as documented in clone(2). Signed-off-by: Thomas Weißschuh Acked-by: Sven Schnelle --- tools/include/nolibc/arch-s390.h | 8 ++++++++ tools/include/nolibc/sys.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s390.h index 6b0e54ed543d..db4ea51a4dbb 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -5,6 +5,7 @@ #ifndef _NOLIBC_ARCH_S390_H #define _NOLIBC_ARCH_S390_H +#include #include /* The struct returned by the stat() syscall, equivalent to stat64(). The @@ -223,4 +224,11 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, return (void *)my_syscall1(__NR_mmap, &args); } #define sys_mmap sys_mmap + +static __attribute__((unused)) +pid_t sys_fork(void) +{ + return my_syscall5(__NR_clone, 0, SIGCHLD, 0, 0, 0); +} +#define sys_fork sys_fork #endif // _NOLIBC_ARCH_S390_H diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index bea9760dbd16..f5a450153a63 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -336,6 +336,7 @@ void exit(int status) * pid_t fork(void); */ +#ifndef sys_fork static __attribute__((unused)) pid_t sys_fork(void) { @@ -351,6 +352,7 @@ pid_t sys_fork(void) #error Neither __NR_clone nor __NR_fork defined, cannot implement sys_fork() #endif } +#endif static __attribute__((unused)) pid_t fork(void) From patchwork Sat Apr 15 21:28:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 673523 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 E9E69C77B77 for ; Sat, 15 Apr 2023 21:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbjDOV2x (ORCPT ); Sat, 15 Apr 2023 17:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjDOV2w (ORCPT ); Sat, 15 Apr 2023 17:28:52 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 615AA30C3; Sat, 15 Apr 2023 14:28:50 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1681594128; bh=Serav5NsrGD7AG0O6Mn+YtgEHgPcj/qioSXyB4VmbSc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Snq8rnmGEhznB84w1h1GMX2CCLnPQiQYZsr7CzHsiLIF0csWLWmOE5ELA15vljlvC s46bmjPStN3vU9wE2zoXbsvn8jXtSdqRvPv8bz/7Wzn1It6pIsB8hDZSumyA7CR067 HSfD1ctfwSw8qR5Krd7KchDszRkk2CAawuIgB+7g= Date: Sat, 15 Apr 2023 23:28:48 +0200 Subject: [PATCH 2/2] tools/nolibc: add testcase for fork()/waitpid() MIME-Version: 1.0 Message-Id: <20230415-nolibc-fork-v1-2-9747c73651c5@weissschuh.net> References: <20230415-nolibc-fork-v1-0-9747c73651c5@weissschuh.net> In-Reply-To: <20230415-nolibc-fork-v1-0-9747c73651c5@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1681594127; l=1787; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Serav5NsrGD7AG0O6Mn+YtgEHgPcj/qioSXyB4VmbSc=; b=CpgzObVEN4lDAf4txDLUIMfLrZ7bQE/nT95ucHYkuVj5n26guKfZ+O3iP0qg8Ub9+Ilj6WS7g cpuzD12N0V7C5TkrMonxcca/bN3j+hm4BHn81dgd4x4FEoZOr1noMTW X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org On s390 the arguments to clone() which is used by fork() are different than other archs. Make sure everything works correctly. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 888da60eb5ba..d294338cf141 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -474,6 +474,25 @@ static int test_getpagesize(void) return !c; } +static int test_fork(void) +{ + int status; + pid_t pid = fork(); + + switch (pid) { + case -1: + return 1; + + case 0: + exit(123); + + default: + pid = waitpid(pid, &status, 0); + + return pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 123; + } +} + /* Run syscall tests between IDs and . * Return 0 on success, non-zero on failure. */ @@ -530,6 +549,7 @@ int run_syscall(int min, int max) CASE_TEST(dup3_0); tmp = dup3(0, 100, 0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; CASE_TEST(dup3_m1); tmp = dup3(-1, 100, 0); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break; CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = "/", [1] = NULL }, NULL), -1, EACCES); break; + CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break; CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break; CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break; CASE_TEST(gettimeofday_null); EXPECT_SYSZR(1, gettimeofday(NULL, NULL)); break;