From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6779F1DE8AD; Thu, 28 May 2026 00:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779928960; cv=none; b=XA/uBK1K/5+qHDUKdoDSOpBDJyV/dqEZDMreovOYu59vJN21x/dKDuJq3dHBv7/ld3DBc3D95/mc7DnxGefqVE1gpiKkDfxOUh4WX9Vur4+TPeyOKmKs9RsZsrd/9sWGZHtXQITxjC1tjRi94dQzyQuq20SMpwUi/wSg5yK4H0Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779928960; c=relaxed/simple; bh=Sw/raEnjUfoIT2HvdYl0g8Ulj5nC52FSfDRwXuORkT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LhdSK6EtTujP2nTdisjeiPveBIqnbSHzh6dl3z4CrXHZ3bh3EozKz1XGZaXGD4aN3qjPPfX5vmh7CtmECHjpuQ5oNA7Ay89Nb27abBAvT2pPmH4PG2MiTR7VdVYlA+maP02FlW3P2ZfKDlbVeL+zsnjodIENAlf1DqylLfAun2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=FHsBi+OY; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="FHsBi+OY" Received: by linux.microsoft.com (Postfix, from userid 1241) id C2BE920B7186; Wed, 27 May 2026 17:42:25 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C2BE920B7186 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779928945; bh=0yKWet6irofp6Dygz5hKnYjBExq95hNouOEHl1lcaYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FHsBi+OYZ9jOcAKcU2N4XgtTRa3DLo/5xpdPQ0VrR5ozMbaqTHr4GszSWV4T/H9ki 7ytnnjuF1mEcG+QD8rrmG5BehOPAJhT0V5AyAw2dJe45d31pNsyjIl5QyHdtmMrzf8 FP7l0XKJtLFJkM48S1NZyz3bc1EfsdeGKLqW7j4U= From: Jork Loeser To: linux-hyperv@vger.kernel.org, linux-mm@kvack.org, kexec@lists.infradead.org Cc: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Jason Miu , Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Baoquan He , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Kees Cook , Ran Xiaokai , Justinien Bouron , Sourabh Jain , Pingfan Liu , "Rafael J. Wysocki" , Mario Limonciello , linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-kernel@vger.kernel.org, Michael Kelley , Jork Loeser Subject: [RFC PATCH 18/20] mshv: Exclude Hyper-V donated pages from crash dump collection Date: Wed, 27 May 2026 17:42:00 -0700 Message-ID: <20260528004204.1484584-19-jloeser@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260528004204.1484584-1-jloeser@linux.microsoft.com> References: <20260528004204.1484584-1-jloeser@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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 +#include #include #include #include @@ -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