Re: [PATCH 6/6] mshv: unmap debugfs stats pages on kexec

Stanislav Kinsburskii
2026-03-30T21:54:15Z

On Fri, Mar 27, 2026 at 01:19:17PM -0700, Jork Loeser wrote:
> On L1VH, debugfs stats pages are overlay pages: the kernel allocates
> them and registers the GPAs with the hypervisor via
> HVCALL_MAP_STATS_PAGE2. These overlay mappings persist in the
> hypervisor across kexec. If the kexec'd kernel reuses those physical
> pages, the hypervisor's overlay semantics cause a machine check
> exception.
>
> Fix this by calling mshv_debugfs_exit() from the reboot notifier,
> which issues HVCALL_UNMAP_STATS_PAGE for each mapped stats page before
> kexec. This releases the overlay bindings so the physical pages can be
> safely reused. Guard mshv_debugfs_exit() against being called when
> init failed.
>
> Signed-off-by: Jork Loeser <jloeser@linux.microsoft.com>
> ---
> drivers/hv/mshv_debugfs.c | 7 ++++++-
> drivers/hv/mshv_root_main.c | 1 +
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hv/mshv_debugfs.c b/drivers/hv/mshv_debugfs.c
> index ebf2549eb44d..f9a4499cf8f3 100644
> --- a/drivers/hv/mshv_debugfs.c
> +++ b/drivers/hv/mshv_debugfs.c
> @@ -676,8 +676,10 @@ int __init mshv_debugfs_init(void)
>
> mshv_debugfs = debugfs_create_dir("mshv", NULL);
> if (IS_ERR(mshv_debugfs)) {
> + err = PTR_ERR(mshv_debugfs);
> + mshv_debugfs = NULL;
> pr_err("%s: failed to create debugfs directory\n", __func__);
> - return PTR_ERR(mshv_debugfs);
> + return err;
> }
>
> if (hv_root_partition()) {
> @@ -712,6 +714,9 @@ int __init mshv_debugfs_init(void)
>
> void mshv_debugfs_exit(void)
> {
> + if (!mshv_debugfs)

nit: this should allow to avoid setting mshv_debugfs to NULL in the
error path of mshv_debugfs_init():

if (!IS_ERR_OR_NULL(mshv_debugfs))

Reviewed-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>

> + return;
> +
> mshv_debugfs_parent_partition_remove();
>
> if (hv_root_partition()) {
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index 281f530b68a9..7038fd830646 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -2252,6 +2252,7 @@ root_scheduler_deinit(void)
> static int mshv_reboot_notify(struct notifier_block *nb,
> unsigned long code, void *unused)
> {
> + mshv_debugfs_exit();
> cpuhp_remove_state(mshv_cpuhp_online);
> return 0;
> }
> --
> 2.43.0
>