]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pidfs: prepare to drop exit_info pointer
authorChristian Brauner <brauner@kernel.org>
Tue, 28 Oct 2025 08:45:51 +0000 (09:45 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 30 Oct 2025 13:25:14 +0000 (14:25 +0100)
There will likely be more info that we need to store in struct
pidfs_attr. We need to make sure that some of the information such as
exit info or coredump info that consists of multiple bits is either
available completely or not at all, but never partially. Currently we
use a pointer that we assign to. That doesn't scale. We can't waste a
pointer for each mulit-part information struct we want to expose. Use a
bitmask instead.

Link: https://patch.msgid.link/20251028-work-coredump-signal-v1-6-ca449b7b7aa0@kernel.org
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/pidfs.c

index 204ebd32791a3a4d12e6ab202d1100912c55bf58..0fad0c969b7aabc397b0a5ec508976512565917e 100644 (file)
@@ -49,7 +49,12 @@ struct pidfs_exit_info {
        __u32 coredump_mask;
 };
 
+enum pidfs_attr_mask_bits {
+       PIDFS_ATTR_BIT_EXIT     = 0,
+};
+
 struct pidfs_attr {
+       unsigned long attr_mask;
        struct simple_xattrs *xattrs;
        struct pidfs_exit_info __pei;
        struct pidfs_exit_info *exit_info;
@@ -333,8 +338,8 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
 
        attr = READ_ONCE(pid->attr);
        if (mask & PIDFD_INFO_EXIT) {
-               exit_info = READ_ONCE(attr->exit_info);
-               if (exit_info) {
+               if (test_bit(PIDFS_ATTR_BIT_EXIT, &attr->attr_mask)) {
+                       smp_rmb();
                        kinfo.mask |= PIDFD_INFO_EXIT;
 #ifdef CONFIG_CGROUPS
                        kinfo.cgroupid = exit_info->cgroupid;
@@ -663,7 +668,8 @@ void pidfs_exit(struct task_struct *tsk)
        exit_info->exit_code = tsk->exit_code;
 
        /* Ensure that PIDFD_GET_INFO sees either all or nothing. */
-       smp_store_release(&attr->exit_info, &attr->__pei);
+       smp_wmb();
+       set_bit(PIDFS_ATTR_BIT_EXIT, &attr->attr_mask);
 }
 
 #ifdef CONFIG_COREDUMP