From: Tony Luck <tony.luck@intel.com>
To: Borislav Petkov <bp@alien8.de>
Cc: HORIGUCHI NAOYA <naoya.horiguchi@nec.com>,
"Li, Zhiquan1" <zhiquan1.li@intel.com>,
"Song, Youquan" <youquan.song@intel.com>,
x86@kernel.org, linux-edac@vger.kernel.org,
linux-kernel@vger.kernel.org, patches@lists.linux.dev,
Tony Luck <tony.luck@intel.com>
Subject: [PATCH v2] x86/mce: Set PG_hwpoison page flag to avoid the capture kernel panic
Date: Wed, 19 Jul 2023 14:16:25 -0700 [thread overview]
Message-ID: <20230719211625.298785-1-tony.luck@intel.com> (raw)
In-Reply-To: <20230127015030.30074-1-tony.luck@intel.com>
From: Zhiquan Li <zhiquan1.li@intel.com>
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 touches the error page again and panics.
Add function mce_set_page_hwpoison_now() which mark a page as
HWPoison before kernel panic() for MCE error, so that the dump
program can check and skip the error page and prevent the capture
kernel panic.
[Tony: Changed TestSetPageHWPoison() to SetPageHWPoison()]
Co-developed-by: Youquan Song <youquan.song@intel.com>
Signed-off-by: Youquan Song <youquan.song@intel.com>
Signed-off-by: Zhiquan Li <zhiquan1.li@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
v2: Replaced "TODO" comment in code with comments based on mailing
list discussion on the lack of value in covering other page types
arch/x86/kernel/cpu/mce/core.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index 89e2aab5d34d..766f64fade51 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -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);
--
2.40.1
next prev parent reply other threads:[~2023-07-19 21:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-27 1:50 [PATCH] " Tony Luck
2023-01-30 2:32 ` HORIGUCHI NAOYA(堀口 直也)
2023-01-30 19:21 ` Luck, Tony
2023-01-31 4:50 ` HORIGUCHI NAOYA(堀口 直也)
2023-02-01 2:47 ` Zhiquan Li
2023-07-19 21:16 ` Tony Luck [this message]
2023-03-27 2:33 [PATCH v2] " Zhiquan Li
2023-03-27 8:37 ` HORIGUCHI NAOYA(堀口 直也)
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=20230719211625.298785-1-tony.luck@intel.com \
--to=tony.luck@intel.com \
--cc=bp@alien8.de \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=naoya.horiguchi@nec.com \
--cc=patches@lists.linux.dev \
--cc=x86@kernel.org \
--cc=youquan.song@intel.com \
--cc=zhiquan1.li@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®