From patchwork Wed Nov 29 14:55:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 171417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp402515vqn; Wed, 29 Nov 2023 07:09:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnsW7+Gq7qN16iRmTirMOfUm8fJKcM7QDCYf9vEzVwuJsgoEDfagPKTSsgrLFaVMvWxLTb X-Received: by 2002:a17:902:dac4:b0:1cf:f353:6e47 with SMTP id q4-20020a170902dac400b001cff3536e47mr7665632plx.20.1701270540515; Wed, 29 Nov 2023 07:09:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701270540; cv=none; d=google.com; s=arc-20160816; b=T7V9iy1/4i7oxQCBfIBQfGAa9qEPBTmmoKgiA74aA7SkIG7OlyRD7w7l9Ijmgm3+DM 9hAIQ5V+MlTZeT2uRTYHCizTKbPevw9P1han/+4mIBRUOY8VuES8u4TRUFekGerC7nY4 vPA7DiLiTyfERQCA5zRRWnICT8tTgzl+VasX5ShASLkYtVJxyx53+Gg46ItkbV7zqJc1 KhfBHBDe3B8/u57/6T8jVnjLDYCyZUo6NUlvEJRPoy3kRvRNz5I1HUdx1kPlgzLjS3JS RMznJr3TZ3rITJImmiiTlxlpQeH27Bvn0InEDk4SfZKGqG2FfYZkBY7S7uiY7WoIKYTZ +LrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=u7fdg9HsOCuKA61WgZU0Q3a150uw7ZsSmWZm77p0STY=; fh=pIvq8ubd1qLpmITja4IINl0Y8I44GyKtT/re3tlUWsI=; b=JoIv9LklLcGJwfrqecA2uJFQT3zRzLXPe4fqN7PmYjwYfKWgmtsO2HO7ajb77St7jS kzWnjwO5YHWZcW95Dek/UaW66R8Ar50nrSw7ksnh5BGxIk6eW8fi182EALfHUJSLWBLV GzP3I9JODncZyhMonoXA9+YMC5oP0L0NTLbIDmEaoCEfI5gMqswAu+ctpcIWWjchj8Qp 2rcy2+ptAjkrOm8m47Y805VG2uV87sJ+vUNmh2r0X9VL1JDXbF5pFenhiQu1o+eWIZQI dNj+s4HJUxdTxg/qt828OqkLx7RJFoJ1zZzQS18cyH2XgdklisNYzz90dYfzbuWE99yl BvGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3VS2nUxh; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id me12-20020a170902fc4c00b001d0220f4543si434288plb.540.2023.11.29.07.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 07:09:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3VS2nUxh; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3F0E98043EC5; Wed, 29 Nov 2023 07:08:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231777AbjK2PIk (ORCPT + 99 others); Wed, 29 Nov 2023 10:08:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234844AbjK2Ozk (ORCPT ); Wed, 29 Nov 2023 09:55:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2045310DF; Wed, 29 Nov 2023 06:55:45 -0800 (PST) Date: Wed, 29 Nov 2023 14:55:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701269743; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u7fdg9HsOCuKA61WgZU0Q3a150uw7ZsSmWZm77p0STY=; b=3VS2nUxhbvX0YkzobvkabVg1G3ZXYUUY0jsOHrr1xGUq925nsPWUfxr+Pe+Uj1OA9ECpMP YK24kCIQjXaT3FOwFPZAcWo4rIrJKB+ScNMprL93VsHStttXFHe7YUtUAFvMt2VkGDXg0S hzvJitaCLYKZmqlm08WTE4ExFf0jnPbapHlxhBoslbH3bfn/7leN4hLCLxkkmovPyUVUGa XE1CFmGKsNk1np+UC4Zt7ktOv2uUf4Hm/pfMQGg/ZrrL+WC10uF/8N58NRSMLqsbH8WJzd VGI7eRuYv+6/HLQE4wnkFSbo/UQ9SyXJtZANpLFUpfof+q3T2jQEYf1NF4iNRA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701269743; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u7fdg9HsOCuKA61WgZU0Q3a150uw7ZsSmWZm77p0STY=; b=Fp0sg0f3pICor0IYtjwps1teD4BvPlL6tKD7Z/lZmK7hU5NZggyIUwRj6UC3jpDt4XhAZY TnGK6OytYQMq14DA== From: "tip-bot2 for Elliot Berman" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/urgent] freezer,sched: Do not restore saved_state of a thawed task Cc: Elliot Berman , "Peter Zijlstra (Intel)" , Abhijeet Dharmapurikar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231120-freezer-state-multiple-thaws-v1-1-f2e1dd7ce5a2@quicinc.com> References: <20231120-freezer-state-multiple-thaws-v1-1-f2e1dd7ce5a2@quicinc.com> MIME-Version: 1.0 Message-ID: <170126974302.398.5668977195119638525.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 07:08:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783911458226168935 X-GMAIL-MSGID: 1783911458226168935 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 AuthorDate: Mon, 20 Nov 2023 09:36:31 -08:00 Committer: Peter Zijlstra 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 Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Abhijeet Dharmapurikar 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);