mm: Safe to clear PGC_allocated on xenheap pages without an extra reference
authorGeorge Dunlap <george.dunlap@citrix.com>
Tue, 6 Aug 2019 11:19:55 +0000 (12:19 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 6 Aug 2019 11:19:55 +0000 (12:19 +0100)
commit45ce5b8749a220ad7c4ce5d5eba7c201a9418078
treef52551f3d62e30e9f84ade46aa2ab712b869eb7d
parent3a9205788bdabb2a23d2fa3b85637b2e629d19e5
mm: Safe to clear PGC_allocated on xenheap pages without an extra reference

Commits ec83f825627 "mm.h: add helper function to test-and-clear
_PGC_allocated" (and subsequent fix-up 44a887d021d "mm.h: fix BUG_ON()
condition in put_page_alloc_ref()") introduced a BUG_ON() to detect
unsafe behavior of callers.

Unfortunately this condition still turns out to be too strict.
xenheap pages are somewhat "magic": calling free_domheap_pages() on
them will not cause free_heap_pages() to be called: whichever part of
Xen allocated them specially must call free_xenheap_pages()
specifically.  (They'll also be handled appropriately at domain
destruction time.)

Only crash Xen when put_page_alloc_ref() finds only a single refcount
if the page is not a xenheap page.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/include/xen/mm.h