From patchwork Mon Nov 20 17:36:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 167294 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp99806vqb; Mon, 20 Nov 2023 09:37:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnRqC7BBoy8918hHY6t8j6yJ2mTdxfdtsSOCyCkYliOjwgswFjFvOK9MAJwqqnQKl4RaHs X-Received: by 2002:a17:902:bc4c:b0:1cc:47cf:946f with SMTP id t12-20020a170902bc4c00b001cc47cf946fmr9384193plz.25.1700501870346; Mon, 20 Nov 2023 09:37:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700501870; cv=none; d=google.com; s=arc-20160816; b=p8aaK2YGajO8i6SIKwCz8ZaJpm7dPgcRsQUUxNaDwXT36qO0Vjs+xoFqETMGS4vLgF vwfK4HZ6mVdk+usASIZMdaTJtkbJaxhcRISDwX1OFztfJCEK9PO1c+du49nFlbgSCzlf RBur/QAIdLfQ2Gw5ETyeds6JPgKs5rCAKbwEQyY1OFh8OzH2VpXxAqxuok28wuzudPCy Xc7XvJVsqSOBG24lMaIU9SaMCn90km8Y8zxbCRHsDkIgXYB+sTyJBBiPALMAiPkcwcOR BEspmkBbXaOW+11aZMaoBoeHsh7D0aJtcTQNbtACdnOMaq0VydLKjtir8SZbGY9a3uUR sU6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=JbCQVIXqkNI2H2MAYTXCqiy7vmoSbLN+sWhONQVWWSE=; fh=NkPvJ5bsylham0ZTJm3gmzlKLfQhTMTVKxpWONm89vA=; b=f1HsBv9ZGgcaCrFs4mbu5FFJV0eQ1zjCnx3AIMVodvsQRAlm0rmFUKvqYP59HIy8uD lZ8pFrWOmX4ps5XfiAMqqaiisK/BSaKRSqB59iqOhNC/bpPY7tzIbgBgMxs4jewCiUe1 wbRM12zx0c9HJ/blYn8KZLZ78E38RJYHvjLdmfN9xMaVqAzdHRJr1k7qaNHncOTO7PYP NmDeXd7u5WNUJMuhKhwm3dmenCW7YXHc5NNlULe1I93M2fbN3JNSBFFW/N0BJIilBzuU NaeZrJOMUVTvzr4N+nhQp51VIzZIKUum6O67jfMr0csp6lJphpsZPnbO3eq17xuK7jb7 He+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=La3sMofq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id l2-20020a170903244200b001cf63d5130csi1839351pls.160.2023.11.20.09.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:37:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=La3sMofq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9B6E280AE239; Mon, 20 Nov 2023 09:37:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233827AbjKTRhT (ORCPT + 27 others); Mon, 20 Nov 2023 12:37:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233871AbjKTRhD (ORCPT ); Mon, 20 Nov 2023 12:37:03 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3CD2131; Mon, 20 Nov 2023 09:36:54 -0800 (PST) Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AKHGVjB020976; Mon, 20 Nov 2023 17:36:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : date : subject : mime-version : content-type : content-transfer-encoding : message-id : references : in-reply-to : to : cc; s=qcppdkim1; bh=JbCQVIXqkNI2H2MAYTXCqiy7vmoSbLN+sWhONQVWWSE=; b=La3sMofqd+WN1wbl9ix7XINzkPV7O+AZHLwTo3dsPuo9fs+Znz2jBl+D6qrQcsiDDhk3 oU/ZhqUCJRtbpBI054rBUjCh6Feu+VuZgQYNklJzA4SV+1KCTC3D6p/d/GUNFT8iHs7i bkeZJawWCdjXnQtVoir2KpguZu1ynWLpv6TNKben2h4gmjpjL3bd3jol3iSBVqFri4eH c4zR5dB6qils+c9H/qiipzjlKW2VtDO+ZRgFmQvX4bfKCqpMao+rbeAQ8DH3igi3tf7p 4FF0unywaB6esJllJPM70RGi9N1CaduTbVcn+AW7IAK0KBdKq4xbSzil647e50oIkCaU FQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ug7ea8rjq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 17:36:44 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AKHahKQ011372 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 17:36:43 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 20 Nov 2023 09:36:42 -0800 From: Elliot Berman Date: Mon, 20 Nov 2023 09:36:31 -0800 Subject: [PATCH 1/2] freezer,sched: do not restore saved_state of a thawed task MIME-Version: 1.0 Message-ID: <20231120-freezer-state-multiple-thaws-v1-1-f2e1dd7ce5a2@quicinc.com> References: <20231120-freezer-state-multiple-thaws-v1-0-f2e1dd7ce5a2@quicinc.com> In-Reply-To: <20231120-freezer-state-multiple-thaws-v1-0-f2e1dd7ce5a2@quicinc.com> To: "Rafael J. Wysocki" , Pavel Machek , "Ingo Molnar" , "Peter Zijlstra (Intel)" CC: , Pavan Kondeti , "Aiqun Yu (Maria)" , , , Elliot Berman , Abhijeet Dharmapurikar X-Mailer: b4 0.13-dev X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 8W7odmxie3OejK1QtSb8I4tvck-TU7eD X-Proofpoint-ORIG-GUID: 8W7odmxie3OejK1QtSb8I4tvck-TU7eD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-20_17,2023-11-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 phishscore=0 mlxscore=0 spamscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311200126 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:37:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783105449401064960 X-GMAIL-MSGID: 1783105449401064960 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") Reviewed-by: Abhijeet Dharmapurikar Signed-off-by: Elliot Berman --- kernel/freezer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/freezer.c b/kernel/freezer.c index c450fa8b8b5e..759006a9a910 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); From patchwork Mon Nov 20 17:36:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 167298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp100773vqb; Mon, 20 Nov 2023 09:39:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHW9sUeton/RySYlvuLznxxQCAUeJYhBwZsaoNk4WFx/jpekopjvpcaBz5O1Rfrj197Ba3O X-Received: by 2002:a05:6808:d4d:b0:3ad:f5b3:844c with SMTP id w13-20020a0568080d4d00b003adf5b3844cmr10198674oik.18.1700501967027; Mon, 20 Nov 2023 09:39:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700501966; cv=none; d=google.com; s=arc-20160816; b=upu2wyfJHAVGPhTKiMm7xO6QNGjq36qSx9bYBA4YvLmegR6m+GucEtVNZRud6KHja3 ubcJOOfjHuduSksC1tx/3NJE7gKQSWDVuItPpNqgQIShDV773WPl+GzI1aZnHXcDeY2I EWqKIef1CgPaDGZhCYj6NTsP0BfZQ7ejFex0F82Rj0CjLbi6SeOKiscjdEqys4zPrCoZ QuDgm3/+mo4lxgD9+S0rZ5euCTksuzcg77ooAeTs+Ka9TrngLARV/P7vmg4+GfM3xz3R ILtkZ4mxUmpbcVlf00250l9jEuT0ju0gp/xONKaJRGtaEwbRU3GQABa3F9R6gc4Q2l5p +0IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=EbzvNwj4CIbtC07B2c+ircX4/1kNKJO9XKufiyTSIJ0=; fh=kgddXo3RMdn8JGN08PGNo6HNr6ogGvFJbbMXx6G5yv0=; b=JDwAiGM3qTGEp9rz/8sI0J/wyKdEL2higFa6WJEmPQkl61k61+rgWbruDlK2xDepAu 4AC2HOtBqDflFMIJyH5GPQavkRAciV6p2VhHUZO+LBWf840YBa70TK3HLXPX7IRT6hBL cblAvOYP4ohsh5fJ7kspW0YLFi0ozyH8a6ZzwtTh/kHLbEDJ5VnPrMf0wqMkwWf5o8Jl 9ur16eeFz0CNos2c0Acn+V7VjHp1z8gNO8TjsQjQHURYRWKBFkxHUc1Rgd4cgEZhZuBJ L82LjiBo7iP1hC5PWCaxp+jYw2O/4QFn4idZzUXAu4oYGWilKzKHD7ibcohYrfzahdqB MUtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aTxztQnt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u30-20020a63235e000000b005be095b2545si8301921pgm.183.2023.11.20.09.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:39:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aTxztQnt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CD53480A5F8B; Mon, 20 Nov 2023 09:37:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233916AbjKTRhV (ORCPT + 27 others); Mon, 20 Nov 2023 12:37:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234078AbjKTRhD (ORCPT ); Mon, 20 Nov 2023 12:37:03 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F90F4; Mon, 20 Nov 2023 09:36:55 -0800 (PST) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AKHHUS3010738; Mon, 20 Nov 2023 17:36:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : date : subject : mime-version : content-type : content-transfer-encoding : message-id : references : in-reply-to : to : cc; s=qcppdkim1; bh=EbzvNwj4CIbtC07B2c+ircX4/1kNKJO9XKufiyTSIJ0=; b=aTxztQnt/n3kiYWGSnST6eD2k8dwK874GKNJptFmMhM1Gc+kY5UyQqMD4uNSzsThTlme zNpLm0jQi9F0fmq0TMzqNrCQprZVOPY4660oUPQgIhKzAaCXnKjLL4i7b/6gW5Ifp2h6 ipuYpiZyrvxumOCxXWXw7YTfyX8ph2hKIbc9Izg7V0WD1r0tU36g+s7aCVhLopmBqJC9 DevQ+oNZSWrdD5G5a9zosJer0Dl3FXFM5kFOxQdp8aNg9ns7KgAHuxQoC8u5Au/9f/M3 IpEqsinsH9AWGkGXpY5FvuOy7NL1R3UITdqcJIGgdKE2IJunnkLeoJmK/mafsyyC0mOp wA== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uem80msb5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 17:36:44 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AKHahSD023791 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 17:36:43 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 20 Nov 2023 09:36:43 -0800 From: Elliot Berman Date: Mon, 20 Nov 2023 09:36:32 -0800 Subject: [PATCH 2/2] freezer,sched: clean saved_state when restoring it during thaw MIME-Version: 1.0 Message-ID: <20231120-freezer-state-multiple-thaws-v1-2-f2e1dd7ce5a2@quicinc.com> References: <20231120-freezer-state-multiple-thaws-v1-0-f2e1dd7ce5a2@quicinc.com> In-Reply-To: <20231120-freezer-state-multiple-thaws-v1-0-f2e1dd7ce5a2@quicinc.com> To: "Rafael J. Wysocki" , Pavel Machek , "Ingo Molnar" , "Peter Zijlstra (Intel)" CC: , Pavan Kondeti , "Aiqun Yu (Maria)" , , , Elliot Berman X-Mailer: b4 0.13-dev X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: MCZ21FUTc8k25bPy33QfEDP9AkGXZS95 X-Proofpoint-ORIG-GUID: MCZ21FUTc8k25bPy33QfEDP9AkGXZS95 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-20_17,2023-11-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=665 adultscore=0 priorityscore=1501 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311200126 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:37:28 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783105550749909530 X-GMAIL-MSGID: 1783105550749909530 Clean saved_state after using it during thaw. Cleaning the saved_state allows us to avoid some unnecessary branches in ttwu_state_match. Signed-off-by: Elliot Berman --- kernel/freezer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/freezer.c b/kernel/freezer.c index 759006a9a910..f57aaf96b829 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -187,6 +187,7 @@ static int __restore_freezer_state(struct task_struct *p, void *arg) if (state != TASK_RUNNING) { WRITE_ONCE(p->__state, state); + p->saved_state = TASK_RUNNING; return 1; }