f2fs_dblock_aops has no ->error_remove_folio(). memory_failure() then falls back to mapping_evict_folio(), which cannot remove a dirty folio. So when a dirty f2fs page-cache page is hard-poisoned, recovery fails: Memory failure: 0x6289: Failed to invalidate Memory failure: 0x6289: recovery action for dirty LRU page: Failed madvise(MADV_HWPOISON) returns -EBUSY and the poisoned folio stays in the page cache. read() keeps returning its contents without an error, and the next fsync() writes it back to disk before reporting -EIO. With a real memory error, the kernel keeps reading the poisoned memory. Set ->error_remove_folio() to generic_error_remove_folio(), as ext4, xfs, btrfs and others do. The folio is then truncated at the time of the error, and f2fs_invalidate_folio() drops its dirty accounting: Memory failure: 0x742b: recovery action for dirty LRU page: Recovered madvise() returns 0 and nothing is written back. fsync() still reports -EIO, and an atomic write with a poisoned page still fails to commit with -EIO and is rolled back. Found and tested with the help of an AI coding assistant. Signed-off-by: Kurt Lin --- Tested on f2fs dev b61a029304bb in a QEMU x86_64 guest (4K blocks) with MADV_HWPOISON on a dirty mmap'd page. The two kernels differ only by this patch: before after recovery action (20 runs) Failed 20/20 Recovered 20/20 madvise() -EBUSY 0 that page on disk after poisoned page not written fsync() (O_DIRECT read) fsync() -EIO -EIO atomic write commit -EIO, rolled back -EIO, rolled back With the patch it is also Recovered in a compress_algorithm=lz4 directory (chattr +c), and in a 4-page file the other three pages read back intact. fsck.f2fs shows nothing new. The mm memory-failure selftest passes with and without the patch, as it does not check the recovery result. Not tested: block size smaller than PAGE_SIZE, large folios, a real memory error. This is the f2fs counterpart of Andrew's FUSE patch: https://lore.kernel.org/all/82801b542ac4481a85ec2c869294ca28.1@linux-foundation.org/ --- fs/f2fs/data.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index cdc9e6e8633c..6df85fb7d5af 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -6403,6 +6403,7 @@ const struct address_space_operations f2fs_dblock_aops = { .migrate_folio = filemap_migrate_folio, .invalidate_folio = f2fs_invalidate_folio, .release_folio = f2fs_release_folio, + .error_remove_folio = generic_error_remove_folio, .is_partially_uptodate = f2fs_is_partially_uptodate, .bmap = f2fs_bmap, .swap_activate = f2fs_swap_activate, --- base-commit: b61a029304bb5531312ebc133b2a895d14dc3fee change-id: 20261201-f2fs-error-remove-folio-37c5167981bf Best regards, -- Kurt Lin