From: Andrew Morton Subject: selftests/mm/memory-failure: extend page-cache test files with pwrite() Date: Mon, 23 Nov 2026 09:58:07 -0800 HPFS does not allow ftruncate() to grow a file. prepare_file() ignores the failure, so the page-cache tests mmap an empty file and die before they can inject a memory failure or check fsync(). Write a zero byte at the end of the requested size instead. This grows the file on HPFS and leaves zero-filled data for the existing tests. Open with O_TRUNC so a file left by an interrupted test starts empty, and check the write result before returning the descriptor. On an HPFS image, the existing test passed 6 of 10 cases. With this change, a diagnostic build passed all 10, including the hard-poisoned dirty page-cache case. Signed-off-by: Andrew Morton Cc: Amir Goldstein Cc: David Hildenbrand Cc: Eugenio Pérez Cc: German Maglione Cc: Kurt Lin Cc: Liam R. Howlett Cc: Miaohe Lin Cc: Michal Hocko Cc: Mike Rapoport Cc: Miklos Szeredi Cc: Muhammad Usama Anjum Cc: Naoya Horiguchi Cc: Ryusuke Konishi Cc: Shuah Khan Cc: Stefan Hajnoczi Cc: Vivek Goyal Cc: Vlastimil Babka tools/testing/selftests/mm/memory-failure.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/tools/testing/selftests/mm/memory-failure.c~selftests-mm-check-that-fsync-reports-hard-poisoned-dirty-page-cache-fix-5 +++ a/tools/testing/selftests/mm/memory-failure.c @@ -265,9 +265,16 @@ static int prepare_file(const char *fnam { int fd; - fd = open(fname, O_RDWR | O_CREAT, 0664); - if (fd >= 0) - ftruncate(fd, size); + fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0664); + if (fd < 0) + return fd; + + /* HPFS cannot grow files with ftruncate(). */ + if (pwrite(fd, "\0", 1, size - 1) != 1) { + close(fd); + unlink(fname); + return -1; + } return fd; } _