From nobody Tue Dec 2 02:59:04 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F5983446D6; Mon, 17 Nov 2025 21:09:13 +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=1763413755; cv=none; b=f5Xdtjr3Zmkm/DHYbMLnsKdIMIZy/y7H5p3UV2F7nLIkEIcjwlcnVr+JNVKzg7BUPJIGf3nL0q9dgZ0KaDyAAvfjlAmyrL3GOQeyxoW2ypYsFnkaprIqClo+AvuOmlzVuostZesIUYDwBgVsforC0uneYJUea5NzxEp9ii5NKBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763413755; c=relaxed/simple; bh=F7720mKzNkCyKDFLO0uVt6mLlc9YPAcJAP0PCon+qxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iJOb37myvn8eiA5lzGAoNQknuYzzWgocs7HCNScl537QBCyd6ffJu9B2nDBsfXYAfhnsRwGKFlTTD7Ifip/VyF392TH+S1O4c5qOBGmYY2trosQnYmlOXA/5iAv+Ge4WhzBMBRFdVn4hbmbmIIKwpCKKo2ACF9lSzMQSPFEHeS8= 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=MOPL+ApF; 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="MOPL+ApF" Received: from home (unknown [72.191.74.189]) by linux.microsoft.com (Postfix) with ESMTPSA id D4803211C29E; Mon, 17 Nov 2025 13:09:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D4803211C29E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1763413746; bh=LSlVSgvFrLjmBkegSWSpoKm3gTlsJwpDrznHfDraKEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOPL+ApF1TVTK4bkcm6N2hEIX4+cOwX3T6th3pzUHVvttfs3ATX4npLeeXz8JjDNx Ng68QVi2L7jsGOTzGngVxTcqHg+cyxPF+eDJx4AQagZ3mUExsdQ9pwP9FH2i2sgjiW TrrYHWw947hDLwUGdRbqo7fCbkAkqBsCF7c+8+s8= From: Praveen K Paladugu To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de Cc: anbelski@linux.microsoft.com, prapal@linux.microsoft.com, easwar.hariharan@linux.microsoft.com, nunodasneves@linux.microsoft.com, skinsburskii@linux.microsoft.com Subject: [PATCH v5 3/3] hyperv: Cleanly shutdown root partition with MSHV Date: Mon, 17 Nov 2025 15:08:18 -0600 Message-ID: <20251117210855.108126-4-prapal@linux.microsoft.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251117210855.108126-1-prapal@linux.microsoft.com> References: <20251117210855.108126-1-prapal@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" When a root partition running on MSHV is powered off, the default behavior is to write ACPI registers to power-off. However, this ACPI write is intercepted by MSHV and will result in a Machine Check Exception(MCE). The root partition eventually panics with a trace similar to: [ 81.306348] reboot: Power down [ 81.314709] mce: [Hardware Error]: CPU 0: Machine Check Exception: 4 B= ank 0: b2000000c0060001 [ 81.314711] mce: [Hardware Error]: TSC 3b8cb60a66 PPIN 11d98332458e4ea9 [ 81.314713] mce: [Hardware Error]: PROCESSOR 0:606a6 TIME 1759339405 S= OCKET 0 APIC 0 microcode ffffffff [ 81.314715] mce: [Hardware Error]: Run the above through 'mcelog --asc= ii' [ 81.314716] mce: [Hardware Error]: Machine check: Processor context co= rrupt [ 81.314717] Kernel panic - not syncing: Fatal machine check To correctly shutdown a root partition running on MSHV hypervisor, sleep state information must be configured within the hypervsior. Later, the HVCALL_ENTER_SLEEP_STATE hypercall should be invoked as the last step in the shutdown sequence. The previous patch configures the sleep state information and this patch invokes HVCALL_ENTER_SLEEP_STATE hypercall to cleanly shutdown the root partition. Signed-off-by: Praveen K Paladugu Co-developed-by: Anatol Belski Signed-off-by: Anatol Belski Reviewed-by: Easwar Hariharan --- arch/x86/hyperv/hv_init.c | 2 ++ arch/x86/include/asm/mshyperv.h | 2 ++ drivers/hv/mshv_common.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 645b52dd732e..24824534ff8d 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 void *hv_hypercall_pg; =20 @@ -562,6 +563,7 @@ void __init hyperv_init(void) * failures here. */ hv_sleep_notifiers_register(); + machine_ops.power_off =3D hv_machine_power_off; } else { hypercall_msr.guest_physical_address =3D vmalloc_to_pfn(hv_hypercall_pg); wrmsrq(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyper= v.h index 166053df0484..4c22f3257368 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -183,9 +183,11 @@ void hv_apic_init(void); void __init hv_init_spinlocks(void); bool hv_vcpu_is_preempted(int vcpu); void hv_sleep_notifiers_register(void); +void hv_machine_power_off(void); #else static inline void hv_apic_init(void) {} static inline void hv_sleep_notifiers_register(void) {}; +static inline void hv_machine_power_off(void) {}; #endif =20 struct irq_domain *hv_create_pci_msi_domain(void); diff --git a/drivers/hv/mshv_common.c b/drivers/hv/mshv_common.c index ee733ba1575e..73505cbdc324 100644 --- a/drivers/hv/mshv_common.c +++ b/drivers/hv/mshv_common.c @@ -216,3 +216,21 @@ void hv_sleep_notifiers_register(void) pr_err("%s: cannot register reboot notifier %d\n", __func__, ret); } + +/* + * Power off the machine by entering S5 sleep state via Hyper-V hypercall. + * This call does not return if successful. + */ +void hv_machine_power_off(void) +{ + unsigned long flags; + struct hv_input_enter_sleep_state *in; + + local_irq_save(flags); + in =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + in->sleep_state =3D HV_SLEEP_STATE_S5; + + (void)hv_do_hypercall(HVCALL_ENTER_SLEEP_STATE, in, NULL); + local_irq_restore(flags); + +} --=20 2.51.0