xfs: compute buffer address correctly in xmbuf_map_backing_mem
Subsystems (2)
PATCH 1/1 xfs: compute buffer address correctly in xmbuf_map_backing_mem
From: Darrick J. Wong <[email protected]>
Prior to commit e614a00117bc2d, xmbuf_map_backing_mem relied on folio_file_page to return the base page for the xmbuf's loff_t in the xfile, and set b_addr to the page_address of that base page.
Now that folio_file_page has been removed from xmbuf_map_backing_mem, we always set b_addr to the folio_address of the folio. This is correct for the situation where the folio size matches the buffer size, but it's totally wrong if tmpfs uses large folios. We need to use offset_in_folio here.
Found via xfs/801, which demonstrated evidence of corruption of an in-memory rmap btree block right after initializing an adjacent block.
--- fs/xfs/xfs_buf_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_buf_mem.c +1 -1
@@ -165,7 +165,7 @@ xmbuf_map_backing_mem(folio_set_dirty (folio);folio_unlock (folio); - bp->b_addr =folio_address (folio); + bp->b_addr =folio_address (folio) +offset_in_folio (folio, pos);return 0 ; }
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Prior to commit
e614a00117bc2d,xmbuf_map_backing_memrelied onfolio_file_pageto return the base page for the xmbuf'sloff_tin the xfile, and setb_addrto thepage_addressof that base page.
Quoted 8 lines
Now that
folio_file_pagehas been removed fromxmbuf_map_backing_mem, we always setb_addrto thefolio_addressof the folio. This is correct for the situation where the folio size matches the buffer size, but it's totally wrong if tmpfs uses large folios. We need to useoffset_in_foliohere.Found via xfs/801, which demonstrated evidence of corruption of an in-memory rmap btree block right after initializing an adjacent block.
Hmm, I thought we'd never get large folios for our non-standard tmpfs use. I guess I was wrong on that..
The fix looks good:
But a little note below:
fs/xfs/xfs_buf_mem.c xmbuf_map_backing_mem( · line 168
Quoted 1 line
fs/xfs/xfs_buf_mem.c +1
-0+ bp->b_addr =folio_address (folio) +offset_in_folio (folio, pos);
Given that this is or at least will become a common pattern, do we want a mm layer helper for it?
Quoted 13 lines · Christoph Hellwig
Quoted 12 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Prior to commit
e614a00117bc2d,xmbuf_map_backing_memrelied onfolio_file_pageto return the base page for the xmbuf'sloff_tin the xfile, and setb_addrto thepage_addressof that base page.Now that
folio_file_pagehas been removed fromxmbuf_map_backing_mem, we always setb_addrto thefolio_addressof the folio. This is correct for the situation where the folio size matches the buffer size, but it's totally wrong if tmpfs uses large folios. We need to useoffset_in_foliohere.
Quoted 5 lines
Quoted 2 lines
Found via xfs/801, which demonstrated evidence of corruption of an in-memory rmap btree block right after initializing an adjacent block.
Hmm, I thought we'd never get large folios for our non-standard tmpfs use. I guess I was wrong on that..
Yeah, you can force THPs for tmpfs. I don't know why you would, the memory usage is gawful on most files that end up in there.
Quoted 10 lines
The fix looks good:
Reviewed-by Christoph Hellwig <[email protected]>But a little note below:
fs/xfs/xfs_buf_mem.c xmbuf_map_backing_mem( · line 168
Quoted 1 line
fs/xfs/xfs_buf_mem.c +1
-0+ bp->b_addr =folio_address (folio) +offset_in_folio (folio, pos);Given that this is or at least will become a common pattern, do we want a mm layer helper for it?
Yeah, we should; this is the third one in XFS. What to name it, though?
void *folio_addr(const struct folio *folio, loff_t pos) ?
I'm surprised there wasn't an equivalent for struct page.
--D
Quoted 11 lines · Darrick J. Wong
Prior to commit
e614a00117bc2d,xmbuf_map_backing_memrelied onfolio_file_pageto return the base page for the xmbuf'sloff_tin the xfile, and setb_addrto thepage_addressof that base page.Now that
folio_file_pagehas been removed fromxmbuf_map_backing_mem, we always setb_addrto thefolio_addressof the folio. This is correct for the situation where the folio size matches the buffer size, but it's totally wrong if tmpfs uses large folios. We need to useoffset_in_foliohere.[...]
Applied to for-next, thanks!
[1/1] xfs: compute buffer address correctly in xmbuf_map_backing_mem
commit: a37b3b9c3cc595521c7f9d9b2b0b2ad367bf9c98
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>