Linux Power Management development
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: rjw@rjwysocki.net, mingo@kernel.org, vincent.guittot@linaro.org,
	dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de,
	Will Deacon <will@kernel.org>, Tejun Heo <tj@kernel.org>,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH] freezer,sched: Rewrite core freezer logic
Date: Mon, 14 Jun 2021 18:54:23 +0200	[thread overview]
Message-ID: <20210614165422.GC13677@redhat.com> (raw)
In-Reply-To: <20210614161221.GC68749@worktop.programming.kicks-ass.net>

On 06/14, Peter Zijlstra wrote:
>
> On Mon, Jun 14, 2021 at 05:42:47PM +0200, Oleg Nesterov wrote:
> >
> > > +	/*
> > > +	 * If stuck in TRACED, and the ptracer is FROZEN, we're frozen too.
> > > +	 */
> > > +	if (task_is_traced(p))
> > > +		return frozen(rcu_dereference(p->parent));
> >
> > This looks racy, p->parent can resume this task and then enter
> > __refrigerator().
>
> But this is about the child, we won't report it frozen, unless the
> parent is also frozen. If the parent is frozen, it cannot resume the
> task.

Yes, but...

> The other way around, if the parent resumes the task and then gets
> frozen,

Yes ...

> then we'll wait until the task gets frozen.

how/where will we wait until the tracee gets frozen ?

Again, suppose that p->parent resumes p and gets frozen after the
task_is_traced(p) check and before the frozen(p->parent) check.

Then try_to_freeze_tasks() can succeed with todo == 0 and miss the
running "p" ?

> > > +	 * If stuck in STOPPED and the parent is FROZEN, we're frozen too.
> > > +	 */
> > > +	if (task_is_stopped(p))
> > > +		return frozen(rcu_dereference(p->real_parent));
> >
> > (you could use ->parent in this case too and unify this check with the
> > "traced" case above)
>
> Are you sure? The way I read the code ptrace_attach() will change
> ->parent, but STOPPED is controlled by the jobctl.

Yes, sorry I was not clear. let me add more details.

task_is_stopped() is only possible if task is not ptraced, see the
"if (!current->ptrace)" check before set_special_state(TASK_STOPPED)
in do_signal_stop(). And if the task is not traced, then
task->parent == task->real_parent.

> > I don't understand. How this connects to ->parent or ->real_parent?
> > SIGCONT can come from anywhere and wake this stopped task up?
>
> Could be me who's not understanding, I thought only the real parent
> could do that.

No, any task can do this, as long as check_kill_permission() succeeds.
Even the kernel can send SIGCONT, say, you can use F_SETSIG(SIGCONT).

> > I guess you do this to avoid freezable_schedule() in ptrace/signal_stop,
> > and we can't use TASK_STOPPED|TASK_FREEZABLE, it should not run after
> > thaw()... But see above, we can't rely on __frozen(parent).
>
> I do this because freezing puts a task in TASK_FROZEN, and that cannot
> preserve TAKS_STOPPED or TASK_TRACED without being subject to wakups

Yes, yes, this is what I tried to say.

Oleg.


  reply	other threads:[~2021-06-14 16:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  8:45 [PATCH] freezer,sched: Rewrite core freezer logic Peter Zijlstra
2021-06-11  8:46 ` Peter Zijlstra
2021-06-11 13:58 ` Rafael J. Wysocki
2021-06-14 15:42 ` Oleg Nesterov
2021-06-14 16:12   ` Peter Zijlstra
2021-06-14 16:54     ` Oleg Nesterov [this message]
2021-06-14 18:38       ` Peter Zijlstra
2021-06-15 15:45         ` Oleg Nesterov
2021-06-15 21:35           ` Peter Zijlstra
2021-06-15 21:50           ` Peter Zijlstra

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=20210614165422.GC13677@redhat.com \
    --to=oleg@redhat.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rjw@rjwysocki.net \
    --cc=rostedt@goodmis.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=will@kernel.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