From nobody Thu Apr 2 14:06:34 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19A93395256; Fri, 27 Mar 2026 20:19:41 +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=1774642782; cv=none; b=Qwn6/54MQCYeTLnIbyx1SxiKoW+zYmVm6AM7aJCNFGXhHK0HoZQdC38SjJd3i/JI1ojss40Z3bfI/cibNOKePnuWf3qJNNPIu7dZPMSqKqwexE5ZKWOrLziOBfu56Ggffxj6iiL247M5Zd0LZgASp8+M7qRyrHTN9B22foQbvmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774642782; c=relaxed/simple; bh=kQx2w6tjXS70FM6QN8ZD2XsXn3DcBvyYIGxSEVKnzeg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pXO1+Hu0v4Rjmd/5IP21NRoYzzzlBeqTppOtOf1x3mLWRVXXS4NmUJbRXMDgjQtYYaIsfIWEyiHUxcM0tsuXL+vdxObptciir/ehmyObA9G2CKSGqS77Yt1l64fO+wTzZ1fYgYMpWl/JxGKfVII8dMq4T7S6hRHL4trgXWRlthI= 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=FvnHWjED; 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="FvnHWjED" Received: by linux.microsoft.com (Postfix, from userid 1241) id 3022420B7128; Fri, 27 Mar 2026 13:19:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3022420B7128 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1774642781; bh=/2DAmCjc8SwftdIXiNdKNR+rhLn04r/3WgiKSyZp/C8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FvnHWjEDYeUYexVg0FBfNcUDc5s1A9Mr9Gg36gSwY2NRXit+iOOoCT0B1rdjkqBfi CkKDLy4s+0SMQsJp58sBjIeEVLAh4OmX7y2btJd0AjQv+a9Irsy7P9z/u7fOQDiDbF /RvT/UYgYPEYpZpNxEh6xN53/xC+oGrvvA4FhmcY= From: Jork Loeser To: linux-hyperv@vger.kernel.org Cc: x86@kernel.org, "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Arnd Bergmann , Roman Kisel , Michael Kelley , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Jork Loeser Subject: [PATCH 1/6] Drivers: hv: vmbus: fix hyperv_cpuhp_online variable shadowing Date: Fri, 27 Mar 2026 13:19:12 -0700 Message-ID: <20260327201920.2100427-2-jloeser@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260327201920.2100427-1-jloeser@linux.microsoft.com> References: <20260327201920.2100427-1-jloeser@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" vmbus_alloc_synic_and_connect() declares a local 'int hyperv_cpuhp_online' that shadows the file-scope global of the same name. The cpuhp state returned by cpuhp_setup_state() is stored in the local, leaving the global at 0 (CPUHP_OFFLINE). When hv_kexec_handler() or hv_machine_shutdown() later call cpuhp_remove_state(hyperv_cpuhp_online) they pass 0, which hits the BUG_ON in __cpuhp_remove_state_cpuslocked(). Remove the local declaration so the cpuhp state is stored in the file-scope global where hv_kexec_handler() and hv_machine_shutdown() expect it. Fixes: 2647c96649ba ("Drivers: hv: Support establishing the confidential VM= Bus connection") Signed-off-by: Jork Loeser Reviewed-by: Stanislav Kinsburskii --- drivers/hv/vmbus_drv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 3e7a52918ce0..301273d61892 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1430,7 +1430,6 @@ static int vmbus_alloc_synic_and_connect(void) { int ret, cpu; struct work_struct __percpu *works; - int hyperv_cpuhp_online; =20 ret =3D hv_synic_alloc(); if (ret < 0) --=20 2.43.0 From nobody Thu Apr 2 14:06:34 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70558396D07; Fri, 27 Mar 2026 20:19:42 +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=1774642783; cv=none; b=EiOE0ZjMI02Up1mwGjqOw9tl8guwAx47LNQE0SBRH/xyZQp6VdS8HTHzFiQB0F5lOpvDuygE1Z7gVOVudjxzo3xmg9pQBBsT24OOL3bttkeOsR+Clvo1Z/jY3esE/+tjeljAfbk1XqVUKC6ltaOWCvSXrXriklG9ClUPLuL7GTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774642783; c=relaxed/simple; bh=TGgnAFzlIDIivrxTgxPOdYRWjFMaQLSOV3k1ZpfrgAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JVvtsZvgGiDKC8Qj8yrLutB3yDkm0OgaLi2KOc4eqBF1WXPfs3SbhA4bvdeaAWc+UAmutOwWoerkvWc6nq4WWndyj0Fa5qO05XZgCpu7Nn8QOv5dGLmszSNU2ee275XVfCKqx9FvrDSZhKsxJPqZG7FvysTb8SRrtE8gfzxZqIs= 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=TZNhmALc; 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="TZNhmALc" Received: by linux.microsoft.com (Postfix, from userid 1241) id 8BD3F20B7129; Fri, 27 Mar 2026 13:19:42 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8BD3F20B7129 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1774642782; bh=oe8/Pqe4w3M//1TBoCPONOMHSy0PBbB0t+C6t5dQLKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZNhmALcDyG4DqfdeyDMw8r4bn7xnDgMtmXe3aYBnnHoeoZp/dQnmEiSpP/HoJ2UG DXVHSDNuZlT2STu+babv6CQE4v8vAcViOkd9emMh4I/tCzIf/fJ5hrJMk3INE9JVih 9z8xzZUYm57M8BKw0ScGToR7EFbtQ0sjhwQwmIbg= From: Jork Loeser To: linux-hyperv@vger.kernel.org Cc: x86@kernel.org, "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Arnd Bergmann , Roman Kisel , Michael Kelley , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Jork Loeser , Anirudh Rayabharam Subject: [PATCH 2/6] x86/hyperv: move stimer cleanup to hv_machine_shutdown() Date: Fri, 27 Mar 2026 13:19:13 -0700 Message-ID: <20260327201920.2100427-3-jloeser@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260327201920.2100427-1-jloeser@linux.microsoft.com> References: <20260327201920.2100427-1-jloeser@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move hv_stimer_global_cleanup() from vmbus's hv_kexec_handler() to hv_machine_shutdown() in the platform code. This ensures stimer cleanup happens before the vmbus unload, which is required for root partition kexec to work correctly. Co-developed-by: Anirudh Rayabharam Signed-off-by: Anirudh Rayabharam Signed-off-by: Jork Loeser Reviewed-by: Stanislav Kinsburskii --- arch/x86/kernel/cpu/mshyperv.c | 8 ++++++-- drivers/hv/vmbus_drv.c | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 89a2eb8a0722..235087456bdf 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -235,8 +235,12 @@ void hv_remove_crash_handler(void) #ifdef CONFIG_KEXEC_CORE static void hv_machine_shutdown(void) { - if (kexec_in_progress && hv_kexec_handler) - hv_kexec_handler(); + if (kexec_in_progress) { + hv_stimer_global_cleanup(); + + if (hv_kexec_handler) + hv_kexec_handler(); + } =20 /* * Call hv_cpu_die() on all the CPUs, otherwise later the hypervisor diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 301273d61892..5d1449f8c6ea 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2892,7 +2892,6 @@ static struct platform_driver vmbus_platform_driver = =3D { =20 static void hv_kexec_handler(void) { - hv_stimer_global_cleanup(); vmbus_initiate_unload(false); /* Make sure conn_state is set as hv_synic_cleanup checks for it */ mb(); --=20 2.43.0 From nobody Thu Apr 2 14:06:34 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 277E7399342; Fri, 27 Mar 2026 20:19:44 +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=1774642785; cv=none; b=P61pTJGwjvzKmVgkTJM6nd3DasBO9ow8XuKvAQ88LyLGxIGkH4jti3hryJX6qiudj1mzLaSyMclQGQeX8YVwVbdKPtSPsNuGCyvB5ztC07rwJui55pzN4wOX5ZN6et5sGuQB/JUFKzxpHPTxrVv99Xj+xSLq/WAPq7/YbLpnQZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774642785; c=relaxed/simple; bh=hNIiNuDPxuZnaMtc1ARblwqwK4xYSWqQw5KM4tx3lJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F6hQvD4/cVPxn1wGo2Pubc0FHL8PXta2pnmifoko2yWpXCQF3eoj4S+7wLN5z1HmCcWFzjWqfr2FXHfO49+MxPPuV9Nhank4JX8e5xzifxVJbS9tKS75cSkdHHT6hPMWx7UsQ3DDNd+8Fx3Mw3LnpiypHKE5dxbA3ORJ4mhHXbc= 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=IYT5/W5f; 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="IYT5/W5f" Received: by linux.microsoft.com (Postfix, from userid 1241) id 4D5E620B712B; Fri, 27 Mar 2026 13:19:44 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4D5E620B712B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1774642784; bh=6pzpu/gJFjinb2P2J9+XytwM6zcdOj6YIrKwdbxm5Zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IYT5/W5f8QvAjtTvI+VM/70qunsoQI/AS3y3nw+46qYI1dyRO2I0yXWjreg7TXRiX 5Fz0R7EBouKWz++F++xOG8ml0PkFJxmsn89SmfMyDv72GbhvhDIWGm6QWDmZtUKxxk fNrQu30SwN0Go0jk1+DTs0681ioi5xh9uLCz1k5Y= From: Jork Loeser To: linux-hyperv@vger.kernel.org Cc: x86@kernel.org, "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Arnd Bergmann , Roman Kisel , Michael Kelley , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Jork Loeser , Anirudh Rayabharam , Stanislav Kinsburskii , Mukesh Rathor Subject: [PATCH 3/6] x86/hyperv: Skip LP/VP creation on kexec Date: Fri, 27 Mar 2026 13:19:14 -0700 Message-ID: <20260327201920.2100427-4-jloeser@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260327201920.2100427-1-jloeser@linux.microsoft.com> References: <20260327201920.2100427-1-jloeser@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After a kexec the logical processors and virtual processors already exist in the hypervisor because they were created by the previous kernel. Attempting to add them again causes either a BUG_ON or corrupted VP state leading to MCEs in the new kernel. Add hv_lp_exists() to probe whether an LP is already present by calling HVCALL_GET_LOGICAL_PROCESSOR_RUN_TIME. When it succeeds the LP exists and we skip the add-LP and create-VP loops entirely. Also add hv_call_notify_all_processors_started() which informs the hypervisor that all processors are online. This is required after adding LPs (fresh boot) and is a no-op on kexec since we skip that path. Co-developed-by: Anirudh Rayabharam Signed-off-by: Anirudh Rayabharam Co-developed-by: Stanislav Kinsburskii Signed-off-by: Stanislav Kinsburskii Co-developed-by: Mukesh Rathor Signed-off-by: Mukesh Rathor Signed-off-by: Jork Loeser Reviewed-by: Stanislav Kinsburskii --- arch/x86/kernel/cpu/mshyperv.c | 7 +++++ drivers/hv/hv_proc.c | 47 ++++++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 10 ++++++++ include/hyperv/hvgdk_mini.h | 1 + include/hyperv/hvhdk_mini.h | 12 +++++++++ 5 files changed, 77 insertions(+) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 235087456bdf..f653feea880b 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -429,6 +429,10 @@ static void __init hv_smp_prepare_cpus(unsigned int ma= x_cpus) } =20 #ifdef CONFIG_X86_64 + /* If AP LPs exist, we are in a kexec'd kernel and VPs already exist */ + if (num_present_cpus() =3D=3D 1 || hv_lp_exists(1)) + return; + for_each_present_cpu(i) { if (i =3D=3D 0) continue; @@ -436,6 +440,9 @@ static void __init hv_smp_prepare_cpus(unsigned int max= _cpus) BUG_ON(ret); } =20 + ret =3D hv_call_notify_all_processors_started(); + WARN_ON(ret); + for_each_present_cpu(i) { if (i =3D=3D 0) continue; diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c index 5f4fd9c3231c..63a48e5a02c5 100644 --- a/drivers/hv/hv_proc.c +++ b/drivers/hv/hv_proc.c @@ -239,3 +239,50 @@ int hv_call_create_vp(int node, u64 partition_id, u32 = vp_index, u32 flags) return ret; } EXPORT_SYMBOL_GPL(hv_call_create_vp); + +int hv_call_notify_all_processors_started(void) +{ + struct hv_input_notify_partition_event *input; + u64 status; + unsigned long irq_flags; + int ret =3D 0; + + local_irq_save(irq_flags); + input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + memset(input, 0, sizeof(*input)); + input->event =3D HV_PARTITION_ALL_LOGICAL_PROCESSORS_STARTED; + status =3D hv_do_hypercall(HVCALL_NOTIFY_PARTITION_EVENT, + input, NULL); + local_irq_restore(irq_flags); + + if (!hv_result_success(status)) { + hv_status_err(status, "\n"); + ret =3D hv_result_to_errno(status); + } + return ret; +} + +bool hv_lp_exists(u32 lp_index) +{ + struct hv_input_get_logical_processor_run_time *input; + struct hv_output_get_logical_processor_run_time *output; + unsigned long flags; + u64 status; + + local_irq_save(flags); + input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); + + input->lp_index =3D lp_index; + status =3D hv_do_hypercall(HVCALL_GET_LOGICAL_PROCESSOR_RUN_TIME, + input, output); + local_irq_restore(flags); + + if (!hv_result_success(status) && + hv_result(status) !=3D HV_STATUS_INVALID_LP_INDEX) { + hv_status_err(status, "\n"); + BUG(); + } + + return hv_result_success(status); +} diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index d37b68238c97..bf601d67cecb 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -347,6 +347,8 @@ bool hv_result_needs_memory(u64 status); int hv_deposit_memory_node(int node, u64 partition_id, u64 status); int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); +int hv_call_notify_all_processors_started(void); +bool hv_lp_exists(u32 lp_index); int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); =20 #else /* CONFIG_MSHV_ROOT */ @@ -366,6 +368,14 @@ static inline int hv_call_add_logical_proc(int node, u= 32 lp_index, u32 acpi_id) { return -EOPNOTSUPP; } +static inline int hv_call_notify_all_processors_started(void) +{ + return -EOPNOTSUPP; +} +static inline bool hv_lp_exists(u32 lp_index) +{ + return false; +} static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_ind= ex, u32 flags) { return -EOPNOTSUPP; diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h index 056ef7b6b360..f2598e186550 100644 --- a/include/hyperv/hvgdk_mini.h +++ b/include/hyperv/hvgdk_mini.h @@ -435,6 +435,7 @@ union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_AS= SIST_PAGE */ /* HV_CALL_CODE */ #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003 +#define HVCALL_GET_LOGICAL_PROCESSOR_RUN_TIME 0x0004 #define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008 #define HVCALL_SEND_IPI 0x000b #define HVCALL_ENABLE_VP_VTL 0x000f diff --git a/include/hyperv/hvhdk_mini.h b/include/hyperv/hvhdk_mini.h index 091c03e26046..b4cb2fa26e9b 100644 --- a/include/hyperv/hvhdk_mini.h +++ b/include/hyperv/hvhdk_mini.h @@ -362,6 +362,7 @@ union hv_partition_event_input { =20 enum hv_partition_event { HV_PARTITION_EVENT_ROOT_CRASHDUMP =3D 2, + HV_PARTITION_ALL_LOGICAL_PROCESSORS_STARTED =3D 4, }; =20 struct hv_input_notify_partition_event { @@ -369,6 +370,17 @@ struct hv_input_notify_partition_event { union hv_partition_event_input input; } __packed; =20 +struct hv_input_get_logical_processor_run_time { + u32 lp_index; +} __packed; + +struct hv_output_get_logical_processor_run_time { + u64 global_time; + u64 local_run_time; + u64 rsvdz0; + u64 hypervisor_time; +} __packed; + struct hv_lp_startup_status { u64 hv_status; u64 substatus1; --=20 2.43.0 From nobody Thu Apr 2 14:06:34 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A639F39DBF9; Fri, 27 Mar 2026 20:19:46 +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=1774642787; cv=none; b=m5Y1HRggLpw6AcdWsRf9CP+ewsUarG/8Vvw2dlKWZeJ6ZUKv8zIwI2mILheMCfKFCJC3bqb1xu5rNMBTz0PomfdN5bQkECnD0ddeVnoTmIEHmpENjMrXtSh5wzKyD8yAGXU75nJ81d62H0+6YqQmbTPSZtiN5trqlSmKVC7CjGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774642787; c=relaxed/simple; bh=n3wRMWxijb5f+Ki/ATxgIfrLW6wOCwMljQUOyeOhKng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H9bJY/BDlTvII9E7/XXapM9mlOjitpOFpQkW2juhA/M5EHOoe1zAkX/JXzIjtoe/t3KYnNTGAppQYkH/O3z0gBhl69KWovgi6MxJl6+Y9L9ORiQwg2FTM7QS8/e69AuLNlQCd1ecTUH6HNcJqE/QXB1bezZYSlorYahVVH354Sw= 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=RTFVT+95; 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="RTFVT+95" Received: by linux.microsoft.com (Postfix, from userid 1241) id DB01320B712D; Fri, 27 Mar 2026 13:19:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DB01320B712D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1774642786; bh=A3whTba+kKlux0T39+Eo6dSgs6pyxVciElJs0djBuTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RTFVT+95MBkFfdiq9i+cyUbuieLWF4mXd+LwBrvQ2cebq5WXZ9GJBhqwP11HhNrMd bXyvfkilSzHtkJMx/KYs3O94YiOk4+aPHkiT4RNGJYEDeT+BVOvWUs9wDKpbQKnpKF 2MrrfyO7nEKBdV/SzjXar/WlPRUZlNiFN45kIGao= From: Jork Loeser To: linux-hyperv@vger.kernel.org Cc: x86@kernel.org, "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Arnd Bergmann , Roman Kisel , Michael Kelley , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Jork Loeser Subject: [PATCH 4/6] mshv: limit SynIC management to MSHV-owned resources Date: Fri, 27 Mar 2026 13:19:15 -0700 Message-ID: <20260327201920.2100427-5-jloeser@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260327201920.2100427-1-jloeser@linux.microsoft.com> References: <20260327201920.2100427-1-jloeser@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The SynIC is shared between VMBus and MSHV. VMBus owns the message page (SIMP), event flags page (SIEFP), global enable (SCONTROL), and SINT2. MSHV adds SINT0, SINT5, and the event ring page (SIRBP). Currently mshv_synic_init() redundantly enables SIMP, SIEFP, and SCONTROL that VMBus already configured, and mshv_synic_cleanup() disables all of them. This is wrong because MSHV can be torn down while VMBus is still active. In particular, a kexec reboot notifier tears down MSHV first. Disabling SCONTROL, SIMP, and SIEFP out from under VMBus causes its later cleanup to write SynIC MSRs while SynIC is disabled, which the hypervisor does not tolerate. Restrict MSHV to managing only the resources it owns: - SINT0, SINT5: mask on cleanup, unmask on init - SIRBP: enable/disable as before - SIMP, SIEFP, SCONTROL: on L1VH leave entirely to VMBus (it already enabled them); on root partition VMBus doesn't run, so MSHV must enable/disable them Signed-off-by: Jork Loeser --- drivers/hv/mshv_synic.c | 109 ++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 42 deletions(-) diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index f8b0337cdc82..8a7d76a10dc3 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -454,7 +454,6 @@ int mshv_synic_init(unsigned int cpu) #ifdef HYPERVISOR_CALLBACK_VECTOR union hv_synic_sint sint; #endif - union hv_synic_scontrol sctrl; struct hv_synic_pages *spages =3D this_cpu_ptr(mshv_root.synic_pages); struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page =3D @@ -462,28 +461,37 @@ int mshv_synic_init(unsigned int cpu) struct hv_synic_event_ring_page **event_ring_page =3D &spages->synic_event_ring_page; =20 - /* Setup the Synic's message page */ + /* + * Map the SYNIC message page. On root partition the hypervisor + * pre-provisions the SIMP GPA but may not set simp_enabled; + * on L1VH, VMBus already fully set it up. Enable it on root. + */ simp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIMP); - simp.simp_enabled =3D true; + if (hv_root_partition()) { + simp.simp_enabled =3D true; + hv_set_non_nested_msr(HV_MSR_SIMP, simp.as_uint64); + } *msg_page =3D memremap(simp.base_simp_gpa << HV_HYP_PAGE_SHIFT, HV_HYP_PAGE_SIZE, MEMREMAP_WB); =20 if (!(*msg_page)) - return -EFAULT; - - hv_set_non_nested_msr(HV_MSR_SIMP, simp.as_uint64); + goto cleanup_simp; =20 - /* Setup the Synic's event flags page */ + /* + * Map the event flags page. Same as SIMP: enable on root, + * already enabled by VMBus on L1VH. + */ siefp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIEFP); - siefp.siefp_enabled =3D true; + if (hv_root_partition()) { + siefp.siefp_enabled =3D true; + hv_set_non_nested_msr(HV_MSR_SIEFP, siefp.as_uint64); + } *event_flags_page =3D memremap(siefp.base_siefp_gpa << PAGE_SHIFT, PAGE_SIZE, MEMREMAP_WB); =20 if (!(*event_flags_page)) - goto cleanup; - - hv_set_non_nested_msr(HV_MSR_SIEFP, siefp.as_uint64); + goto cleanup_siefp; =20 /* Setup the Synic's event ring page */ sirbp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIRBP); @@ -492,7 +500,7 @@ int mshv_synic_init(unsigned int cpu) PAGE_SIZE, MEMREMAP_WB); =20 if (!(*event_ring_page)) - goto cleanup; + goto cleanup_siefp; =20 hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); =20 @@ -515,28 +523,33 @@ int mshv_synic_init(unsigned int cpu) sint.as_uint64); #endif =20 - /* Enable global synic bit */ - sctrl.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SCONTROL); - sctrl.enable =3D 1; - hv_set_non_nested_msr(HV_MSR_SCONTROL, sctrl.as_uint64); + /* + * On L1VH, VMBus owns SCONTROL and has already enabled it. + * On root partition, VMBus doesn't run so we must enable it. + */ + if (hv_root_partition()) { + union hv_synic_scontrol sctrl; + + sctrl.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SCONTROL); + sctrl.enable =3D 1; + hv_set_non_nested_msr(HV_MSR_SCONTROL, sctrl.as_uint64); + } =20 return 0; =20 -cleanup: - if (*event_ring_page) { - sirbp.sirbp_enabled =3D false; - hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); - memunmap(*event_ring_page); - } - if (*event_flags_page) { +cleanup_siefp: + if (*event_flags_page) + memunmap(*event_flags_page); + if (hv_root_partition()) { siefp.siefp_enabled =3D false; hv_set_non_nested_msr(HV_MSR_SIEFP, siefp.as_uint64); - memunmap(*event_flags_page); } - if (*msg_page) { +cleanup_simp: + if (*msg_page) + memunmap(*msg_page); + if (hv_root_partition()) { simp.simp_enabled =3D false; hv_set_non_nested_msr(HV_MSR_SIMP, simp.as_uint64); - memunmap(*msg_page); } =20 return -EFAULT; @@ -545,10 +558,7 @@ int mshv_synic_init(unsigned int cpu) int mshv_synic_cleanup(unsigned int cpu) { union hv_synic_sint sint; - union hv_synic_simp simp; - union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; - union hv_synic_scontrol sctrl; struct hv_synic_pages *spages =3D this_cpu_ptr(mshv_root.synic_pages); struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page =3D @@ -568,28 +578,43 @@ int mshv_synic_cleanup(unsigned int cpu) hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_DOORBELL_SINT_INDEX, sint.as_uint64); =20 - /* Disable Synic's event ring page */ + /* Disable SYNIC event ring page owned by MSHV */ sirbp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIRBP); sirbp.sirbp_enabled =3D false; hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); memunmap(*event_ring_page); =20 - /* Disable Synic's event flags page */ - siefp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIEFP); - siefp.siefp_enabled =3D false; - hv_set_non_nested_msr(HV_MSR_SIEFP, siefp.as_uint64); + /* + * Release our mappings of the message and event flags pages. + * On root partition, we enabled SIMP/SIEFP =E2=80=94 disable them. + * On L1VH, VMBus owns the MSRs, leave them alone. + */ memunmap(*event_flags_page); + if (hv_root_partition()) { + union hv_synic_simp simp; + union hv_synic_siefp siefp; =20 - /* Disable Synic's message page */ - simp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIMP); - simp.simp_enabled =3D false; - hv_set_non_nested_msr(HV_MSR_SIMP, simp.as_uint64); + siefp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIEFP); + siefp.siefp_enabled =3D false; + hv_set_non_nested_msr(HV_MSR_SIEFP, siefp.as_uint64); + + simp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIMP); + simp.simp_enabled =3D false; + hv_set_non_nested_msr(HV_MSR_SIMP, simp.as_uint64); + } memunmap(*msg_page); =20 - /* Disable global synic bit */ - sctrl.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SCONTROL); - sctrl.enable =3D 0; - hv_set_non_nested_msr(HV_MSR_SCONTROL, sctrl.as_uint64); + /* + * On root partition, we enabled SCONTROL in init =E2=80=94 disable it. + * On L1VH, VMBus owns SCONTROL, leave it alone. + */ + if (hv_root_partition()) { + union hv_synic_scontrol sctrl; + + sctrl.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SCONTROL); + sctrl.enable =3D 0; + hv_set_non_nested_msr(HV_MSR_SCONTROL, sctrl.as_uint64); + } =20 return 0; } --=20 2.43.0 From nobody Thu Apr 2 14:06:34 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E78F39E19C; Fri, 27 Mar 2026 20:19:48 +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=1774642789; cv=none; b=icI5bPCFN13hD6cdxoM1HQPisc7xiRq95bvkoLa1YdsKAxAPkaOoBieFVw4GSh6AjErtWbYNzNJa74SUNvsgY8B2B4bQ3JfEOXyAJcEFwelQ+5imu9cjKtfm6QjjuNUHL4umNsddfFWkgJziGBkyFNBKDuE+x0jWBEdqaOnghUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774642789; c=relaxed/simple; bh=9841nyKGaCMbJiPamuLtSUu7rGO7k/yXSVzxhwUWwlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BSXslF6WNogllqkt+Je0LNnCjp/h+R+hUA3HPtgFr3LXZJSWF85aWZzE6CtqM8R/7kjCg3diRbx0tTiOWGA6MdtmFMBU1KFP+6RDJrzJAFIHGcyBZRobsZFQqF0Ty79xYNggbN+ezhzbxgAta0x/cHMkyJ3dPzm0tc82vw4nwuU= 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=ZgpfBo+1; 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="ZgpfBo+1" Received: by linux.microsoft.com (Postfix, from userid 1241) id 6827D20B7136; Fri, 27 Mar 2026 13:19:48 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6827D20B7136 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1774642788; bh=q3fRO5i4ffy4kvgvvmuRdroHrhQi79GfqaNfwbQdhoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZgpfBo+1mH6j9miu3hxMlnZgvqerHsdINKpFUq65uV1DN5p1VHdbrCbmg8CMrN5rZ McK/PjMiYvJAcsp59nJdu6zKIgfHz0kuGPkBdcmCzl7a5EAO+cuKKJ6a5HeW0wONek cI5pjrUY79Pj9rMYilgAIpfpteMHnhS02jaV7bvk= From: Jork Loeser To: linux-hyperv@vger.kernel.org Cc: x86@kernel.org, "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Arnd Bergmann , Roman Kisel , Michael Kelley , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Jork Loeser Subject: [PATCH 5/6] mshv: clean up SynIC state on kexec for L1VH Date: Fri, 27 Mar 2026 13:19:16 -0700 Message-ID: <20260327201920.2100427-6-jloeser@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260327201920.2100427-1-jloeser@linux.microsoft.com> References: <20260327201920.2100427-1-jloeser@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Register the mshv reboot notifier for all parent partitions, not just root. Previously the notifier was gated on hv_root_partition(), so on L1VH (where hv_root_partition() is false) SINT0, SINT5, and SIRBP were never cleaned up before kexec. The kexec'd kernel then inherited stale unmasked SINTs and an enabled SIRBP pointing to freed memory. The L1VH SIRBP also needs special handling: unlike the root partition where the hypervisor provides the SIRBP page, L1VH must allocate its own page and program the GPA into the MSR. Add this allocation to mshv_synic_init() and the corresponding free to mshv_synic_cleanup(). Remove the unnecessary mshv_root_partition_init/exit wrappers and register the reboot notifier directly in mshv_parent_partition_init(). Make mshv_reboot_nb static since it no longer needs external linkage. Signed-off-by: Jork Loeser Reviewed-by: Stanislav Kinsburskii --- drivers/hv/mshv_root_main.c | 21 ++++----------------- drivers/hv/mshv_synic.c | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index e6509c980763..281f530b68a9 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2256,20 +2256,10 @@ static int mshv_reboot_notify(struct notifier_block= *nb, return 0; } =20 -struct notifier_block mshv_reboot_nb =3D { +static struct notifier_block mshv_reboot_nb =3D { .notifier_call =3D mshv_reboot_notify, }; =20 -static void mshv_root_partition_exit(void) -{ - unregister_reboot_notifier(&mshv_reboot_nb); -} - -static int __init mshv_root_partition_init(struct device *dev) -{ - return register_reboot_notifier(&mshv_reboot_nb); -} - static int __init mshv_init_vmm_caps(struct device *dev) { int ret; @@ -2339,8 +2329,7 @@ static int __init mshv_parent_partition_init(void) if (ret) goto remove_cpu_state; =20 - if (hv_root_partition()) - ret =3D mshv_root_partition_init(dev); + ret =3D register_reboot_notifier(&mshv_reboot_nb); if (ret) goto remove_cpu_state; =20 @@ -2368,8 +2357,7 @@ static int __init mshv_parent_partition_init(void) deinit_root_scheduler: root_scheduler_deinit(); exit_partition: - if (hv_root_partition()) - mshv_root_partition_exit(); + unregister_reboot_notifier(&mshv_reboot_nb); remove_cpu_state: cpuhp_remove_state(mshv_cpuhp_online); free_synic_pages: @@ -2387,8 +2375,7 @@ static void __exit mshv_parent_partition_exit(void) misc_deregister(&mshv_dev); mshv_irqfd_wq_cleanup(); root_scheduler_deinit(); - if (hv_root_partition()) - mshv_root_partition_exit(); + unregister_reboot_notifier(&mshv_reboot_nb); cpuhp_remove_state(mshv_cpuhp_online); free_percpu(mshv_root.synic_pages); } diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index 8a7d76a10dc3..32f91a714c97 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -495,13 +495,29 @@ int mshv_synic_init(unsigned int cpu) =20 /* Setup the Synic's event ring page */ sirbp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIRBP); - sirbp.sirbp_enabled =3D true; - *event_ring_page =3D memremap(sirbp.base_sirbp_gpa << PAGE_SHIFT, - PAGE_SIZE, MEMREMAP_WB); =20 - if (!(*event_ring_page)) - goto cleanup_siefp; + if (hv_root_partition()) { + *event_ring_page =3D memremap(sirbp.base_sirbp_gpa << PAGE_SHIFT, + PAGE_SIZE, MEMREMAP_WB); + + if (!(*event_ring_page)) + goto cleanup_siefp; + } else { + /* + * On L1VH the hypervisor does not provide a SIRBP page. + * Allocate one and program its GPA into the MSR. + */ + *event_ring_page =3D (struct hv_synic_event_ring_page *) + get_zeroed_page(GFP_KERNEL); + + if (!(*event_ring_page)) + goto cleanup_siefp; =20 + sirbp.base_sirbp_gpa =3D virt_to_phys(*event_ring_page) + >> PAGE_SHIFT; + } + + sirbp.sirbp_enabled =3D true; hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); =20 #ifdef HYPERVISOR_CALLBACK_VECTOR @@ -581,8 +597,15 @@ int mshv_synic_cleanup(unsigned int cpu) /* Disable SYNIC event ring page owned by MSHV */ sirbp.as_uint64 =3D hv_get_non_nested_msr(HV_MSR_SIRBP); sirbp.sirbp_enabled =3D false; - hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); - memunmap(*event_ring_page); + + if (hv_root_partition()) { + hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); + memunmap(*event_ring_page); + } else { + sirbp.base_sirbp_gpa =3D 0; + hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); + free_page((unsigned long)*event_ring_page); + } =20 /* * Release our mappings of the message and event flags pages. --=20 2.43.0 From nobody Thu Apr 2 14:06:34 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FA1D39EF12; Fri, 27 Mar 2026 20:19:49 +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=1774642790; cv=none; b=bn826xsh5MMjQWG7GYT7rqzAsEQPJXZDjjEmyGk3owpAKR0ZcD2PNQAe0hRqk2sd7hwcg4X6urulT6gvCjabU8d6SEJPYDkZf8g6uELWA2pu4r48bCPuA3D8eprlOM1TtJAWodKPCTsxVPmVEhp1x9TsFBd93FUFU3J2z1qjUaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774642790; c=relaxed/simple; bh=eJFkaRo9CKhZlto6iDCuLzjnu9hkc3JVC3IjFHx3XJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RNi67YtdlL5Oi0SlkvYrIWENxRMtQ6JypEDVhOzVBRC7kVjxoVoQSP/pTDipjtiFvGcxpt9XBWlgAqPvqZHxESso0Dg1nFquvR6T3xZqb0ghv3hcCL6ON1DIpScOd35sTVAbBSdpCVLjm7/8YqFU+fVZycU2AziaA/HgKyo28kU= 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=Uesr+RPz; 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="Uesr+RPz" Received: by linux.microsoft.com (Postfix, from userid 1241) id AB74820B7135; Fri, 27 Mar 2026 13:19:49 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AB74820B7135 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1774642789; bh=dtJ8seWmbMqGCQ41xKmiIdEUtLNh0z2d7AxXL8JOv/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uesr+RPzzxWsPaVhwsg0gOb8TIvmzpSFiFCwxkwk1mEQL3yy9GtUb4EQcH6ln2XmL CESk+Hz1cI6K9LtRAcEfr+AH8TZY9sqWLm2qG21grKU7LcaAKpkJNJf6bmEATWmxez Kk2h8YUORX8cKaxF3MilozBjdvDU9XTEKE6gn2v0= From: Jork Loeser To: linux-hyperv@vger.kernel.org Cc: x86@kernel.org, "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Arnd Bergmann , Roman Kisel , Michael Kelley , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Jork Loeser Subject: [PATCH 6/6] mshv: unmap debugfs stats pages on kexec Date: Fri, 27 Mar 2026 13:19:17 -0700 Message-ID: <20260327201920.2100427-7-jloeser@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260327201920.2100427-1-jloeser@linux.microsoft.com> References: <20260327201920.2100427-1-jloeser@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Stanislav Kinsburskii --- 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) =20 mshv_debugfs =3D debugfs_create_dir("mshv", NULL); if (IS_ERR(mshv_debugfs)) { + err =3D PTR_ERR(mshv_debugfs); + mshv_debugfs =3D NULL; pr_err("%s: failed to create debugfs directory\n", __func__); - return PTR_ERR(mshv_debugfs); + return err; } =20 if (hv_root_partition()) { @@ -712,6 +714,9 @@ int __init mshv_debugfs_init(void) =20 void mshv_debugfs_exit(void) { + if (!mshv_debugfs) + return; + mshv_debugfs_parent_partition_remove(); =20 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; } --=20 2.43.0