PM / hibernate: memory_bm_find_bit(): Tighten node optimisation
authorAndy Whitcroft <apw@canonical.com>
Wed, 25 Sep 2019 14:39:12 +0000 (15:39 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sun, 20 Oct 2019 23:24:27 +0000 (01:24 +0200)
commitda6043fe85eb5ec621e34a92540735dcebbea134
tree0dcf23803a614d89ffa60ba5db2d4cd879b2dc3e
parent7d194c2100ad2a6dded545887d02754948ca5241
PM / hibernate: memory_bm_find_bit(): Tighten node optimisation

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>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/snapshot.c