don't abuse task_struct.group_leader
Subsystems (10)
v2 cover don't abuse task_struct.group_leader
Andrew, can you take these simple cleanups?
The patches do not depend on each other, this series just removes the usage of ->group_leader when it is "obviously unnecessary".
I am going to move ->group_leader from task_struct to signal_struct or at least add the new task_group_leader() helper. So I will send more tree-wide changes on top of this series.
Link to V1: https://lore.kernel.org/all/[email protected]/
V2 doesn't differ, I only added the acks I got (thanks!).
7/7 was not reviewed, but looks really trivial.
Oleg.
---
drivers/android/binder.c | 9 ++++----- drivers/android/binder_alloc.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +---- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 ---------- drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/infiniband/core/umem_odp.c | 4 ++-- net/core/netclassid_cgroup.c | 2 +- 9 files changed, 12 insertions(+), 26 deletions(-)
PATCH v2 1/7 android/binder: don't abuse current->group_leader
Cleanup and preparation to simplify the next changes.
- Use current->tgid instead of current->group_leader->pid
- Use the value returned by get_task_struct() to initialize proc->tsk
--- drivers/android/binder.c | 7 +++---- drivers/android/binder_alloc.c | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/android/binder.c +3 -4
@@ -6046,7 +6046,7 @@ static int binder_open(struct inode *nodp, struct file *filp)bool existing_pid = false;binder_debug (BINDER_DEBUG_OPEN_CLOSE ,"%s: %d:%d\n" , __func__, - current->group_leader->pid, current->pid); + current->tgid, current->pid); proc =kzalloc (sizeof (*proc),GFP_KERNEL );if (proc ==NULL )
@@ -6055,8 +6055,8 @@ static int binder_open(struct inode *nodp, struct file *filp)dbitmap_init (&proc->dmap);spin_lock_init (&proc->inner_lock);spin_lock_init (&proc->outer_lock); -get_task_struct (current->group_leader); - proc->tsk = current->group_leader; + proc->tsk =get_task_struct (current->group_leader); + proc->pid = current->tgid; proc->cred =get_cred (filp->f_cred);INIT_LIST_HEAD (&proc->todo);init_waitqueue_head (&proc->freeze_wait);
@@ -6075,7 +6075,6 @@ static int binder_open(struct inode *nodp, struct file *filp)binder_alloc_init (&proc->alloc);binder_stats_created (BINDER_STAT_PROC ); - proc->pid = current->group_leader->pid;INIT_LIST_HEAD (&proc->delivered_death);INIT_LIST_HEAD (&proc->delivered_freeze);INIT_LIST_HEAD (&proc->waiting_threads);
drivers/android/binder_alloc.c +1 -1
@@ -1233,7 +1233,7 @@ static struct shrinker *binder_shrinker; VISIBLE_IF_KUNIT void __binder_alloc_init(struct binder_alloc *alloc,struct list_lru *freelist) { - alloc->pid = current->group_leader->pid; + alloc->pid = current->tgid; alloc->mm = current->mm;mmgrab (alloc->mm);mutex_init (&alloc->mutex);
Signature · 1 line
2.52.0
PATCH v2 2/7 android/binder: use same_thread_group(proc->tsk, current) in binder_mmap()
In reply to Oleg NesterovWith or without this change the checked condition can be falsely true if proc->tsk execs, but this is fine: binder_alloc_mmap_handler() checks vma->vm_mm == alloc->mm.
--- drivers/android/binder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/android/binder.c +1 -1
@@ -6015,7 +6015,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma) {struct binder_proc *proc = filp->private_data; -if (proc->tsk != current->group_leader) +if (!same_thread_group (proc->tsk, current))return -EINVAL ; binder_debug(BINDER_DEBUG_OPEN_CLOSE,
Signature · 1 line
2.52.0
PATCH v2 3/7 drm/amdgpu: don't abuse current->group_leader
In reply to Oleg NesterovCleanup and preparation to simplify the next changes.
- Use current->tgid instead of current->group_leader->pid
- Use get_task_pid(current, PIDTYPE_TGID) instead of get_task_pid(current->group_leader, PIDTYPE_PID)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
@@ -1421,7 +1421,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, goto create_evict_fence_fail; } - info->pid =get_task_pid (current->group_leader,PIDTYPE_PID ); + info->pid =get_task_pid (current,PIDTYPE_TGID );INIT_DELAYED_WORK (&info->restore_userptr_work, amdgpu_amdkfd_restore_userptr_worker);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -2554,7 +2554,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)if (current->group_leader->mm != current->mm)return ; - vm->task_info->tgid = current->group_leader->pid; + vm->task_info->tgid = current->tgid;get_task_comm (vm->task_info->process_name, current->group_leader); }
Signature · 1 line
2.52.0
PATCH v2 4/7 drm/amd: kill the outdated "Only the pthreads threading model is supported" checks
In reply to Oleg NesterovNowaday task->group_leader->mm != task->mm is only possible if
a) task is not a group leader and b) task->group_leader->mm == NULL because task->group_leader has already exited using sys_exit().
I don't think that drm/amd tries to detect/nack this case.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 --- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 ---------- 2 files changed, 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -3
@@ -2551,9 +2551,6 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) vm->task_info->task.pid = current->pid;get_task_comm (vm->task_info->task.comm, current); -if (current->group_leader->mm != current->mm) -return ; - vm->task_info->tgid = current->tgid;get_task_comm (vm->task_info->process_name, current->group_leader); }
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -10
@@ -833,12 +833,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)if (!(thread->mm &&mmget_not_zero (thread->mm)))return ERR_PTR (-EINVAL ); -/* Only the pthreads threading model is supported. */ -if (thread->group_leader->mm != thread->mm) { -mmput (thread->mm); -return ERR_PTR (-EINVAL ); - } -/* If the process just called exec(3), it is possible that the * cleanup of the kfd_process (following the release of the mm * of the old process image) is still in the cleanup work queue.
@@ -918,10 +912,6 @@ struct kfd_process *kfd_get_process(const struct task_struct *thread)if (!thread->mm)return ERR_PTR (-EINVAL ); -/* Only the pthreads threading model is supported. */ -if (thread->group_leader->mm != thread->mm) -return ERR_PTR (-EINVAL ); - process =find_process (thread, false);if (!process)return ERR_PTR (-EINVAL );
Signature · 1 line
2.52.0
PATCH v2 5/7 drm/pan*: don't abuse current->group_leader
In reply to Oleg NesterovCleanup and preparation to simplify the next changes.
Use current->tgid instead of current->group_leader->pid.
--- drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/panfrost/panfrost_gem.c +1 -1
@@ -17,7 +17,7 @@static void panfrost_gem_debugfs_bo_add (struct panfrost_device *pfdev,struct panfrost_gem_object *bo) { - bo->debugfs.creator.tgid = current->group_leader->pid; + bo->debugfs.creator.tgid = current->tgid;get_task_comm (bo->debugfs.creator.process_name, current->group_leader);mutex_lock (&pfdev->debugfs.gems_lock);
drivers/gpu/drm/panthor/panthor_gem.c +1 -1
@@ -27,7 +27,7 @@ static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo)struct panthor_device *ptdev =container_of (bo->base.base.dev, struct panthor_device, base); - bo->debugfs.creator.tgid = current->group_leader->pid; + bo->debugfs.creator.tgid = current->tgid;get_task_comm (bo->debugfs.creator.process_name, current->group_leader);mutex_lock (&ptdev->gems.lock);
Signature · 1 line
2.52.0
PATCH v2 6/7 RDMA/umem: don't abuse current->group_leader
In reply to Oleg NesterovCleanup and preparation to simplify the next changes.
Use current->tgid instead of current->group_leader->pid.
--- drivers/infiniband/core/umem_odp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/core/umem_odp.c +2 -2
@@ -149,7 +149,7 @@ struct ib_umem_odp *ib_umem_odp_alloc_implicit(struct ib_device *device, umem->owning_mm = current->mm; umem_odp->page_shift =PAGE_SHIFT ; - umem_odp->tgid =get_task_pid (current->group_leader,PIDTYPE_PID ); + umem_odp->tgid =get_task_pid (current,PIDTYPE_TGID );ib_init_umem_implicit_odp (umem_odp);return umem_odp; }
@@ -258,7 +258,7 @@ struct ib_umem_odp *ib_umem_odp_get(struct ib_device *device, umem_odp->page_shift =HPAGE_SHIFT ;#endif - umem_odp->tgid =get_task_pid (current->group_leader,PIDTYPE_PID ); + umem_odp->tgid =get_task_pid (current,PIDTYPE_TGID ); ret =ib_init_umem_odp (umem_odp, ops);if (ret) goto err_put_pid;
Signature · 1 line
2.52.0
PATCH v2 7/7 netclassid: use thread_group_leader(p) in update_classid_task()
In reply to Oleg NesterovCleanup and preparation to simplify the next changes.
--- net/core/netclassid_cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/netclassid_cgroup.c +1 -1
@@ -93,7 +93,7 @@ static void update_classid_task(struct task_struct *p, u32 classid)/* Only update the leader task, when many threads in this task, * so it can avoid the useless traversal. */ -if (p != p->group_leader) +if (!thread_group_leader (p))return ; do {
Signature · 1 line
2.52.0
Re: [PATCH v2 7/7] netclassid: use thread_group_leader(p) in update_classid_task()
Quoted 1 line · On Sun, 25 Jan 2026 17:08:00 +0100 Oleg Nesterov wrote:
Cleanup and preparation to simplify the next changes.
Re: [PATCH v2 7/7] netclassid: use thread_group_leader(p) in update_classid_task()
In reply to Oleg NesterovQuoted 2 lines · On Sun, 25 Jan 2026 17:08:00 +0100 Oleg Nesterov <[email protected]> wrote:
Cleanup and preparation to simplify the next changes.
"next changes". This is the final patch?
Quoted 13 lines
net/core/netclassid_cgroup.c +1
-1@@ -93,7 +93,7 @@ static void update_classid_task(struct task_struct *p, u32 classid)/* Only update the leader task, when many threads in this task, * so it can avoid the useless traversal. */ -if (p != p->group_leader) +if (!thread_group_leader (p))return ; do {Signature · 1 line
2.52.0
Re: [PATCH v2 7/7] netclassid: use thread_group_leader(p) in update_classid_task()
Quoted 6 lines · On Mon, 26 Jan 2026 12:50:48 -0800 Andrew Morton <[email protected]>…
Quoted 2 lines · On Sun, 25 Jan 2026 17:08:00 +0100 Oleg Nesterov <[email protected]> wrote:
Cleanup and preparation to simplify the next changes.
"next changes". This is the final patch?
Ah, sorry, [0/n] explains. I'll make that "planned future changes".