From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbcGNKhK (ORCPT ); Thu, 14 Jul 2016 06:37:10 -0400 Received: from mga09.intel.com ([134.134.136.24]:53104 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751116AbcGNKhF (ORCPT ); Thu, 14 Jul 2016 06:37:05 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,362,1464678000"; d="scan'208";a="1006630602" Subject: Re: [PATCH] PM / hibernate: Introduce snapshot test mode for hibernation To: "Rafael J. Wysocki" , Pavel Machek References: <1467873658-31986-1-git-send-email-yu.c.chen@intel.com> <20160713095005.GA27870@amd> <578615D5.3060501@intel.com> <20160713102156.GA14505@atrey.karlin.mff.cuni.cz> <57861A70.9090606@intel.com> <20160713170123.GA13546@amd> <20160713202611.GA32111@amd> <20160713214546.GA26692@amd> Cc: Linux PM , "Rafael J. Wysocki" , Len Brown , Linux Kernel Mailing List From: Chen Yu Message-ID: <57876D21.8050003@intel.com> Date: Thu, 14 Jul 2016 18:44:49 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2016年07月14日 06:18, Rafael J. Wysocki wrote: > On Thu, Jul 14, 2016 at 12:00 AM, Rafael J. Wysocki wrote: >> On Wed, Jul 13, 2016 at 11:45 PM, Pavel Machek wrote: >>> On Wed 2016-07-13 22:44:24, Rafael J. Wysocki wrote: >>>> On Wed, Jul 13, 2016 at 10:26 PM, Pavel Machek wrote: >>>>> On Wed 2016-07-13 22:04:27, Rafael J. Wysocki wrote: >>>>>> On Wed, Jul 13, 2016 at 7:01 PM, Pavel Machek wrote: >>>>>>> Hi! >>>>>>> >>>>>>>>>> and then swapon the swap device, and do a testing. This should be safer? >>>>>>>>> Yeah, that's the way. Read-only root is other option. >>>>>>>>> >>>>>>>>>>> I guess updating documentation would be welcome from my side, >>>>>>>>>>> otherwise it should be ok. >>>>>>>>>> OK, I'll update the documents. >>>>>>>>> Just add fat warning into the documentation. >>>>>>>> OK. >>>>>>> Actually... If you could add >>>>>>> >>>>>>> printk(KERN_ALERT "Hibernation image written. If you have any >>>>>>> filesystems mounted read-write and attempt to resume, you'll corrupt >>>>>>> your data. To prevent that, remove the hibernation image.\n") >>>>>>> >>>>>>> ...I guess that would save someone's filesystem. (Yes, very high >>>>>>> loglevel. If you attempt to do this from anything else then singleuser >>>>>>> or initrd, you are asking for problems, so... lets make sure user sees >>>>>>> it.) >>>>>> Please see the new version of this patch: >>>>>> https://patchwork.kernel.org/patch/9226837/ >>>>> New version changes nothing, right? You still need to be sure >>>>> filesystems are not mounted r/w. So I would still like to see printk() >>>>> with warning. >>>> It shouldn't matter how they are mounted, because the contents of >>>> persistent storage don't change. >>> @@ -721,6 +724,9 @@ int hibernate(void) >>> atomic_inc(&snapshot_device_available); >>> Unlock: >>> unlock_system_sleep(); >>> + if (snapshot_test) >>> + software_resume(); >>> + >>> return error; >>> } >>> >>> Aha, I see, immediate wakeup here. Makes sense. ... ... >>> >>> No. >>> >>> AFAICT, freezer is used in hibernation_snapshot, which means at >>> Unlock:, kernel threads are running; software_resume() freezes them >>> again, but they had chance to run and potentially corrupt the >>> persistent storage... right? >> OK, there is a bug. >> >> The thawing of user space is potentially dangerous, so in the >> "snapshot" test mode hibernate() should just call >> free_basic_memory_bitmaps() and from there invoke the code below the >> Check_image label in software_resume(), roughly. > Or rather call free_basic_memory_bitmaps() and > unlock_device_hotplug(), then do swsusp_check() and invoke the code > starting with the "PM: Loading hibernation image.\n" message in > software_resume(). OK, I've used this solution and sent a v3 out. thanks! > > Thanks, > Rafael