linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Andy Whitcroft <apw@canonical.com>
Cc: linux-pm@vger.kernel.org, Len Brown <len.brown@intel.com>,
	Pavel Machek <pavel@ucw.cz>,
	Andrea Righi <andrea.righi@canonical.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] PM / hibernate: memory_bm_find_bit -- tighten node optimisation
Date: Fri, 11 Oct 2019 11:49:29 +0200	[thread overview]
Message-ID: <2167643.HFCj9E3NaD@kreacher> (raw)
In-Reply-To: <20190925143912.22593-1-apw@canonical.com>

On Wednesday, September 25, 2019 4:39:12 PM CEST Andy Whitcroft wrote:
> When looking for a bit by number we make use of the cached result from the
> preceding lookup to speed up operation.  Firstly we check if the requested
> pfn is within the cached zone and if not lookup the new zone.  We then
> check if the offset for that pfn falls within the existing cached node.
> This happens regardless of whether the node is within the zone we are
> now scanning.  With certain memory layouts it is possible for this to
> false trigger creating a temporary alias for the pfn to a different bit.
> This leads the hibernation code to free memory which it was never allocated
> with the expected fallout.
> 
> Ensure the zone we are scanning matches the cached zone before considering
> the cached node.
> 
> Deep thanks go to Andrea for many, many, many hours of hacking and testing
> that went into cornering this bug.
> 
> Reported-by: Andrea Righi <andrea.righi@canonical.com>
> Tested-by: Andrea Righi <andrea.righi@canonical.com>
> Signed-off-by: Andy Whitcroft <apw@canonical.com>
> ---
>  kernel/power/snapshot.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
> index 83105874f255..26b9168321e7 100644
> --- a/kernel/power/snapshot.c
> +++ b/kernel/power/snapshot.c
> @@ -734,8 +734,15 @@ static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
>  	 * We have found the zone. Now walk the radix tree to find the leaf node
>  	 * for our PFN.
>  	 */
> +
> +	/*
> +	 * If the zone we wish to scan is the the current zone and the
> +	 * pfn falls into the current node then we do not need to walk
> +	 * the tree.
> +	 */
>  	node = bm->cur.node;
> -	if (((pfn - zone->start_pfn) & ~BM_BLOCK_MASK) == bm->cur.node_pfn)
> +	if (zone == bm->cur.zone &&
> +	    ((pfn - zone->start_pfn) & ~BM_BLOCK_MASK) == bm->cur.node_pfn)
>  		goto node_found;
>  
>  	node      = zone->rtree;
> 

Applying as 5.5 material, thanks!





      reply	other threads:[~2019-10-11  9:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 14:39 [PATCH 1/1] PM / hibernate: memory_bm_find_bit -- tighten node optimisation Andy Whitcroft
2019-10-11  9:49 ` Rafael J. Wysocki [this message]

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=2167643.HFCj9E3NaD@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=andrea.righi@canonical.com \
    --cc=apw@canonical.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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).