linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] mm: fix is_pinnable_page against on cma page
@ 2022-05-10 21:17 Minchan Kim
  2022-05-10 22:56 ` John Hubbard
  0 siblings, 1 reply; 46+ messages in thread
From: Minchan Kim @ 2022-05-10 21:17 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, LKML, Paul E . McKenney, John Hubbard, John Dias,
	Minchan Kim, David Hildenbrand

Pages on CMA area could have MIGRATE_ISOLATE as well as MIGRATE_CMA
so current is_pinnable_page could miss CMA pages which has MIGRATE_
ISOLATE. It ends up pinning CMA pages as longterm at pin_user_pages
APIs so CMA allocation keep failed until the pin is released.


     CPU 0                                   CPU 1 - Task B

cma_alloc
alloc_contig_range
					pin_user_pages_fast(FOLL_LONGTERM)
change pageblock as MIGRATE_ISOLATE
					internal_get_user_pages_fast
                                        lockless_pages_from_mm
                                        gup_pte_range
                                        try_grab_folio
                                        is_pinnable_page
                                          return true;
                                        So, pinned the page successfully.
page migration failure with pinned page
					..
                                        .. After 30 sec
					unpin_user_page(page)

CMA allocation succeeded after 30 sec.

The CMA allocation path protects the migration type change race
using zone->lock but what GUP path need to know is just whether the
page is on CMA area or not rather than exact migration type.
Thus, we don't need zone->lock but just checks migration type in
either of (MIGRATE_ISOLATE and MIGRATE_CMA).

Adding the MIGRATE_ISOLATE check in is_pinnable_page could cause
rejecting of pinning pages on MIGRATE_ISOLATE pageblocks even
though it's neither CMA nor movable zone if the page is temporarily
unmovable. However, such a migration failure by unexpected temporal
refcount holding is general issue, not only come from MIGRATE_ISOLATE
and the MIGRATE_ISOLATE is also transient state like other temporal
elevated refcount problem.

Cc: David Hildenbrand <david@redhat.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
* from v3 - https://lore.kernel.org/all/20220509153430.4125710-1-minchan@kernel.org/
  * Fix typo and adding more description - akpm

* from v2 - https://lore.kernel.org/all/20220505064429.2818496-1-minchan@kernel.org/
  * Use __READ_ONCE instead of volatile - akpm

* from v1 - https://lore.kernel.org/all/20220502173558.2510641-1-minchan@kernel.org/
  * fix build warning - lkp
  * fix refetching issue of migration type
  * add side effect on !ZONE_MOVABLE and !MIGRATE_CMA in description - david

 include/linux/mm.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6acca5cecbc5..cbf79eb790e0 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1625,8 +1625,19 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
 #ifdef CONFIG_MIGRATION
 static inline bool is_pinnable_page(struct page *page)
 {
-	return !(is_zone_movable_page(page) || is_migrate_cma_page(page)) ||
-		is_zero_pfn(page_to_pfn(page));
+#ifdef CONFIG_CMA
+	/*
+	 * use volatile to use local variable mt instead of
+	 * refetching mt value.
+	 */
+	int __mt = get_pageblock_migratetype(page);
+	int mt = __READ_ONCE(__mt);
+
+	if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE)
+		return false;
+#endif
+
+	return !(is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page)));
 }
 #else
 static inline bool is_pinnable_page(struct page *page)
-- 
2.36.0.512.ge40c2bad7a-goog


^ permalink raw reply related	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2022-05-24 16:59 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 21:17 [PATCH v4] mm: fix is_pinnable_page against on cma page Minchan Kim
2022-05-10 22:56 ` John Hubbard
2022-05-10 23:31   ` Minchan Kim
2022-05-10 23:58     ` John Hubbard
2022-05-11  0:09       ` Minchan Kim
2022-05-11  4:32         ` John Hubbard
2022-05-11 21:46           ` Minchan Kim
2022-05-11 22:25             ` John Hubbard
2022-05-11 22:37               ` Minchan Kim
2022-05-11 22:49                 ` John Hubbard
2022-05-11 23:08                   ` Minchan Kim
2022-05-11 23:13                     ` John Hubbard
2022-05-11 23:15                       ` Minchan Kim
2022-05-11 23:28                         ` Minchan Kim
2022-05-11 23:33                           ` John Hubbard
2022-05-11 23:45                       ` Paul E. McKenney
2022-05-11 23:57                         ` John Hubbard
2022-05-12  0:12                           ` Paul E. McKenney
2022-05-12  0:12                           ` John Hubbard
2022-05-12  0:22                             ` Paul E. McKenney
2022-05-12  0:26                               ` Minchan Kim
2022-05-12  0:34                                 ` John Hubbard
2022-05-12  0:49                                   ` Paul E. McKenney
2022-05-12  1:02                                     ` John Hubbard
2022-05-12  1:03                                     ` Minchan Kim
2022-05-12  1:08                                       ` John Hubbard
2022-05-12  2:18                                         ` John Hubbard
2022-05-12  3:44                                           ` Minchan Kim
2022-05-12  4:47                                             ` John Hubbard
2022-05-17 14:00                                             ` Jason Gunthorpe
2022-05-17 18:12                                               ` John Hubbard
2022-05-17 19:28                                                 ` Jason Gunthorpe
2022-05-17 20:12                                                   ` John Hubbard
2022-05-17 20:21                                                     ` Paul E. McKenney
2022-05-23 16:33                                                     ` Minchan Kim
2022-05-24  2:55                                                       ` John Hubbard
2022-05-24  5:16                                                         ` Minchan Kim
2022-05-24  6:22                                                           ` John Hubbard
2022-05-24 14:19                                                           ` Jason Gunthorpe
2022-05-24 15:43                                                             ` Minchan Kim
2022-05-24 15:48                                                               ` Jason Gunthorpe
2022-05-24 16:37                                                                 ` Paul E. McKenney
2022-05-24 16:59                                                                   ` Minchan Kim
2022-05-12  3:57                                           ` Paul E. McKenney
2022-05-12  1:03                                   ` Minchan Kim
2022-05-12  0:35                                 ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).