public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Matt Fleming <matt@codeblueprint.co.uk>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: Re: [patch V4 2/2] signal: Allow tasks to cache one sigqueue struct
Date: Tue, 23 Mar 2021 19:04:42 +0100	[thread overview]
Message-ID: <20210323180442.GC29219@redhat.com> (raw)
In-Reply-To: <20210322092259.067712342@linutronix.de>

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.


  reply	other threads:[~2021-03-23 18:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22  9:19 [patch V4 0/2] signals: Allow caching one sigqueue object per task Thomas Gleixner
2021-03-22  9:19 ` [patch V4 1/2] signal: Hand SIGQUEUE_PREALLOC flag to __sigqueue_alloc() Thomas Gleixner
2021-04-15  8:37   ` [tip: sched/core] " tip-bot2 for Thomas Gleixner
2021-03-22  9:19 ` [patch V4 2/2] signal: Allow tasks to cache one sigqueue struct Thomas Gleixner
2021-03-23 18:04   ` Oleg Nesterov [this message]
2021-03-23 19:24     ` Thomas Gleixner
2021-03-23 21:05       ` [patch V5 " Thomas Gleixner
2021-03-24 18:03         ` Oleg Nesterov
2021-04-15  8:37         ` [tip: sched/core] " tip-bot2 for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210323180442.GC29219@redhat.com \
    --to=oleg@redhat.com \
    --cc=bigeasy@linutronix.de \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=ebiederm@xmission.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox