From nobody Sat Oct 11 12:07:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB17629B8F1; Tue, 10 Jun 2025 12:42:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559351; cv=none; b=Cx0zB6BTp0Fzf22spqCjFlDxLnMMI1OxbNJxomw5UdbRHGym2LvRz3afqXZKoYVxqCOt3IiGCMTlHYd2VBC59c9Oo7TOzRDYkwxfxT/tqHX3aT7gUNeORNjJnS20C3V0QRap/xVpQ0GDujzfVNMc7wE2yAZl1IWLvOHzNrpfT1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559351; c=relaxed/simple; bh=6UL7PmSArRGjWy99kORj1lgNcSgJ/MyAd1s1wJFb20E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XDziKzZVz2G9HLTQWNmnT+Bv0hnFpRMSY0F8ZWEEl2jOAVb25BehRdJRFi58zcwKrZsPG7F09D79476o1JdgJ/MlZ9o7w8vW314gbIhTx4d9j3lethgsVxi6y6OL1fBXOcC2qog+jYUjfqv7UMYOf9egH++u6d99/l+zz0PUxHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NF1TBFbX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NF1TBFbX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC25CC4CEF1; Tue, 10 Jun 2025 12:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749559351; bh=6UL7PmSArRGjWy99kORj1lgNcSgJ/MyAd1s1wJFb20E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NF1TBFbXITRTtLJbw6ype55O031EKcr+gASqj38J7Df9hxfhy7rjefT55STR3CoRM iGZdsAaidWU3Ny5lxDIhPQZgn8eGq2oPAkW5uE3/jEjtk2ldX/mDefww8IIDtSPHaG XCqM7elV6ImN3GpAXGhi/jA4idmNOoQ1a4//ASqzg2pGmYx88VHD4MvVVy3+LUlyez AzU4mWHgrXF/jpZqJoT7aKpK1d9tb/9e7OPfeomm0aRphCfOcAPnlJ4UTShlakVztA /+Cj/MGVlZJlu15aWVgSWiqRj3pAC0if2nlW/PWv6K49XfKWL8a8XeMamXm/IgQaKD PRDmP2tBAVN1g== From: Mark Brown Date: Tue, 10 Jun 2025 13:29:44 +0100 Subject: [PATCH v2 1/4] tools/nolibc: Replace ifdef with if defined() in sys.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250610-arm64-gcs-vfork-exit-v2-1-929443dfcf82@kernel.org> References: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> In-Reply-To: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> To: Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christian Brauner , Catalin Marinas , Will Deacon , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=5318; i=broonie@kernel.org; h=from:subject:message-id; bh=6UL7PmSArRGjWy99kORj1lgNcSgJ/MyAd1s1wJFb20E=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBoSCguIPphodbvD/cIpCx0ME4glp1n+6d6CjV3o71t 8h+1jiyJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCaEgoLgAKCRAk1otyXVSH0M2oB/ 9fmmNzWMCiCTgAJhiEcjOSaZbtIX5XYMlHbVyWdrPeTa3Bzh3qpgoFUnauFIPkmiY+Z9wip8RS7N+j iImW+jgl479RO0PyID4cKzummrByynJgTyCMI4TSxelaURYaf82EiVEkzFbM82U+Qp7vp/H7t7/TQ+ 9ZM09NQQJLXon1mAHBV5LV0+28DLQsR2zi4Jh5ZQ6DDXkBap37JRlJHKnbcaZmz+WOhULg5Rqh8uK9 WbUG5ndvCDx0d8jxbZ/4jB0NoTG9valUIfkn/5eONEF/1E538FlmARo9bnPlQZ7dSPjO210sdPiYsl quXOAoLQxe6JMsPVnQFHJbm5JAVl8o X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Thomas has requested that if defined() be used in place of ifdef but currently ifdef is used consistently in sys.h. Update all the instances of ifdef to if defined(). Suggested-by: Thomas Wei=C3=9Fschuh Signed-off-by: Mark Brown --- tools/include/nolibc/sys.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 9556c69a6ae1..aabac97a7fb0 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -139,7 +139,7 @@ int chdir(const char *path) static __attribute__((unused)) int sys_chmod(const char *path, mode_t mode) { -#ifdef __NR_fchmodat +#if defined(__NR_fchmodat) return my_syscall4(__NR_fchmodat, AT_FDCWD, path, mode, 0); #elif defined(__NR_chmod) return my_syscall2(__NR_chmod, path, mode); @@ -162,7 +162,7 @@ int chmod(const char *path, mode_t mode) static __attribute__((unused)) int sys_chown(const char *path, uid_t owner, gid_t group) { -#ifdef __NR_fchownat +#if defined(__NR_fchownat) return my_syscall5(__NR_fchownat, AT_FDCWD, path, owner, group, 0); #elif defined(__NR_chown) return my_syscall3(__NR_chown, path, owner, group); @@ -236,7 +236,7 @@ int dup(int fd) static __attribute__((unused)) int sys_dup2(int old, int new) { -#ifdef __NR_dup3 +#if defined(__NR_dup3) return my_syscall3(__NR_dup3, old, new, 0); #elif defined(__NR_dup2) return my_syscall2(__NR_dup2, old, new); @@ -256,7 +256,7 @@ int dup2(int old, int new) * int dup3(int old, int new, int flags); */ =20 -#ifdef __NR_dup3 +#if defined(__NR_dup3) static __attribute__((unused)) int sys_dup3(int old, int new, int flags) { @@ -320,7 +320,7 @@ void exit(int status) static __attribute__((unused)) pid_t sys_fork(void) { -#ifdef __NR_clone +#if defined(__NR_clone) /* note: some archs only have clone() and not fork(). Different archs * have a different API, but most archs have the flags on first arg and * will not use the rest with no other flag. @@ -382,7 +382,7 @@ int getdents64(int fd, struct linux_dirent64 *dirp, int= count) static __attribute__((unused)) uid_t sys_geteuid(void) { -#ifdef __NR_geteuid32 +#if defined(__NR_geteuid32) return my_syscall0(__NR_geteuid32); #else return my_syscall0(__NR_geteuid); @@ -500,7 +500,7 @@ int getpagesize(void) static __attribute__((unused)) uid_t sys_getuid(void) { -#ifdef __NR_getuid32 +#if defined(__NR_getuid32) return my_syscall0(__NR_getuid32); #else return my_syscall0(__NR_getuid); @@ -538,7 +538,7 @@ int kill(pid_t pid, int signal) static __attribute__((unused)) int sys_link(const char *old, const char *new) { -#ifdef __NR_linkat +#if defined(__NR_linkat) return my_syscall5(__NR_linkat, AT_FDCWD, old, AT_FDCWD, new, 0); #elif defined(__NR_link) return my_syscall2(__NR_link, old, new); @@ -561,7 +561,7 @@ int link(const char *old, const char *new) static __attribute__((unused)) off_t sys_lseek(int fd, off_t offset, int whence) { -#ifdef __NR_lseek +#if defined(__NR_lseek) return my_syscall3(__NR_lseek, fd, offset, whence); #else return __nolibc_enosys(__func__, fd, offset, whence); @@ -572,7 +572,7 @@ static __attribute__((unused)) int sys_llseek(int fd, unsigned long offset_high, unsigned long offset_low, __kernel_loff_t *result, int whence) { -#ifdef __NR_llseek +#if defined(__NR_llseek) return my_syscall5(__NR_llseek, fd, offset_high, offset_low, result, when= ce); #else return __nolibc_enosys(__func__, fd, offset_high, offset_low, result, whe= nce); @@ -609,7 +609,7 @@ off_t lseek(int fd, off_t offset, int whence) static __attribute__((unused)) int sys_mkdir(const char *path, mode_t mode) { -#ifdef __NR_mkdirat +#if defined(__NR_mkdirat) return my_syscall3(__NR_mkdirat, AT_FDCWD, path, mode); #elif defined(__NR_mkdir) return my_syscall2(__NR_mkdir, path, mode); @@ -631,7 +631,7 @@ int mkdir(const char *path, mode_t mode) static __attribute__((unused)) int sys_rmdir(const char *path) { -#ifdef __NR_rmdir +#if defined(__NR_rmdir) return my_syscall1(__NR_rmdir, path); #elif defined(__NR_unlinkat) return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); @@ -654,7 +654,7 @@ int rmdir(const char *path) static __attribute__((unused)) long sys_mknod(const char *path, mode_t mode, dev_t dev) { -#ifdef __NR_mknodat +#if defined(__NR_mknodat) return my_syscall4(__NR_mknodat, AT_FDCWD, path, mode, dev); #elif defined(__NR_mknod) return my_syscall3(__NR_mknod, path, mode, dev); @@ -843,7 +843,7 @@ pid_t setsid(void) static __attribute__((unused)) int sys_symlink(const char *old, const char *new) { -#ifdef __NR_symlinkat +#if defined(__NR_symlinkat) return my_syscall3(__NR_symlinkat, old, AT_FDCWD, new); #elif defined(__NR_symlink) return my_syscall2(__NR_symlink, old, new); @@ -900,7 +900,7 @@ int umount2(const char *path, int flags) static __attribute__((unused)) int sys_unlink(const char *path) { -#ifdef __NR_unlinkat +#if defined(__NR_unlinkat) return my_syscall3(__NR_unlinkat, AT_FDCWD, path, 0); #elif defined(__NR_unlink) return my_syscall1(__NR_unlink, path); --=20 2.39.5 From nobody Sat Oct 11 12:07:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 320DE29C340; Tue, 10 Jun 2025 12:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559354; cv=none; b=oqOVuk9NklePhcY9IiRiGIv4I7S34712OOZvHotJaZLtbIHwgBmOR037d4HLiJTkFDzQ9ZiwDYHqGYnXMF7EmwZ3M9pgzgxXLUgpsuEppCuarwFoPIJvXtMt3lKsjj4wVn4OkJNKVKRkUWjj5l5g7hSyakDfNbR9O8DizCOv2hQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559354; c=relaxed/simple; bh=J6AFLpxqvQUWE4ch4VBYYdyyIA1JHulBUl77i0XMQXw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Sm7J83djf9VcOmm6GqE/zpOnYCsaVHJ09JRQpgi3C2yPm48omoEBP9JwY24QqHOi5UkPGG2cfrzHKCSjFRWBusXY9xbw/rY452jEKQd+Wjr3sRxzr1045wBYtPyhzWCvBw7WfNJEjS4OdLVnEnjnmn1CPto4LgQUh+8QLpi+888= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NRkuzvM1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NRkuzvM1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FCB9C4CEED; Tue, 10 Jun 2025 12:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749559354; bh=J6AFLpxqvQUWE4ch4VBYYdyyIA1JHulBUl77i0XMQXw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NRkuzvM1VuWrjni1jIHamlCP5Bf1frhkd/OQ6upItw68wDuIDQ1w3JYAKfbPY1Sel H5fw+qaJ6BDT3n2lXXAAxygtCxT6mJBewqs0LfJhbg0liyACN1ArVO1sqhIUoP4srk Sr9bAd64TUSiT441BkLsLPAQbKzvz8GVl8ATS2d9ZiV0PVC6bX4ddtl8GQ7/OIwuNL VJdq0ggAuB9KpbiTPog1ER1NI4nHonjdr2vkoViqzSWM2f0qzyRE2fOJRwGWGtlCip nNuxSAZZ1A5LNrfl9qVcDSlHNWjc4ax4O2s2vdzysJDPhGZanrVgCL2x49ZOre1E6z K5uRdO1yCKOfA== From: Mark Brown Date: Tue, 10 Jun 2025 13:29:45 +0100 Subject: [PATCH v2 2/4] tools/nolibc: Provide vfork() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250610-arm64-gcs-vfork-exit-v2-2-929443dfcf82@kernel.org> References: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> In-Reply-To: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> To: Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christian Brauner , Catalin Marinas , Will Deacon , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1550; i=broonie@kernel.org; h=from:subject:message-id; bh=J6AFLpxqvQUWE4ch4VBYYdyyIA1JHulBUl77i0XMQXw=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBoSCgvukmbaMjh17UgVr99O7M6G30oiXXdn4BKoDV/ rkfEdzyJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCaEgoLwAKCRAk1otyXVSH0KMuB/ 4wSoNjdhT70WakS3tv5X9iBatU6hPJ1jqe4SqsQejll0GFhY4EP6j92MKruox3yVgGp1es9BfWiK7k pHdfUp4iCpcVTo1xaJBB1kS47mnEoMvOYLFccmH9Ka8i+j2G+FpSqtaD/xhQL34NNbtCk84Js59oAY cF6v4jl1b6CYWsDFpwxBYvZ3Mv4rVE9ZOfGch/2tA/dnmeIopWbEBZeBciROMX312SXGh0+3A1CCsU 2unwKDDBDqYbC62Cj+arSFXSG9p4cN3HD596UwoRvcOk8ocu/PHCgN3/5trKu3VQfR5t8IigKQc6up RP53ygLYtS+Kxmxi1rrN9y5tMeVTap X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB To allow testing of vfork() support in the arm64 basic-gcs test provide an implementation for nolibc, using the vfork() syscall if one is available and otherwise clone3(). We implement in terms of clone3() since the order of the arguments for clone() varies between architectures. Signed-off-by: Mark Brown --- tools/include/nolibc/sys.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index aabac97a7fb0..5932ae8828a1 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -22,6 +22,7 @@ #include #include #include /* for O_* and AT_* */ +#include /* for clone_args */ #include /* for statx() */ =20 #include "errno.h" @@ -340,6 +341,32 @@ pid_t fork(void) return __sysret(sys_fork()); } =20 +static __attribute__((unused)) +pid_t sys_vfork(void) +{ +#if defined(__NR_vfork) + return my_syscall0(__NR_vfork); +#elif defined(__NR_clone3) + /* + * clone() could be used but has different argument orders per + * architecture. + */ + struct clone_args args =3D { + .flags =3D CLONE_VM | CLONE_VFORK, + .exit_signal =3D SIGCHLD, + }; + + return my_syscall2(__NR_clone3, &args, sizeof(args)); +#else + return __nolibc_enosys(__func__); +#endif +} + +static __attribute__((unused)) +pid_t vfork(void) +{ + return __sysret(sys_vfork()); +} =20 /* * int fsync(int fd); --=20 2.39.5 From nobody Sat Oct 11 12:07:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 331E22BD596; Tue, 10 Jun 2025 12:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559357; cv=none; b=DxCHlbThzNS6zaHtpTvWsnAsRyhiZYVYgoBE9WagfgpEhhEivx+AEvCKjaGvGB+n35Ep6S5/PmU5UwuUBGiCquk997CQklmRu844tZcuY5ba7f8ZWtkdDgHY7bX54yVSOIbqp8J3CrcghbWT/3fHVgAuPZYnnJEn8YMPW5mHNTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559357; c=relaxed/simple; bh=MPMWLRYngQawDoNsJTy1uY6kJqIuvjy1h24Z2RiXIbc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cZ1AhZi4E76tGMfG1Dt4F9HWgHP3M6jBL7PMFPxjZWnY6rP1XeCUEKNAJlca2yP0/2WysVYoQzqXuCp3nRetkUR4C/yRG3MYM163uHMNrU3/UD+3ai0DZmOqaUViMej/VGPG73P1FnxVIsaGpw6CZViMDu29HIBswXG5xYiSedQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=glBwew/x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="glBwew/x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5A36C4CEF1; Tue, 10 Jun 2025 12:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749559356; bh=MPMWLRYngQawDoNsJTy1uY6kJqIuvjy1h24Z2RiXIbc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=glBwew/xFmsZblnYcnNsAy1jYkxzM4R88S3WM282+ssBywad88KAcynoLh4nQ3jWW sjFOzZ05tqVqeFn8u6wcWhzO75akYaC5rCA8skeJtwkpCUDEDJLDjVvujYHly8BhNN JYlp6/sXfqObip4YtoTd/QX5sKb/iibdGgwxxJm3IbN344byyjdTDQ4diY6OD6R2Fx 03+RphiaJD2bJ6NxKIyUuKeTTSNmnHjysgOvsnI9gIeaTu7T+gAhjxdOXx0QdvZ/Fj FFoAlFN8xy/hbtb0NlasKEkB2Xqb+65Albdyk97TCPtgHzbS9Pu/phLjGvwhmlmXVr +naFK3qzQjxcw== From: Mark Brown Date: Tue, 10 Jun 2025 13:29:46 +0100 Subject: [PATCH v2 3/4] kselftest/arm64: Add a test for vfork() with GCS Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250610-arm64-gcs-vfork-exit-v2-3-929443dfcf82@kernel.org> References: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> In-Reply-To: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> To: Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christian Brauner , Catalin Marinas , Will Deacon , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2389; i=broonie@kernel.org; h=from:subject:message-id; bh=MPMWLRYngQawDoNsJTy1uY6kJqIuvjy1h24Z2RiXIbc=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBoSCgwon8lvvXCpJn3/Mg5a+oD+zXp/XHAV9+svyua 26OqNAmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCaEgoMAAKCRAk1otyXVSH0HZfB/ 45rn40YaQ0Kbg0ebFttFNnd4Er7dRx9zeFK/ZIcExaR3lUaClGkfta2V5Ols4VL47KPVN6YDU2emP6 IPoSEUafk4vAFOmeWh4So43TxcJfML7IQ7avt5LHWdMRogKtZsW+6E43qFehbP1byBaQQvRdZwhi43 s9gBHgi7AVqVpIk8UiFI71ONqtS57iVqTJzL7kEEjfvUR7Z6EpUgj6f1Wpu3nrn4fp6rwRF7Ja87d1 3xwnFBFUXbA0WMTg96jZ6qUJ0bNDSf3FtkrpG9fl4HCXGIDcqEHeiWLPcJKWHlibyXw43YPACsInRY pUE7H+a3NHL9W//mX98HZ3a7H1KsXe X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Ensure that we've got at least some coverage of the special cases around vfork() by adding a test case in basic-gcs doing the same thing as the plain fork() one - vfork(), do a few checks and then return to the parent. Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- tools/testing/selftests/arm64/gcs/basic-gcs.c | 63 +++++++++++++++++++++++= ++++ 1 file changed, 63 insertions(+) diff --git a/tools/testing/selftests/arm64/gcs/basic-gcs.c b/tools/testing/= selftests/arm64/gcs/basic-gcs.c index 3fb9742342a3..96ea51cf7163 100644 --- a/tools/testing/selftests/arm64/gcs/basic-gcs.c +++ b/tools/testing/selftests/arm64/gcs/basic-gcs.c @@ -298,6 +298,68 @@ static bool test_fork(void) return pass; } =20 +/* A vfork()ed process can run and exit */ +static bool test_vfork(void) +{ + unsigned long child_mode; + int ret, status; + pid_t pid; + bool pass =3D true; + + pid =3D vfork(); + if (pid =3D=3D -1) { + ksft_print_msg("vfork() failed: %d\n", errno); + pass =3D false; + goto out; + } + if (pid =3D=3D 0) { + /* In child, make sure we can call a function, read + * the GCS pointer and status and then exit */ + valid_gcs_function(); + get_gcspr(); + + ret =3D my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, + &child_mode, 0, 0, 0); + if (ret =3D=3D 0 && !(child_mode & PR_SHADOW_STACK_ENABLE)) { + ksft_print_msg("GCS not enabled in child\n"); + ret =3D -EINVAL; + } + + exit(ret); + } + + /* + * In parent, check we can still do function calls then block + * for the child. + */ + valid_gcs_function(); + + ksft_print_msg("Waiting for child %d\n", pid); + + ret =3D waitpid(pid, &status, 0); + if (ret =3D=3D -1) { + ksft_print_msg("Failed to wait for child: %d\n", + errno); + return false; + } + + if (!WIFEXITED(status)) { + ksft_print_msg("Child exited due to signal %d\n", + WTERMSIG(status)); + pass =3D false; + } else { + if (WEXITSTATUS(status)) { + ksft_print_msg("Child exited with status %d\n", + WEXITSTATUS(status)); + pass =3D false; + } + } + +out: + + return pass; +} + typedef bool (*gcs_test)(void); =20 static struct { @@ -314,6 +376,7 @@ static struct { { "enable_invalid", enable_invalid, true }, { "map_guarded_stack", map_guarded_stack }, { "fork", test_fork }, + { "vfork", test_vfork }, }; =20 int main(void) --=20 2.39.5 From nobody Sat Oct 11 12:07:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37B782D29AB; Tue, 10 Jun 2025 12:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559359; cv=none; b=YS+NH7+QG5T26mdk58UU6uufqwTmU3C67QT01Xw9lonuUsQHgcNxq2vF10NIru0UeG/6hJ0ee/dAZ0M31fshx9wrS2GdGy+mTHAEBJSc4eyY+Tc2EwwkxIeHl4vE0zM4hdJFSDxFW57cWsRaVRAFDRSYoxFwRqgU3Wts2GkHvAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749559359; c=relaxed/simple; bh=k95pgC8uYho6a+kXi0z4LRYhCqPs5d/JUrw8wGO3J2U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fSs65CyMnk+9eUm+nKxP2ufUEK43YPw8T5NDDDle30k53795GRSGpnwnD+eawmxzLkdhC4wBYX78pnaXAxBgLRV7ntFFn0H/xcMg1SzswE34JudME7G3RHlLSP3hVy+EgNiQESAjvlSTrU2gJVmt+3Bobda4ttQrtEa/hrMpIfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fsiOLuLe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fsiOLuLe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41A25C4CEED; Tue, 10 Jun 2025 12:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749559359; bh=k95pgC8uYho6a+kXi0z4LRYhCqPs5d/JUrw8wGO3J2U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fsiOLuLeWL0Xc10yYKUqloJZrMK1OEjyoEhpFU4o9QzSidpZAra4hPBB5dBZHhTiD 818/zMhWNXIzcABdmDfAocm2GV76ezuqm30eFM7DmhXckY6byX65N+1evCEqymg+sW lu64hmcgqbkzIE7rhtT7qZTWyjAwtjLRchWyEogktA94XotyEb/R6YAmBGf0oK1qxC ggKRces2B3P1Fe7CTZhEIYRWZJUB2IqqtcUQ3DNcis/3t1tYzAeGSeH0wmlTvCmp3H ETpHkoqFe1JHz+R8IbIQwYSyRGaTeA4EkNLGDYRwJOwuZ+lPfqUgtAB+VRg9oVSicx r/N3xxxb68ZnQ== From: Mark Brown Date: Tue, 10 Jun 2025 13:29:47 +0100 Subject: [PATCH v2 4/4] selftests/nolibc: Add coverage of vfork() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250610-arm64-gcs-vfork-exit-v2-4-929443dfcf82@kernel.org> References: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> In-Reply-To: <20250610-arm64-gcs-vfork-exit-v2-0-929443dfcf82@kernel.org> To: Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Christian Brauner , Catalin Marinas , Will Deacon , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2649; i=broonie@kernel.org; h=from:subject:message-id; bh=k95pgC8uYho6a+kXi0z4LRYhCqPs5d/JUrw8wGO3J2U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBoSCgxDdwtoQD5Ra5mGt8UN9d0cGbAAOvD/dkn3A8W VjR+qxGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCaEgoMQAKCRAk1otyXVSH0KAyB/ wNxl/FZnzIgWNyszdC7wdp+VFWDFsz2+WxB5+A7fijMn1rBBYPdS9gFZ7FyJq76U9gJMF/OX53Dv+n 0w5hk73UhIcowtY/r4Am4WrncCAQFz5TPbLI9JJBN/+O9AiSaY38wRZYEii2mKgpkOK9QQctIGh/ck KPDJsyo0hWQlC9gEx1qSWwa+sRGQNFPJFIUJm3mSxPdN1/ba/yacvFEa/2iHekpWMmE28bsA+eqcfz tvacCJX3aLeHlKjchkXnsBgVlr2chtd1Mtu67XWWLIBGhtJIfoK1eTpRPt3dFHovRdUufo6bAc+J88 9nG2A0178MlZI1YF5zXGIYbnGlfd8b X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Generalise the existing fork() test to also cover the newly added vfork() implementation. Signed-off-by: Mark Brown --- tools/testing/selftests/nolibc/nolibc-test.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index dbe13000fb1a..d682434c6442 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -877,7 +877,12 @@ int test_file_stream(void) return 0; } =20 -int test_fork(void) +enum fork_type { + FORK_STANDARD, + FORK_VFORK, +}; + +int test_fork(enum fork_type type) { int status; pid_t pid; @@ -886,14 +891,23 @@ int test_fork(void) fflush(stdout); fflush(stderr); =20 - pid =3D fork(); + switch (type) { + case FORK_STANDARD: + pid =3D fork(); + break; + case FORK_VFORK: + pid =3D vfork(); + break; + default: + return 1; + } =20 switch (pid) { case -1: return 1; =20 case 0: - exit(123); + _exit(123); =20 default: pid =3D waitpid(pid, &status, 0); @@ -1330,7 +1344,7 @@ int run_syscall(int min, int max) CASE_TEST(dup3_m1); tmp =3D dup3(-1, 100, 0); EXPECT_SYSER(1, = tmp, -1, EBADF); if (tmp !=3D -1) close(tmp); break; CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0]= =3D "/", [1] =3D NULL }, NULL), -1, EACCES); break; CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break; - CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break; + CASE_TEST(fork); EXPECT_SYSZR(1, test_fork(FORK_STANDARD));= 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(directories); EXPECT_SYSZR(proc, test_dirent()); break; @@ -1374,6 +1388,7 @@ int run_syscall(int min, int max) CASE_TEST(uname_fault); EXPECT_SYSER(1, uname(NULL), -1, EFAULT); = break; CASE_TEST(unlink_root); EXPECT_SYSER(1, unlink("/"), -1, EISDIR); = break; CASE_TEST(unlink_blah); EXPECT_SYSER(1, unlink("/proc/self/blah"),= -1, ENOENT); break; + CASE_TEST(vfork); EXPECT_SYSZR(1, test_fork(FORK_VFORK)); br= eak; CASE_TEST(wait_child); EXPECT_SYSER(1, wait(&tmp), -1, ECHILD); b= reak; CASE_TEST(waitpid_min); EXPECT_SYSER(1, waitpid(INT_MIN, &tmp, WNO= HANG), -1, ESRCH); break; CASE_TEST(waitpid_child); EXPECT_SYSER(1, waitpid(getpid(), &tmp, WN= OHANG), -1, ECHILD); break; --=20 2.39.5