linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: implement "memory.oops_if_bad_pte=1" boot option
@ 2025-07-09 18:10 Alexey Dobriyan
  2025-07-09 22:37 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Alexey Dobriyan @ 2025-07-09 18:10 UTC (permalink / raw)
  To: akpm
  Cc: linux-kernel, linux-mm, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko

Implement

	memory.oops_if_bad_pte=1

boot option which oopses the machine instead of dreadful

	BUG: Bad page map in process

message.

This is intended
for people who want to panic at the slightest provocation and
for people who ruled out hardware problems which in turn means that
delaying vmcore collection is counter-productive.

Linux doesn't (never?) panicked on PTE corruption and even implemented
ratelimited version of the message meaning it can go for minutes and
even hours without anyone noticing which is exactly the opposite of what
should be done to facilitate debugging.

Not enabled by default.

Not advertised.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 mm/memory.c                                 | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index b0cda5aab398..90b92b312802 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -42,6 +42,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/mm.h>
 #include <linux/mm_inline.h>
+#include <linux/moduleparam.h>
 #include <linux/sched/mm.h>
 #include <linux/sched/numa_balancing.h>
 #include <linux/sched/task.h>
@@ -480,6 +481,13 @@ static inline void add_mm_rss_vec(struct mm_struct *mm, int *rss)
 			add_mm_counter(mm, i, rss[i]);
 }
 
+/*
+ * Oops instead of printing "Bad page map in process" message and
+ * trying to continue.
+ */
+static bool oops_if_bad_pte __ro_after_init = false;
+module_param(oops_if_bad_pte, bool, 0444);
+
 /*
  * This function is called to print an error when a bad pte
  * is found. For example, we might have a PFN-mapped pte in
@@ -490,6 +498,13 @@ static inline void add_mm_rss_vec(struct mm_struct *mm, int *rss)
 static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
 			  pte_t pte, struct page *page)
 {
+	/*
+	 * This line is a formality to collect vmcore ASAP. Real bug
+	 * (hardware or software) happened earlier, current registers and
+	 * backtrace aren't interesting.
+	 */
+	BUG_ON(oops_if_bad_pte);
+
 	pgd_t *pgd = pgd_offset(vma->vm_mm, addr);
 	p4d_t *p4d = p4d_offset(pgd, addr);
 	pud_t *pud = pud_offset(p4d, addr);
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-07-10 18:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-09 18:10 [PATCH] mm: implement "memory.oops_if_bad_pte=1" boot option Alexey Dobriyan
2025-07-09 22:37 ` Andrew Morton
2025-07-10 16:46   ` Alexey Dobriyan
2025-07-10  7:35 ` Vlastimil Babka
2025-07-10 16:47   ` Alexey Dobriyan
2025-07-10 16:16 ` Lorenzo Stoakes
2025-07-10 16:57   ` Alexey Dobriyan
2025-07-10 17:02     ` Lorenzo Stoakes
2025-07-10 18:29       ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).