From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1DCC6CA1002 for ; Sat, 6 Sep 2025 14:37:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9C26110E3A5; Sat, 6 Sep 2025 14:37:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="oD09KgU5"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id E195610E3B0; Sat, 6 Sep 2025 14:37:23 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id CA0854347A; Sat, 6 Sep 2025 14:37:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2CB8C4CEF9; Sat, 6 Sep 2025 14:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757169443; bh=e45GnWdTbpGR5XbbMlWgx0cpqS/IXSsc+dt4fnRje1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oD09KgU5b1aNTAyh3zXohPA9+D+bEAdiiDFpdtUF75+tApgwdwUlwlGFmlvTZ8ZH1 IO+4mjFdpysiPLG/mG5+TcHV4DohKihMDmIy7v6LihFW02+rvX+fYZJXdEF1UGA+IG mL8X//U20AcW4PM/rHHgGSyMzPNYOahJnRvm/lxu4S/J0BpPIpqgtBtTdC99ufdhAD p8DPKdDD0sxjXF5LOfDqoFfkPP0OQsJD/7FYwcuy59Yk1UT9sBMUZlbUi731Fvy+4M 2KTQtTSyNhU4FtC4J13VzyZy5gtzywkVqETICLlWe1hQSx1+k+oxeg1whAKOyuIyyt v5ABlhpW+GB4Q== 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 , "Mario Limonciello (AMD)" , Denis Benato Subject: [PATCH v6 RESEND 11/11] PM: Use hibernate flows for system power off Date: Sat, 6 Sep 2025 09:36:42 -0500 Message-ID: <20250906143642.2590808-12-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250906143642.2590808-1-superm1@kernel.org> References: <20250906143642.2590808-1-superm1@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" 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) --- 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