From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,vbabka@kernel.org,surenb@google.com,shuah@kernel.org,rppt@kernel.org,nao.horiguchi@gmail.com,mhocko@suse.com,ljs@kernel.org,linmiaohe@huawei.com,liam@infradead.org,david@kernel.org,corbet@lwn.net,leitao@debian.org,akpm@linux-foundation.org
Subject: + selftests-mm-regression-test-for-panic_on_unrecoverable_memory_failure.patch added to mm-new branch
Date: Fri, 24 Apr 2026 05:51:49 -0700 [thread overview]
Message-ID: <20260424125149.C3063C19425@smtp.kernel.org> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6511 bytes --]
The patch titled
Subject: selftests/mm: regression test for panic_on_unrecoverable_memory_failure
has been added to the -mm mm-new branch. Its filename is
selftests-mm-regression-test-for-panic_on_unrecoverable_memory_failure.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-regression-test-for-panic_on_unrecoverable_memory_failure.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
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is 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: Breno Leitao <leitao@debian.org>
Subject: selftests/mm: regression test for panic_on_unrecoverable_memory_failure
Date: Fri, 24 Apr 2026 05:24:02 -0700
Add a test that enables vm.panic_on_unrecoverable_memory_failure and
injects MADV_HWPOISON on a userspace anonymous page. The page must still
be recovered via SIGBUS — it must not trigger a kernel panic.
This is the regression test for the panic_on_unrecoverable_mf() recheck: a
buddy page being concurrently allocated to userspace can briefly land on
the MF_MSG_KERNEL_HIGH_ORDER branch (refcount 0, not in buddy), and
without the recheck the kernel would panic on what is actually a
recoverable userspace page.
Run in a forked child so the SIGBUS path is fully exercised; if the kernel
ever regresses and panics, the host VM dies and the harness reports the
binary as never returning, which is itself a clear failure signal.
Skips when the sysctl is not present (feature not built in) or when the
test cannot write to it (insufficient privilege). Saves and restores the
original sysctl value.
Link: https://lore.kernel.org/20260424-ecc_panic-v5-4-a35f4b50425c@debian.org
Signed-off-by: Breno Leitao <leitao@debian.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/testing/selftests/mm/memory-failure.c | 84 ++++++++++++++++++
1 file changed, 84 insertions(+)
--- a/tools/testing/selftests/mm/memory-failure.c~selftests-mm-regression-test-for-panic_on_unrecoverable_memory_failure
+++ a/tools/testing/selftests/mm/memory-failure.c
@@ -17,9 +17,13 @@
#include <sys/vfs.h>
#include <linux/magic.h>
#include <errno.h>
+#include <sys/wait.h>
+#include <stdlib.h>
#include "vm_util.h"
+#define PANIC_SYSCTL "/proc/sys/vm/panic_on_unrecoverable_memory_failure"
+
enum inject_type {
MADV_HARD,
MADV_SOFT,
@@ -355,4 +359,84 @@ TEST_F(memory_failure, dirty_pagecache)
ASSERT_EQ(close(fd), 0);
}
+static int read_sysctl_int(const char *path, int *out)
+{
+ char buf[16];
+ int fd, n;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ n = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ if (n <= 0)
+ return -1;
+ buf[n] = '\0';
+ *out = atoi(buf);
+ return 0;
+}
+
+static int write_sysctl_int(const char *path, int val)
+{
+ char buf[16];
+ int fd, len, ret = 0;
+
+ fd = open(path, O_WRONLY);
+ if (fd < 0)
+ return -1;
+ len = snprintf(buf, sizeof(buf), "%d\n", val);
+ if (write(fd, buf, len) != len)
+ ret = -1;
+ close(fd);
+ return ret;
+}
+
+/*
+ * Regression test for vm.panic_on_unrecoverable_memory_failure.
+ *
+ * With the sysctl on, hwpoison injection on a userspace anonymous page
+ * must still be recovered via SIGBUS — it must not trigger a kernel
+ * panic. This guards the panic_on_unrecoverable_mf() recheck that rules
+ * out concurrent buddy allocations being misclassified as unrecoverable
+ * kernel pages (MF_MSG_KERNEL_HIGH_ORDER).
+ *
+ * If the kernel regresses and panics, the host VM dies and the test
+ * harness will report the binary as never having returned — which is
+ * itself a clear failure signal.
+ */
+TEST(panic_on_unrecoverable_user_page)
+{
+ unsigned long page_size;
+ int saved, status;
+ void *addr;
+ pid_t pid;
+
+ if (read_sysctl_int(PANIC_SYSCTL, &saved))
+ SKIP(return, "%s not available\n", PANIC_SYSCTL);
+ if (write_sysctl_int(PANIC_SYSCTL, 1))
+ SKIP(return, "cannot enable %s (need root?)\n", PANIC_SYSCTL);
+
+ page_size = sysconf(_SC_PAGESIZE);
+
+ pid = fork();
+ ASSERT_NE(pid, -1);
+ if (pid == 0) {
+ addr = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (addr == MAP_FAILED)
+ _exit(1);
+ *(volatile char *)addr = 1;
+ if (madvise(addr, page_size, MADV_HWPOISON))
+ _exit(2);
+ FORCE_READ(*(volatile char *)addr);
+ _exit(0); /* unreachable: SIGBUS expected */
+ }
+
+ ASSERT_EQ(waitpid(pid, &status, 0), pid);
+ write_sysctl_int(PANIC_SYSCTL, saved);
+
+ ASSERT_TRUE(WIFSIGNALED(status));
+ ASSERT_EQ(WTERMSIG(status), SIGBUS);
+}
+
TEST_HARNESS_MAIN
_
Patches currently in -mm which might be from leitao@debian.org are
kho-fix-error-handling-in-kho_add_subtree.patch
mm-memory-failure-report-mf_msg_kernel-for-reserved-pages.patch
mm-memory-failure-add-panic-option-for-unrecoverable-pages.patch
documentation-document-panic_on_unrecoverable_memory_failure-sysctl.patch
selftests-mm-regression-test-for-panic_on_unrecoverable_memory_failure.patch
mm-vmstat-spread-vmstat_update-requeue-across-the-stat-interval.patch
reply other threads:[~2026-04-24 12:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260424125149.C3063C19425@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=leitao@debian.org \
--cc=liam@infradead.org \
--cc=linmiaohe@huawei.com \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=mm-commits@vger.kernel.org \
--cc=nao.horiguchi@gmail.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.