mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Elliot Berman" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Elliot Berman <quic_eberman@quicinc.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Abhijeet Dharmapurikar <quic_adharmap@quicinc.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/urgent] freezer,sched: Do not restore saved_state of a thawed task
Date: Wed, 29 Nov 2023 14:55:43 -0000	[thread overview]
Message-ID: <170126974302.398.5668977195119638525.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20231120-freezer-state-multiple-thaws-v1-1-f2e1dd7ce5a2@quicinc.com>

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     23ab79e8e469e2605beec2e3ccb40d19c68dd2e0
Gitweb:        https://git.kernel.org/tip/23ab79e8e469e2605beec2e3ccb40d19c68dd2e0
Author:        Elliot Berman <quic_eberman@quicinc.com>
AuthorDate:    Mon, 20 Nov 2023 09:36:31 -08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 29 Nov 2023 15:43:48 +01:00

freezer,sched: Do not restore saved_state of a thawed task

It is possible for a task to be thawed multiple times when mixing the
*legacy* cgroup freezer and system-wide freezer. To do this, freeze the
cgroup, do system-wide freeze/thaw, then thaw the cgroup. When this
happens, then a stale saved_state can be written to the task's state
and cause task to hang indefinitely. Fix this by only trying to thaw
tasks that are actually frozen.

This change also has the marginal benefit avoiding unnecessary
wake_up_state(p, TASK_FROZEN) if we know the task is already thawed.
There is not possibility of time-of-compare/time-of-use race when we skip
the wake_up_state because entering/exiting TASK_FROZEN is guarded by
freezer_lock.

Fixes: 8f0eed4a78a8 ("freezer,sched: Use saved_state to reduce some spurious wakeups")
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Abhijeet Dharmapurikar <quic_adharmap@quicinc.com>
Link: https://lore.kernel.org/r/20231120-freezer-state-multiple-thaws-v1-1-f2e1dd7ce5a2@quicinc.com
---
 kernel/freezer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/freezer.c b/kernel/freezer.c
index c450fa8..759006a 100644
--- a/kernel/freezer.c
+++ b/kernel/freezer.c
@@ -201,7 +201,7 @@ void __thaw_task(struct task_struct *p)
 	if (WARN_ON_ONCE(freezing(p)))
 		goto unlock;
 
-	if (task_call_func(p, __restore_freezer_state, NULL))
+	if (!frozen(p) || task_call_func(p, __restore_freezer_state, NULL))
 		goto unlock;
 
 	wake_up_state(p, TASK_FROZEN);

  reply	other threads:[~2023-11-29 15:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-20 17:36 [PATCH 0/2] freezer,sched: do " Elliot Berman
2023-11-20 17:36 ` [PATCH 1/2] " Elliot Berman
2023-11-29 14:55   ` tip-bot2 for Elliot Berman [this message]
2023-11-20 17:36 ` [PATCH 2/2] freezer,sched: clean saved_state when restoring it during thaw Elliot Berman
2023-11-29 14:55   ` [tip: sched/core] freezer,sched: Clean " tip-bot2 for Elliot Berman
2023-11-28  9:12 ` [PATCH 0/2] freezer,sched: do not restore saved_state of a thawed task Aiqun(Maria) Yu
2023-11-28 17:31   ` Peter Zijlstra
2023-11-28 17:33     ` Elliot Berman
2023-11-28 17:54       ` 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=170126974302.398.5668977195119638525.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=quic_adharmap@quicinc.com \
    --cc=quic_eberman@quicinc.com \
    --cc=x86@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

all inboxes | Powered by JetHome®