From nobody Mon Nov 23 04:18:28 2026 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=1793192041; cv=none; d=zohomail.com; s=zohoarc; b=XcBY4Si9Dmdn12s61YLkyJKJlApevvjK6m91NpiCfNg1RqknpJxEMT30j0oBiHCctzkNsIYhrGeN8bQpNFwsdKuOjJY04exbCOfC6L9fuqUX2tL7amQc94jU3/M7f3VSdljZ4YLZpFF3a9yKg9KCjs7uagLok3tZ58KCxH4luy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793192041; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rd9gswxwnBAs0JOrlNb83sBtN0BQsFy29vi+l+Usd08=; b=kN/dh1AHLWL45oYJvKysPDdG/T5crD9lc8ub5W1vkpkLOA6wnicYkAnVLIWy5MRHEO6rcoEbNu/G6rozj1aW6km9ZIpspOEunS0tmWRHcJCrjlXRMEJQAj1uuiTtdS9rSrTmqc107UE0Nay5eaklprEgoQA3UqFavEPRzs50i7Y= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793192041678280.41505367837385; Wed, 28 Oct 2026 05:54:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39e-0001Ct-Tf; Wed, 28 Oct 2026 08:53:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xM39c-0001B2-Q5 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:20 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39a-0003LE-T9 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:20 -0400 Received: from DESKTOP-TUU1E5L.fritz.box (p3e9c09f4.dip0.t-ipconnect.de [62.156.9.244]) by linux.microsoft.com (Postfix) with ESMTPSA id 43B3520B7167; Wed, 28 Oct 2026 05:53:03 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 43B3520B7167 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1793191985; bh=rd9gswxwnBAs0JOrlNb83sBtN0BQsFy29vi+l+Usd08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ow+t051+naD6wd4acZXMjYGgx1JAXVE7ZyJip76LdKkv3Rc7k4UWkFNhhf3nD9zx5 0MpkG+xUxTHCXwrrZdwX/piIclC0fdYxFCl17uUASdVR4zuvaGIA64w2AHuaTzrPjB quGlOJUHvuCFQJsh1UdevSICrwGYzCMfqu8etj6U= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: Wei Liu , Richard Henderson , Paolo Bonzini , Pierrick Bouvier , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Wei Liu , "Michael S. Tsirkin" , Magnus Kulke , Magnus Kulke , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 1/4] target/i386/mshv: fix vCPU run result contract Date: Wed, 28 Oct 2026 13:53:05 +0100 Message-Id: <20261028125308.147630-2-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261028125308.147630-1-magnuskulke@linux.microsoft.com> References: <20261028125308.147630-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=lists1p.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, 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: qemu development 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: 1793192043540154100 Content-Type: text/plain; charset="utf-8" Currently the return semantics of mshv_run_vcpu() are broken. They return a mix of int and exit_reason, ignoring the out param *exit. This change propagates errno's to the call site and sets the *exit value accordingly. We also consider the case when an ioctl has return due to a qemu-requested interruption of the call, this is a legitimate condition that should not produce an error. Fixes: 6dec60528c4 (target/i386/mshv: Implement mshv_vcpu_run()) Signed-off-by: Magnus Kulke Reviewed-by: Mohamed Mediouni --- target/i386/mshv/mshv-cpu.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index 4df73bb497..e3c155da2e 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -2124,7 +2124,6 @@ static int arch_set_single_step(CPUState *cpu, bool e= nable) int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *e= xit) { int ret; - enum MshvVmExit exit_reason; int cpu_fd =3D mshv_vcpufd(cpu); bool single_step; =20 @@ -2142,7 +2141,12 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_messa= ge *msg, MshvVmExit *exit) =20 ret =3D ioctl(cpu_fd, MSHV_RUN_VP, msg); if (ret < 0) { - return MshvVmExitShutdown; + if (errno =3D=3D EINTR) { + *exit =3D MshvVmExitSpecial; + return 0; + } + error_report("failed to run vCPU: %s", strerror(errno)); + return -errno; } =20 /* disable single stepping by flipping RFLAGS.TF */ @@ -2154,31 +2158,33 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_mess= age *msg, MshvVmExit *exit) =20 switch (msg->header.message_type) { case HVMSG_UNRECOVERABLE_EXCEPTION: - return MshvVmExitShutdown; + *exit =3D MshvVmExitShutdown; + return 0; case HVMSG_UNMAPPED_GPA: case HVMSG_GPA_INTERCEPT: - ret =3D handle_mmio(cpu, msg, &exit_reason); + ret =3D handle_mmio(cpu, msg, exit); if (ret < 0) { error_report("failed to handle mmio"); - return -1; + return ret; } - return exit_reason; + return 0; case HVMSG_X64_IO_PORT_INTERCEPT: ret =3D handle_pio(cpu, msg); if (ret < 0) { - return MshvVmExitSpecial; + error_report("failed to handle PIO"); + return ret; } - return MshvVmExitIgnore; + *exit =3D MshvVmExitIgnore; + return 0; case HVMSG_X64_EXCEPTION_INTERCEPT: bql_lock(); - ret =3D handle_exception_interrupt(cpu, msg, &exit_reason); + ret =3D handle_exception_interrupt(cpu, msg, exit); bql_unlock(); if (ret < 0) { error_report("failed to handle exception intercept"); return -1; } - *exit =3D exit_reason; - return exit_reason; + return 0; default: break; } --=20 2.34.1 From nobody Mon Nov 23 04:18:28 2026 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=1793192053; cv=none; d=zohomail.com; s=zohoarc; b=I4OgaU4qQH4+TIw7ERVz8Je38fJZA/6Z9ifZEhDqL9C8+3XT4o8iJg9wsAVBEmF+D3kM54V9OrKsnFg7Vmu+N0kbYP9chJNnQVhCTqw7FLDIjw5rqhvpcWZ4SQIqSRqlkFKa7idMUL2RKD3DKwTchX2eR3K9U8WT1DTQt6+ZYzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793192053; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VHZV6Y1ILH+FySY+U2WVfcUnldyMs55Rrz1vvnu181Q=; b=VMXJhs2PWTPZVR0f7yEtzMv7hKs1dwbrBHe6tR/WrwlLjbgYn04y/OPIeUzYhuJRI74aezOAwS8LmE2jiGO6PEyxrD3Y+IoAed8+RQYgR4L2wDc9I0LQcvh+uUlZslWrDcm4tKs0sSx+/cJgRHNFgsUte7Mnw64BMWcNURr6sjk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793192053544671.8278797761279; Wed, 28 Oct 2026 05:54:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39h-0001EG-0A; Wed, 28 Oct 2026 08:53:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xM39f-0001DW-75 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:23 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39d-0003MS-O8 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:22 -0400 Received: from DESKTOP-TUU1E5L.fritz.box (p3e9c09f4.dip0.t-ipconnect.de [62.156.9.244]) by linux.microsoft.com (Postfix) with ESMTPSA id 6A8E720B7168; Wed, 28 Oct 2026 05:53:06 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6A8E720B7168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1793191988; bh=VHZV6Y1ILH+FySY+U2WVfcUnldyMs55Rrz1vvnu181Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5nI6ki418onpaVXqTnx1uT7cc6exj0dWG1zQHfG4CWQ4JOdPmM3nO0bmdA6eIHAf si7qjhFaYdS0rcnxLkdI5kRvSbBvaPhJAlCfpQUFM+MIqpo/N4RbxHs54jlWdjGl+2 EiofPuDgL1pKNxsQ/rgM/4prREa115kx18TqLIl8= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: Wei Liu , Richard Henderson , Paolo Bonzini , Pierrick Bouvier , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Wei Liu , "Michael S. Tsirkin" , Magnus Kulke , Magnus Kulke , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 2/4] accel/mshv: stop VM on vCPU execution errors Date: Wed, 28 Oct 2026 13:53:06 +0100 Message-Id: <20261028125308.147630-3-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261028125308.147630-1-magnuskulke@linux.microsoft.com> References: <20261028125308.147630-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=lists1p.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, 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: qemu development 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: 1793192061659154100 Content-Type: text/plain; charset="utf-8" Currently we abort the process immediately if the ioctl returns an error, so the error handling routine outside the loop cannot be reached. We also enumerate the enum variants explicitly to make it obvious how every exit reason is being handled. Signed-off-by: Magnus Kulke Reviewed-by: Mohamed Mediouni --- accel/mshv/mshv-all.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index d820a67b95..7289c8d1c2 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -778,8 +778,8 @@ static int mshv_cpu_exec(CPUState *cpu) =20 ret =3D mshv_run_vcpu(mshv_state->vm, cpu, &mshv_msg, &exit_reason= ); if (ret < 0) { - error_report("Failed to run on vcpu %d", cpu->cpu_index); - abort(); + error_report("Failed to run on vCPU %d", cpu->cpu_index); + break; } =20 switch (exit_reason) { @@ -788,7 +788,8 @@ static int mshv_cpu_exec(CPUState *cpu) case MshvVmExitDebug: ret =3D EXCP_DEBUG; break; - default: + case MshvVmExitSpecial: + case MshvVmExitShutdown: ret =3D EXCP_INTERRUPT; break; } --=20 2.34.1 From nobody Mon Nov 23 04:18:28 2026 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=1793192061; cv=none; d=zohomail.com; s=zohoarc; b=JuZCAb0RnMqxNMUKqntSiuCEBHhdwoumBt339Lp1QZCJy90bU9yOIx7o2imRz1vBa4/B6DG6oQ3OVro8y30rZ8FJZw9nxOoMzbx3OnTvFEFhPcC3NpRoxHWw9/8JOfc0q3+4ayXA4tQcw0jvAJNxidOTD4FiGrRGzrlOe05k2OQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793192061; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ysLqVAbYfxKCz2a7+IxW7TWxV16fVnF2peR7YvfIyws=; b=gBgZnHgrqK2KeI2IsRgOrYuwvzSUQ3RnmQdQiq/38EwQQw8LYuWjJeax8q+Y1nM7Z5IEfghYjgxSkxl9qjpfvTjQeNEXKHtcI4HS0eWl3Uk4Hp7osjUZb1maJjUCNisWQ7bRKi+iiox8FGXS1/jvZJsvBO5uB5NAdxDTayKf60s= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793192060901311.0635436562444; Wed, 28 Oct 2026 05:54:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39l-0001Fd-9q; Wed, 28 Oct 2026 08:53:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xM39j-0001FG-Qz for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:27 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39h-0003N9-6h for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:27 -0400 Received: from DESKTOP-TUU1E5L.fritz.box (p3e9c09f4.dip0.t-ipconnect.de [62.156.9.244]) by linux.microsoft.com (Postfix) with ESMTPSA id B11F820B7169; Wed, 28 Oct 2026 05:53:09 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B11F820B7169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1793191992; bh=ysLqVAbYfxKCz2a7+IxW7TWxV16fVnF2peR7YvfIyws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yg50ZF02CYV8BnKdaCh5SsQWl1cEC4OW+kPjyurGDbS69AFg+XQYxQkpwLwyTJRuS /I6DlSSvcVx9ldG8akoeuX2cqt2Mpu2AowAuYw4E+tXgFzuafgBGWlmIKP/aMQZAEP ON1RCpvvzaKJrtoleENYFhuHb3BVh2lRVDFP7ziA= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: Wei Liu , Richard Henderson , Paolo Bonzini , Pierrick Bouvier , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Wei Liu , "Michael S. Tsirkin" , Magnus Kulke , Magnus Kulke , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 3/4] target/i386/mshv: deliver legacy PIC interrupts Date: Wed, 28 Oct 2026 13:53:07 +0100 Message-Id: <20261028125308.147630-4-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261028125308.147630-1-magnuskulke@linux.microsoft.com> References: <20261028125308.147630-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=lists1p.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, 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: qemu development 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: 1793192063971158501 Content-Type: text/plain; charset="utf-8" To inject legacy interrupts in the MSHV accelerator, we have to request a "deliverability notification" once the PIC asserts an interrupt. Once we receive a INTERRUPTION_DELIVERABLE exit from the hypervisor we can proceed to acknowledge the interrupt and write to the PENDING_EVENT0 register with EXT_INT event type and the respective vector. Since an interrupt is supposed to wake a vCPU stopped by HLT, we do clear the halt_suspend field of the INTERNAL_ACTIVITY_STATE register. We also need to consider pending EXT_INT events in migration, splitting the mapping of pending_exc into two discrete EXCEPTION and EXT_INT event types. Signed-off-by: Magnus Kulke Reviewed-by: Mohamed Mediouni --- hw/i386/x86-cpu.c | 9 +- include/hw/hyperv/hvgdk_mini.h | 42 ++++++++- include/system/mshv_int.h | 1 + meson.build | 1 + target/i386/mshv/mshv-cpu.c | 155 +++++++++++++++++++++++++++++++-- target/i386/mshv/trace-events | 7 ++ target/i386/mshv/trace.h | 2 + 7 files changed, 200 insertions(+), 17 deletions(-) create mode 100644 target/i386/mshv/trace-events create mode 100644 target/i386/mshv/trace.h diff --git a/hw/i386/x86-cpu.c b/hw/i386/x86-cpu.c index fba313376c..7b9299272a 100644 --- a/hw/i386/x86-cpu.c +++ b/hw/i386/x86-cpu.c @@ -46,12 +46,8 @@ static void pic_irq_request(void *opaque, int irq, int l= evel) =20 trace_x86_pic_interrupt(irq, level); =20 - if (mshv_irqchip_in_kernel()) { - return; - } - if (cpu_is_apic_enabled(cpu->apic_state) && !kvm_irqchip_in_kernel() && - !whpx_irqchip_in_kernel()) { + !mshv_irqchip_in_kernel() && !whpx_irqchip_in_kernel()) { CPU_FOREACH(cs) { cpu =3D X86_CPU(cs); if (apic_accept_pic_intr(cpu->apic_state)) { @@ -77,7 +73,8 @@ int cpu_get_pic_interrupt(CPUX86State *env) X86CPU *cpu =3D env_archcpu(env); int intno; =20 - if (!kvm_irqchip_in_kernel() && !whpx_irqchip_in_kernel()) { + if (!kvm_irqchip_in_kernel() && !mshv_irqchip_in_kernel() && + !whpx_irqchip_in_kernel()) { intno =3D apic_get_interrupt(cpu->apic_state); if (intno >=3D 0) { return intno; diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h index 0983e3a58d..e585661b2c 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -30,10 +30,11 @@ typedef enum hv_register_name { HV_REGISTER_INTERNAL_ACTIVITY_STATE =3D 0x00000004, =20 /* Pending Interruption Register */ - HV_REGISTER_PENDING_INTERRUPTION =3D 0x00010002, - HV_REGISTER_INTERRUPT_STATE =3D 0x00010003, - HV_REGISTER_PENDING_EVENT0 =3D 0x00010004, - HV_REGISTER_PENDING_EVENT1 =3D 0x00010005, + HV_REGISTER_PENDING_INTERRUPTION =3D 0x00010002, + HV_REGISTER_INTERRUPT_STATE =3D 0x00010003, + HV_REGISTER_PENDING_EVENT0 =3D 0x00010004, + HV_REGISTER_PENDING_EVENT1 =3D 0x00010005, + HV_REGISTER_DELIVERABILITY_NOTIFICATIONS =3D 0x00010006, =20 /* X64 User-Mode Registers */ HV_X64_REGISTER_RAX =3D 0x00020000, @@ -313,6 +314,21 @@ union hv_x64_pending_exception_event { }; }; =20 +#define HV_X64_PENDING_EVENT_EXCEPTION 0 +#define HV_X64_PENDING_EVENT_EXT_INT 5 + +union hv_x64_pending_ext_int_event { + uint64_t as_uint64[2]; + struct { + uint64_t event_pending:1; + uint64_t event_type:3; + uint64_t reserved0:4; + uint64_t vector:8; + uint64_t reserved1:48; + uint64_t reserved2; + }; +}; + union hv_x64_pending_virtualization_fault_event { uint64_t as_uint64[2]; struct { @@ -443,6 +459,17 @@ union hv_x64_interrupt_state_register { }; }; =20 +union hv_x64_deliverability_notifications_register { + uint64_t as_uint64; + struct { + uint64_t nmi_notification:1; + uint64_t interrupt_notification:1; + uint64_t interrupt_priority:4; + uint64_t reserved:42; + uint64_t sints:16; + }; +}; + union hv_intercept_suspend_register { uint64_t as_uint64; struct { @@ -469,6 +496,7 @@ typedef union hv_register_value { union hv_x64_pending_interruption_register pending_interruption; union hv_x64_msr_npiep_config_contents npiep_config; union hv_x64_pending_exception_event pending_exception_event; + union hv_x64_pending_ext_int_event pending_ext_int_event; union hv_x64_pending_virtualization_fault_event pending_virtualization_fault_event; union hv_x64_register_sev_control sev_control; @@ -715,6 +743,12 @@ struct hv_x64_intercept_message_header { uint64_t rflags; } QEMU_PACKED; =20 +struct hv_x64_interruption_deliverable_message { + struct hv_x64_intercept_message_header header; + uint32_t deliverable_type; + uint32_t reserved; +} QEMU_PACKED; + union hv_x64_io_port_access_info { uint8_t as_uint8; struct { diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index 1f77ffd152..d527cd8d77 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -45,6 +45,7 @@ typedef struct MshvHvCallArgs { struct AccelCPUState { int cpufd; MshvHvCallArgs hvcall_args; + bool pic_interrupt_window; }; =20 typedef struct MshvMemoryListener { diff --git a/meson.build b/meson.build index bbef9d9c29..24caec97a9 100644 --- a/meson.build +++ b/meson.build @@ -3686,6 +3686,7 @@ if have_system or have_user 'target/hppa', 'target/i386', 'target/i386/kvm', + 'target/i386/mshv', 'target/i386/whpx', 'target/loongarch', 'target/mips/tcg', diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index e3c155da2e..7032e0f6ac 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -771,6 +771,7 @@ static int get_vcpu_events(CPUState *cpu) union hv_x64_pending_interruption_register pending_int; union hv_x64_interrupt_state_register int_state; union hv_x64_pending_exception_event pending_exc; + union hv_x64_pending_ext_int_event pending_ext_int; int ret; =20 ret =3D mshv_get_generic_regs(cpu, assocs, ARRAY_SIZE(assocs)); @@ -782,6 +783,7 @@ static int get_vcpu_events(CPUState *cpu) pending_int.as_uint64 =3D assocs[0].value.reg64; int_state.as_uint64 =3D assocs[1].value.reg64; pending_exc =3D assocs[2].value.pending_exception_event; + pending_ext_int =3D assocs[2].value.pending_ext_int_event; =20 /* Clear previous state. injected ints/excs are blanked w/ -1 */ env->interrupt_injected =3D -1; @@ -841,14 +843,25 @@ static int get_vcpu_events(CPUState *cpu) env->hflags2 &=3D ~HF2_NMI_MASK; } =20 - /* HV_REGISTER_PENDING_EVENT0: pending exception not yet injected */ + /* HV_REGISTER_PENDING_EVENT0: event not yet injected */ if (pending_exc.event_pending) { - env->exception_pending =3D 1; - env->exception_nr =3D pending_exc.vector; - env->has_error_code =3D pending_exc.deliver_error_code; - env->error_code =3D pending_exc.error_code; - env->exception_has_payload =3D (pending_exc.exception_parameter != =3D 0); - env->exception_payload =3D pending_exc.exception_parameter; + switch (pending_exc.event_type) { + case HV_X64_PENDING_EVENT_EXCEPTION: + env->exception_pending =3D 1; + env->exception_nr =3D pending_exc.vector; + env->has_error_code =3D pending_exc.deliver_error_code; + env->error_code =3D pending_exc.error_code; + env->exception_has_payload =3D pending_exc.exception_parameter= !=3D 0; + env->exception_payload =3D pending_exc.exception_parameter; + break; + case HV_X64_PENDING_EVENT_EXT_INT: + env->interrupt_injected =3D pending_ext_int.vector; + break; + default: + error_report("unknown pending event type %u", + pending_exc.event_type); + return -EINVAL; + } } =20 /* @@ -2091,6 +2104,119 @@ static int handle_exception_interrupt(CPUState *cpu, return 0; } =20 +static int set_pic_interrupt_window(CPUState *cpu, bool enabled) +{ + union hv_x64_deliverability_notifications_register notifications =3D {= 0 }; + struct hv_register_assoc assoc =3D { 0 }; + AccelCPUState *cpu_state =3D cpu->accel; + int ret; + + notifications.interrupt_notification =3D enabled; + + assoc.name =3D HV_REGISTER_DELIVERABILITY_NOTIFICATIONS; + assoc.value.reg64 =3D notifications.as_uint64; + + /* we are already waiting for a PIC interrupt window */ + if (cpu_state->pic_interrupt_window =3D=3D enabled) { + return 0; + } + + trace_mshv_set_pic_interrupt_window(cpu->cpu_index, enabled); + + ret =3D mshv_set_generic_regs(cpu, &assoc, 1); + if (ret < 0) { + error_report("failed to set deliverability notifications register"= ); + return ret; + } + + cpu_state->pic_interrupt_window =3D enabled; + return 0; +} + +static inline int request_pic_interrupt_window(CPUState *cpu) +{ + return set_pic_interrupt_window(cpu, true); +} + +static inline int clear_pic_interrupt_window(CPUState *cpu) +{ + return set_pic_interrupt_window(cpu, false); +} + +static int handle_interrupt_deliverable(CPUState *cpu, + const struct hyperv_message *msg) +{ + CPUX86State *env =3D &X86_CPU(cpu)->env; + struct hv_x64_interruption_deliverable_message info; + union hv_x64_pending_ext_int_event event =3D { 0 }; + struct hv_register_assoc assocs[2] =3D { 0 }; + struct hv_register_assoc *event_assoc =3D &assocs[0], + *activity_assoc =3D &assocs[1]; + union hv_internal_activity_register activity; + bool is_suspended; + int ret, vector; + + memcpy(&info, msg->payload, sizeof(info)); + if (info.deliverable_type !=3D MSHV_HV_INTERRUPTION_TYPE_EXT_INT) { + error_report("unexpected deliverable interruption type %u", + info.deliverable_type); + return -1; + } + + ret =3D clear_pic_interrupt_window(cpu); + if (ret < 0) { + error_report("failed to clear PIC interrupt window"); + return -1; + } + + bql_lock(); + cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD); + vector =3D cpu_get_pic_interrupt(env); + bql_unlock(); + + /* vector =3D=3D -1 means the PIC has no longer a pending interrupt */ + if (vector < 0) { + return 0; + } + + trace_mshv_pic_interrupt(cpu->cpu_index, vector); + + /* we check whether the vcpu is halted first */ + activity_assoc->name =3D HV_REGISTER_INTERNAL_ACTIVITY_STATE; + ret =3D mshv_get_generic_regs(cpu, activity_assoc, 1); + if (ret < 0) { + error_report("failed to read activity state before PIC delivery"); + return -1; + } + + event.event_pending =3D 1; + event.event_type =3D HV_X64_PENDING_EVENT_EXT_INT; + event.vector =3D vector; + + event_assoc->name =3D HV_REGISTER_PENDING_EVENT= 0; + event_assoc->value.pending_ext_int_event =3D event; + + /* + * If the vcpu was hlt suspended we clear the suspend bit, otherwise we + * only set the pending event. + */ + activity =3D activity_assoc->value.internal_activity; + is_suspended =3D activity.halt_suspend; + if (is_suspended) { + activity.halt_suspend =3D 0; + activity_assoc->value.internal_activity =3D activity; + } + + ret =3D mshv_set_generic_regs(cpu, assocs, is_suspended ? 2 : 1); + if (ret < 0) { + error_report("failed to set pending event%s", + is_suspended ? " and activity state" : ""); + return ret; + } + + return 0; +} + /* * Flip RFLAGS.TF like WHPX. Set it only on the live register, not env->ef= lags, * so a later store won't put it back. @@ -2139,6 +2265,14 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_messa= ge *msg, MshvVmExit *exit) } } =20 + if (cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)) { + ret =3D request_pic_interrupt_window(cpu); + if (ret < 0) { + error_report("failed to request PIC interrupt window"); + return -1; + } + } + ret =3D ioctl(cpu_fd, MSHV_RUN_VP, msg); if (ret < 0) { if (errno =3D=3D EINTR) { @@ -2185,6 +2319,13 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_messa= ge *msg, MshvVmExit *exit) return -1; } return 0; + case HVMSG_X64_INTERRUPTION_DELIVERABLE: + ret =3D handle_interrupt_deliverable(cpu, msg); + if (ret < 0) { + return ret; + } + *exit =3D MshvVmExitIgnore; + return 0; default: break; } diff --git a/target/i386/mshv/trace-events b/target/i386/mshv/trace-events new file mode 100644 index 0000000000..347ce040ab --- /dev/null +++ b/target/i386/mshv/trace-events @@ -0,0 +1,7 @@ +# Authors: Magnus Kulke +# +# SPDX-License-Identifier: GPL-2.0-or-later + +mshv_run_vcpu_eintr(uint32_t cpu) "cpu_index=3D%d" +mshv_set_pic_interrupt_window(uint32_t cpu, bool enabled) "cpu_index=3D%d = enabled=3D%d" +mshv_pic_interrupt(uint32_t cpu, uint8_t vector) "cpu_index=3D%d vector=3D= 0x%x" diff --git a/target/i386/mshv/trace.h b/target/i386/mshv/trace.h new file mode 100644 index 0000000000..81b6b655c7 --- /dev/null +++ b/target/i386/mshv/trace.h @@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include "trace/trace-target_i386_mshv.h" --=20 2.34.1 From nobody Mon Nov 23 04:18:28 2026 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=1793192048; cv=none; d=zohomail.com; s=zohoarc; b=mM+eH5MOTqhjNnGMGCET/7XGj2+ztECvFCSya+SXYU96EpkrceaDAbu/PLx90d201BbmN5MgtEF0f2C673D+ZsWgyyyekC9ayIWXwgfBSJ40jBVNkUDAQY3+Q8ngsw43ZfD2FdlW1z6jgyqlCNMEoqOtXYrTDh/89NrXexKotPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793192048; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LI/6qZq71tt5xJqVIMNONpxnKeLBczut589IV+eWx2o=; b=cofS1KMBX+AFnSh63xBUaZMDSeCAVZI3Ix4sr+oVrsKWgXFzt3yNkuMANAsFaKhkf2Y38MjKu98kgaG33od83OLmUIvZ+CcqrtvHlWbyACBMYd7VwpKI/43+upj1JUV8uZRVzlSButGftijXFMt+6aMrBhnPhpUM2RUHEQNNB+E= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793192048675774.237459106161; Wed, 28 Oct 2026 05:54:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39n-0001Gb-Rj; Wed, 28 Oct 2026 08:53:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xM39m-0001GF-L0 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:30 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM39l-0003NZ-2I for qemu-devel@nongnu.org; Wed, 28 Oct 2026 08:53:30 -0400 Received: from DESKTOP-TUU1E5L.fritz.box (p3e9c09f4.dip0.t-ipconnect.de [62.156.9.244]) by linux.microsoft.com (Postfix) with ESMTPSA id 439CD20B716A; Wed, 28 Oct 2026 05:53:13 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 439CD20B716A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1793191995; bh=LI/6qZq71tt5xJqVIMNONpxnKeLBczut589IV+eWx2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZgZxP7xbj6ARzGOmOvD9nbr2ABosQMukaS2CnvY21o5IDPXeyIoajrVdsp3i5Q2IL aqgcJr3xsW//BzwvbCUvToTqTqamr+gXajXETi4TAr8MRpMUBxzjiFRfyq68fJeJ/1 yXyjjd93TlkJvEZT/pvtjOP6gZgO3+/F8k4WsBG8= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: Wei Liu , Richard Henderson , Paolo Bonzini , Pierrick Bouvier , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Wei Liu , "Michael S. Tsirkin" , Magnus Kulke , Magnus Kulke , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 4/4] accel/mshv: do not coalesce vCPU kicks Date: Wed, 28 Oct 2026 13:53:08 +0100 Message-Id: <20261028125308.147630-5-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261028125308.147630-1-magnuskulke@linux.microsoft.com> References: <20261028125308.147630-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=lists1p.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, 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: qemu development 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: 1793192049856158500 Content-Type: text/plain; charset="utf-8" MSHV today lacks an immediate-exit API. QEMU tehre kicks a vCPU by sending SIG_IPI to interrupt an active MSHV_VP_RUN ioctl invocation. The generic kick path suppresses repeat signals using CPUState::thread_kicked, which is cleared when we return to the the outer vCPU loop (in mshv_vcpu_thread()). MSHV cannot guarantee that a signal will cause sucha return: it may be handled between MSHV_VP_RUN calls or MSHV_RUN_VP may return an unrelated intercept instead of EINTR. Hence we install an MSHV-specific kick impl that sends SIG_IPI for every requested vCPU kick. Signed-off-by: Magnus Kulke --- accel/mshv/mshv-all.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index 7289c8d1c2..0f733cac9d 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -888,6 +888,24 @@ static void mshv_start_vcpu_thread(CPUState *cpu) QEMU_THREAD_JOINABLE); } =20 +static void mshv_kick_vcpu_thread(CPUState *cpu) +{ + int err; + + /* don't kick ourselves, we are already running */ + if (qemu_cpu_is_self(cpu)) { + return; + } + + err =3D pthread_kill(cpu->thread->thread, SIG_IPI); + /* in case the vcpu thread has been torn down we don't want to abort */ + if (err && err !=3D ESRCH) { + error_report("failed to kick MSHV vCPU %d: %s", + cpu->cpu_index, strerror(err)); + abort(); + } +} + static void do_mshv_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg) { @@ -996,6 +1014,7 @@ static void mshv_accel_ops_class_init(ObjectClass *oc,= const void *data) AccelOpsClass *ops =3D ACCEL_OPS_CLASS(oc); =20 ops->create_vcpu_thread =3D mshv_start_vcpu_thread; + ops->kick_vcpu_thread =3D mshv_kick_vcpu_thread; ops->cpu_thread_is_idle =3D mshv_vcpu_thread_is_idle; ops->synchronize_post_init =3D mshv_cpu_synchronize_post_init; ops->synchronize_post_reset =3D mshv_cpu_synchronize_post_reset; --=20 2.34.1