linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Potapenko <glider@google.com>
To: Johannes Stezenbach <js@sig21.net>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Pavel Machek <pavel@ucw.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>, Michal Hocko <mhocko@suse.cz>,
	linux-pm@vger.kernel.org
Subject: Re: init_on_free breaks hibernate
Date: Tue, 14 Jan 2020 12:38:53 +0100	[thread overview]
Message-ID: <CAG_fn=VjzJSguf4ZB2x8Xn=U9MCHyfyqd2DVwPPC36t5+S+VsQ@mail.gmail.com> (raw)
In-Reply-To: <CAG_fn=UgU3vibsaug6p35Xs1dzLgBecA48t-PqS9OtRTHNu54g@mail.gmail.com>

> > Strange about the resume=/dev/vda, it worked for me the way I described it.
> > Maybe device numbers are dynamic, 254:0 is what I got from ls -l /dev/vda.
> Indeed, for me it's 253:0, and resuming from console works with that number.
>
> > > The memory corruption is also reproducible for me, taking a look.
> >

I think I know what is causing the problem.
Upon resume the free pages may contain stale information from the
kernel that initiated the resume.
There's clear_free_pages()
(https://elixir.bootlin.com/linux/latest/source/kernel/power/snapshot.c#L1148)
that clears the pages in the case CONFIG_PAGE_POISONING_ZERO is
enabled, we just need to reuse it for init_on_free.
See the potential fix below.

Rafael, Pavel, I've noticed that in the setup suggested by Johannes
even the defconfig kernel with heap initialization cannot hibernate
more than twice, the third hibernate hangs.
Is that a known problem?

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 26b9168321e7..d65f2d5ab694 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1147,24 +1147,24 @@ void free_basic_memory_bitmaps(void)

 void clear_free_pages(void)
 {
-#ifdef CONFIG_PAGE_POISONING_ZERO
        struct memory_bitmap *bm = free_pages_map;
        unsigned long pfn;

        if (WARN_ON(!(free_pages_map)))
                return;

-       memory_bm_position_reset(bm);
-       pfn = memory_bm_next_pfn(bm);
-       while (pfn != BM_END_OF_MAP) {
-               if (pfn_valid(pfn))
-                       clear_highpage(pfn_to_page(pfn));
-
+       if (IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) || want_init_on_free()) {
+               memory_bm_position_reset(bm);
                pfn = memory_bm_next_pfn(bm);
+               while (pfn != BM_END_OF_MAP) {
+                       if (pfn_valid(pfn))
+                               clear_highpage(pfn_to_page(pfn));
+
+                       pfn = memory_bm_next_pfn(bm);
+               }
+               memory_bm_position_reset(bm);
+               pr_info("free pages cleared after restore\n");
        }
-       memory_bm_position_reset(bm);
-       pr_info("free pages cleared after restore\n");
-#endif /* PAGE_POISONING_ZERO */
 }

  reply	other threads:[~2020-01-14 11:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-23 21:13 init_on_free breaks hibernate Johannes Stezenbach
2020-01-13  9:26 ` Johannes Stezenbach
2020-01-13 11:07   ` Rafael J. Wysocki
2020-01-13 13:42     ` Alexander Potapenko
2020-01-13 15:18   ` Alexander Potapenko
2020-01-13 15:41     ` Alexander Potapenko
2020-01-13 17:15       ` Johannes Stezenbach
2020-01-14 10:07         ` Alexander Potapenko
2020-01-14 11:38           ` Alexander Potapenko [this message]
2020-01-14 22:36             ` Rafael J. Wysocki
2020-01-15  9:10               ` Alexander Potapenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAG_fn=VjzJSguf4ZB2x8Xn=U9MCHyfyqd2DVwPPC36t5+S+VsQ@mail.gmail.com' \
    --to=glider@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=js@sig21.net \
    --cc=keescook@chromium.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mhocko@suse.cz \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).