@@ -156,6 +156,30 @@ void mce_unregister_decode_chain(struct notifier_block *nb)
}
EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
+/*
+ * Kdump can exclude the HWPosion page to avoid touch the error page again,
+ * the prerequisite is the PG_hwpoison page flag is set. However, for some
+ * MCE fatal error cases, there are no opportunity to queue a task
+ * for calling memory_failure(), as a result, the capture kernel panic.
+ * This function mark the page as HWPoison before kernel panic() for MCE.
+ *
+ * This covers normal 4KByte pages. There is little/no value in covering
+ * other page types. E.g.
+ * SGX: These cannot be dumped.
+ * PMEM: Pointless to dump these. Persistent memory contents remain
+ * available across reboots.
+ * HugeTLB: These are user pages. Generally filtered out of the kdump
+ * to keep size small. Not helpful to debug kernel issues.
+ */
+static void mce_set_page_hwpoison_now(unsigned long pfn)
+{
+ struct page *p;
+
+ p = pfn_to_online_page(pfn);
+ if (p)
+ SetPageHWPoison(p);
+}
+
static void __print_mce(struct mce *m)
{
pr_emerg(HW_ERR "CPU %d: Machine Check%s: %Lx Bank %d: %016Lx\n",
@@ -286,6 +310,8 @@ static noinstr void mce_panic(const char *msg, struct mce *final, char *exp)
if (!fake_panic) {
if (panic_timeout == 0)
panic_timeout = mca_cfg.panic_timeout;
+ if (final && (final->status & MCI_STATUS_ADDRV))
+ mce_set_page_hwpoison_now(final->addr >> PAGE_SHIFT);
panic(msg);
} else
pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);