[COMMON] mm: fix cma page migration race condition
authorSunyoung Kang <sy0816.kang@samsung.com>
Tue, 14 Jun 2016 06:09:20 +0000 (15:09 +0900)
committerhskang <hs1218.kang@samsung.com>
Mon, 27 Aug 2018 07:21:26 +0000 (16:21 +0900)
commit8f9be7e0afe7c3d74da1701c5745e29bc58e7032
tree669f43885f8568464216348f566d89f315adcee9
parentbba9a1302f3c962c0303d994d376c7706e268723
[COMMON] mm: fix cma page migration race condition

The below callstack makes VM_BUG_ON in race condition.
So this fixes it by moving the page isolation into before
pte_unmap_unlock().

----------------------------------------------------------
CPU0 CPU1
__need_migrate_cma_page
   PageLRU(page)
pte_unmap_unlock
isolate_migrate_pages_range
migrate_pages # clear pageLRU
# _count == 0
__migrate_cma_pinpage
   __isolate_lru_page # failure on !PageLRU
get_page_foll # VM_BUG on page->_count == 0
----------------------------------------------------------

This patch effects that get_user_pages() may stop on a page that is
under a racing but it guarantees that the state of the page is
consistent. Therefore, the caller of get_user_pages() should always
check if the pinning all required pages is successful.

Change-Id: I7947db746e8aaed23ea7344ee0483073bbd2d51c
Signed-off-by: Sunyoung Kang <sy0816.kang@samsung.com>
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
mm/gup.c