From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CE4553570C1; Tue, 9 Sep 2025 19:17:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757445421; cv=none; b=Ui26gJBpWWHayWA7h//XSLwdfa8b0z4TxFgDGe5eDFYC8bQZ+XqCkZqeetxPi/r6I8xUdASaDQjU0vK2fCRZ0kalTsfhmoArJ7FDFu0eA4nUuLYYwhhjbcstUuF9HYCC8VpYG5nWKYPrEr+BvzOZwkneUN1bj4bJt34ERz1JjaE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757445421; c=relaxed/simple; bh=3S7JR1J0KLdyO8pzE3T0jrrcCJZbmsNBb/5yq5sNZ4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m6qrpox/vYJllnuHPmb/vZMvuNpK8bCmwepjGCDBZo0QSZoZ/mW6f8YcN/tRyYZCmAbgsw38JZYoiDr0ODd6cBx/BObUWKBjeD7V2DiexQZGen+wjl48UYc3b3y2VUgVVuO/Bpl4RPHgvGT1re0wSFYyadWrUaEUMB0oY/J3QO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BZPx17BJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BZPx17BJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71BBBC4CEFB; Tue, 9 Sep 2025 19:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757445421; bh=3S7JR1J0KLdyO8pzE3T0jrrcCJZbmsNBb/5yq5sNZ4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BZPx17BJcjBtzqBfOofygLJoWjpryBLy94iyWDVTJSc8fSyZi1iutt9KOs0CbXhrG 7jssnzrLaHsKm97Lf9k5rgwk6N7g1wO9731N4Gs3rPcMqoRUk3KajLbdo2nWl/o0M9 l3HX2gAaU3K/QdryeGaiTuldFFZVidaOofVTTtNib2rtu1AO1QAUugqpzx8bB0RAwW eMDOOrtfPAK77qaLWHFEFbd4miURqNtXQxBdxjghk12LSq6ch5K5tAgX6LsfjalByW ykvqikgi65r3/Qh915xzVpkpw8PJCCBvlzp/41fKSIahKgSgIgis6c8cKLvitBSzkh G9cUzIBziEYSw== From: "Mario Limonciello (AMD)" To: "Rafael J . Wysocki" , Greg Kroah-Hartman , Danilo Krummrich , Bjorn Helgaas Cc: Pavel Machek , Len Brown , =?UTF-8?q?Christian=20K=C3=B6nig?= , "James E . J . Bottomley" , "Martin K . Petersen" , Steven Rostedt , linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software Suspend, aka swsusp)), amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM DRIVERS), dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-scsi@vger.kernel.org (open list:SCSI SUBSYSTEM), linux-usb@vger.kernel.org (open list:USB SUBSYSTEM), linux-trace-kernel@vger.kernel.org (open list:TRACING), AceLan Kao , Kai-Heng Feng , Mark Pearson , =?UTF-8?q?Merthan=20Karaka=C5=9F?= , Eric Naim , "Guilherme G . Piccoli" , "Mario Limonciello (AMD)" , Denis Benato Subject: [PATCH v7 11/12] PM: Use hibernate flows for system power off Date: Tue, 9 Sep 2025 14:16:18 -0500 Message-ID: <20250909191619.2580169-12-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250909191619.2580169-1-superm1@kernel.org> References: <20250909191619.2580169-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the system is powered off the kernel will call device_shutdown() which will issue callbacks into PCI core to wake up a device and call it's shutdown() callback. This will leave devices in ACPI D0 which can cause some devices to misbehave with spurious wakeups and also leave some devices on which will consume power needlessly. The issue won't happen if the device is in D3 before system shutdown, so putting device to low power state before shutdown solves the issue. ACPI Spec 6.5, "7.4.2.5 System \_S4 State" says "Devices states are compatible with the current Power Resource states. In other words, all devices are in the D3 state when the system state is S4." The following "7.4.2.6 System \_S5 State (Soft Off)" states "The S5 state is similar to the S4 state except that OSPM does not save any context." so it's safe to assume devices should be at D3 for S5. To accomplish this, use the PMSG_POWEROFF event to call all the device hibernate callbacks when the kernel is compiled with hibernate support. If compiled without hibernate support or hibernate fails fall back into the previous shutdown flow. Cc: AceLan Kao Cc: Kai-Heng Feng Cc: Mark Pearson Cc: Merthan Karakaş Tested-by: Eric Naim Tested-by: Denis Benato Link: https://lore.kernel.org/linux-pci/20231213182656.6165-1-mario.limonciello@amd.com/ Link: https://lore.kernel.org/linux-pci/20250506041934.1409302-1-superm1@kernel.org/ Signed-off-by: Mario Limonciello (AMD) --- v5: * split to multiple commits, re-order v4: * https://lore.kernel.org/linux-pci/20250616175019.3471583-1-superm1@kernel.org/ v3: * Add new PMSG_POWEROFF and PM_EVENT_POWEROFF which alias to poweroff callbacks * Don't try to cleanup on dpm_suspend_start() or dpm_suspend_end() failures Jump right into normal shutdown flow instead. * https://lore.kernel.org/linux-pm/20250609024619.407257-1-superm1@kernel.org/T/#me6db0fb946e3d604a8f3d455128844ed802c82bb --- kernel/reboot.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/reboot.c b/kernel/reboot.c index ec087827c85cd..c8835f8e5f271 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -305,6 +306,11 @@ static void kernel_shutdown_prepare(enum system_states state) (state == SYSTEM_HALT) ? SYS_HALT : SYS_POWER_OFF, NULL); system_state = state; usermodehelper_disable(); +#ifdef CONFIG_HIBERNATE_CALLBACKS + if (!dpm_suspend_start(PMSG_POWEROFF) && !dpm_suspend_end(PMSG_POWEROFF)) + return; + pr_emerg("Failed to power off devices, using shutdown instead.\n"); +#endif device_shutdown(); } /** -- 2.43.0