pidfds: add coredump_code field to pidfd_info
PATCH 1/1 pidfds: add coredump_code field to pidfd_info
The struct pidfd_info currently exposes in a field called coredump_signal the signal number (si_signo) that triggered the dump (for example, 11 for SIGSEGV). However, it is also valuable to understand the reason why that signal was sent. This additional context is provided by the signal code (si_code), such as 2 for SEGV_ACCERR.
Add a new field to struct pidfd_info called coredump_code with the value of si_code for the benefit of sysadmins who pipe core dumps to user-space programs for later analysis. The following snippet illustrates a simplified C program that consumes coredump_signal and coredump_code, and then logs core dump signals and codes to a file:
int pidfd = (int)atoi(argv[1]);
struct pidfd_info info = {
.mask = PIDFD_INFO_EXIT | PIDFD_INFO_COREDUMP,
};
if (ioctl(pidfd, PIDFD_GET_INFO, &info) == 0)
if (info.mask & PIDFD_INFO_COREDUMP)
fprintf(f, "PID=%d, si_signo: %d si_code: %d\n",
info.pid, info.coredump_signal, info.coredump_code);Assuming the program is installed under /usr/local/bin/core-logger, core dump processing can be enabled by setting /proc/sys/kernel/core_pattern to '|/usr/local/bin/dumpstuff %F'.
systemd-coredump(8) already uses pidfds to process core dumps, and it could be extended to include the values of coredump_code too.
--- fs/pidfs.c | 12 ++++--- include/uapi/linux/pidfd.h | 3 ++ .../coredump/coredump_socket_protocol_test.c | 26 +++++++++++++++ .../selftests/coredump/coredump_socket_test.c | 32 +++++++++++++++++++ .../coredump/coredump_test_helpers.c | 4 +-- tools/testing/selftests/pidfd/pidfd.h | 5 +++ .../testing/selftests/pidfd/pidfd_info_test.c | 1 + 7 files changed, 77 insertions(+), 6 deletions(-)
fs/pidfs.c +8 -4
@@ -55,6 +55,7 @@ struct pidfs_attr { };__u32 coredump_mask;__u32 coredump_signal; +__u32 coredump_code; };static struct rhashtable pidfs_ino_ht;
@@ -331,7 +332,8 @@ static __u32 pidfs_coredump_mask(unsigned long mm_flags) PIDFD_INFO_EXIT | \ PIDFD_INFO_COREDUMP | \ PIDFD_INFO_SUPPORTED_MASK | \ - PIDFD_INFO_COREDUMP_SIGNAL) + PIDFD_INFO_COREDUMP_SIGNAL | \ + PIDFD_INFO_COREDUMP_CODE)static long pidfd_info (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -345,7 +347,7 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)const struct cred *c;__u64 mask; -BUILD_BUG_ON (sizeof (struct pidfd_info ) !=PIDFD_INFO_SIZE_VER2 ); +BUILD_BUG_ON (sizeof (struct pidfd_info ) !=PIDFD_INFO_SIZE_VER3 );if (!uinfo)return -EINVAL ;
@@ -378,9 +380,10 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)if (mask &PIDFD_INFO_COREDUMP ) {if (test_bit (PIDFS_ATTR_BIT_COREDUMP , &attr->attr_mask)) {smp_rmb (); - kinfo.mask |=PIDFD_INFO_COREDUMP |PIDFD_INFO_COREDUMP_SIGNAL ; + kinfo.mask |=PIDFD_INFO_COREDUMP |PIDFD_INFO_COREDUMP_SIGNAL |PIDFD_INFO_COREDUMP_CODE ; kinfo.coredump_mask = attr->coredump_mask; kinfo.coredump_signal = attr->coredump_signal; + kinfo.coredump_code = attr->coredump_code; } }
@@ -730,8 +733,9 @@ void pidfs_coredump(const struct coredump_params *cprm)PIDFD_COREDUMPED ;/* If coredumping is set to skip we should never end up here. */ VFS_WARN_ON_ONCE (attr->coredump_mask &PIDFD_COREDUMP_SKIP ); -/* Expose the signal number that caused the coredump. */ +/* Expose the signal number and code that caused the coredump. */ attr->coredump_signal = cprm->siginfo->si_signo; + attr->coredump_code = cprm->siginfo->si_code;smp_wmb ();set_bit (PIDFS_ATTR_BIT_COREDUMP , &attr->attr_mask); }
include/uapi/linux/pidfd.h +3 -0
@@ -28,10 +28,12 @@#define PIDFD_INFO_COREDUMP (1UL << 4)/* Only returned if requested. */ #define PIDFD_INFO_SUPPORTED_MASK (1UL << 5)/* Want/got supported mask flags */ #define PIDFD_INFO_COREDUMP_SIGNAL (1UL << 6)/* Always returned if PIDFD_INFO_COREDUMP is requested. */ +#define PIDFD_INFO_COREDUMP_CODE (1UL << 7)/* Always returned if PIDFD_INFO_COREDUMP is requested. */ #define PIDFD_INFO_SIZE_VER0 64/* sizeof first published struct */ #define PIDFD_INFO_SIZE_VER1 72/* sizeof second published struct */ #define PIDFD_INFO_SIZE_VER2 80/* sizeof third published struct */ +#define PIDFD_INFO_SIZE_VER3 88/* sizeof fourth published struct */ /* * Values for @coredump_mask in pidfd_info.
@@ -98,6 +100,7 @@ struct pidfd_info {struct /* coredump info */ {__u32 coredump_mask;__u32 coredump_signal; +__u32 coredump_code; };__u64 supported_mask;/* Mask flags that this kernel supports */ };
tools/testing/selftests/coredump/coredump_socket_protocol_test.c +26 -0
@@ -1004,6 +1004,8 @@ TEST_F(coredump, socket_request_invalid_size_large)* * Verify that when using socket-based coredump protocol, * the coredump_signal field is correctly exposed as SIGSEGV. +* Also check that the coredump_code field is correctly exposed +* as SEGV_MAPERR. */ TEST_F(coredump, socket_coredump_signal_sigsegv) {
@@ -1079,6 +1081,18 @@ TEST_F(coredump, socket_coredump_signal_sigsegv) goto out; } +/* Verify coredump_code is available and correct */ +if (!(info.mask &PIDFD_INFO_COREDUMP_CODE )) { +fprintf (stderr,"socket_coredump_signal_sigsegv: PIDFD_INFO_COREDUMP_CODE not set in mask\n" ); + goto out; + } + +if (info.coredump_code !=SEGV_MAPERR ) { +fprintf (stderr,"socket_coredump_signal_sigsegv: coredump_code=%d, expected SEGV_MAPERR=%d\n" , + info.coredump_code,SEGV_MAPERR ); + goto out; + } +if (!read_coredump_req (fd_coredump, &req)) {fprintf (stderr,"socket_coredump_signal_sigsegv: read_coredump_req failed\n" ); goto out;
@@ -1128,6 +1142,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGSEGV ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SEGV_MAPERR );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
@@ -1137,6 +1153,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)* * Verify that when using socket-based coredump protocol, * the coredump_signal field is correctly exposed as SIGABRT. +* Also check that the coredump_code field is correctly exposed +* as SI_TKILL. */ TEST_F(coredump, socket_coredump_signal_sigabrt) {
@@ -1212,6 +1230,12 @@ TEST_F(coredump, socket_coredump_signal_sigabrt) goto out; } +if (info.coredump_code !=SI_TKILL ) { +fprintf (stderr,"socket_coredump_signal_sigabrt: coredump_code=%d, expected SI_TKILL=%d\n" , + info.coredump_code,SI_TKILL ); + goto out; + } +if (!read_coredump_req (fd_coredump, &req)) {fprintf (stderr,"socket_coredump_signal_sigabrt: read_coredump_req failed\n" ); goto out;
@@ -1261,6 +1285,8 @@ TEST_F(coredump, socket_coredump_signal_sigabrt)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGABRT ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SI_TKILL );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
tools/testing/selftests/coredump/coredump_socket_test.c +32 -0
@@ -435,6 +435,8 @@ TEST_F(coredump, socket_no_listener)* * Verify that when using simple socket-based coredump (@ pattern), * the coredump_signal field is correctly exposed as SIGSEGV. +* Also check that the coredump_code field is correctly exposed +* as SEGV_MAPERR. */ TEST_F(coredump, socket_coredump_signal_sigsegv) {
@@ -509,6 +511,18 @@ TEST_F(coredump, socket_coredump_signal_sigsegv) goto out; } +/* Verify coredump_code is available and correct */ +if (!(info.mask &PIDFD_INFO_COREDUMP_CODE )) { +fprintf (stderr,"socket_coredump_signal_sigsegv: PIDFD_INFO_COREDUMP_CODE not set in mask\n" ); + goto out; + } + +if (info.coredump_code !=SEGV_MAPERR ) { +fprintf (stderr,"socket_coredump_signal_sigsegv: coredump_code=%d, expected SEGV_MAPERR=%d\n" , + info.coredump_code,SEGV_MAPERR ); + goto out; + } + fd_core_file =open_coredump_tmpfile (self->fd_tmpfs_detached);if (fd_core_file <0 ) {fprintf (stderr,"socket_coredump_signal_sigsegv: open_coredump_tmpfile failed: %m\n" );
@@ -572,6 +586,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGSEGV ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SEGV_MAPERR );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
@@ -581,6 +597,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)* * Verify that when using simple socket-based coredump (@ pattern), * the coredump_signal field is correctly exposed as SIGABRT. +* Also check that the coredump_code field is correctly exposed +* as SI_TKILL. */ TEST_F(coredump, socket_coredump_signal_sigabrt) {
@@ -655,6 +673,18 @@ TEST_F(coredump, socket_coredump_signal_sigabrt) goto out; } +/* Verify coredump_code is available and correct */ +if (!(info.mask &PIDFD_INFO_COREDUMP_CODE )) { +fprintf (stderr,"socket_coredump_signal_sigabrt: PIDFD_INFO_COREDUMP_CODE not set in mask\n" ); + goto out; + } + +if (info.coredump_code !=SI_TKILL ) { +fprintf (stderr,"socket_coredump_signal_sigabrt: coredump_code=%d, expected SI_TKILL=%d\n" , + info.coredump_code,SI_TKILL ); + goto out; + } + fd_core_file =open_coredump_tmpfile (self->fd_tmpfs_detached);if (fd_core_file <0 ) {fprintf (stderr,"socket_coredump_signal_sigabrt: open_coredump_tmpfile failed: %m\n" );
@@ -718,6 +748,8 @@ TEST_F(coredump, socket_coredump_signal_sigabrt)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGABRT ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SI_TKILL );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
tools/testing/selftests/coredump/coredump_test_helpers.c +2 -2
@@ -148,8 +148,8 @@ bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info)fprintf (stderr,"get_pidfd_info: ioctl(PIDFD_GET_INFO) failed: %m\n" );return false; } -fprintf (stderr,"get_pidfd_info: mask=0x%llx, coredump_mask=0x%x, coredump_signal=%d\n" , - (unsigned long long )info->mask, info->coredump_mask, info->coredump_signal); +fprintf (stderr,"get_pidfd_info: mask=0x%llx, coredump_mask=0x%x, coredump_signal=%d, coredump_code=%d\n" , + (unsigned long long )info->mask, info->coredump_mask, info->coredump_signal, info->coredump_code);return true; }
tools/testing/selftests/pidfd/pidfd.h +5 -0
@@ -156,6 +156,10 @@#define PIDFD_INFO_COREDUMP_SIGNAL (1UL << 6)#endif +#ifndef PIDFD_INFO_COREDUMP_CODE +#define PIDFD_INFO_COREDUMP_CODE (1UL << 7) +#endif +#ifndef PIDFD_COREDUMPED #define PIDFD_COREDUMPED (1U << 0)/* Did crash and... */ #endif
@@ -194,6 +198,7 @@ struct pidfd_info {struct {__u32 coredump_mask;__u32 coredump_signal; +__u32 coredump_code; };__u64 supported_mask; };
tools/testing/selftests/pidfd/pidfd_info_test.c +1 -0
@@ -724,6 +724,7 @@ TEST(supported_mask_field)ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_SUPPORTED_MASK ));ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_COREDUMP_SIGNAL )); +ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_COREDUMP_CODE ));/* Clean up */ sys_pidfd_send_signal (pidfd,SIGKILL ,NULL ,0 );
Signature · 1 line
2.43.0
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Emanuele,
kernel test robot noticed the following build errors:
[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes brauner-vfs/vfs.all linus/master v7.0-rc4 next-20260320] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Emanuele-Rocca/pidfds-add-coredump_code-field-to-pidfd_info/20260321-125434 base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next patch link: https://lore.kernel.org/r/ab29J6KsQm8Xg3LR%40NH27D9T0LF patch subject: [PATCH] pidfds: add coredump_code field to pidfd_info config: i386-allnoconfig (https://download.01.org/0day-ci/archive/20260321/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260321/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <command-line>:
In function 'pidfd_info',
inlined from 'pidfd_ioctl' at fs/pidfs.c:527:10:
>> include/linux/compiler_types.h:706:45: error: call to '__compiletime_assert_410' declared with attribute error: BUILD_BUG_ON failed: sizeof(struct pidfd_info) != PIDFD_INFO_SIZE_VER3
706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:687:25: note: in definition of macro '__compiletime_assert'
687 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:706:9: note: in expansion of macro '_compiletime_assert'
706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
fs/pidfs.c:350:9: note: in expansion of macro 'BUILD_BUG_ON'
350 | BUILD_BUG_ON(sizeof(struct pidfd_info) != PIDFD_INFO_SIZE_VER3);
| ^~~~~~~~~~~~vim +/__compiletime_assert_410 +706 include/linux/compiler_types.h
eb5c2d4b45e3d2 Will Deacon 2020-07-21 692 eb5c2d4b45e3d2 Will Deacon 2020-07-21 693 #define _compiletime_assert(condition, msg, prefix, suffix) \ eb5c2d4b45e3d2 Will Deacon 2020-07-21 694 __compiletime_assert(condition, msg, prefix, suffix) eb5c2d4b45e3d2 Will Deacon 2020-07-21 695 eb5c2d4b45e3d2 Will Deacon 2020-07-21 696 /** eb5c2d4b45e3d2 Will Deacon 2020-07-21 697 * compiletime_assert - break build and emit msg if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 698 * @condition: a compile-time constant condition to check eb5c2d4b45e3d2 Will Deacon 2020-07-21 699 * @msg: a message to emit if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 700 * eb5c2d4b45e3d2 Will Deacon 2020-07-21 701 * In tradition of POSIX assert, this macro will break the build if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 702 * supplied condition is *false*, emitting the supplied error message if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 703 * compiler has support to do so. eb5c2d4b45e3d2 Will Deacon 2020-07-21 704 */ eb5c2d4b45e3d2 Will Deacon 2020-07-21 705 #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @706 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)eb5c2d4b45e3d2 Will Deacon 2020-07-21 707
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
The struct pidfd_info currently exposes in a field called coredump_signal the signal number (si_signo) that triggered the dump (for example, 11 for SIGSEGV). However, it is also valuable to understand the reason why that signal was sent. This additional context is provided by the signal code (si_code), such as 2 for SEGV_ACCERR.
Add a new field to struct pidfd_info called coredump_code with the value of si_code for the benefit of sysadmins who pipe core dumps to user-space programs for later analysis. The following snippet illustrates a simplified C program that consumes coredump_signal and coredump_code, and then logs core dump signals and codes to a file:
int pidfd = (int)atoi(argv[1]);
struct pidfd_info info = {
.mask = PIDFD_INFO_EXIT | PIDFD_INFO_COREDUMP,
};
if (ioctl(pidfd, PIDFD_GET_INFO, &info) == 0)
if (info.mask & PIDFD_INFO_COREDUMP)
fprintf(f, "PID=%d, si_signo: %d si_code: %d\n",
info.pid, info.coredump_signal, info.coredump_code);Assuming the program is installed under /usr/local/bin/core-logger, core dump processing can be enabled by setting /proc/sys/kernel/core_pattern to '|/usr/local/bin/dumpstuff %F'.
systemd-coredump(8) already uses pidfds to process core dumps, and it could be extended to include the values of coredump_code too.
---
V1 -> V2: Add coredump_pad to struct pidfd_info to ensure the struct has the same size on both 64 bit and 32 bit systems.
fs/pidfs.c | 12 ++++--- include/uapi/linux/pidfd.h | 4 +++ .../coredump/coredump_socket_protocol_test.c | 26 +++++++++++++++ .../selftests/coredump/coredump_socket_test.c | 32 +++++++++++++++++++ .../coredump/coredump_test_helpers.c | 4 +-- tools/testing/selftests/pidfd/pidfd.h | 5 +++ .../testing/selftests/pidfd/pidfd_info_test.c | 1 + 7 files changed, 78 insertions(+), 6 deletions(-)
fs/pidfs.c +8 -4
@@ -55,6 +55,7 @@ struct pidfs_attr { };__u32 coredump_mask;__u32 coredump_signal; +__u32 coredump_code; };static struct rhashtable pidfs_ino_ht;
@@ -331,7 +332,8 @@ static __u32 pidfs_coredump_mask(unsigned long mm_flags) PIDFD_INFO_EXIT | \ PIDFD_INFO_COREDUMP | \ PIDFD_INFO_SUPPORTED_MASK | \ - PIDFD_INFO_COREDUMP_SIGNAL) + PIDFD_INFO_COREDUMP_SIGNAL | \ + PIDFD_INFO_COREDUMP_CODE)static long pidfd_info (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -345,7 +347,7 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)const struct cred *c;__u64 mask; -BUILD_BUG_ON (sizeof (struct pidfd_info ) !=PIDFD_INFO_SIZE_VER2 ); +BUILD_BUG_ON (sizeof (struct pidfd_info ) !=PIDFD_INFO_SIZE_VER3 );if (!uinfo)return -EINVAL ;
@@ -378,9 +380,10 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)if (mask &PIDFD_INFO_COREDUMP ) {if (test_bit (PIDFS_ATTR_BIT_COREDUMP , &attr->attr_mask)) {smp_rmb (); - kinfo.mask |=PIDFD_INFO_COREDUMP |PIDFD_INFO_COREDUMP_SIGNAL ; + kinfo.mask |=PIDFD_INFO_COREDUMP |PIDFD_INFO_COREDUMP_SIGNAL |PIDFD_INFO_COREDUMP_CODE ; kinfo.coredump_mask = attr->coredump_mask; kinfo.coredump_signal = attr->coredump_signal; + kinfo.coredump_code = attr->coredump_code; } }
@@ -730,8 +733,9 @@ void pidfs_coredump(const struct coredump_params *cprm)PIDFD_COREDUMPED ;/* If coredumping is set to skip we should never end up here. */ VFS_WARN_ON_ONCE (attr->coredump_mask &PIDFD_COREDUMP_SKIP ); -/* Expose the signal number that caused the coredump. */ +/* Expose the signal number and code that caused the coredump. */ attr->coredump_signal = cprm->siginfo->si_signo; + attr->coredump_code = cprm->siginfo->si_code;smp_wmb ();set_bit (PIDFS_ATTR_BIT_COREDUMP , &attr->attr_mask); }
include/uapi/linux/pidfd.h +4 -0
@@ -28,10 +28,12 @@#define PIDFD_INFO_COREDUMP (1UL << 4)/* Only returned if requested. */ #define PIDFD_INFO_SUPPORTED_MASK (1UL << 5)/* Want/got supported mask flags */ #define PIDFD_INFO_COREDUMP_SIGNAL (1UL << 6)/* Always returned if PIDFD_INFO_COREDUMP is requested. */ +#define PIDFD_INFO_COREDUMP_CODE (1UL << 7)/* Always returned if PIDFD_INFO_COREDUMP is requested. */ #define PIDFD_INFO_SIZE_VER0 64/* sizeof first published struct */ #define PIDFD_INFO_SIZE_VER1 72/* sizeof second published struct */ #define PIDFD_INFO_SIZE_VER2 80/* sizeof third published struct */ +#define PIDFD_INFO_SIZE_VER3 88/* sizeof fourth published struct */ /* * Values for @coredump_mask in pidfd_info.
@@ -98,6 +100,8 @@ struct pidfd_info {struct /* coredump info */ {__u32 coredump_mask;__u32 coredump_signal; +__u32 coredump_code; +__u32 coredump_pad;/* align supported_mask to 8 bytes */ };__u64 supported_mask;/* Mask flags that this kernel supports */ };
tools/testing/selftests/coredump/coredump_socket_protocol_test.c +26 -0
@@ -1004,6 +1004,8 @@ TEST_F(coredump, socket_request_invalid_size_large)* * Verify that when using socket-based coredump protocol, * the coredump_signal field is correctly exposed as SIGSEGV. +* Also check that the coredump_code field is correctly exposed +* as SEGV_MAPERR. */ TEST_F(coredump, socket_coredump_signal_sigsegv) {
@@ -1079,6 +1081,18 @@ TEST_F(coredump, socket_coredump_signal_sigsegv) goto out; } +/* Verify coredump_code is available and correct */ +if (!(info.mask &PIDFD_INFO_COREDUMP_CODE )) { +fprintf (stderr,"socket_coredump_signal_sigsegv: PIDFD_INFO_COREDUMP_CODE not set in mask\n" ); + goto out; + } + +if (info.coredump_code !=SEGV_MAPERR ) { +fprintf (stderr,"socket_coredump_signal_sigsegv: coredump_code=%d, expected SEGV_MAPERR=%d\n" , + info.coredump_code,SEGV_MAPERR ); + goto out; + } +if (!read_coredump_req (fd_coredump, &req)) {fprintf (stderr,"socket_coredump_signal_sigsegv: read_coredump_req failed\n" ); goto out;
@@ -1128,6 +1142,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGSEGV ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SEGV_MAPERR );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
@@ -1137,6 +1153,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)* * Verify that when using socket-based coredump protocol, * the coredump_signal field is correctly exposed as SIGABRT. +* Also check that the coredump_code field is correctly exposed +* as SI_TKILL. */ TEST_F(coredump, socket_coredump_signal_sigabrt) {
@@ -1212,6 +1230,12 @@ TEST_F(coredump, socket_coredump_signal_sigabrt) goto out; } +if (info.coredump_code !=SI_TKILL ) { +fprintf (stderr,"socket_coredump_signal_sigabrt: coredump_code=%d, expected SI_TKILL=%d\n" , + info.coredump_code,SI_TKILL ); + goto out; + } +if (!read_coredump_req (fd_coredump, &req)) {fprintf (stderr,"socket_coredump_signal_sigabrt: read_coredump_req failed\n" ); goto out;
@@ -1261,6 +1285,8 @@ TEST_F(coredump, socket_coredump_signal_sigabrt)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGABRT ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SI_TKILL );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
tools/testing/selftests/coredump/coredump_socket_test.c +32 -0
@@ -435,6 +435,8 @@ TEST_F(coredump, socket_no_listener)* * Verify that when using simple socket-based coredump (@ pattern), * the coredump_signal field is correctly exposed as SIGSEGV. +* Also check that the coredump_code field is correctly exposed +* as SEGV_MAPERR. */ TEST_F(coredump, socket_coredump_signal_sigsegv) {
@@ -509,6 +511,18 @@ TEST_F(coredump, socket_coredump_signal_sigsegv) goto out; } +/* Verify coredump_code is available and correct */ +if (!(info.mask &PIDFD_INFO_COREDUMP_CODE )) { +fprintf (stderr,"socket_coredump_signal_sigsegv: PIDFD_INFO_COREDUMP_CODE not set in mask\n" ); + goto out; + } + +if (info.coredump_code !=SEGV_MAPERR ) { +fprintf (stderr,"socket_coredump_signal_sigsegv: coredump_code=%d, expected SEGV_MAPERR=%d\n" , + info.coredump_code,SEGV_MAPERR ); + goto out; + } + fd_core_file =open_coredump_tmpfile (self->fd_tmpfs_detached);if (fd_core_file <0 ) {fprintf (stderr,"socket_coredump_signal_sigsegv: open_coredump_tmpfile failed: %m\n" );
@@ -572,6 +586,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGSEGV ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SEGV_MAPERR );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
@@ -581,6 +597,8 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)* * Verify that when using simple socket-based coredump (@ pattern), * the coredump_signal field is correctly exposed as SIGABRT. +* Also check that the coredump_code field is correctly exposed +* as SI_TKILL. */ TEST_F(coredump, socket_coredump_signal_sigabrt) {
@@ -655,6 +673,18 @@ TEST_F(coredump, socket_coredump_signal_sigabrt) goto out; } +/* Verify coredump_code is available and correct */ +if (!(info.mask &PIDFD_INFO_COREDUMP_CODE )) { +fprintf (stderr,"socket_coredump_signal_sigabrt: PIDFD_INFO_COREDUMP_CODE not set in mask\n" ); + goto out; + } + +if (info.coredump_code !=SI_TKILL ) { +fprintf (stderr,"socket_coredump_signal_sigabrt: coredump_code=%d, expected SI_TKILL=%d\n" , + info.coredump_code,SI_TKILL ); + goto out; + } + fd_core_file =open_coredump_tmpfile (self->fd_tmpfs_detached);if (fd_core_file <0 ) {fprintf (stderr,"socket_coredump_signal_sigabrt: open_coredump_tmpfile failed: %m\n" );
@@ -718,6 +748,8 @@ TEST_F(coredump, socket_coredump_signal_sigabrt)ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_SIGNAL ));ASSERT_EQ (info.coredump_signal,SIGABRT ); +ASSERT_TRUE (!!(info.mask &PIDFD_INFO_COREDUMP_CODE )); +ASSERT_EQ (info.coredump_code,SI_TKILL );wait_and_check_coredump_server (pid_coredump_server, _metadata, self); }
tools/testing/selftests/coredump/coredump_test_helpers.c +2 -2
@@ -148,8 +148,8 @@ bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info)fprintf (stderr,"get_pidfd_info: ioctl(PIDFD_GET_INFO) failed: %m\n" );return false; } -fprintf (stderr,"get_pidfd_info: mask=0x%llx, coredump_mask=0x%x, coredump_signal=%d\n" , - (unsigned long long )info->mask, info->coredump_mask, info->coredump_signal); +fprintf (stderr,"get_pidfd_info: mask=0x%llx, coredump_mask=0x%x, coredump_signal=%d, coredump_code=%d\n" , + (unsigned long long )info->mask, info->coredump_mask, info->coredump_signal, info->coredump_code);return true; }
tools/testing/selftests/pidfd/pidfd.h +5 -0
@@ -156,6 +156,10 @@#define PIDFD_INFO_COREDUMP_SIGNAL (1UL << 6)#endif +#ifndef PIDFD_INFO_COREDUMP_CODE +#define PIDFD_INFO_COREDUMP_CODE (1UL << 7) +#endif +#ifndef PIDFD_COREDUMPED #define PIDFD_COREDUMPED (1U << 0)/* Did crash and... */ #endif
@@ -194,6 +198,7 @@ struct pidfd_info {struct {__u32 coredump_mask;__u32 coredump_signal; +__u32 coredump_code; };__u64 supported_mask; };
tools/testing/selftests/pidfd/pidfd_info_test.c +1 -0
@@ -724,6 +724,7 @@ TEST(supported_mask_field)ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_COREDUMP ));ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_SUPPORTED_MASK ));ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_COREDUMP_SIGNAL )); +ASSERT_TRUE (!!(info.supported_mask &PIDFD_INFO_COREDUMP_CODE ));/* Clean up */ sys_pidfd_send_signal (pidfd,SIGKILL ,NULL ,0 );
Signature · 1 line
2.47.3
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Emanuele,
kernel test robot noticed the following build errors:
[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes brauner-vfs/vfs.all linus/master v7.0-rc4 next-20260320] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Emanuele-Rocca/pidfds-add-coredump_code-field-to-pidfd_info/20260321-125434 base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next patch link: https://lore.kernel.org/r/ab29J6KsQm8Xg3LR%40NH27D9T0LF patch subject: [PATCH] pidfds: add coredump_code field to pidfd_info config: i386-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260321/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260321/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <command-line>:
In function 'pidfd_info',
inlined from 'pidfd_ioctl' at fs/pidfs.c:527:10:
>> ././include/linux/compiler_types.h:706:45: error: call to '__compiletime_assert_515' declared with attribute error: BUILD_BUG_ON failed: sizeof(struct pidfd_info) != PIDFD_INFO_SIZE_VER3
706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
././include/linux/compiler_types.h:687:25: note: in definition of macro '__compiletime_assert'
687 | prefix ## suffix(); \
| ^~~~~~
././include/linux/compiler_types.h:706:9: note: in expansion of macro '_compiletime_assert'
706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
fs/pidfs.c:350:9: note: in expansion of macro 'BUILD_BUG_ON'
350 | BUILD_BUG_ON(sizeof(struct pidfd_info) != PIDFD_INFO_SIZE_VER3);
| ^~~~~~~~~~~~vim +/__compiletime_assert_515 +706 ././include/linux/compiler_types.h
eb5c2d4b45e3d2 Will Deacon 2020-07-21 692 eb5c2d4b45e3d2 Will Deacon 2020-07-21 693 #define _compiletime_assert(condition, msg, prefix, suffix) \ eb5c2d4b45e3d2 Will Deacon 2020-07-21 694 __compiletime_assert(condition, msg, prefix, suffix) eb5c2d4b45e3d2 Will Deacon 2020-07-21 695 eb5c2d4b45e3d2 Will Deacon 2020-07-21 696 /** eb5c2d4b45e3d2 Will Deacon 2020-07-21 697 * compiletime_assert - break build and emit msg if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 698 * @condition: a compile-time constant condition to check eb5c2d4b45e3d2 Will Deacon 2020-07-21 699 * @msg: a message to emit if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 700 * eb5c2d4b45e3d2 Will Deacon 2020-07-21 701 * In tradition of POSIX assert, this macro will break the build if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 702 * supplied condition is *false*, emitting the supplied error message if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 703 * compiler has support to do so. eb5c2d4b45e3d2 Will Deacon 2020-07-21 704 */ eb5c2d4b45e3d2 Will Deacon 2020-07-21 705 #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @706 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)eb5c2d4b45e3d2 Will Deacon 2020-07-21 707
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki