From nobody Tue Dec 16 23:26:54 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 878EE27181C; Thu, 27 Feb 2025 21:47:30 +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=1740692851; cv=none; b=BS9vkcrl/KDJ2H+4/ltmM3GNi9oMskpLPSi9WJYs2a9Ir0nxF7+RnUkzkZGm/RhN8k/Z3A7hynHUmqYEBoj24B3YoGUAinFIft+MTzgdW99T8xI91dyzi29YuKCfApaCwUWrkiBhObNmUKa22KsegC37O07GtgB7eVLmRB5f6HY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740692851; c=relaxed/simple; bh=WySDr8RJ9iCLor9PMBDB1y+NCIU0CrhEp2pDvg0Fxyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qRVp7/WJiz4t2Rrpr0n2hUW9qhL5aPDKln9NgZVhj89H2ifTc38sGWC+RNvzXAB21ZHMt71NL9NeXvUNRHkLPyynfPEz/NlMfjIsr9vJFQ8RIErv4Tfs1BZPlY0lPVjNt5YiazAfJrgDCWHhSqh2crX+leb9NyQyEukUx/kiaPw= 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=CPtbNjbY; 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="CPtbNjbY" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id E74CC210EAC2; Thu, 27 Feb 2025 13:47:29 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E74CC210EAC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1740692850; bh=s3v611mj9neOZEEDQBmvrzVPT6h/ZL3vkxwXr7kCv58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CPtbNjbYUG3bYxCW8gfwP1wQq74PCAZUa65DuX8Trtd2vyGokSj0v1R1J50MrDtEO B7XHRom2pFp7sEheXbWuuDj/gESJpE7mQcPhod6solvor+LjwBLuDZsD6e17p9CJMq SN63NDFXZMjXgR84Hg1pTYpHw6RTWjsmg0NZgXuc= From: Roman Kisel To: bp@alien8.de, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mingo@redhat.com, ssengar@linux.microsoft.com, tglx@linutronix.de, wei.liu@kernel.org, x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v3 1/2] x86/hyperv: Add VTL mode emergency restart callback Date: Thu, 27 Feb 2025 13:47:27 -0800 Message-ID: <20250227214728.15672-2-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250227214728.15672-1-romank@linux.microsoft.com> References: <20250227214728.15672-1-romank@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" By default, X86(-64) systems use the emergecy restart routine in the course of which the code unconditionally writes to the physical address of 0x472 to indicate the boot mode to the firmware (BIOS or UEFI). When the kernel itself runs as a firmware in the VTL mode, that write corrupts the memory of the guest upon emergency restarting. Preserving the state intact in that situation is important for debugging, at least. Define the specialized machine callback to avoid that write and use the triple fault to perform emergency restart. Signed-off-by: Roman Kisel --- arch/x86/hyperv/hv_vtl.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 4e1b1e3b5658..4421b75ad9a9 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -12,6 +12,7 @@ #include #include #include +#include #include <../kernel/smpboot.h> =20 extern struct boot_params boot_params; @@ -22,6 +23,27 @@ static bool __init hv_vtl_msi_ext_dest_id(void) return true; } =20 +/* + * The `native_machine_emergency_restart` function from `reboot.c` writes + * to the physical address 0x472 to indicate the type of reboot for the + * firmware. We cannot have that in VSM as the memory composition might + * be more generic, and such write effectively corrupts the memory thus + * making diagnostics harder at the very least. + */ +static void __noreturn hv_vtl_emergency_restart(void) +{ + /* + * Cause a triple fault and the immediate reset. Here the code does not r= un + * on the top of any firmware, whereby cannot reach out to its services. + * The inifinite loop is for the improbable case that the triple fault do= es + * not work and have to preserve the state intact for debugging. + */ + for (;;) { + idt_invalidate(); + __asm__ __volatile__("int3"); + } +} + void __init hv_vtl_init_platform(void) { pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); @@ -235,6 +257,7 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsi= gned long start_eip) =20 int __init hv_vtl_early_init(void) { + machine_ops.emergency_restart =3D hv_vtl_emergency_restart; /* * `boot_cpu_has` returns the runtime feature support, * and here is the earliest it can be used. --=20 2.43.0 From nobody Tue Dec 16 23:26:54 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC76927181D; Thu, 27 Feb 2025 21:47:30 +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=1740692852; cv=none; b=c7bNvG/OJmKWClctZ+GTWs7RrW0icTrHIJX/kelzjQPo8dIPOAYZPqdKdQlaN87b8lRLNAqVDqWepJoMUiVrhnv4wB47I383aqQF+5xA/mYcgNOoIB1Yd32r1nkKB/nGGB2eKXn/j0W3cxBfZsFuEz0G7PuBu8HJSoIc9EbZ9k0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740692852; c=relaxed/simple; bh=H0sc0Dzoy3F2dNp0PaU0lxzNo4cuwBbWvkCnJDbwqsA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NIN3MlOxGnhXCZPHkIC2efbM/3MffoS0BeQik+soMiFKszsFPTmgLjewDVBtXzxmrMy8Sdwiuj61CXC93VnME4Fik3A4G6aB4xZ6fJdPJKR/dS9LFf3h5c3VhHao3osazZfgXEEU+LU699cH0h4KxbvL0w5VATD5SN8QGBlE8EI= 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=d+kvVWYu; 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="d+kvVWYu" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 2800A210EAC4; Thu, 27 Feb 2025 13:47:30 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2800A210EAC4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1740692850; bh=V+jj0mO8JyhApYoPayBDHN4fMJAhT0KBvP1icd3eeMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d+kvVWYu2LDYS7bWYTjj8pFx1l2C3c+zT4wVBxA3dJFu4CIPjgiA7jkPe1XeCO93u 5X+Pdtogasp8BKWFLGKZijAYJprER5zqXn6pcpFi/WAq6O+BixXX1EP06F8Eel/M0W tIt3R7My9wUrXQm4TsCX/OEaxl5z7E8rlD+VkrYQ= From: Roman Kisel To: bp@alien8.de, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mingo@redhat.com, ssengar@linux.microsoft.com, tglx@linutronix.de, wei.liu@kernel.org, x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v3 2/2] x86/hyperv: Add VTL mode callback for restarting the system Date: Thu, 27 Feb 2025 13:47:28 -0800 Message-ID: <20250227214728.15672-3-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250227214728.15672-1-romank@linux.microsoft.com> References: <20250227214728.15672-1-romank@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" The kernel runs as a firmware in the VTL mode, and the only way to restart in the VTL mode on x86 is to triple fault. Thus, one has to always supply "reboot=3Dt" on the kernel command line in the VTL mode, and missing that renders rebooting not working. Define the machine restart callback to always use the triple fault to provide the robust configuration by default. Signed-off-by: Roman Kisel --- arch/x86/hyperv/hv_vtl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 4421b75ad9a9..582fe820e29c 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -44,6 +44,15 @@ static void __noreturn hv_vtl_emergency_restart(void) } } =20 +/* + * The only way to restart in the VTL mode is to triple fault as the kerne= l runs + * as firmware. + */ +static void __noreturn hv_vtl_restart(char __maybe_unused *cmd) +{ + hv_vtl_emergency_restart(); +} + void __init hv_vtl_init_platform(void) { pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); @@ -258,6 +267,8 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsi= gned long start_eip) int __init hv_vtl_early_init(void) { machine_ops.emergency_restart =3D hv_vtl_emergency_restart; + machine_ops.restart =3D hv_vtl_restart; + /* * `boot_cpu_has` returns the runtime feature support, * and here is the earliest it can be used. --=20 2.43.0