mm/page_alloc: correct first_dirty calculations during block merging
authorSergey Dyasli <sergey.dyasli@citrix.com>
Thu, 12 Jul 2018 08:45:11 +0000 (10:45 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 12 Jul 2018 08:45:11 +0000 (10:45 +0200)
commit1e2df9608857b5355f2ec3b1a34b87a2007dcd16
treef07b0b23bc01f695d56298ed8e1a686d1cd979f2
parentf1ad5ff73e7d07e6a18488430583168a857f2847
mm/page_alloc: correct first_dirty calculations during block merging

Currently it's possible to hit an assertion in alloc_heap_pages():

Assertion 'first_dirty != INVALID_DIRTY_IDX || !(pg[i].count_info & PGC_need_scrub)' failed at page_alloc.c:988

This can happen because a piece of logic to calculate first_dirty
during block merging in free_heap_pages() is missing for the following
scenario:

1. Current block's first_dirty equals to INVALID_DIRTY_IDX
2. Successor block is free but its first_dirty != INVALID_DIRTY_IDX
3. The successor is merged into current block
4. Current block's first_dirty still equals to INVALID_DIRTY_IDX

This will trigger the assertion during allocation of such block in
alloc_heap_pages() because there will be pages with PGC_need_scrub
bit set despite the claim of first_dirty that the block is scrubbed.

Add the missing piece of logic and slightly update the comment for
the predecessor case to better capture the code's intent.

Fixes 1a37f33ea613 ("mm: Place unscrubbed pages at the end of pagelist")

Signed-off-by: Sergey Dyasli <sergey.dyasli@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
xen/common/page_alloc.c