From: Jork Loeser <jloeser@linux.microsoft.com>
To: linux-hyperv@vger.kernel.org, linux-mm@kvack.org,
kexec@lists.infradead.org
Cc: "K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Long Li <longli@microsoft.com>, Mike Rapoport <rppt@kernel.org>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pratyush Yadav <pratyush@kernel.org>,
Alexander Graf <graf@amazon.com>, Jason Miu <jasonmiu@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>, Baoquan He <bhe@redhat.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>, Kees Cook <kees@kernel.org>,
Ran Xiaokai <ran.xiaokai@zte.com.cn>,
Justinien Bouron <jbouron@amazon.com>,
Sourabh Jain <sourabhjain@linux.ibm.com>,
Pingfan Liu <piliu@redhat.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Mario Limonciello <mario.limonciello@amd.com>,
linux-arm-kernel@lists.infradead.org, x86@kernel.org,
linux-kernel@vger.kernel.org,
Michael Kelley <mhklinux@outlook.com>,
Jork Loeser <jloeser@linux.microsoft.com>
Subject: [RFC PATCH 18/20] mshv: Exclude Hyper-V donated pages from crash dump collection
Date: Wed, 27 May 2026 17:42:00 -0700 [thread overview]
Message-ID: <20260528004204.1484584-19-jloeser@linux.microsoft.com> (raw)
In-Reply-To: <20260528004204.1484584-1-jloeser@linux.microsoft.com>
Pages donated to Hyper-V must not be read during crash dump collection.
They are not ordinary RAM and accessing them can hang or corrupt the
crash kernel.
Use the KHO radix tree of preserved pages to drive a vmcore pfn_is_ram()
callback. The radix tree root PA is passed to the crash kernel via
Hyper-V crash MSR P2, since the old kernel's KHO FDT is not accessible
from the crash kernel's direct map.
Signed-off-by: Jork Loeser <jloeser@linux.microsoft.com>
---
drivers/hv/mshv_page_preserve.c | 80 +++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/drivers/hv/mshv_page_preserve.c b/drivers/hv/mshv_page_preserve.c
index bc3a3a688f5b..e16fb946790d 100644
--- a/drivers/hv/mshv_page_preserve.c
+++ b/drivers/hv/mshv_page_preserve.c
@@ -11,6 +11,7 @@
#define pr_fmt(fmt) "mshv: " fmt
#include <asm/mshyperv.h>
+#include <linux/crash_dump.h>
#include <linux/kexec.h>
#include <linux/kexec_handover.h>
#include <linux/kho_radix_tree.h>
@@ -327,6 +328,57 @@ static int __init alloc_tree(void)
return 0;
}
+#ifdef CONFIG_CRASH_DUMP
+static struct kho_radix_crash_tree crash_preserved_pages_tree;
+
+/**
+ * restore_crash_tree() - Set up the crash tree for dump-time page exclusion.
+ *
+ * In the crash kernel, the old kernel's memory is not in the direct map.
+ * The old kernel stashes the radix tree root PA in Hyper-V crash MSR P2
+ * so we can retrieve it without touching the old kernel's FDT.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+static int __init restore_crash_tree(void)
+{
+ phys_addr_t root_pa;
+
+ root_pa = hv_get_msr(HV_MSR_CRASH_P2);
+ if (!root_pa)
+ return -ENOENT;
+
+ /*
+ * The MSR may contain stale data from a previous
+ * hyperv_report_panic(). Sanity-check that it looks like a
+ * page-aligned physical address within the architectural limit.
+ */
+ if (!PAGE_ALIGNED(root_pa) || root_pa >> MAX_POSSIBLE_PHYSMEM_BITS) {
+ pr_warn("Invalid crash tree root PA: 0x%llx\n",
+ (unsigned long long)root_pa);
+ return -EINVAL;
+ }
+
+ return kho_radix_crash_init(&crash_preserved_pages_tree, root_pa);
+}
+
+static bool mshv_vmcore_pfn_is_ram(struct vmcore_cb *cb, unsigned long pfn)
+{
+ /*
+ * MSHV-owned pages must not be read during crash dump collection.
+ * Currently all pages are registered at order 0. If higher-order
+ * registrations are added, this lookup will need to handle them
+ * (e.g. by querying multiple orders or using a range-based API).
+ */
+ return !kho_radix_crash_contains_page(&crash_preserved_pages_tree,
+ pfn, 0);
+}
+
+static struct vmcore_cb mshv_vmcore_cb = {
+ .pfn_is_ram = mshv_vmcore_pfn_is_ram,
+};
+#endif
+
static struct notifier_block reboot_notifier = {
.notifier_call = reboot_cb,
.priority = 0,
@@ -347,6 +399,24 @@ int __init mshv_preserve_init(void)
{
int err;
+#ifdef CONFIG_CRASH_DUMP
+ if (is_kdump_kernel()) {
+ /*
+ * Crash kernel only needs the pfn_is_ram callback to exclude
+ * MSHV-owned pages from the dump. No page restoration, no
+ * reboot notifier — the crash kernel reboots after collection.
+ */
+ err = restore_crash_tree();
+ if (err) {
+ pr_err("Could not set up crash page tree: %d; MSHV pages may appear in dump\n",
+ err);
+ return 0;
+ }
+ register_vmcore_cb(&mshv_vmcore_cb);
+ return 0;
+ }
+#endif
+
if (!kho_is_enabled()) {
pr_err("KHO is disabled; page deposits will fail.\n");
return 0;
@@ -383,5 +453,15 @@ int __init mshv_preserve_init(void)
*/
panic("Could not register reboot notification: %d\n", err);
+ /*
+ * Stash the radix tree root PA in crash MSR P2 so the crash
+ * kernel can retrieve it without touching the old kernel's FDT
+ * (which is not in the crash kernel's direct map). The root
+ * pointer is stable once the tree is initialized — pages are
+ * added/removed within the existing tree structure.
+ */
+ hv_set_msr(HV_MSR_CRASH_P2,
+ virt_to_phys(preserved_pages_tree.root));
+
return 0;
}
--
2.43.0
next prev parent reply other threads:[~2026-05-28 0:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 0:41 [RFC PATCH 00/20] mshv: enable kexec with Hyper-V donated pages and partitions Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 01/20] kho: generalize radix tree APIs Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 02/20] kho: store incoming radix tree in kho_in Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 03/20] kho: add a struct for radix callbacks Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 04/20] kho: add callback for table pages Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 05/20] kho: add data argument to radix walk callback Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 06/20] kho: allow early-boot usage of the KHO radix tree Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 07/20] kho: allow destroying " Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 08/20] kho: add kho_radix_init_tree() Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 09/20] memblock: introduce MEMBLOCK_KHO_SCRATCH_EXT Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 10/20] kho: extended scratch Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 11/20] kho: return virtual address of mem_map Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 12/20] mm/hugetlb: make bootmem allocation work with KHO Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 13/20] kho: add radix tree freeze and del_key() error reporting Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 14/20] kho: Add crash-kernel-safe radix tree presence check Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 15/20] mshv: Use page tracker to manage MSHV-owned pages and preserve with KHO Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 16/20] mshv: Add debugfs interface to page tracker Jork Loeser
2026-05-28 0:41 ` [RFC PATCH 17/20] hyperv: Reserve crash MSR P2 for page preservation root PA Jork Loeser
2026-05-28 0:42 ` Jork Loeser [this message]
2026-05-28 0:42 ` [RFC PATCH 19/20] kexec: export kexec_in_progress for modules Jork Loeser
2026-05-28 0:42 ` [RFC PATCH 20/20] mshv: freeze and vacuum partitions across kexec Jork Loeser
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=20260528004204.1484584-19-jloeser@linux.microsoft.com \
--to=jloeser@linux.microsoft.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=decui@microsoft.com \
--cc=graf@amazon.com \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=jasonmiu@google.com \
--cc=jbouron@amazon.com \
--cc=kees@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=kys@microsoft.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longli@microsoft.com \
--cc=mario.limonciello@amd.com \
--cc=mhklinux@outlook.com \
--cc=mingo@redhat.com \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=pasha.tatashin@soleen.com \
--cc=piliu@redhat.com \
--cc=pratyush@kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=ran.xiaokai@zte.com.cn \
--cc=rppt@kernel.org \
--cc=sourabhjain@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=wei.liu@kernel.org \
--cc=will@kernel.org \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox