[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)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:22:59 +0000 (20:22 +0300)
commit6d5bd010358ff5221647b0b94d8b8018bf5f3f1e
treebb1c51f0d322557926da3a332ad714707a944508
parent7b1e8331d9bbc4ce528b1a0596b1febc805b7dbf
[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