On 03/22, Thomas Gleixner wrote: > > +static void sigqueue_cache_or_free(struct sigqueue *q, bool cache) > +{ > + /* > + * Cache one sigqueue per task. This pairs with the consumer side > + * in __sigqueue_alloc() and needs READ/WRITE_ONCE() to prevent the > + * compiler from store tearing and to tell KCSAN that the data race > + * is intentional when run without holding current->sighand->siglock, > + * which is fine as current obviously cannot run __sigqueue_free() > + * concurrently. > + */ > + if (cache && !READ_ONCE(current->sigqueue_cache)) > + WRITE_ONCE(current->sigqueue_cache, q); > + else > + kmem_cache_free(sigqueue_cachep, q); > +} > + > +void exit_task_sigqueue_cache(struct task_struct *tsk) > +{ > + /* Race free because @tsk is mopped up */ > + struct sigqueue *q = tsk->sigqueue_cache; > + > + if (q) { > + tsk->sigqueue_cache = NULL; > + /* If task is self reaping, don't cache it back */ > + sigqueue_cache_or_free(q, tsk != current); ^^^^^^^^^^^^^^ Still not right or I am totally confused.
tsk != current can be true if an exiting (and autoreaping) sub-thread releases its group leader. IOW. Suppose a process has 2 threads, its parent ignores SIGCHLD. The group leader L exits. Then its sub-thread T exits too and calls release_task(T). In this case the tsk != current is false. But after that T calls release_task(L) and L != T is true. I'd suggest to free tsk->sigqueue_cache in __exit_signal() unconditionally and remove the "bool cache" argument from sigqueue_cache_or_free(). Oleg.