Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/9] selftests/mm/memory-failure: check that fsync() reports hard-poisoned dirty page-cache
@ 2026-11-28  6:51 Andrew Morton
  2026-11-28  6:51 ` [PATCH 2/9] selftests/mm/memory-failure: truncate poisoned FUSE page-cache before teardown Andrew Morton
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Andrew Morton @ 2026-11-28  6:51 UTC (permalink / raw)
  To: Kurt Lin
  Cc: linux-mm, Andrew Morton, Miaohe Lin, Naoya Horiguchi,
	David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
	Mike Rapoport, Michal Hocko, Shuah Khan, Muhammad Usama Anjum,
	Amir Goldstein, Eugenio Pérez, German Maglione,
	Miklos Szeredi, Ryusuke Konishi, Stefan Hajnoczi, Vivek Goyal

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4207 bytes --]

From: Andrew Morton <akpm@linux-foundation.org>
Subject: selftests/mm/memory-failure: check that fsync() reports hard-poisoned dirty page-cache
Date: Mon, 23 Nov 2026 23:18:44 -0800

MADV_HWPOISON on a dirty page-cache page records -EIO in the mapping.  The
test currently requires close() to succeed but never checks whether the
error was reported.  Filesystems with ->flush() may return EIO from
close(), while those without it can leave the error unnoticed.

Require fsync() to return EIO after hard poisoning.  It consumes the
mapping error before close(), allowing the NFS skip to go.  The clean and
dirty page-cache cases also skip tmpfs, ramfs and hugetlbfs because they
have no backing store from which to reread a poisoned clean page.

With the complete selftest patch stack under x86_64 QEMU, ext4, FUSE and
NFSv4.2 reported 10 passes; NILFS2 reported 9 passes and 1 skip.  The FUSE
server used for this test was a minimal server, not virtiofs.

Fixes: d51b5076c746 ("selftests/mm: add memory failure dirty pagecache test")
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Kurt Lin <lylin1023@gmail.com>
Closes: https://lore.kernel.org/20261123-memory-failure-fuse-skip-v1-1-19dcbda6e2e8@gmail.com
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@arm.com>
Cc: Amir Goldstein <amir73il@gmail.com>
Cc: Eugenio Pérez <eperezma@redhat.com>
Cc: German Maglione <gmaglione@redhat.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>

 tools/testing/selftests/mm/memory-failure.c |   38 ++++++++++++++----
 1 file changed, 30 insertions(+), 8 deletions(-)

--- a/tools/testing/selftests/mm/memory-failure.c~selftests-mm-check-that-fsync-reports-hard-poisoned-dirty-page-cache
+++ a/tools/testing/selftests/mm/memory-failure.c
@@ -300,6 +300,29 @@ static int get_fs_type(int fd)
 	return ret ? 0 : (int)fs.f_type;
 }
 
+/*
+ * The page-cache tests need a filesystem which keeps its data on backing
+ * store.  When a clean page is poisoned the kernel drops it and the data is
+ * read back in.  When a dirty page is poisoned the data is lost, and the
+ * kernel records -EIO in the mapping for fsync() to report.
+ *
+ * tmpfs and ramfs keep their data only in the page cache.  The poisoned
+ * page cannot be dropped and read back, and their fsync() does nothing, so
+ * neither expectation holds.  hugetlbfs is the same, and it also poisons a
+ * whole huge page.  shmem has its own tests below.
+ */
+static bool fs_has_backing_store(int fs_type)
+{
+	switch ((unsigned int)fs_type) {
+	case 0:
+	case TMPFS_MAGIC:
+	case RAMFS_MAGIC:
+	case HUGETLBFS_MAGIC:
+		return false;
+	}
+	return true;
+}
+
 TEST_F(memory_failure, clean_pagecache)
 {
 	int fd;
@@ -311,7 +334,7 @@ TEST_F(memory_failure, clean_pagecache)
 	if (fd < 0)
 		SKIP(return, "failed to open test file.\n");
 	fs_type = get_fs_type(fd);
-	if (!fs_type || fs_type == TMPFS_MAGIC) {
+	if (!fs_has_backing_store(fs_type)) {
 		close(fd);
 		SKIP(return, "unsupported filesystem :%x\n", fs_type);
 	}
@@ -353,13 +376,7 @@ TEST_F(memory_failure, dirty_pagecache)
 	if (fd < 0)
 		SKIP(return, "failed to open test file.\n");
 	fs_type = get_fs_type(fd);
-	/*
-	 * MADV_HARD poisoning of dirty page-cache data records an expected
-	 * -EIO in the file mapping. NFS reports this error on close(), so
-	 * skip this variant.
-	 */
-	if (!fs_type || fs_type == TMPFS_MAGIC ||
-	    (fs_type == NFS_SUPER_MAGIC && variant->type == MADV_HARD)) {
+	if (!fs_has_backing_store(fs_type)) {
 		close(fd);
 		SKIP(return, "unsupported filesystem :%x\n", fs_type);
 	}
@@ -386,6 +403,11 @@ TEST_F(memory_failure, dirty_pagecache)
 
 	ASSERT_EQ(munmap(addr, self->page_size), 0);
 
+	if (variant->type == MADV_HARD) {
+		ASSERT_EQ(fsync(fd), -1);
+		ASSERT_EQ(errno, EIO);
+	}
+
 	ASSERT_EQ(close(fd), 0);
 }
 
_


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

end of thread, other threads:[~2026-11-28 18:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  6:51 [PATCH 1/9] selftests/mm/memory-failure: check that fsync() reports hard-poisoned dirty page-cache Andrew Morton
2026-11-28  6:51 ` [PATCH 2/9] selftests/mm/memory-failure: truncate poisoned FUSE page-cache before teardown Andrew Morton
2026-11-28  6:52 ` [PATCH 3/9] selftests/mm/memory-failure: skip poisoned dirty page-cache on NILFS2 Andrew Morton
2026-11-28  6:52 ` [PATCH 4/9] selftest/mm/memory-failure: keep page-cache files linked until cleanup Andrew Morton
2026-11-28  6:52 ` [PATCH 5/9] selftests/mm/memory-failure: skip hard dirty page-cache test on CephFS Andrew Morton
2026-11-28  6:52 ` [PATCH 6/9] selftests/mm/memory-failure: close dirty page-cache files before unlinking them Andrew Morton
2026-11-28  6:52 ` [PATCH 7/9] selftests/mm/memory-failure: extend page-cache test files with pwrite() Andrew Morton
2026-11-28  6:52 ` [PATCH 8/9] selftests/mm/memory-failure: write the whole page-cache test file for OMFS Andrew Morton
2026-11-28  6:52 ` [PATCH 9/9] selftests/mm/memory-failure: accept EIO from close after poisoning dirty data Andrew Morton
2026-11-28 18:36 ` [PATCH 1/9] selftests/mm/memory-failure: check that fsync() reports hard-poisoned dirty page-cache Kurt Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox