From patchwork Tue Oct 24 09:14:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Feng X-Patchwork-Id: 738119 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93D1DC00A8F for ; Tue, 24 Oct 2023 09:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232558AbjJXJPv (ORCPT ); Tue, 24 Oct 2023 05:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232975AbjJXJPu (ORCPT ); Tue, 24 Oct 2023 05:15:50 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 465578E for ; Tue, 24 Oct 2023 02:15:41 -0700 (PDT) X-UUID: e4eeb2b0724d11ee8051498923ad61e6-20231024 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=C65fuxLFHO408wA3c7k4bgrNlQElbjQowZkoFRSLHFY=; b=hfPIYdB1mJWUFZjJyA/Dmk6Up1r7rdB6SDjmJN21JsJdU3l0lNOVWaDYSWbGEJvUfJfZrs+dstAANSEb06gVYLeehr778HNqPGWKr23TwN7uJ6tyHZRnFyA/5PIWMy3+tpfg0ABUV4GK8JWaBLtmtVB4oT1BOhr7ML7yj3SQSLk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32, REQID:76b84638-957b-4b68-bdc9-e406572ece75, IP:0, U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:5f78ec9, CLOUDID:32f640d7-04a0-4e50-8742-3543eab8cb8e, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO, DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: e4eeb2b0724d11ee8051498923ad61e6-20231024 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 163662820; Tue, 24 Oct 2023 17:15:37 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 24 Oct 2023 17:15:36 +0800 Received: from mcddlt001.gcn.mediatek.inc (10.19.240.15) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 24 Oct 2023 17:15:35 +0800 From: To: , , CC: , , , , , , Chris Feng Subject: [PATCH] PM: hibernate: Fix the bug where wake events cannot wake system during hibernation Date: Tue, 24 Oct 2023 17:14:47 +0800 Message-ID: <20231024091447.108072-1-chris.feng@mediatek.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Chris Feng Wake-up events that occur in the hibernation process's hibernation_platform_enter() cannot wake up the system. Although the current hibernation framework will execute part of the recovery process after a wake-up event occurs, it ultimately performs a shutdown operation because the system does not check the return value of hibernation_platform_enter(). Moreover, when restoring the device before system shutdown, the device's I/O and DMA capabilities will be turned on, which can lead to data loss. To solve this problem, check the return value of hibernation_platform_enter(). When it returns a non-zero value, execute the hibernation recovery process, discard the previously saved image, and ultimately return to the working state. Signed-off-by: Chris Feng --- kernel/power/hibernate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 8d35b9f9aaa3..16d8027a195d 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -642,9 +642,9 @@ int hibernation_platform_enter(void) */ static void power_down(void) { -#ifdef CONFIG_SUSPEND int error; +#ifdef CONFIG_SUSPEND if (hibernation_mode == HIBERNATION_SUSPEND) { error = suspend_devices_and_enter(mem_sleep_current); if (error) { @@ -667,7 +667,13 @@ static void power_down(void) kernel_restart(NULL); break; case HIBERNATION_PLATFORM: - hibernation_platform_enter(); + error = hibernation_platform_enter(); + if (error) { + swsusp_unmark(); + events_check_enabled = false; + pr_err("Hibernation Abort.\n"); + return; + } fallthrough; case HIBERNATION_SHUTDOWN: if (kernel_can_power_off())