Re: [PATCH v3] x86/hibernate: Use fixmap for saving unmapped pages

From: Dave Hansen
Date: Mon Jan 23 2023 - 13:15:50 EST


On 1/19/23 15:51, Rick Edgecombe wrote:
> Hibernate uses the direct map to read memory it saves to disk. Since
> sometimes pages are not accessible on the direct map ("not present" on
> x86), it has special case logic to temporarily make a page present. On x86
> these direct map addresses can be mapped at various page sizes, but the
> logic works ok as long as the not present pages are always mapped as
> PAGE_SIZE such that they don't require a split to map the region as
> present. If the address was mapped not present by a larger page size, the
> split may fail and hibernate would then try to read an address mapped not
> present.

The "split" thing here kinda threw me a bit.

First, this code depends on having a 'struct page'. On 64-bit, that
means that the pages at least have an address in the direct map.

But, that doesn't mean that there's an actual mapping in the direct map
for the page. Lots of things zap the direct map. To make up for this,
the hibernate code tries to temporarily restore a zapped mapping with
hibernate_map_page()->set_direct_map_default_noflush().

What's the actual failure mode here, though? Does __change_page_attr()
just fail to find an existing PTE and fall over? Or, does it actually
try to and fail to allocate the PTE page?