* [PATCH] mm: get the folio's refcnt before clear PG_lru in folio_isolate_lru
@ 2024-03-27 7:55 zhaoyang.huang
2024-03-27 12:10 ` Matthew Wilcox
0 siblings, 1 reply; 2+ messages in thread
From: zhaoyang.huang @ 2024-03-27 7:55 UTC (permalink / raw)
To: Andrew Morton, Matthew Wilcox, Christoph Hellwig, linux-mm,
linux-kernel, Zhaoyang Huang, steve.kang
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
Bellowing race happens when the caller of folio_isolate_lru rely on the
refcnt of page cache. Moving folio_get ahead of folio_test_clear_lru to
make it more robust.
0. Thread_isolate calls folio_isolate_lru by holding one refcnt of page
cache and get preempted before folio_get.
folio_isolate_lru
VM_BUG_ON(!folio->refcnt)
if (folio_test_clear_lru(folio))
<preempted>
folio_get()
1. Thread_release calls release_pages and meet the scenario of the folio
get its refcnt of page cache removed before folio_put_testzero
release_pages
<folio is removed from page cache>
folio_put_testzero(folio) == true
<refcnt added by collection is the only one here and get
deducted>
if(folio_test_clear_lru(folio))
lruvec_del_folio(folio)
<folio failed to be deleted from LRU>
list_add(folio, pages_to_free);
<LRU's integrity is broken by above list_add>
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
mm/vmscan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 3ef654addd44..42f15ca06e09 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1731,10 +1731,10 @@ bool folio_isolate_lru(struct folio *folio)
VM_BUG_ON_FOLIO(!folio_ref_count(folio), folio);
+ folio_get(folio);
if (folio_test_clear_lru(folio)) {
struct lruvec *lruvec;
- folio_get(folio);
lruvec = folio_lruvec_lock_irq(folio);
lruvec_del_folio(lruvec, folio);
unlock_page_lruvec_irq(lruvec);
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: get the folio's refcnt before clear PG_lru in folio_isolate_lru
2024-03-27 7:55 [PATCH] mm: get the folio's refcnt before clear PG_lru in folio_isolate_lru zhaoyang.huang
@ 2024-03-27 12:10 ` Matthew Wilcox
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2024-03-27 12:10 UTC (permalink / raw)
To: zhaoyang.huang
Cc: Andrew Morton, Christoph Hellwig, linux-mm, linux-kernel,
Zhaoyang Huang, steve.kang
On Wed, Mar 27, 2024 at 03:55:16PM +0800, zhaoyang.huang wrote:
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>
> Bellowing race happens when the caller of folio_isolate_lru rely on the
> refcnt of page cache. Moving folio_get ahead of folio_test_clear_lru to
> make it more robust.
No, as explained to you multiple times before.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-27 12:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27 7:55 [PATCH] mm: get the folio's refcnt before clear PG_lru in folio_isolate_lru zhaoyang.huang
2024-03-27 12:10 ` Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox