mm/page_alloc.c: place zone_id check before VM_BUG_ON_PAGE check
authorWeijie Yang <[email protected]>
Tue, 10 Feb 2015 22:11:39 +0000 (14:11 -0800)
committerLinus Torvalds <[email protected]>
Tue, 10 Feb 2015 22:30:34 +0000 (14:30 -0800)
commit4c5018ce06c6be292d4ed96cecf2c8dda361a923
tree0e695e86f11df493ad7fcf73daf7fc0fb8ce6c3f
parent753162cd849c45580fb5aaa7f3597c81e74e391c
mm/page_alloc.c: place zone_id check before VM_BUG_ON_PAGE check

If the freeing page and its buddy page are not at the same zone, the
current holding zone->lock for the freeing page cann't prevent buddy page
getting allocated, this could trigger VM_BUG_ON_PAGE in page_is_buddy() at
a very tiny chance, such as:

cpu 0: cpu 1:
hold zone_1 lock
check page and it buddy
PageBuddy(buddy) is true hold zone_2 lock
page_order(buddy) == order is true alloc buddy
trigger VM_BUG_ON_PAGE(page_count(buddy) != 0)

zone_1->lock prevents the freeing page getting allocated
zone_2->lock prevents the buddy page getting allocated
they are not the same zone->lock.

If we can't remove the zone_id check statement, it's better handle this
rare race.  This patch fixes this by placing the zone_id check before the
VM_BUG_ON_PAGE check.

Signed-off-by: Weijie Yang <[email protected]>
Acked-by: Mel Gorman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Rik van Riel <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/page_alloc.c