tools/mm: add hwpoison-panic tool
Subsystems (2)
PATCH v3 1/1 tools/mm: add hwpoison-panic tool
Add a tool that enables the vm.panic_on_unrecoverable_memory_failure sysctl, picks a kernel-owned PFN and writes its physical address to hard_offline_page. Three page kinds are selectable with -k: rodata (default), slab or pgtable. In all cases the host should panic.
Example:
# ./hwpoison-panic -k slab --yes-panic-my-kernel
injecting hwpoison at phys 0x100032000 (pfn 0x100032, kind=slab)
expecting kernel panic: 'Memory failure: <pfn>: unrecoverable page'In dmesg, you will see:
Memory failure: 0x100032: unhandlable page.
Memory failure: 0x100032: recovery action for reserved kernel page: Ignored
Kernel panic - not syncing: Memory failure: 0x100032: unrecoverable pageThis lives in tools/mm rather than selftests/mm because every successful run crashes the machine, which is not something to run from CI.
The --yes-panic-my-kernel argument is required so an accidental invocation does not take the box down.
---
Changes in v3:
- s/(16UL << 20)/SZ_16M/ and including ../../include/linux/sizes.h
- s/MEMORY_HOTPLUG/MEMORY_FAILURE/
- Link to v2: https://patch.msgid.link/20260803-memory_failure_rewrite_test-v2-1-ed020ce42129@debian.org
Changes in v2:
- Reword the file header, the tool triggers a panic rather than
confirming one (SJ Park)
- Rename -f to --yes-panic-my-kernel and say in usage() what it costs
(SJ Park)
- Call check_prereqs() before getpagesize() (SJ Park)
- Use 64-bit types for physical addresses and PFNs. On a 32-bit build
the old long/unsigned long pair truncated addresses above 4G, and the
negative error sentinel was indistinguishable from a valid address at
or above 2G
- Link to v1: https://patch.msgid.link/20260731-memory_failure_rewrite_test-v1-1-6aa8c6435693@debian.org
To: Andrew Morton <[email protected]>
To: Miaohe Lin <[email protected]>
To: Naoya Horiguchi <[email protected]>
To: Paul Walmsley <[email protected]>
To: Palmer Dabbelt <[email protected]>
To: Albert Ou <[email protected]>
To: Alexandre Ghiti <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
--- MAINTAINERS | 1 + tools/mm/.gitignore | 1 + tools/mm/Makefile | 2 + tools/mm/memory-failure/hwpoison-panic.c | 359 +++++++++++++++++++++++++++++++ 4 files changed, 363 insertions(+)
MAINTAINERS +1 -0
@@ -12094,6 +12094,7 @@ F: include/linux/memory-failure.h F: include/trace/events/memory-failure.h F: mm/hwpoison-inject.c F: mm/memory-failure.c +F: tools/mm/memory-failure/ F: tools/testing/selftests/mm/memory-failure.c HYCON HY46XX TOUCHSCREEN SUPPORT
tools/mm/.gitignore +1 -0
@@ -3,3 +3,4 @@ slabinfo page-types page_owner_sort thp_swap_allocator_test +memory-failure/hwpoison-panic
tools/mm/Makefile +2 -0
@@ -4,6 +4,7 @@ include ../scripts/Makefile.include BUILD_TARGETS=page-types slabinfo page_owner_sort page_owner_filter thp_swap_allocator_test +BUILD_TARGETS+=memory-failure/hwpoison-panic INSTALL_TARGETS = $(BUILD_TARGETS) thpmaps LIB_DIR = ../lib/api
@@ -24,6 +25,7 @@ $(LIBS): clean: $(RM) page-types slabinfo page_owner_sort page_owner_filter thp_swap_allocator_test + $(RM) memory-failure/hwpoison-panic make -C $(LIB_DIR) clean sbindir ?= /usr/sbin
tools/mm/memory-failure/hwpoison-panic.c new file +359 -0
359 lines not on this page · raw message
---
base-commit: 95d6a9ccef99117115e41e9adb271243bd5e985b
change-id: 20260728-memory_failure_rewrite_test-7a309a601a6e
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Quoted 17 lines · Breno Leitao
Add a tool that enables the vm.panic_on_unrecoverable_memory_failure sysctl, picks a kernel-owned PFN and writes its physical address to
hard_offline_page. Three page kinds are selectable with -k: rodata (default), slab or pgtable. In all cases the host should panic.Example:
# ./hwpoison-panic -k slab --yes-panic-my-kernel injecting hwpoison at phys 0x100032000 (pfn 0x100032, kind=slab) expecting kernel panic: 'Memory failure: <pfn>: unrecoverable page'In dmesg, you will see:
Memory failure: 0x100032: unhandlable page. Memory failure: 0x100032: recovery action for reserved kernel page: Ignored Kernel panic - not syncing: Memory failure: 0x100032: unrecoverable page
Quoted 7 lines
This lives in
tools/mmrather than selftests/mm because every successful run crashes the machine, which is not something to run from CI.The --yes-panic-my-kernel argument is required so an accidental invocation does not take the box down.
Signed-off-by Breno Leitao <[email protected]>
Thanks for your update. LGTM.
Thanks.
.
Quoted 10 lines · On Thu, 13 Aug 2026 04:45:15 -0700 Breno Leitao <[email protected]> wrote:
Add a tool that enables the vm.panic_on_unrecoverable_memory_failure sysctl, picks a kernel-owned PFN and writes its physical address to
hard_offline_page. Three page kinds are selectable with -k: rodata (default), slab or pgtable. In all cases the host should panic.Example:
# ./hwpoison-panic -k slab --yes-panic-my-kernel injecting hwpoison at phys 0x100032000 (pfn 0x100032, kind=slab) expecting kernel panic: 'Memory failure: <pfn>: unrecoverable page'
Too trivial nit, but I couldn't resist. Why print '<pfn>' instead of the real pfn value, while we know it?
Quoted 7 lines
In dmesg, you will see:
Memory failure: 0x100032: unhandlable page. Memory failure: 0x100032: recovery action for reserved kernel page: Ignored Kernel panic - not syncing: Memory failure: 0x100032: unrecoverable page
Quoted 5 lines
This lives in
tools/mmrather than selftests/mm because every successful run crashes the machine, which is not something to run from CI.The --yes-panic-my-kernel argument is required so an accidental invocation does not take the box down.
Looks useful to me, thank you!
Quoted 2 lines
Signed-off-by Breno Leitao <[email protected]>
[...]
Quoted 8 lines
tools/mm/memory-failure/hwpoison-panic.c new file +8
-0+static const char *inject_hwpoison (const struct page_kind *kind, +uint64_t phys_addr,uint64_t pfn) +{ +char buf[32 ]; +int fd, len; +ssize_t ret; + + printf("injecting hwpoison at phys 0x%llx (pfn 0x%llx, kind=%s)\n",
tools/mm/memory-failure/hwpoison-panic.c line 207
Quoted 10 lines
tools/mm/memory-failure/hwpoison-panic.c new file +10
-0+ (unsigned long long )phys_addr, (unsigned long long )pfn, + kind->name); +printf ("expecting kernel panic: 'Memory failure: <pfn>: unrecoverable page'\n" ); +fflush (stdout); + + fd =open (INJECT_PATH ,O_WRONLY ); +if (fd <0 ) +return "cannot open " INJECT_PATH ; + + len =snprintf (buf,sizeof (buf),"0x%llx" , (unsigned long long )phys_addr);
Yet another trivial comment. I'm not a big fan of >80 columns lines, but I understand there are various tastes :)
Thanks,
SJ
[...]
Quoted 17 lines · Breno Leitao
Add a tool that enables the vm.panic_on_unrecoverable_memory_failure sysctl, picks a kernel-owned PFN and writes its physical address to
hard_offline_page. Three page kinds are selectable with -k: rodata (default), slab or pgtable. In all cases the host should panic.Example:
# ./hwpoison-panic -k slab --yes-panic-my-kernel injecting hwpoison at phys 0x100032000 (pfn 0x100032, kind=slab) expecting kernel panic: 'Memory failure: <pfn>: unrecoverable page'In dmesg, you will see:
Memory failure: 0x100032: unhandlable page. Memory failure: 0x100032: recovery action for reserved kernel page: Ignored Kernel panic - not syncing: Memory failure: 0x100032: unrecoverable page
Quoted 5 lines
This lives in
tools/mmrather than selftests/mm because every successful run crashes the machine, which is not something to run from CI.The --yes-panic-my-kernel argument is required so an accidental invocation does not take the box down.
This is not upstream yet, right?
Anything missing or is this good to go in?
Signature · 3 lines
Cheers, David
Quoted 18 lines · David Hildenbrand (Arm)
Quoted 17 lines · Breno Leitao
Add a tool that enables the vm.panic_on_unrecoverable_memory_failure sysctl, picks a kernel-owned PFN and writes its physical address to
hard_offline_page. Three page kinds are selectable with -k: rodata (default), slab or pgtable. In all cases the host should panic.Example:
# ./hwpoison-panic -k slab --yes-panic-my-kernel injecting hwpoison at phys 0x100032000 (pfn 0x100032, kind=slab) expecting kernel panic: 'Memory failure: <pfn>: unrecoverable page'In dmesg, you will see:
Memory failure: 0x100032: unhandlable page. Memory failure: 0x100032: recovery action for reserved kernel page: Ignored Kernel panic - not syncing: Memory failure: 0x100032: unrecoverable page
Quoted 7 lines
Quoted 5 lines
This lives in
tools/mmrather than selftests/mm because every successful run crashes the machine, which is not something to run from CI.The --yes-panic-my-kernel argument is required so an accidental invocation does not take the box down.
This is not upstream yet, right?
Right. :-(
Quoted 1 line
Anything missing or is this good to go in?
I would say this is good to go, David.
--breno
David Hildenbrand (Arm)
Acked-byQuoted 25 lines · Breno Leitao
Quoted 24 lines · David Hildenbrand (Arm)
Quoted 22 lines · Breno Leitao
Add a tool that enables the vm.panic_on_unrecoverable_memory_failure sysctl, picks a kernel-owned PFN and writes its physical address to
hard_offline_page. Three page kinds are selectable with -k: rodata (default), slab or pgtable. In all cases the host should panic.Example:
# ./hwpoison-panic -k slab --yes-panic-my-kernel injecting hwpoison at phys 0x100032000 (pfn 0x100032, kind=slab) expecting kernel panic: 'Memory failure: <pfn>: unrecoverable page'In dmesg, you will see:
Memory failure: 0x100032: unhandlable page. Memory failure: 0x100032: recovery action for reserved kernel page: Ignored Kernel panic - not syncing: Memory failure: 0x100032: unrecoverable pageThis lives in
tools/mmrather than selftests/mm because every successful run crashes the machine, which is not something to run from CI.The --yes-panic-my-kernel argument is required so an accidental invocation does not take the box down.
Quoted 7 lines
Quoted 1 line
This is not upstream yet, right?
Right. :-(
Quoted 1 line
Anything missing or is this good to go in?
I would say this is good to go, David.
Agreed, nothing jumped at me and this is useful.
@Andrew will you pick this up?
Signature · 3 lines
Cheers, David