Skip to contentSkip to conversation

mm: delete unsafe BUG from page_cache_add_speculative()

PATCH Applied Hugh Dickins 4 participants 5 messages Dec 9, 2021 – Dec 10, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: delete unsafe BUG from page_cache_add_speculative()

It is not easily reproducible, but on 5.16-rc I have several times hit the VM_BUG_ON_PAGE(PageTail(page), page) in page_cache_add_speculative():
usually from filemap_get_read_batch() for an ext4 read, yesterday from next_uptodate_page() from filemap_map_pages() for a shmem fault.

That BUG used to be placed where page_ref_add_unless() had succeeded, but now it is placed before folio_ref_add_unless() is attempted: that is not safe, since it is only the acquired reference which makes the page safe from racing THP collapse or split.

We could keep the BUG, checking PageTail only when folio_ref_try_add_rcu() has succeeded; but I don't think it adds much value - just delete it.

Fixes 020853b6f5ea ("mm: Add folio_try_get_rcu()")

---

 include/linux/pagemap.h |    1 -
 1 file changed, 1 deletion(-)
include/linux/pagemap.h +0 -1
@@ -285,7 +285,6 @@ static inline struct inode *folio_inode(
 
 static inline bool page_cache_add_speculative(struct page *page, int count)
 {
-	VM_BUG_ON_PAGE(PageTail(page), page);
 	return folio_ref_try_add_rcu((struct folio *)page, count);
 }
 
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Hugh Dickins

It is not easily reproducible, but on 5.16-rc I have several times hit the VM_BUG_ON_PAGE(PageTail(page), page) in page_cache_add_speculative():
usually from filemap_get_read_batch() for an ext4 read, yesterday from next_uptodate_page() from filemap_map_pages() for a shmem fault.

That BUG used to be placed where page_ref_add_unless() had succeeded, but now it is placed before folio_ref_add_unless() is attempted: that is not safe, since it is only the acquired reference which makes the page safe from racing THP collapse or split.

Quoted 5 lines

We could keep the BUG, checking PageTail only when folio_ref_try_add_rcu() has succeeded; but I don't think it adds much value - just delete it.

Fixes 020853b6f5ea ("mm: Add folio_try_get_rcu()")
Signature · 1 line
 Kirill A. Shutemov
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Hugh Dickins
Quoted 5 lines · Hugh Dickins

It is not easily reproducible, but on 5.16-rc I have several times hit the VM_BUG_ON_PAGE(PageTail(page), page) in page_cache_add_speculative():
usually from filemap_get_read_batch() for an ext4 read, yesterday from next_uptodate_page() from filemap_map_pages() for a shmem fault.

Quoted 7 lines

That BUG used to be placed where page_ref_add_unless() had succeeded, but now it is placed before folio_ref_add_unless() is attempted: that is not safe, since it is only the acquired reference which makes the page safe from racing THP collapse or split.

We could keep the BUG, checking PageTail only when folio_ref_try_add_rcu() has succeeded; but I don't think it adds much value - just delete it.

Whoops, that was careless of me. I agree with your reasoning and patch.

Quoted 17 lines
Fixes 020853b6f5ea ("mm: Add folio_try_get_rcu()")

---

 include/linux/pagemap.h |    1 -
 1 file changed, 1 deletion(-)
include/linux/pagemap.h +0 -1
@@ -285,7 +285,6 @@ static inline struct inode *folio_inode(
 
 static inline bool page_cache_add_speculative(struct page *page, int count)
 {
-	VM_BUG_ON_PAGE(PageTail(page), page);
 	return folio_ref_try_add_rcu((struct folio *)page, count);
 }
 
maintainer
#3 lore raw
In reply to Hugh Dickins
Quoted 10 lines · On Wed, 8 Dec 2021 23:19:18 -0800 (PST) Hugh Dickins <[email protected]> wrote:

It is not easily reproducible, but on 5.16-rc I have several times hit the VM_BUG_ON_PAGE(PageTail(page), page) in page_cache_add_speculative():
usually from filemap_get_read_batch() for an ext4 read, yesterday from next_uptodate_page() from filemap_map_pages() for a shmem fault.

That BUG used to be placed where page_ref_add_unless() had succeeded, but now it is placed before folio_ref_add_unless() is attempted: that is not safe, since it is only the acquired reference which makes the page safe from racing THP collapse or split.

Quoted 5 lines

We could keep the BUG, checking PageTail only when folio_ref_try_add_rcu() has succeeded; but I don't think it adds much value - just delete it.

Fixes 020853b6f5ea ("mm: Add folio_try_get_rcu()")

I added cc:stable to this.

#4 lore raw
Quoted 12 lines · Andrew Morton
Quoted 10 lines · On Wed, 8 Dec 2021 23:19:18 -0800 (PST) Hugh Dickins <[email protected]> wrote:

It is not easily reproducible, but on 5.16-rc I have several times hit the VM_BUG_ON_PAGE(PageTail(page), page) in page_cache_add_speculative():
usually from filemap_get_read_batch() for an ext4 read, yesterday from next_uptodate_page() from filemap_map_pages() for a shmem fault.

That BUG used to be placed where page_ref_add_unless() had succeeded, but now it is placed before folio_ref_add_unless() is attempted: that is not safe, since it is only the acquired reference which makes the page safe from racing THP collapse or split.

Quoted 7 lines
Quoted 5 lines

We could keep the BUG, checking PageTail only when folio_ref_try_add_rcu() has succeeded; but I don't think it adds much value - just delete it.

Fixes 020853b6f5ea ("mm: Add folio_try_get_rcu()")

I added cc:stable to this.

Thanks, but no, cc:stable not needed: the fixed commit went into 5.16-rc1, and did not go to stable itself. There was an identical VM_BUG_ON_PAGE in the old __page_cache_add_speculative(), but that one was correctly placed, so there's no need for the old one to be removed.

Hugh