From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oIPfJOB2tF4yOgAA0tVLHw (envelope-from ) for ; Thu, 07 May 2020 21:00:16 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id OJEqOex2tF7OHwAAB5/wlQ (envelope-from ) for ; Thu, 07 May 2020 21:00:28 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B813E940E99 for ; Thu, 7 May 2020 21:00:24 +0000 (UTC) Received: from localhost ([::1]:38822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWnd3-0000A4-2G for larch@yhetil.org; Thu, 07 May 2020 17:00:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWnch-00009j-6X for guix-patches@gnu.org; Thu, 07 May 2020 17:00:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:60740) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jWncg-0002jT-RC for guix-patches@gnu.org; Thu, 07 May 2020 17:00:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jWncg-0005hS-PN for guix-patches@gnu.org; Thu, 07 May 2020 17:00:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40927] Subject=[bug#40927] [PATCH] Allow resume from swap device during boot References: <87zhawax60.fsf@m4x.org> Resent-From: Jean-Baptiste Note Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 07 May 2020 21:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40927 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: me@tobias.gr, Danny Milosavljevic Cc: 40927@debbugs.gnu.org Received: via spool by 40927-submit@debbugs.gnu.org id=B40927.158888514321793 (code B ref 40927); Thu, 07 May 2020 21:00:02 +0000 Received: (at 40927) by debbugs.gnu.org; 7 May 2020 20:59:03 +0000 Received: from localhost ([127.0.0.1]:44053 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWnbj-0005fQ-72 for submit@debbugs.gnu.org; Thu, 07 May 2020 16:59:03 -0400 Received: from mail-wm1-f42.google.com ([209.85.128.42]:53375) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWnbg-0005es-SR for 40927@debbugs.gnu.org; Thu, 07 May 2020 16:59:01 -0400 Received: by mail-wm1-f42.google.com with SMTP id k12so8060999wmj.3 for <40927@debbugs.gnu.org>; Thu, 07 May 2020 13:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:in-reply-to:date:message-id:user-agent :mime-version; bh=mCEmIBe0AJkZ8Wes/QnqGwgWBK62F7eXNYiXrYl6Jmw=; b=piDYMRa5Tph2x0VS7/v/BdhssjncISd1+qiygdamIcP4pmFmAT0VAzsbCQaktcJV4e joAKnWQZoLzI1ThEvpbTcZb/KwJ2KmS8E6GJP34tcJSefGArxMQwAdZPKT75hNd1xU42 qOBkjX9vaIIbdp1khYkUf3tcaB9cvoj9+NdfyrVzy7WP9wXcM6jFS8kPJ9UbnjwEBLNQ lkOe7YCYfy6gWQou/1w4Skn3NaKav0OiBoI/BPXKV4QVNDONxIzYovHP87BbS87J43Ec vdxmVH3x7k4dHT4ONOyj+oMetdB1N5WsXQt2ramfRpDUkJDAfnez8xEgpTBuKOiF6U+4 9Orw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to:date :message-id:user-agent:mime-version; bh=mCEmIBe0AJkZ8Wes/QnqGwgWBK62F7eXNYiXrYl6Jmw=; b=n3yv50VNoufjnunwRWrI2AIenax7tSVcLNfZJwW7Tfl0mZeIi0hEPIk5YOnmdadw/l Y8Ue8yVN8LW15uJh29RR/YJl/Nr4DF9h3UGZFW0HK8hQQN8dsd/OeDyLaYR0An+rdBFA NHdNFyVIGVVRuU9GL4WxX+MM2+KgyvgqZiAn8h4hLjI8pAUAHX9h08tFdQVPaqbXluP6 wWQC6v5hBsMkvygDqnyJjW5xLhQbidLyrfT80aMkmjG6hEzlAk157OaA1LFOCyuiqtHr h1zKEabr5avs455dMBwZo9zJ1LTri28Btr+xyTZbu9ydM1Zy7zOBVm15LOPWVefzPoB6 NUCw== X-Gm-Message-State: AGi0PuZvt4kkkzPbjr3POcGw4/T8A4P0umX0cDVxtoqU1BcIo9b20Ubj 67C2DD+xJJdTzn3ExdFUVCmviPcDG6Y= X-Google-Smtp-Source: APiQypKCWxa5XzF4wNTZPAUyle5KO7QuqKOpF066384x0xvqtMIOqhh8SmRdr3thkL/RE31TqVKgdQ== X-Received: by 2002:a1c:b4d4:: with SMTP id d203mr2930881wmf.188.1588885134145; Thu, 07 May 2020 13:58:54 -0700 (PDT) Received: from guixrules ([2a01:e35:2e0b:a6b0:e2ce:c3ff:fe74:cec8]) by smtp.gmail.com with ESMTPSA id z1sm9955030wmf.15.2020.05.07.13.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 13:58:53 -0700 (PDT) From: Jean-Baptiste Note In-reply-to: 874ksxnurk.fsf@nckx Date: Thu, 07 May 2020 20:58:45 +0000 Message-ID: <87o8qz798a.fsf@m4x.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: 0.5 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -0.5 (/) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 X-Spam-Score: -2.11 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=piDYMRa5; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Scan-Result: default: False [-2.11 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.49829441647295]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; R_DKIM_REJECT(1.00)[gmail.com:s=20161025]; HAS_ATTACHMENT(0.00)[]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.10), country: US(-0.00), ip: 2001:470:142::17(-0.50)]; DWL_DNSWL_BLOCKED(0.00)[2001:470:142::17:from]; DKIM_TRACE(0.00)[gmail.com:-]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; SIGNED_PGP(-2.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:+,4:+,5:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jean-baptiste.note@m4x.org,guix-patches-bounces@gnu.org]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; URIBL_BLOCKED(0.00)[gnu.org:email,m4x.org:email,tobias.gr:email,posteo.net:email]; MIME_GOOD(-0.20)[multipart/signed,multipart/mixed,text/plain,text/x-patch]; PREVIOUSLY_DELIVERED(0.00)[40927@debbugs.gnu.org]; DMARC_NA(0.00)[m4x.org]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_SEVEN(0.00)[9]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: CTS2F1lx2a+z --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Dear Tobias, I hopefully found a way to reply to your message directly. I've checked resume with your patch -- actually a slightly reworked version of it; a few remarks: =2D I've amended it as per Danny's suggestions regarding documentation loca= tion =2D I've adjusted it to take the guixy --resume and --noresume options rather than the kernel norm resume and noresume. In particular this allows me to test the 'kernel' resume path and the 'initrd' resume path with the same os definition quickly, only adjusting the GRUB cmdline within GRUB. =2D I find the added copyright years on top strange -- shouldn't it be 2020 ?=20 The results of my tests are attached as a separate file. In a nutshell: =2D I can confirm that on my kernel (default guix linux-libre-5.4) the resume=3D option by itself does not resume at all. This seems to have been reported already: https://lists.gnu.org/archive/html/bug-guix/2016-11/msg00060.html =2D resume-by-uuid from userspace does not work =2D resume-by-label from userspace does not work either (as much as I'd like them to). (please note that, on top of this, I found no way to specify the swap devices in the os definition by UUID or LABEL either -- so the limitation does not bother me in the current state). Each time these loop for 20 seconds, waiting for the partition to appear (the partition is there, from dmesg, but somehow is not in the database looked for in (canonicalize-device-spec spec) -- weird). Regarding the interface, I'm not sure we should feel bound by the argument naming convention of the kernel for resume handling from userspace -- we could leave its own namespace for the kernel to handle, for those kernels that can, and separate the resume handling as done by initrd in a separate, more guixy namespace. Actually I don't really understand why we would want overlapping of names for two different codepaths; I think separating the names brings more flexibility (you can control from the GRUB commandline which resume path you want to take) and less confusion (it is clearer from the commandline where the resuming will/should be handled). To summarize: * I still think that this feature is greatly needed: we can hibernate with the current software stack, but the default kernel won't resume, leaving the system in a bad state (swap is not activated by shepherd, see logs), and we need manual swapon to leave this bad state; * This version of the patch looks like it can handle UUID and LABEL, while it can't -- for reasons that i've not dug; * Meanwhile I find resume-by-uuid or resume-by-label currently pointless, given the limited ways we have to specify swap devices in the OS definition file. I'd be in favor of doing the following: * Dropping support for UUID and LABEL in the code *OR* signalling clearly in some comment that the path is currently non-functional; * Including the patch ASAP to avoid the really bad state we're in currently after a suspend. * Using the guixy --resume and --noresume options rather than the kernel ones Please let me know how to proceed, and let me know how to handle the copyright notice. Kind regards, Jean-Baptiste --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=tests_resume.txt Content-Transfer-Encoding: quoted-printable Content-Description: resume tests logs # by device node -- does work jb@guixrules ~$ sudo loginctl hibernate jb@guixrules ~$ cat /proc/cmdline=20 BOOT_IMAGE=3D/gnu/store/bkpkbms3mp8s45kpir4f2cnvxvgdvssp-linux-libre-5.4.39= /bzImage --root=3Ded73cc09-aff3-41e4-90b6-51fb41a7d225 --system=3D/gnu/stor= e/xcdn9naivwxhr4x0cq669zzn9f02x706-system --load=3D/gnu/store/xcdn9naivwxhr= 4x0cq669zzn9f02x706-system/boot modprobe.blacklist=3Dpcspkr,snd_pcsp --resu= me=3D/dev/sda3 quiet # by UUID -- does not work jb@guixrules ~$ sudo swaplabel /dev/sdb3 swaplabel: /dev/sdb3: not a valid swap partition jb@guixrules ~$ sudo swapon /dev/sdb3 swapon: /dev/sdb3: software suspend data detected. Rewriting the swap signa= ture. jb@guixrules ~$ sudo swaplabel /dev/sdb3 LABEL: resume_device UUID: 446c81d4-efcf-4508-a9ab-bb38f74ff77d jb@guixrules ~$ cat /proc/cmdline=20 BOOT_IMAGE=3D/gnu/store/bkpkbms3mp8s45kpir4f2cnvxvgdvssp-linux-libre-5.4.39= /bzImage --root=3Ded73cc09-aff3-41e4-90b6-51fb41a7d225 --system=3D/gnu/stor= e/xcdn9naivwxhr4x0cq669zzn9f02x706-system --load=3D/gnu/store/xcdn9naivwxhr= 4x0cq669zzn9f02x706-system/boot modprobe.blacklist=3Dpcspkr,snd_pcsp --resu= me=3D446c81d4-efcf-4508-a9ab-bb38f74ff77d quiet jb@guixrules ~$ diff <(echo 446c81d4-efcf-4508-a9ab-bb38f74ff77d) <(echo 44= 6c81d4-efcf-4508-a9ab-bb38f74ff77d) jb@guixrules ~$ echo $? 0 # by LABEL -- does not work jb@guixrules ~$ sudo swaplabel /dev/sdb3 swaplabel: /dev/sdb3: not a valid swap partition jb@guixrules ~$ sudo swapon /dev/sdb3 swapon: /dev/sdb3: software suspend data detected. Rewriting the swap signa= ture. jb@guixrules ~$ sudo swaplabel=20 swaplabel: no device specified Try 'swaplabel --help' for more information. jb@guixrules ~$ sudo swaplabel /dev/sdb3 LABEL: resume_device UUID: 446c81d4-efcf-4508-a9ab-bb38f74ff77d jb@guixrules ~$ cat /proc/cmdline=20 BOOT_IMAGE=3D/gnu/store/bkpkbms3mp8s45kpir4f2cnvxvgdvssp-linux-libre-5.4.39= /bzImage --root=3Ded73cc09-aff3-41e4-90b6-51fb41a7d225 --system=3D/gnu/stor= e/xcdn9naivwxhr4x0cq669zzn9f02x706-system --load=3D/gnu/store/xcdn9naivwxhr= 4x0cq669zzn9f02x706-system/boot modprobe.blacklist=3Dpcspkr,snd_pcsp --resu= me=3Dresume_device quiet # leaving it to the kernel -- does not work jb@guixrules ~$ sudo swaplabel /dev/sdb3 swaplabel: /dev/sdb3: not a valid swap partition jb@guixrules ~$ sudo swapon /dev/sdb3 swapon: /dev/sdb3: software suspend data detected. Rewriting the swap signa= ture. jb@guixrules ~$ cat /proc/cmdline=20 BOOT_IMAGE=3D/gnu/store/bkpkbms3mp8s45kpir4f2cnvxvgdvssp-linux-libre-5.4.39= /bzImage --root=3Ded73cc09-aff3-41e4-90b6-51fb41a7d225 --system=3D/gnu/stor= e/xcdn9naivwxhr4x0cq669zzn9f02x706-system --load=3D/gnu/store/xcdn9naivwxhr= 4x0cq669zzn9f02x706-system/boot modprobe.blacklist=3Dpcspkr,snd_pcsp resume= =3D/dev/sdb3 quiet --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-linux-boot-Resume-from-hibernation.patch Content-Transfer-Encoding: quoted-printable Content-Description: resume patch with longopt From=20889fc647a84289747ae840778f0313193eca1316 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Note Date: Wed, 6 May 2020 20:38:21 +0000 Subject: [PATCH] linux-boot: Resume from hibernation. MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * gnu/build/linux-boot.scm (resume-if-hibernated): New procedure. (boot-system): Call it unless =E2=80=98noresume=E2=80=99 was specified. =2D-- gnu/build/linux-boot.scm | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index 05e833c0c6..be1cda0181 100644 =2D-- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Cour= t=C3=A8s +;;; Copyright =C2=A9 2016, 2017, 2019, 2020 Tobias Geerinckx-Rice ;;; Copyright =C2=A9 2017 Mathieu Othacehe ;;; Copyright =C2=A9 2019 Guillaume Le Vaillant ;;; @@ -110,6 +111,52 @@ OPTION doesn't appear in ARGUMENTS." (substring arg (+ 1 (string-index arg #\=3D))))) arguments))) =20 +(define (resume-if-hibernated device) + "Resume from hibernation if possible. This is safe ONLY if no on-disk f= ile +systems have been mounted; calling it later risks severe file system +corruption! See in the kernel source +directory. This is the caller's responsibility, as is catching exceptions= if +resumption was supposed to happen but didn't. + +Resume only from DEVICE if it's a string. If it's #f, use the kernel's de= fault +hibernation device (CONFIG_PM_STD_PARTITION). Never return if resumption +succeeds. Return nothing otherwise. The kernel logs any details to dmesg= ." + + (define (string->major:minor string) + "Return a string with MAJOR:MINOR numbers of the device specified by S= TRING." + + ;; The "resume=3D" kernel command-line option always provides a string= , which + ;; can represent a device, a UUID, or a label. Check for all three. + (let* ((spec (cond ((string-prefix? "/" string) string) + ((uuid string) =3D> identity) + (else (file-system-label string)))) + ;; XXX kernel's swsusp_resume_can_resume() waits for the resume + ;; device to appear if =E2=80=98resumewait=E2=80=99 is found on= the command line; + ;; our canonicalize-device-spec gives up after 20 seconds. We + ;; could loop (ew!) if someone relies on it=E2=80=A6 + (device (canonicalize-device-spec spec)) + (rdev (stat:rdev (stat device))) + (minor (modulo rdev 256)) + (major (/ (- rdev minor) 256))) + (format #f "~a:~a" major minor))) + + ;; Write the MAJOR:MINOR numbers of the specified or default resume DEVI= CE to + ;; this magic file. The kernel will immediately try to resume from it. + (let ((resume "/sys/power/resume")) + (when (file-exists? resume) ; this kernel supports hibernation + ;; Honour the kernel's default device (only) if none other was given. + (let ((major:minor (if device + (string->major:minor device) + (let ((default (call-with-input-file resume + read-line))) + ;; Don't waste time echoing =E2=80=98nothin= g=E2=80=99 to /sys. + (if (string=3D? "0:0" default) + #f + default))))) + (when major:minor + (call-with-output-file resume ; may throw an =E2=80=98Invalid ar= gument=E2=80=99 + (cut display major:minor <>))))))) ; may never return + (define* (make-disk-device-nodes base major #:optional (minor 0)) "Make the block device nodes around BASE (something like \"/root/dev/sda= \") with the given MAJOR number, starting with MINOR." @@ -504,6 +551,12 @@ upon error." (load-linux-modules-from-directory linux-modules linux-module-directory) =20 + (unless (member "--noresume" args) + ;; Try to resume immediately after loading (storage) modules + ;; but before any on-disk file systems have been mounted. + (false-if-exception ; failure is not fatal + (resume-if-hibernated (find-long-option "--resume" args)))) + (when keymap-file (let ((status (system* "loadkeys" keymap-file))) (unless (zero? status) =2D-=20 2.26.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEPxcq3dp4FVY5UpckkC0pVsuz75YFAl60doUACgkQkC0pVsuz 75bf4A//SgQPn8X66AT1smg6yuue4f4dr+yuoptzl3uSgo0VqbhhgcYHU5sUN+u6 0fVmII0LtUqqN7bRCIJZQpPR6zh6A0cXRhtGe/6wtoVz4y4PlUleMIRcuZgtK79g kCNEoKmSv6WHxU8jwdd3kmoXZ0gPwdxs9cJRII+Z6kveT09rlMkCrDAMIMw0sJBX PWZxChp12hbPqvFLb0vlUXQH43CNjdJecJPzH2y49z/ZryBsW4S4QPvahyd03y3K 4TKyF/KYTSoKy+x3c1Nae2LhOvLz4eSuiNyMJM2KUuNdCd2AELYzBmB2usoZbEpl cJtFkualiMfPmW1BXBKWmATlZUPWAOLVM3fnTcPPar7OwnPSaQWVJo5E/Ha18yeh ChLf92OZ/mqallTNJ8bARI/c0BVs1XLdbjL96dVGz4dZLNShMQPYi38NdFjRnNDf 9b6ZVucP9l/Diar+ev0xHO1T/CtH+TpFcLJwnBbn5L96OSNtAYZrw72G3RRhoAox ZcQ0NhsRhVMMo7BlwkzfrNDoGQJjJwL+WvM49pQ2z+uWrHKv7IZ+taKR2fXPqi+4 QH6YqO79SiQdZ0KT+3MnMnwkcldVLHzIVHRDd6xDQ/kneY4tqP/mwGf/hGriUE+M E6AqSL95lZ4Gh55KkPxJoYs7jOhQx9UUOebHW9Od8Gus4M4nOHg= =1l4t -----END PGP SIGNATURE----- --==-=-=--