linux-pm.vger.kernel.org archive mirror
 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>,
	linux-kernel@vger.kernel.org, tj@kernel.org,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH v2 4/4] freezer,sched: Rewrite core freezer logic
Date: Wed, 7 Jul 2021 16:14:12 +0200	[thread overview]
Message-ID: <20210707141412.GA17818@redhat.com> (raw)
In-Reply-To: <20210624092616.009504322@infradead.org>

sorry for delay...

I am still trying to understand this series, just one note for now.

On 06/24, Peter Zijlstra wrote:
>
> +static bool __freeze_task(struct task_struct *p)
> +{
> +	unsigned long flags;
> +	unsigned int state;
> +	bool frozen = false;
> +
> +	raw_spin_lock_irqsave(&p->pi_lock, flags);
> +	state = READ_ONCE(p->__state);
> +	if (state & (TASK_FREEZABLE|__TASK_STOPPED|__TASK_TRACED)) {
> +		/*
> +		 * Only TASK_NORMAL can be augmented with TASK_FREEZABLE,
> +		 * since they can suffer spurious wakeups.
> +		 */
> +		if (state & TASK_FREEZABLE)
> +			WARN_ON_ONCE(!(state & TASK_NORMAL));
> +
> +#ifdef CONFIG_LOCKDEP
> +		/*
> +		 * It's dangerous to freeze with locks held; there be dragons there.
> +		 */
> +		if (!(state & __TASK_FREEZABLE_UNSAFE))
> +			WARN_ON_ONCE(debug_locks && p->lockdep_depth);
> +#endif
> +
> +		if (state & (__TASK_STOPPED|__TASK_TRACED))
> +			WRITE_ONCE(p->__state, TASK_FROZEN|__TASK_FROZEN_SPECIAL);

Well, this doesn't look right.

Firstly, this can race with ptrace_freeze_traced() which can set
p->__state = __TASK_TRACED and clear TASK_FROZEN. Or with
__set_current_state(TASK_RUNNING) in ptrace_stop().


But the main problem is that you can't simply remove __TASK_TRACED,
this can confuse the debugger, any ptrace() request will fail as if
the tracee was killed.


Another problem. Suppose that p->parent sleeps in do_wait(). p calls
ptrace_stop(), sets __TASK_TRACED, and wakes the parent up.

__freeze_task() clears __TASK_TRACED.

The parent calls wait_task_stopped(p) but it fails because
task_is_traced() returns false. The parent sleeps again, and forever
because __thaw_special() won't notify it.


Or. Suppose that __freeze_task() removes __TASK_STOPPED. The new
debugger comes, the tracee should switch from STOPPED to TRACED. But
this won't happen because task_is_stopped() in ptrace_() will return
false and task_set_jobctl_pending/signal_wake_up_state won't be called.

Oleg.


  reply	other threads:[~2021-07-07 14:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24  9:21 [PATCH v2 0/4] Freezer rewrite Peter Zijlstra
2021-06-24  9:21 ` [PATCH v2 1/4] freezer: Have {,un}lock_system_sleep() save/restore flags Peter Zijlstra
2021-06-24  9:21 ` [PATCH v2 2/4] freezer,umh: Clean up freezer/initrd interaction Peter Zijlstra
2021-06-24  9:21 ` [PATCH v2 3/4] ptrace: Track __TASK_TRACED state in p->ptrace Peter Zijlstra
2021-06-24  9:22 ` [PATCH v2 4/4] freezer,sched: Rewrite core freezer logic Peter Zijlstra
2021-07-07 14:14   ` Oleg Nesterov [this message]
2021-08-05 11:50     ` Peter Zijlstra
2021-06-30 17:05 ` [PATCH v2 0/4] Freezer rewrite Rafael J. Wysocki
2021-07-06 13:12 ` 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=20210707141412.GA17818@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;
as well as URLs for NNTP newsgroup(s).