From nobody Sat Nov 15 14:52:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1751391367; cv=none; d=zohomail.com; s=zohoarc; b=GSE1zei3F7B+7n7SXkecyYG4ncCuisWWeulZO681Y/1zlN17ZWnXtBql5zVxO1shE4wYQ+lTVNUb1B3soA1Eh2OYCP8SZtZpMh3nXTOCY2r1QnVfLtPoiM4jozWXsZr/bSrPDBhFTXCj3PjZyk6DuBYGDmcZU4wLsw+N+ng/TEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751391367; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QZDzWZMzPcxjbTxKmB09N+RGsXAVaQXEfIPlk952L+A=; b=X52u8a4BPkoqlsX89d42MvWNFsbAM1+z50XNeEehmQUG9ChxFfMjbQml6mZMignM3aE0ewBCnF38UX1xeaoPza34w7tKlMq48Vtz875/0dA7Q71+tRyP3X0bbbODlGY0t69+nwEH6Ab7olzFyCejNTc6LjNvYfceKlGZs23aQ78= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751391367553328.93391832931593; Tue, 1 Jul 2025 10:36:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uWepZ-0006zn-Jp; Tue, 01 Jul 2025 13:31:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uWeos-0006QX-69 for qemu-devel@nongnu.org; Tue, 01 Jul 2025 13:30:59 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uWeon-0007Lo-Uq for qemu-devel@nongnu.org; Tue, 01 Jul 2025 13:30:57 -0400 Received: from localhost.localdomain (unknown [167.220.208.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 587C92112239; Tue, 1 Jul 2025 10:30:39 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 587C92112239 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1751391042; bh=QZDzWZMzPcxjbTxKmB09N+RGsXAVaQXEfIPlk952L+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nAoKdtVNyuqUyc09TylOCS8LtYVm73YSqrpvHbe0mdOLOXS7U0Z83VvOF0lKc7MNP MP9tPX7sPMG5pi717O1/+BUipKnzRY4smMTShilc8FLlVurqoXXq74O46Fodbd5Tox w+BWxs9Mgf+IelfAdhogp/BFiVrTQ0XLZhc9+om4= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: Cameron Esfahani , Phil Dennis-Jordan , Roman Bolshakov , Thomas Huth , Zhao Liu , Wei Liu , Paolo Bonzini , Wei Liu , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Cornelia Huck , Magnus Kulke , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v2 25/27] target/i386/mshv: Handle HVMSG_X64_HALT vm exit Date: Tue, 1 Jul 2025 19:28:32 +0200 Message-Id: <20250701172834.44849-26-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250701172834.44849-1-magnuskulke@linux.microsoft.com> References: <20250701172834.44849-1-magnuskulke@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=magnuskulke@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1751391368338116600 Content-Type: text/plain; charset="utf-8" Implemented handler for HVMSG_X64_HALT exit messages from the hypervisor. Signed-off-by: Magnus Kulke --- accel/mshv/mshv-all.c | 3 +++ include/system/mshv.h | 1 + target/i386/mshv/mshv-cpu.c | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index e9f880b83e..f6ad2b6d2b 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -506,6 +506,9 @@ static int mshv_cpu_exec(CPUState *cpu) switch (exit_reason) { case MshvVmExitIgnore: break; + case MshvVmExitHlt: + ret =3D EXCP_HLT; + break; default: ret =3D EXCP_INTERRUPT; break; diff --git a/include/system/mshv.h b/include/system/mshv.h index 63104af68c..27d7e3dff3 100644 --- a/include/system/mshv.h +++ b/include/system/mshv.h @@ -99,6 +99,7 @@ typedef enum MshvVmExit { MshvVmExitIgnore =3D 0, MshvVmExitShutdown =3D 1, MshvVmExitSpecial =3D 2, + MshvVmExitHlt =3D 3, } MshvVmExit; =20 void mshv_init_mmio_emu(void); diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index 353073ed50..41a3398ec8 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -14,6 +14,7 @@ #include "qemu/error-report.h" #include "qemu/memalign.h" #include "qemu/typedefs.h" +#include "qemu/main-loop.h" =20 #include "system/mshv.h" #include "system/address-spaces.h" @@ -1413,6 +1414,26 @@ static int handle_pio(CPUState *cpu, const struct hy= perv_message *msg) return handle_pio_non_str(cpu, &info); } =20 +static int handle_halt(CPUState *cpu) +{ + int ret =3D 0; + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + uint32_t hw_irq =3D cpu->interrupt_request & CPU_INTERRUPT_HARD; + uint32_t nmi_irq =3D cpu->interrupt_request & CPU_INTERRUPT_NMI; + bool irqs_enabled =3D (env->eflags & IF_MASK) !=3D 0; + + bql_lock(); + if (!nmi_irq && (!hw_irq || !irqs_enabled)) { + cpu->exception_index =3D EXCP_HLT; + cpu->halted =3D true; + ret =3D 1; + } + bql_unlock(); + + return ret; +} + int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *e= xit) { int ret; @@ -1441,6 +1462,11 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_messa= ge *msg, MshvVmExit *exit) return MshvVmExitSpecial; } return MshvVmExitIgnore; + case HVMSG_X64_HALT: + ret =3D handle_halt(cpu); + if (ret < 0) { + return MshvVmExitHlt; + } default: break; } --=20 2.34.1