From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9DAC34F27E for ; Tue, 20 Jan 2026 17:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768929055; cv=none; b=RdSIMp74VMY6i6jaepPbiMzY2rNUpNmhLPeGa3g8gNVpgiQhCn3a6lSRrxErBSph6c0u3QfdC8kyiFozyS2ZS16kABadN0IMDec3Fo3irdd7IElbWjtjfkBM4GhKHXMsTRXOMDtlFCaT5ZNDISeq+qTdxTV5HPr7Pp2XntuJ2ks= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768929055; c=relaxed/simple; bh=DI/cttLANtv/5DLfOFp7XaQZKiElGFOHNqzBEHF3UtA=; h=Date:To:From:Subject:Message-Id; b=rd9Fcmo03Ab9dIwY+EOdW+ZUIXcaRGuNP9Wv1KrTp2MD7gifieXqDeEpm19Ey8U88xvvk2MBgfgyBpU7vbqxKq1db+iyEabb4ktXWSMpKZXpuYsb1gde3cbYA+Lbl4P/1/CsflCO4uDxGWBijncDcB7stLH18M4QTesScpiw5f0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=KuMqWxgP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="KuMqWxgP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52600C16AAE; Tue, 20 Jan 2026 17:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1768929054; bh=DI/cttLANtv/5DLfOFp7XaQZKiElGFOHNqzBEHF3UtA=; h=Date:To:From:Subject:From; b=KuMqWxgPMT6KsjAoksexaTwIzPDiOj+W3rfF1+Fix8g5fZg4W84jz51YB4Yyb6La3 oXOB44irBwqpMTnE7yGHT99jh8i0UmIv5BiCJLn8b1K3E95dnbUwtaSViUufar43pF izMGZPAaf5KjR8g6z7QnwjfQUwrKxGsJQ7yes760= Date: Tue, 20 Jan 2026 09:10:53 -0800 To: mm-commits@vger.kernel.org,vbabka@suse.cz,surenb@google.com,shuah@kernel.org,rppt@kernel.org,nao.horiguchi@gmail.com,mhocko@suse.com,lorenzo.stoakes@oracle.com,liam.howlett@oracle.com,david@kernel.org,linmiaohe@huawei.com,akpm@linux-foundation.org From: Andrew Morton Subject: + selftests-mm-add-memory-failure-dirty-pagecache-test.patch added to mm-new branch Message-Id: <20260120171054.52600C16AAE@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: selftests/mm: add memory failure dirty pagecache test has been added to the -mm mm-new branch. Its filename is selftests-mm-add-memory-failure-dirty-pagecache-test.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-add-memory-failure-dirty-pagecache-test.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Miaohe Lin Subject: selftests/mm: add memory failure dirty pagecache test Date: Tue, 20 Jan 2026 20:32:39 +0800 This patch adds a new testcase to validate memory failure handling for dirty pagecache. This performs similar operations as clean pagecaches except fsync() is not used to keep pages dirty. This test helps ensure that memory failure handling for dirty pagecache works correctly, including proper SIGBUS delivery, page isolation, and recovery paths. Link: https://lkml.kernel.org/r/20260120123239.909882-4-linmiaohe@huawei.com Signed-off-by: Miaohe Lin Cc: David Hildenbrand Cc: Liam Howlett Cc: Lorenzo Stoakes Cc: Michal Hocko Cc: Mike Rapoport Cc: Naoya Horiguchi Cc: Shuah Khan Cc: Suren Baghdasaryan Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- tools/testing/selftests/mm/memory-failure.c | 62 ++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) --- a/tools/testing/selftests/mm/memory-failure.c~selftests-mm-add-memory-failure-dirty-pagecache-test +++ a/tools/testing/selftests/mm/memory-failure.c @@ -29,8 +29,10 @@ enum inject_type { enum result_type { MADV_HARD_ANON, MADV_HARD_CLEAN_PAGECACHE, + MADV_HARD_DIRTY_PAGECACHE, MADV_SOFT_ANON, MADV_SOFT_CLEAN_PAGECACHE, + MADV_SOFT_DIRTY_PAGECACHE, }; static jmp_buf signal_jmp_buf; @@ -162,6 +164,7 @@ static void check(struct __test_metadata case MADV_SOFT_ANON: case MADV_HARD_CLEAN_PAGECACHE: case MADV_SOFT_CLEAN_PAGECACHE: + case MADV_SOFT_DIRTY_PAGECACHE: /* It is not expected to receive a SIGBUS signal. */ ASSERT_EQ(setjmp, 0); @@ -172,6 +175,7 @@ static void check(struct __test_metadata ASSERT_NE(pagemap_get_pfn(self->pagemap_fd, vaddr), self->pfn); break; case MADV_HARD_ANON: + case MADV_HARD_DIRTY_PAGECACHE: /* The SIGBUS signal should have been received. */ ASSERT_EQ(setjmp, 1); @@ -244,6 +248,18 @@ TEST_F(memory_failure, anon) ASSERT_EQ(munmap(addr, self->page_size), 0); } +static int prepare_file(const char *fname, unsigned long size) +{ + int fd; + + fd = open(fname, O_RDWR | O_CREAT, 0664); + if (fd >= 0) { + unlink(fname); + ftruncate(fd, size); + } + return fd; +} + /* Borrowed from mm/gup_longterm.c. */ static __fsword_t get_fs_type(int fd) { @@ -259,17 +275,14 @@ static __fsword_t get_fs_type(int fd) TEST_F(memory_failure, clean_pagecache) { - const char *fname = "./clean-page-cache-test-file"; int fd; char *addr; int ret; __fsword_t fs_type; - fd = open(fname, O_RDWR | O_CREAT, 0664); + fd = prepare_file("./clean-page-cache-test-file", self->page_size); if (fd < 0) SKIP(return, "failed to open test file.\n"); - unlink(fname); - ftruncate(fd, self->page_size); fs_type = get_fs_type(fd); if (!fs_type || fs_type == TMPFS_MAGIC) SKIP(return, "unsupported filesystem :%lx\n", fs_type); @@ -297,6 +310,47 @@ TEST_F(memory_failure, clean_pagecache) cleanup(_metadata, self, addr); + ASSERT_EQ(munmap(addr, self->page_size), 0); + + ASSERT_EQ(close(fd), 0); +} + +TEST_F(memory_failure, dirty_pagecache) +{ + int fd; + char *addr; + int ret; + __fsword_t fs_type; + + fd = prepare_file("./dirty-page-cache-test-file", self->page_size); + if (fd < 0) + SKIP(return, "failed to open test file.\n"); + fs_type = get_fs_type(fd); + if (!fs_type || fs_type == TMPFS_MAGIC) + SKIP(return, "unsupported filesystem :%lx\n", fs_type); + + addr = mmap(0, self->page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) + SKIP(return, "mmap failed, not enough memory.\n"); + memset(addr, 0xce, self->page_size); + + prepare(_metadata, self, addr); + + ret = sigsetjmp(signal_jmp_buf, 1); + if (!self->triggered) { + self->triggered = true; + ASSERT_EQ(variant->inject(self, addr), 0); + FORCE_READ(*addr); + } + + if (variant->type == MADV_HARD) + check(_metadata, self, addr, MADV_HARD_DIRTY_PAGECACHE, ret); + else + check(_metadata, self, addr, MADV_SOFT_DIRTY_PAGECACHE, ret); + + cleanup(_metadata, self, addr); + ASSERT_EQ(munmap(addr, self->page_size), 0); ASSERT_EQ(close(fd), 0); _ Patches currently in -mm which might be from linmiaohe@huawei.com are selftests-mm-add-memory-failure-anonymous-page-test.patch selftests-mm-add-memory-failure-clean-pagecache-test.patch selftests-mm-add-memory-failure-dirty-pagecache-test.patch