Skip to contentSkip to conversation

taskstats_tgid_free: fix usage

PATCH In review Oleg Nesterov 2 participants 2 messages Oct 26, 2006 – Oct 31, 2006

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 3/6 taskstats_tgid_free: fix usage

taskstats_tgid_free() is called on copy_process's error path. This is wrong.

IF (clone_flags & CLONE_THREAD)
We should not clear ->signal->taskstats, current uses it, it probably has a valid accumulated info.
ELSE
taskstats_tgid_init() set ->signal->taskstats = NULL, there is nothing to free.

Move the callsite to __exit_signal(). We don't need any locking, entire thread group is exiting, nobody should have a reference to soon to be released ->signal.

include/linux/taskstats_kern.h renamed from include/linux/taskstats_kern.h~3_free +2 -11
@@ -49,17 +49,8 @@ static inline void taskstats_tgid_alloc(
 
 static inline void taskstats_tgid_free(struct signal_struct *sig)
 {
-	struct taskstats *stats = NULL;
-	unsigned long flags;
-
-	spin_lock_irqsave(&sig->stats_lock, flags);
-	if (sig->stats) {
-		stats = sig->stats;
-		sig->stats = NULL;
-	}
-	spin_unlock_irqrestore(&sig->stats_lock, flags);
-	if (stats)
-		kmem_cache_free(taskstats_cache, stats);
+	if (sig->stats)
+		kmem_cache_free(taskstats_cache, sig->stats);
 }
 
 extern void taskstats_exit_alloc(struct taskstats **, unsigned int *);
kernel/fork.c renamed from kernel/fork.c~3_free +0 -1
@@ -897,7 +897,6 @@ static inline int copy_signal(unsigned l
 void __cleanup_signal(struct signal_struct *sig)
 {
 	exit_thread_group_keys(sig);
-	taskstats_tgid_free(sig);
 	kmem_cache_free(signal_cachep, sig);
 }
 
kernel/exit.c renamed from kernel/exit.c~3_free +1 -0
@@ -128,6 +128,7 @@ static void __exit_signal(struct task_st
 	flush_sigqueue(&tsk->pending);
 	if (sig) {
 		flush_sigqueue(&sig->shared_pending);
+		taskstats_tgid_free(sig);
 		__cleanup_signal(sig);
 	}
 }
Acked-by on v1 3/6
#1 lore raw
Quoted 9 lines · Oleg Nesterov

taskstats_tgid_free() is called on copy_process's error path. This is wrong.

IF (clone_flags & CLONE_THREAD)
We should not clear ->signal->taskstats, current uses it, it probably has a valid accumulated info.
ELSE
taskstats_tgid_init() set ->signal->taskstats = NULL, there is nothing to free.

Quoted 5 lines

Move the callsite to __exit_signal(). We don't need any locking, entire thread group is exiting, nobody should have a reference to soon to be released ->signal.

Looks good!

---

Balbir Singh,
Linux Technology Center,
IBM Software Labs