]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - kernel/taskstats.c
Merge tag 'linux-watchdog-5.5-fixes' of git://www.linux-watchdog.org/linux-watchdog
[linux.git] / kernel / taskstats.c
index 13a0f2e6ebc2c5de1d1a3c00a780ef9588d4cfb7..e2ac0e37c4ae7bac1b574e8b660a1203d01a75fd 100644 (file)
@@ -554,25 +554,33 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
 static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
 {
        struct signal_struct *sig = tsk->signal;
-       struct taskstats *stats;
+       struct taskstats *stats_new, *stats;
 
-       if (sig->stats || thread_group_empty(tsk))
-               goto ret;
+       /* Pairs with smp_store_release() below. */
+       stats = smp_load_acquire(&sig->stats);
+       if (stats || thread_group_empty(tsk))
+               return stats;
 
        /* No problem if kmem_cache_zalloc() fails */
-       stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
+       stats_new = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
 
        spin_lock_irq(&tsk->sighand->siglock);
-       if (!sig->stats) {
-               sig->stats = stats;
-               stats = NULL;
+       stats = sig->stats;
+       if (!stats) {
+               /*
+                * Pairs with smp_store_release() above and order the
+                * kmem_cache_zalloc().
+                */
+               smp_store_release(&sig->stats, stats_new);
+               stats = stats_new;
+               stats_new = NULL;
        }
        spin_unlock_irq(&tsk->sighand->siglock);
 
-       if (stats)
-               kmem_cache_free(taskstats_cache, stats);
-ret:
-       return sig->stats;
+       if (stats_new)
+               kmem_cache_free(taskstats_cache, stats_new);
+
+       return stats;
 }
 
 /* Send pid data out on exit */