The hard dirty_pagecache variant uses MADV_HWPOISON to exercise recovery
of a dirty file-backed page. The recovery path records -EIO in the
address_space mapping, which NFS later reports when the test closes the
file. This makes the test fail after the hwpoison checks have completed.

Skip this variant when the test file is on NFS. Keep the hard clean-page
and both soft-offline variants enabled because they use folio removal,
invalidation, or migration rather than recording a delayed writeback
error.

The unsupported-filesystem path in clean_pagecache() also returns
without closing the opened test file. Close the descriptor before
skipping there and in dirty_pagecache().

Reviewed-by: Miaohe Lin <[email protected]>
Signed-off-by: Muhammad Usama Anjum <[email protected]>
---
Changes since v2:
- Explain why the hard dirty-page variant is skipped on NFS.

Changes since v1:
- Limit the NFS skip to the hard dirty-page variant.
---
 tools/testing/selftests/mm/memory-failure.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/mm/memory-failure.c 
b/tools/testing/selftests/mm/memory-failure.c
index 032ed952057c6..5d00aab31f9b5 100644
--- a/tools/testing/selftests/mm/memory-failure.c
+++ b/tools/testing/selftests/mm/memory-failure.c
@@ -283,8 +283,10 @@ 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_type || fs_type == TMPFS_MAGIC) {
+               close(fd);
                SKIP(return, "unsupported filesystem :%x\n", fs_type);
+       }
 
        addr = mmap(0, self->page_size, PROT_READ | PROT_WRITE,
                    MAP_SHARED, fd, 0);
@@ -325,8 +327,16 @@ TEST_F(memory_failure, dirty_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)
+       /*
+        * 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)) {
+               close(fd);
                SKIP(return, "unsupported filesystem :%x\n", fs_type);
+       }
 
        addr = mmap(0, self->page_size, PROT_READ | PROT_WRITE,
                    MAP_SHARED, fd, 0);
-- 
2.47.3


Reply via email to