Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp556375lqp; Fri, 5 Apr 2024 01:45:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOjKAB7VRMJ0t1C2KLiGrdbphGyyKnc/ljViMwRjDTAzkaKihmIw6K1WvOJXh5HyICFJ8wEYxipq1qsHVsEpGy8uFc/dl47Fn5NVGu2A== X-Google-Smtp-Source: AGHT+IEX4OBDu+uwZKwizVGtQ/4YEZhb4pkeV5kzsEr68fbIcUz2RPnNQCrZNcOzSp0SQC8kuiRY X-Received: by 2002:a17:90a:df86:b0:2a2:8ed7:da38 with SMTP id p6-20020a17090adf8600b002a28ed7da38mr710009pjv.2.1712306750719; Fri, 05 Apr 2024 01:45:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712306750; cv=pass; d=google.com; s=arc-20160816; b=X6fdcq96G/RCMSR68NZM3ERo1qK/VynvMuyKP9AZZFoKHWkBLCUXJdaEmvN0JolkgH 20/aYRyFthcp2ak0nvhxw/0haqBS3Ehs6aPpwIMq2BVbAJnlJNK3nKmgifrYX8fMA2v7 +tCqBQpLF7YpwTjoxvr4Rmt7NKtF9mA42HpAVHyTYWfm25Igoicv3jI3VCRbeunozxjz Y6mw1Bov4jDx7/56/QFfTqQuUYD6kQT1wi/76hVqi1lhq5wW6G9YCIJSjVwG9aUW6ioY 3KVfcSm4neRnFkWjfOQTZh+1N6KuYQwuQpzP9n1f2HQFKPia00nIisogF/U3ywA+5AlJ P7kQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :dkim-signature:dkim-signature:from; bh=vz9gdAWslzxa17vDr2RXb+lx+EfINHoYwLIVtOfMNtI=; fh=IS50kfuJO0sIatEHsJeB995UPbwSZ8Qu2uwz5C2wVRI=; b=PuqyQIANs6FgZ263PRpxkOLs3eqtb4Mrncm4WJvF58olEJV9f3m22p8Jh0VmIVb+AB 2M3zGgx5ZD5lWUce8VmNx2pA76OGEo2qB/XGeI375waCPpbgy3aTLyw+evMvhI7kMND6 93LZA8GWi2eAf3vkglj6S6h6LYyA44dvxDbDHtK6QY7gY2lMElbcdAM/yebKSZSCNX6u I4ldsa0sr6WfZNRDeSSLwhn9eqHWMu7IUXfMygfiwMnRAopbaMRGIgQ0S/e+9JY9O3L2 VmdOhyQQbMmpl03G8xtnmW2FSDFI3a9WbSZJw5qYbR+mKlTwk6fB7nAEWJUbKHODC4gz hlOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZGPpchnC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-132659-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132659-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e8-20020a17090a9a8800b002a479c95e20si342159pjp.175.2024.04.05.01.45.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 01:45:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132659-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZGPpchnC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-132659-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132659-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C962D28591E for ; Fri, 5 Apr 2024 08:34:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9E6015F338; Fri, 5 Apr 2024 08:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZGPpchnC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iZLMIhAp" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 560B1145B09; Fri, 5 Apr 2024 08:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712306066; cv=none; b=kfeWoybO/nqJ5Lo3cYBHPypD3zKDzfKP+eZ4fo3F2MSoJJGAmlYjnUeXZ8JVkqzeLawnaXTZhCSg/4tbFrP28exqEuQ6WIlUerNF2+9Z5vQ++jtqrBhHoDq+cdKYy2Zc8z7e4U5ACXnIhykKOeosa7AC6gTjo3pIePsBzaR5Eg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712306066; c=relaxed/simple; bh=PR+7ds2HGo2jve0t4aq/uu/b6Ds20Iyx2n8veKfoFqw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=HK1rdOznsgn8upsoFiRQkeY96ToXCvGZ2Bfxr2+DNcme8bjYf8rYTsNINvbxM5SgQZ1z6/Vr8x9v8mhhcJJpD5yNmIJiM4OCXri2EPd48NfnvEryki0V6H+8W+SD+yveBus3EodM82IlnMUHIDdiRL7sq48LfaaL8//7e7JcChU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZGPpchnC; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iZLMIhAp; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712306062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=vz9gdAWslzxa17vDr2RXb+lx+EfINHoYwLIVtOfMNtI=; b=ZGPpchnCt2RNbT1lS8u3Ih0SiM+WOpteLMPsAwQ2vFB493JDuLNdAtMbGkH7fpOTvPb9fk m1120JXJwnveC1nXpyaK1rPS2V491lHQfJc6id+zFOSNc0t4TBXShc5uRu1sro6eHWqt1m rQiL4q23e++KHIaySuYVwMORQKaWpxRJ7bWSx7Bvb6ftAv2lp/y1/iSDe7pcAkzp5gcOLW DBbDs6gUMDF3LWHTeZUsbIt5Pb49M6Ks1sCeutSkNb5v/SJQsrXjCYFhodwMel2EVRfxIx 1b3TbK/fx+iRazqNaDuSIb37FqBz4MsOcXvQ3Qt7Yn7y7gCAoJUNZe3l7hfrQg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712306062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=vz9gdAWslzxa17vDr2RXb+lx+EfINHoYwLIVtOfMNtI=; b=iZLMIhApPYlZDWKi3sN9uPbNXcXtdkpN8bUfaaTBYWnX5UPJJWpYteetnuJCCVS+Wir8MR Tj/It3XOCiV9SBCw== To: linux-kernel@vger.kernel.org Cc: "Rafael J . Wysocki" , Pavel Machek , Len Brown , Ulf Hansson , linux-pm@vger.kernel.org, Frederic Weisbecker , Thomas Gleixner , x86@kernel.org, Anna-Maria Behnsen , Mario Limonciello , stable@kernel.org Subject: [PATCH] PM: s2idle: Make sure CPUs will wakeup directly on resume Date: Fri, 5 Apr 2024 10:34:10 +0200 Message-Id: <20240405083410.4896-1-anna-maria@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit s2idle works like a regular suspend with freezing processes and freezing devices. All CPUs except the control CPU go into idle. Once this is completed the control CPU kicks all other CPUs out of idle, so that they reenter the idle loop and then enter s2idle state. The control CPU then issues an swait() on the suspend state and therefore enters the idle loop as well. Due to being kicked out of idle, the other CPUs leave their NOHZ states, which means the tick is active and the corresponding hrtimer is programmed to the next jiffie. On entering s2idle the CPUs shut down their local clockevent device to prevent wakeups. The last CPU which enters s2idle shuts down its local clockevent and freezes timekeeping. On resume, one of the CPUs receives the wakeup interrupt, unfreezes timekeeping and its local clockevent and starts the resume process. At that point all other CPUs are still in s2idle with their clockevents switched off. They only resume when they are kicked by another CPU or after resuming devices and then receiving a device interrupt. That means there is no guarantee that all CPUs will wakeup directly on resume. As the consequence there is no guarantee that timers which are queued on those CPUs and should expire directly after resume, are handled. Also timer list timers which are remotely queued to one of those CPUs after resume will not result in a reporgramming IPI as the tick is active. A queue hrtimer will also not result in a reprogramming IPI because the first hrtimer event is already in the past. The recent introduction of the timer pull model (7ee988770326 ("timers: Implement the hierarchical pull model")) amplifies this problem, if the current migrator is one of the non woken up CPUs. When a non pinned timer list timer is queued and the queueing CPU goes idle, it relies on the still suspended migrator CPU to expire the timer which will happen by chance. The problem existis since commit 8d89835b0467 ("PM: suspend: Do not pause cpuidle in the suspend-to-idle path"). There the cpuidle_pause() call which in turn invoked a wakeup for all idle CPUs was moved to a later point in the resume process. This might not be reached or reached very late because it waits on a timer of a still suspended CPU. Address this by kicking all CPUs out of idle after the control CPU returns from swait() so that they resume their timers and restore consistent system state. Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218641 Fixes: 8d89835b0467 ("PM: suspend: Do not pause cpuidle in the suspend-to-idle path") Signed-off-by: Anna-Maria Behnsen Tested-by: Mario Limonciello Cc: stable@kernel.org --- kernel/power/suspend.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index e3ae93bbcb9b..09f8397bae15 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -106,6 +106,12 @@ static void s2idle_enter(void) swait_event_exclusive(s2idle_wait_head, s2idle_state == S2IDLE_STATE_WAKE); + /* + * Kick all CPUs to ensure that they resume their timers and restore + * consistent system state. + */ + wake_up_all_idle_cpus(); + cpus_read_unlock(); raw_spin_lock_irq(&s2idle_lock); -- 2.39.2