From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099303; cv=none; d=zohomail.com; s=zohoarc; b=EO6qKkzw8WBHMqugf6jolwkGVncB+ZbcIrqb8aeB8Vh8aeky8p6FVlNgp1IQd3QtFKi4hyWy9ZGKBUA+YUhaiCIUbP9qJWj9EYvg7eg8dGxpmUGrpkMaz/1rqI0sjmD4uZ/Wg2qO+EOS0hlQsleCv1HwgfQjLOepMZu92L17pF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099303; 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=jSFEY3OW57r5Gmf0SB6G349rIgUNCT10rXc1M/CBSww=; b=j3+aNsSuGw+GnvN5lp1U83R2tW5rvyPUm9nxKkIDwFR0FuSJzrXBXpL2/QbQiju6KYMz2ExhmK+GJ0VSvVcaB68ljsIs90jwqSUK8WIxBDmhs6o8bTqjYeoVZb8IeNHYouNnxd5Cct4QF2yirSz/A8ts9xdn2YtM7vFKc7n8XiE= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099303068405.1074318861786; Mon, 13 Apr 2026 09:55:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKWy-0006nH-9C; Mon, 13 Apr 2026 12:53:00 -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 1wCKWw-0006mw-Mn for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:52:58 -0400 Received: from p-west2-cluster3-host9-snip4-10.eps.apple.com ([57.103.69.73] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKWv-0005Cl-7D for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:52:58 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 0ED5C1803B94; Mon, 13 Apr 2026 16:52:54 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id BE50A1803BAD; Mon, 13 Apr 2026 16:52:28 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099176; x=1778691176; bh=jSFEY3OW57r5Gmf0SB6G349rIgUNCT10rXc1M/CBSww=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=PvccHx7PvzHmF3vMEdsLETkZnnUwuGMzSf8xqKW1ZW8c0L11s5cT7zv33vKmzX41qLTuzF/dZrDS4V2pmckEDVCprVhRKLOY73eh0XuQ8ZnR/VouEVs7txtpa2PUHcJ65oJRBd9c06YNXZwTyUhXos8lOOXWUA93Tad/nuouiz8+MHMN573b7xJhyMIziqlNHKYTdqnVg3QS9dfW386vCjIt0iDjZYAE4Z3qPRaUnAe6SnSRNIq7aBrv0sYfpzx1E+2eiuiimE88ffe1gbFemqOFCff/FLJJ6DUsc4swAN9z1Aa12lRDCTtHUHZuzljyCgjZrt2sOALocw9m30NQbw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 01/15] target/i386: emulate: include name of unhandled instruction Date: Mon, 13 Apr 2026 18:52:03 +0200 Message-ID: <20260413165217.47105-2-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: SFoHx0F6OAK2uSAMZBhwRZxjpRQL8sab X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX6xqYqYLaFLeo B6RdLnn+RUCJtG/97gm/thuX8hJObWsNKRzKz3+/0Yr2Y6jhK9gEncoMoxN6mvHdKptWg3H2JGb ncqK5U5gSqNP5SvN+qtkVt3tUNwRSSVH+/VfNJrvBqh/KYPFS7Rm4vfHmxJ2TGA56hgm7YjcbLh +oCVgpgD3sbm7ougjXh0lhnI/QsGVpSP9XQYfTX/cRBXWYa5mJgMDeeZpYyQsnYpyCl1JcRZ4Lg B9npnhA7rtxoiEE1mbgWOdB3FRmr1r1j/UvRHyhQdRL5n2QxhPSsqY5UNQ6MoVYS7v6cJitL0b7 C7lJCicRVEZYsJwxLbi+oj/TX1S8F8BaJGKow2iRbPKE0JT1YSoEDFgMTzz4xg= X-Proofpoint-GUID: SFoHx0F6OAK2uSAMZBhwRZxjpRQL8sab X-Authority-Info-Out: v=2.4 cv=DohbOW/+ c=1 sm=1 tr=0 ts=69dd1f67 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=x0iqa3ucmZZh0HPruXgA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 clxscore=1030 mlxlogscore=900 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.73; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099304386154100 Content-Type: text/plain; charset="utf-8" Instead of just the command number, include the instruction name to make de= bugging easier. Signed-off-by: Mohamed Mediouni --- target/i386/emulate/x86_emu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/i386/emulate/x86_emu.c b/target/i386/emulate/x86_emu.c index 55b1a68eb6..c2da1a133f 100644 --- a/target/i386/emulate/x86_emu.c +++ b/target/i386/emulate/x86_emu.c @@ -1399,8 +1399,8 @@ static void init_cmd_handler(void) bool exec_instruction(CPUX86State *env, struct x86_decode *ins) { if (!_cmd_handler[ins->cmd].handler) { - printf("Unimplemented handler (" TARGET_FMT_lx ") for %d (%x %x)\n= ", - env->eip, + printf("Unimplemented handler (" TARGET_FMT_lx ") for %s - %d (%x = %x)\n", + env->eip, decode_cmd_to_string(ins->cmd), ins->cmd, ins->opcode[0], ins->opcode_len > 1 ? ins->opcode[1] : 0); env->eip +=3D ins->len; --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099241; cv=none; d=zohomail.com; s=zohoarc; b=oB2eznA+Gl+JmUwfLc6wv4SD2ai9Xg28s1yUYYtNQ3azQ4vsGLKaM5AhjWXGY7RoCXkgbIY5wTEsX6MySSSzY3PmxRzQS7wnwW/6yoYWmzz5C8ltqqM2srqf2QiVeNMNlnsx/l69CJVsGUtZ5oJ23hLw9LXeF0b8K10bQhFYh7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099241; 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=zl2db1VwfCW29E4LtwT7zz4buZdQP1VZYTXVu1kcs+o=; b=ipbQt1TGXTCMI1kbkyvnaZPI9UBCQ9RNLbVdPxDNIs9QvROIecRI0W2LMlkDfgUoYPUycpEC/j6OOmtxv+7rGgot7C359xHa/esJtFR31kKgiCHpNKE4+pr/NhgPIx9M5D8Z0gJzPSkN9lSRxx0zfZ4N5hzWpksutfpcP54TWY8= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099240854575.8330771690366; Mon, 13 Apr 2026 09:54:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKX2-0006oW-C0; Mon, 13 Apr 2026 12:53:04 -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 1wCKX0-0006nz-47 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:02 -0400 Received: from p-west2-cluster3-host12-snip4-4.eps.apple.com ([57.103.69.37] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKWy-0005MH-8c for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:01 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 997D61800CA4; Mon, 13 Apr 2026 16:52:58 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 87BAE180387F; Mon, 13 Apr 2026 16:52:36 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099179; x=1778691179; bh=zl2db1VwfCW29E4LtwT7zz4buZdQP1VZYTXVu1kcs+o=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=ewl/MbjpWhR3eXntVewRg6OEEE91VXeQPNR5806uknNjFTX2h2wupMTJdxGjgk/K3nRnkOnzI7jV4KQQuzCthBH/e7SEBZtKXw0TCirKgBA32a1Pg1m7VUq4aQPhnQO85boCD3CU85Ri+IjtGbTBLpeAbxMD9WKAQ5ExPurgEgyWePrcamU+d4ki/eoLyVeRZBR19XtA2LPPtkFp6uBvvq/y3EQjgSUz0lx2YFbuJMScl9byOx2VOqgdy2z9rECL+pAKGvBydeQ9R7RWKpiuI7KQsH3ZvZZ71XYHeBh/dcGjrat8dRWsEsdd8iIGb2AI2Y3dP+ze/hU9OrzLvPhqbA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 02/15] whpx: i386: x2apic emulation Date: Mon, 13 Apr 2026 18:52:04 +0200 Message-ID: <20260413165217.47105-3-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX2dATQn9d38Ob 6tF0ije/+VlR9qHrJHvA8sWQbXwAh5EPq6426S1wq2LE4BUw7vqO1rYTMb3EIAwDDw6LtqnqXvU 4eNIs89wqZICNZmwpWikQid5zAGu8NLtpItiJkc0TlfA30IWzTdu1Zljqy4fwFcG89bUehhRvmW B8rEAmozWcljdRX1Ual/I8A3eRQKD/qHlo/IO3sXVHICy8C0MAcr73M8wj2ea18Vn2Yq4/f2Cnr PXytKF/rb5SYLBMUyA+zLveIDBNddV71vXcKlF++W/hydZv3FBQEfggTrd4LKaxoGNiWOVe70NY 0GJrswWkItvI4mB93QWQLEdNL554nFqsbS2dc4zPWHYernMjoIUrtOxuQVI4BU= X-Proofpoint-ORIG-GUID: rk_IeUzlxogWYICjJwglqZnkkTjJ6bQ_ X-Authority-Info-Out: v=2.4 cv=d4/4CBjE c=1 sm=1 tr=0 ts=69dd1f6a cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nj4AhdDZwDx412jv8JQA:9 X-Proofpoint-GUID: rk_IeUzlxogWYICjJwglqZnkkTjJ6bQ_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=734 lowpriorityscore=0 adultscore=0 malwarescore=0 bulkscore=0 mlxscore=0 clxscore=1030 phishscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.37; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099244758158500 Content-Type: text/plain; charset="utf-8" Add x2apic emulation to WHPX for the kernel-irqchip=3Doff case. Unfortunately, it looks like there isn't a workaround available for proper behavior of PIC interrupts when kernel-irqchip=3Don for Windows 10. The OS is out of support outside of extended security updates so this will not be addressed. The performance boost is quite visible for multicore guests. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 134 +++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index e56ae2b343..4127440c0c 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1082,6 +1082,8 @@ HRESULT whpx_set_exception_exit_bitmap(UINT64 excepti= ons) /* Register for MSR and CPUID exits */ memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.ExtendedVmExits.X64MsrExit =3D 1; + prop.ExtendedVmExits.X64CpuidExit =3D 1; + if (exceptions !=3D 0) { prop.ExtendedVmExits.ExceptionExit =3D 1; } @@ -1898,6 +1900,18 @@ int whpx_vcpu_run(CPUState *cpu) WHV_REGISTER_NAME reg_names[3]; UINT32 reg_count; bool is_known_msr =3D 0;=20 + uint64_t val; + + if (vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + val =3D ((uint32_t)vcpu->exit_ctx.MsrAccess.Rax) | + ((uint64_t)(vcpu->exit_ctx.MsrAccess.Rdx) << 32); + } else { + /* + * Workaround for [-Werror=3Dmaybe-uninitialized] + * with GCC. Not needed with Clang. + */ + val =3D 0; + } =20 reg_names[0] =3D WHvX64RegisterRip; reg_names[1] =3D WHvX64RegisterRax; @@ -1911,7 +1925,47 @@ int whpx_vcpu_run(CPUState *cpu) && !vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite && !whpx_irqchip_in_kernel()) { is_known_msr =3D 1; - reg_values[1].Reg32 =3D (uint32_t)X86_CPU(cpu)->env.apic_b= us_freq; + val =3D X86_CPU(cpu)->env.apic_bus_freq; + } + + if (!whpx_irqchip_in_kernel() && + vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D MSR_IA32_APICBAS= E) { + is_known_msr =3D 1; + if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + /* Read path unreachable on Hyper-V */ + abort(); + } else { + WHV_REGISTER_VALUE reg =3D {.Reg64 =3D val}; + int msr_ret =3D cpu_set_apic_base(X86_CPU(cpu)->apic_s= tate, val); + if (msr_ret < 0) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + } + whpx_set_reg(cpu, WHvX64RegisterApicBase, reg); + } + } + + if (!whpx_irqchip_in_kernel() && + vcpu->exit_ctx.MsrAccess.MsrNumber >=3D MSR_APIC_START && + vcpu->exit_ctx.MsrAccess.MsrNumber <=3D MSR_APIC_END) { + int index =3D vcpu->exit_ctx.MsrAccess.MsrNumber - MSR_API= C_START; + int msr_ret; + is_known_msr =3D 1; + if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + bql_lock(); + msr_ret =3D apic_msr_read(X86_CPU(cpu)->apic_state, in= dex, &val); + bql_unlock(); + reg_values[1].Reg64 =3D val; + if (msr_ret < 0) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + } + } else { + bql_lock(); + msr_ret =3D apic_msr_write(X86_CPU(cpu)->apic_state, i= ndex, val); + bql_unlock(); + if (msr_ret < 0) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + } + } } /* * For all unsupported MSR access we: @@ -1921,6 +1975,11 @@ int whpx_vcpu_run(CPUState *cpu) reg_count =3D vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite ? 1 : 3; =20 + if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + reg_values[1].Reg32 =3D (uint32_t)val; + reg_values[2].Reg32 =3D (uint32_t)(val >> 32); + } + if (!is_known_msr) { trace_whpx_unsupported_msr_access(vcpu->exit_ctx.MsrAccess= .MsrNumber, vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite); @@ -1939,6 +1998,47 @@ int whpx_vcpu_run(CPUState *cpu) ret =3D 0; break; } + case WHvRunVpExitReasonX64Cpuid: { + WHV_REGISTER_VALUE reg_values[5] =3D {0}; + WHV_REGISTER_NAME reg_names[5]; + UINT32 reg_count =3D 5; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + + reg_names[0] =3D WHvX64RegisterRip; + reg_names[1] =3D WHvX64RegisterRax; + reg_names[2] =3D WHvX64RegisterRcx; + reg_names[3] =3D WHvX64RegisterRdx; + reg_names[4] =3D WHvX64RegisterRbx; + + reg_values[0].Reg64 =3D + vcpu->exit_ctx.VpContext.Rip + + vcpu->exit_ctx.VpContext.InstructionLength; + + reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRax; + reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRcx; + reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRdx; + reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRbx; + + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 1) { + if (cpu_has_x2apic_feature(env)) { + reg_values[2].Reg64 |=3D CPUID_EXT_X2APIC; + } + } + + hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( + whpx->partition, + cpu->cpu_index, + reg_names, reg_count, + reg_values); + + if (FAILED(hr)) { + error_report("WHPX: Failed to set CpuidAccess state " + " registers, hr=3D%08lx", hr); + } + ret =3D 0; + break; + } case WHvRunVpExitReasonException: whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); =20 @@ -2136,6 +2236,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; bool is_legacy_os =3D false; + UINT32 cpuidExitList[] =3D {1}; =20 whpx =3D &whpx_global; =20 @@ -2354,6 +2455,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) /* Register for MSR and CPUID exits */ memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.ExtendedVmExits.X64MsrExit =3D 1; + prop.ExtendedVmExits.X64CpuidExit =3D 1; =20 hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, @@ -2366,6 +2468,36 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 + memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); + prop.X64MsrExitBitmap.UnhandledMsrs =3D 1; + if (!whpx_irqchip_in_kernel()) { + prop.X64MsrExitBitmap.ApicBaseMsrWrite =3D 1; + } + + hr =3D whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeX64MsrExitBitmap, + &prop, + sizeof(WHV_PARTITION_PROPERTY)); + if (FAILED(hr)) { + error_report("WHPX: Failed to set MSR exit bitmap, hr=3D%08lx", hr= ); + ret =3D -EINVAL; + goto error; + } + + hr =3D whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeCpuidExitList, + cpuidExitList, + RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32)); + + if (FAILED(hr)) { + error_report("WHPX: Failed to set partition CpuidExitList hr=3D%08= lx", + hr); + ret =3D -EINVAL; + goto error; + } + /* * We do not want to intercept any exceptions from the guest, * until we actually start debugging with gdb. --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099293; cv=none; d=zohomail.com; s=zohoarc; b=BSrFT56wtUiLHSUNy40yG9sp5Z5TxTEtvObt34VQtp8C7agB/CzppeAAdycY2wsaMP/oggx5aGBLAYW0c9eCiXRitNBmmwHs8wM+5JAzgc3PxnwoyxHzdrEBgLGP2kbvvQxEVWn+ILF9HPatnhLhUrOGurlqhXyum1vg25DoUNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099293; 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=Ash1yi3VlTyxdP0Aar5CNwwUDY+XErFVJjyfbU7EpDA=; b=iztRoUGxdU+7o93OVWriobitOTw4yVM79hKZdDytyMQ8Ls+62845cvnf+4ydXoi1ip7IOqlzpUq7TZIbFfCxmgwtnSyctPlobVhM7Eld/c4H9Ta+M4Sb5jjBQS2Ou6yRPedrKcQIFknqpwXxeApU9fE4f64bHbV/vGE0AKngD/A= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099293336766.7290573718212; Mon, 13 Apr 2026 09:54:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKX3-0006oq-Pg; Mon, 13 Apr 2026 12:53:05 -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 1wCKX2-0006oX-Gs for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:04 -0400 Received: from p-west2-cluster3-host4-snip4-2.eps.apple.com ([57.103.69.15] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKX0-0005SA-Kr for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:04 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id ABD091800370; Mon, 13 Apr 2026 16:53:00 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 071891803BA1; Mon, 13 Apr 2026 16:52:43 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099181; x=1778691181; bh=Ash1yi3VlTyxdP0Aar5CNwwUDY+XErFVJjyfbU7EpDA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=UZWHVG5hnJedSxcqc0hme5ybL6ZWwZXrh2emqg/H9B+iCxbJLATLQ72Rz7yD7PKmSSkXN6HbrTM/8uoFy2+23ayugTPS8s3JqhcWlHER+Hw+U/NK1kJXdFQkMxMcBCOdAEQCXS1cNfsR6cI0dvI23xpZ/pRcPE6R80FbL5lAjE1MJTnBVazL7y9LyFMyAebV63aUrgokVe1IJNUXugKyxTBA3hGmHJeRD4/kB0+nKA6dRrfge0We/oDeNeo2Ul1OAWuiu27h2wbhL2Jg2WX1RlksAX0DrGSWcKTC2OPExeAAUwOLxGFJL0BiJbrgwqwGsm8L5GqIqTAo8MX5tmBhgw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 03/15] whpx: i386: wire up feature probing Date: Mon, 13 Apr 2026 18:52:05 +0200 Message-ID: <20260413165217.47105-4-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: BTPwP6TZV_ChDQcQlcJkz6Y9GTT-WQAE X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX/wECH8Lvq1SH vc0anSawCkv/rZY2x35ff9eLf+Qhhm52RTcLZfMz6gNjuA1kA8wpSGSpDFYbo4+PNbXBar4dG+6 B136jKZyOWC8/GnFWAdJV6wNepDO9UJ3LVj4NHcDEK8Xyfb85NwcECuw6XxzwOtuBkLOgt0KAyR c+rrvRu5GmjaHCZ3h0XxPHI4kGJwk1yVVwUU6947abuEqTklTx/ow+PuwSOUBo1dwumrIf3UdIF qhmRUd0o+aSjhQHRdraS6W9YMmjjhdr6ZJpUaXtJUdmW1NkQhtXUeVKaIMwBVINL0PUpYj3PFL/ WUrF+xS5nCPWvRCW6Nhb+TO7TneneFa6LOn9+C3lUNxZYDu7bWUvHGvp59LgIo= X-Authority-Info-Out: v=2.4 cv=Cu2ys34D c=1 sm=1 tr=0 ts=69dd1f6d cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Gr33WSPopR-aU8k7cJUA:9 X-Proofpoint-GUID: BTPwP6TZV_ChDQcQlcJkz6Y9GTT-WQAE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 clxscore=1030 adultscore=0 malwarescore=0 mlxlogscore=985 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.15; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099294356154100 Content-Type: text/plain; charset="utf-8" Windows 10 doesn't have the API for this, so using this only for Windows 11. Signed-off-by: Mohamed Mediouni --- include/system/whpx-internal.h | 9 ++++ target/i386/cpu.c | 25 ++++++++++++ target/i386/whpx/whpx-all.c | 75 ++++++++++++++++++++++++++++++++-- target/i386/whpx/whpx-i386.h | 4 ++ 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 target/i386/whpx/whpx-i386.h diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index 8482901f71..5902124b63 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -73,6 +73,14 @@ void whpx_apic_get(APICCommonState *s); X(HRESULT, WHvGetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partit= ion, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 Registe= rCount, WHV_REGISTER_VALUE* RegisterValues)) \ X(HRESULT, WHvSetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partit= ion, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 Registe= rCount, const WHV_REGISTER_VALUE* RegisterValues)) \ =20 +#ifdef __x86_64__ +#define LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL_ARCH(X) \ + X(HRESULT, WHvGetVirtualProcessorCpuidOutput, \ + (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Eax, \ + UINT32 Ecx, WHV_CPUID_OUTPUT *CpuidOutput)) +#else +#define LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL_ARCH(X) +#endif /* * These are supplemental functions that may not be present * on all versions and are not critical for basic functionality. @@ -89,6 +97,7 @@ void whpx_apic_get(APICCommonState *s); UINT32 StateSize)) \ X(HRESULT, WHvResetPartition, \ (WHV_PARTITION_HANDLE Partition)) \ + LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL_ARCH(X) =20 #define WHP_DEFINE_TYPE(return_type, function_name, signature) \ typedef return_type (WINAPI *function_name ## _t) signature; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c6fd1dc00e..0000093fa3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -26,6 +26,8 @@ #include "tcg/helper-tcg.h" #include "exec/translation-block.h" #include "system/hvf.h" +#include "system/whpx.h" +#include "whpx/whpx-i386.h" #include "hvf/hvf-i386.h" #include "kvm/kvm_i386.h" #include "kvm/tdx.h" @@ -8087,6 +8089,17 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *= cpu, FeatureWord w) r =3D hvf_get_supported_cpuid(wi->cpuid.eax, wi->cpuid.ecx, wi->cpuid.reg); + } else if (whpx_enabled()) { + if (wi->type !=3D CPUID_FEATURE_WORD) { + return 0; + } + if (whpx_is_legacy_os()) { + r =3D wi->tcg_features; + } else { + r =3D whpx_get_supported_cpuid(wi->cpuid.eax, + wi->cpuid.ecx, + wi->cpuid.reg); + } } else if (tcg_enabled() || qtest_enabled()) { r =3D wi->tcg_features; } else { @@ -8168,6 +8181,18 @@ static void x86_cpu_get_supported_cpuid(uint32_t fun= c, uint32_t index, *ebx =3D hvf_get_supported_cpuid(func, index, R_EBX); *ecx =3D hvf_get_supported_cpuid(func, index, R_ECX); *edx =3D hvf_get_supported_cpuid(func, index, R_EDX); + } else if (whpx_enabled()) { + if (whpx_is_legacy_os()) { + *eax =3D 0; + *ebx =3D 0; + *ecx =3D 0; + *edx =3D 0; + } else { + *eax =3D whpx_get_supported_cpuid(func, index, R_EAX); + *ebx =3D whpx_get_supported_cpuid(func, index, R_EBX); + *ecx =3D whpx_get_supported_cpuid(func, index, R_ECX); + *edx =3D whpx_get_supported_cpuid(func, index, R_EDX); + } } else { *eax =3D 0; *ebx =3D 0; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 4127440c0c..2d527b90dd 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -36,6 +36,7 @@ #include "system/whpx-accel-ops.h" #include "system/whpx-all.h" #include "system/whpx-common.h" +#include "whpx-i386.h" =20 #include "emulate/x86_decode.h" #include "emulate/x86_emu.h" @@ -49,6 +50,8 @@ /* for kernel-irqchip=3Doff */ #define HV_X64_MSR_APIC_FREQUENCY 0x40000023 =20 +static bool is_modern_os =3D true; + static const WHV_REGISTER_NAME whpx_register_names[] =3D { =20 /* X64 General purpose registers */ @@ -1062,6 +1065,71 @@ static void whpx_init_emu(void) init_emu(&whpx_x86_emul_ops); } =20 +bool whpx_is_legacy_os(void) +{ + return !is_modern_os; +} + +uint32_t whpx_get_supported_cpuid(uint32_t func, uint32_t idx, int reg) +{ + WHV_CPUID_OUTPUT output; + uint32_t eax, ebx, ecx, edx; + uint32_t cpu_index =3D 0; + bool temp_cpu =3D true; + HRESULT hr; + + hr =3D whp_dispatch.WHvCreateVirtualProcessor( + whpx_global.partition, cpu_index, 0); + + /* This means that the CPU already exists... */ + if (FAILED(hr)) { + temp_cpu =3D false; + } + + hr =3D whp_dispatch.WHvGetVirtualProcessorCpuidOutput(whpx_global.part= ition, + cpu_index, func, idx, &output); + + if (FAILED(hr)) { + abort(); + } + + if (temp_cpu) { + hr =3D whp_dispatch.WHvDeleteVirtualProcessor(whpx_global.partitio= n, cpu_index); + if (FAILED(hr)) { + abort(); + } + } + + eax =3D output.Eax; + ebx =3D output.Ebx; + ecx =3D output.Ecx; + edx =3D output.Edx; + + /* + * We can emulate X2APIC even for the kernel-irqchip=3Doff case. + * CPUID_EXT_HYPERVISOR and CPUID_HT should be considered present + * always, so report them as unconditionally supported here. + */ + if (func =3D=3D 1) { + ecx |=3D CPUID_EXT_X2APIC; + ecx |=3D CPUID_EXT_HYPERVISOR; + edx |=3D CPUID_HT; + } + + switch (reg) { + case R_EAX: + return eax; + case R_EBX: + return ebx; + case R_ECX: + return ecx; + case R_EDX: + return edx; + default: + return 0; + } +} + /* * Controls whether we should intercept various exceptions on the guest, * namely breakpoint/single-step events. @@ -2235,7 +2303,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_CAPABILITY_FEATURES features =3D {0}; WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; - bool is_legacy_os =3D false; UINT32 cpuidExitList[] =3D {1}; =20 whpx =3D &whpx_global; @@ -2395,7 +2462,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) if (FAILED(hr)) { warn_report("WHPX: Failed to get performance " "monitoring features, hr=3D%08lx", hr); - is_legacy_os =3D true; + is_modern_os =3D false; } else { hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, @@ -2435,7 +2502,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.DirectSyntheticTimers =3D 1; } =20 - if (!is_legacy_os && whpx->hyperv_enlightenments_allowed) { + if (is_modern_os && whpx->hyperv_enlightenments_allowed) { hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, @@ -2446,7 +2513,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) ret =3D -EINVAL; goto error; } - } else if (is_legacy_os && whpx->hyperv_enlightenments_required) { + } else if (!is_modern_os && whpx->hyperv_enlightenments_required) { error_report("Hyper-V enlightenments not available on legacy Windo= ws"); ret =3D -EINVAL; goto error; diff --git a/target/i386/whpx/whpx-i386.h b/target/i386/whpx/whpx-i386.h new file mode 100644 index 0000000000..6db9a75d39 --- /dev/null +++ b/target/i386/whpx/whpx-i386.h @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +uint32_t whpx_get_supported_cpuid(uint32_t func, uint32_t idx, int reg); +bool whpx_is_legacy_os(void); --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099263; cv=none; d=zohomail.com; s=zohoarc; b=bEg2rvfmrciIB+ozpar1T3I7fV3Ir3aEb6qNsk8++kZcEZpOlgX9hGdqFCwuEbNmblOWXWEFweLRTS2r9c38OCxnUsQdF3MxFK+Bj5npC5BX/fs02bccG6+OSPxjaATAVemhnxVTPGSD9E8bgEuIURveN5ejk5jd0lsvbK2fiY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099263; 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=LeCfULzXVq8eMeXoD4HoazACVFGuCL5m06fQgObX99k=; b=go9ZU3+56Xs5B11YxymwSivTU+shp4UggFOONctPecvKRKbA9EUtc6ZwDA5w960l2k1i4ycZWpsFx8UU6DLFueouQ6jOnfubcWEC4q9W2wE11rPug7CpOL4fawyBeFj1iyFmK2p0B5SxVV4C1jdgi2bzXzYOUiemoPckp734X3I= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099263205685.1466370517364; Mon, 13 Apr 2026 09:54:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKX5-0006p5-6R; Mon, 13 Apr 2026 12:53:07 -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 1wCKX3-0006oo-M7 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:05 -0400 Received: from p-west2-cluster3-host11-snip4-10.eps.apple.com ([57.103.69.33] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKX2-0005U3-6b for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:05 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 9E2D618000AE; Mon, 13 Apr 2026 16:53:02 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 671BC1800E80; Mon, 13 Apr 2026 16:52:49 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099183; x=1778691183; bh=LeCfULzXVq8eMeXoD4HoazACVFGuCL5m06fQgObX99k=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=b06QdDmop1Dk+cVqitILiw49u24OfzEbnO77OpjFElGETtxiSCkhMXGHzvWv+qGxcOOkO7ijmaEKc8aM4y1m4SBgksq8atCFd4IjMjplU3dplFpAeWG/Xi7Lu1ssEwD2KkiPxoRY8ghmahAVaXU4V2LDTPIJg1exzJFFjJv56MiQ7ubcQC6qvSBXEZafaOfx0LDMUzBvsKog0X2G4jYUnGSerb2hlgZSxoIvoEXuMvZ9fe5GAsCHGR/ventjysQJ/kHF0/5jqb0TYg5JzP+IifWpe8nSBucFtdgDjbnnG5QA1nHPa8OzrWHwPpFYnAkkhlrgkrzrXc6CtoIWz/OJkQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 04/15] whpx: i386: disable TbFlushHypercalls for emulated LAPIC Date: Mon, 13 Apr 2026 18:52:06 +0200 Message-ID: <20260413165217.47105-5-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfXxwal4o7XcHSs XwzwYt5vz6Roq6TGPRTdo5doL2hIA8OMEjYJobySAj+EADEa2yt9TH9z+2ZZRLM4GOBk98o+JN0 EoPl1d1asIoz5PvlS3X8ifcEI5KOiwmLv000Sn6RivtphAQ1is/AjwidGxFAA4klyrBhuqayu6v 9NwW0AnivSpgHKMuOroiNrnfKfc0iRTHIcmRnJ1mNxMO++Gu4j15bBx/3uxzz31ULKBUVPS5+CI veJynqx2V746N0NM2LpLANJSShz2vGh80CEoX+TxD0O3knhk0oWiY1r6R7gBQdeBrfxOglZuBsY OcPmREZ+We+6YrdOnXzkHdswmmi6fl5fXdB874IjVx7wG8c13IC6XUHTxbcRFQ= X-Proofpoint-GUID: aw5CZczzaVh_z1R4ZgvLIbMh_jaMwaI9 X-Authority-Info-Out: v=2.4 cv=botBxUai c=1 sm=1 tr=0 ts=69dd1f6e cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Rm0zj2O9plGGl-KjdfMA:9 X-Proofpoint-ORIG-GUID: aw5CZczzaVh_z1R4ZgvLIbMh_jaMwaI9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 adultscore=0 phishscore=0 bulkscore=0 mlxlogscore=710 malwarescore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.33; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099266248154100 Content-Type: text/plain; charset="utf-8" AccessHypercallRegs was present twice so clean that up. Remove TbFlushHypercalls (and its extended Gva range sub-feature) from the user-mode LAPIC case as it behaves oddly there. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 2d527b90dd..0908dfd134 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2489,10 +2489,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.AccessPartitionReferenceTsc =3D 1; synthetic_features.Bank0.AccessHypercallRegs =3D 1; synthetic_features.Bank0.AccessFrequencyRegs =3D 1; - synthetic_features.Bank0.EnableExtendedGvaRangesForFlushVirtualAddress= List =3D 1; synthetic_features.Bank0.AccessVpIndex =3D 1; - synthetic_features.Bank0.AccessHypercallRegs =3D 1; - synthetic_features.Bank0.TbFlushHypercalls =3D 1; =20 if (whpx_irqchip_in_kernel()) { synthetic_features.Bank0.AccessSynicRegs =3D 1; @@ -2500,6 +2497,12 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.AccessIntrCtrlRegs =3D 1; synthetic_features.Bank0.SyntheticClusterIpi =3D 1; synthetic_features.Bank0.DirectSyntheticTimers =3D 1; + /* + * These technically work without the Hyper-V LAPIC + * but behave oddly for multi-core VMs. + */ + synthetic_features.Bank0.TbFlushHypercalls =3D 1; + synthetic_features.Bank0.EnableExtendedGvaRangesForFlushVirtualAdd= ressList =3D 1; } =20 if (is_modern_os && whpx->hyperv_enlightenments_allowed) { --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099302; cv=none; d=zohomail.com; s=zohoarc; b=S84z0DY3/TWfZaUGy5HM2PLGJSmMmQfpnvUkyZPXvqpMXZv6UkzVSj1+uUjamwSnCGC1MVBu/jRlG30P4HIGa6XPDv8lIy1EJ7LjjBB7M8N9cENwtYSGAUi66cc96wy5yRhC8hB2Uo7xtdxud7sA9ov8imWTZDc4gqTjKc6zXFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099302; 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=dugTy6Mycl0V8PO55M7zjkrIKW6irE2gkRf+Eg5CDxE=; b=igKNzf9zWbLOYMGxMPZVr1EJ0b6KXET6SQVqH8ArwPfvxuvXpn4zS1os+iAeizwSq1AG6Mj3pE9+TGx/sbKiKTM9nv/Wd+ZezVXfYK1nasonTw1RrHuwQj8jrxtSGW2RxJguEJb00yzfV5meaFBIunOqw38rFu0iWOGkjuvY7gE= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099302900492.13489451924875; Mon, 13 Apr 2026 09:55:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKX7-0006ps-KL; Mon, 13 Apr 2026 12:53:09 -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 1wCKX5-0006pZ-Pp for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:07 -0400 Received: from p-west2-cluster3-host10-snip4-5.eps.apple.com ([57.103.69.78] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKX4-0005Uo-GW for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:07 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 4CB501803867; Mon, 13 Apr 2026 16:53:04 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 41D3718027C9; Mon, 13 Apr 2026 16:52:53 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099185; x=1778691185; bh=dugTy6Mycl0V8PO55M7zjkrIKW6irE2gkRf+Eg5CDxE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=OoAU7QDA417nXkBvZvsaC9TIWHxDuEahpTUEgIqVtnuB0vPF3SSO1FvFYPHgz8mBZI6rcU/61uOKqidbaWOEsuvqj7j0XjJ1YEaO1uasmghJmD1kZWyDfUMto9DEZ9E3OECxTSnbYCuvc3rhQHaGVhY5LLDZmnA+pm2SZHccB4E1M2pPFdMiheBqPzfj+0E5Er05a/GjMUpnHpBDW6timv8MLmuJrH0mLgoGH3HTImpbt0KXt0qSjaXuCNDlnpI3QRWyd1ggxVfc4rspSP47T8vpHofYx/gGjAPHhV+9KrCKdM3yCk4hSY0rBmt7HnnTmQyOcUK2toq/y3+m1hdyvg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 05/15] whpx: i386: enable x2apic by default for user-mode LAPIC Date: Mon, 13 Apr 2026 18:52:07 +0200 Message-ID: <20260413165217.47105-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX07bLHUGJOf87 KcOB/kb1h2iVHeKxVHGey1Sq9UqDjiNkRYcNV1NO2tRangfbfsT30FXJ247xgTB2gC8Nz2yt27A 7FQtY4LWhqzZUGU0955Pw38BcfWEUmxUF9UAukOBHEH5+YKXiu4Xr6/k0FIFEp8LD78WMuDDR7x +1AAlZNxhKjjJ3u5bz55tLVZhhXhBy9H0xzO8a1NI03sYZPii1fnWc5MUoFzJ9cp+mTS/Q/f8e2 cjM7KMohhjisR6pm/FYeU8wC8X45g859GzigFW2YDDwZ5X9h62tGQWOYgj3Jl8V1VlUb+nPyKaR PZ8ZUMSi/pDu9zTDLT6VPaelBXmS7Ou2pkvNvpwJjtoJ0O4lWdzRgF1yzVPiAs= X-Authority-Info-Out: v=2.4 cv=HMrO14tv c=1 sm=1 tr=0 ts=69dd1f70 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=uAk9FrDoCeqUxh5yT_MA:9 X-Proofpoint-GUID: CzQrjLTzAkOavsb_VOZShRLwS7xgizJT X-Proofpoint-ORIG-GUID: CzQrjLTzAkOavsb_VOZShRLwS7xgizJT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 adultscore=0 phishscore=0 clxscore=1030 mlxlogscore=999 lowpriorityscore=0 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.78; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099304389154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 0908dfd134..66f263558f 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2281,11 +2281,18 @@ error: return ret; } =20 +static PropValue whpx_default_props[] =3D { + { "x2apic", "on" }, + { NULL, NULL }, +}; + + void whpx_cpu_instance_init(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); =20 host_cpu_instance_init(cpu); + x86_cpu_apply_props(cpu, whpx_default_props); } =20 /* --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099270; cv=none; d=zohomail.com; s=zohoarc; b=Q7psH/lMQFjyPhYYz+7MI1BQwxO7wpOSGKMblPz224WP6NVlxlxzU+vqkt0jIoZqyO4dmntrDAgHhYeDEeFAef03wVZ7Ga3I1zp8lwWCorHp9EamjVOlufpZm4S9F0N2UcNg9V2Y9bkZFr3W/huvy/5ZyW25Aude+mi6vgj5bSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099270; 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=oQob0705w1vpsKwSbilmxpp8KQiyruObQqebQ5RZ0Dc=; b=j2pVfJi9HRPElPzZL9RV1IjEtHUtJ/QYVjUVWM6hcKP2H2YqP+zUklZ3dqQO5VllBMpWYK+3P8Zp4hvNlSSl8l9nXb2llzQabhkyKFTY6UTWkSW1+bVwstOdpuXfrn0nG7KP0S0pGEg+cec1qq/YuuiQNbAHy1C9Narfxg/H3MM= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099270232442.44190492504856; Mon, 13 Apr 2026 09:54:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKX8-0006qO-O8; Mon, 13 Apr 2026 12:53:10 -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 1wCKX7-0006q4-SY for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:09 -0400 Received: from p-west2-cluster3-host5-snip4-3.eps.apple.com ([57.103.69.86] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKX6-0005Uv-3s for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:09 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 76DF618027E6; Mon, 13 Apr 2026 16:53:06 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id BE72E180047D; Mon, 13 Apr 2026 16:52:57 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099186; x=1778691186; bh=oQob0705w1vpsKwSbilmxpp8KQiyruObQqebQ5RZ0Dc=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Ekljg24y5XdqPHkpPRHPRcjP3tmBwFEl0VhuMmmeROEnRACTvKx80EHtVrYJaZBsijmDxgLTSYuzIZaG0GCICd82iprpIkdFlNDxdmnBa7BpBJlnOiFzXuIGnkfjTdGZgAl2RMBSzx/Rn5NyfpW4ypq06d+v+ElhLZInE1gPIcMv75WqfVTmkW9HE7RjXFEdeh1Y0XOU+EZWqVb1++QSik711H7nY1z/WxMBhwSdfL84iljZ6bKjYlZHpqNVihT0a3BjEw53wjBwEdTumS2T/LVzq+rELZP0q+416i42dpuatm9LcsbuIE18beTdwiU/AdRK+v8VysLFzn4oxgpS3Q== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 06/15] whpx: i386: reintroduce enlightenments for Windows 10 Date: Mon, 13 Apr 2026 18:52:08 +0200 Message-ID: <20260413165217.47105-7-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX/udrLk4wTy69 kFs6kysHx/d+UdZeR5xTxB66ebCTaCl0aA1NIwJvUcpOeiQ8RX5eMwBvXHyy6vrUh/7m9nBsR61 kA9LuLW4v74giOu1D9cXXsVzLpRy6NvKHxcJQeFko8itemh2xgKNgz1XMypwGvXUCLpJJh8dEFc jz9mpmb1t1+cxN2xmkvsQREL1NPQvimKNY6cKmxnosbTpsJCx0yf54xz3SmCE/MjNRxjkOctfjX mNkd70Iv5whX0fH5kLFNxvrSkQxMiAr3v3NBwgjTuFlpOuW9pWSNMueaEFEeiZ1oENm76WN4KCH RjfdFUP4grDojhYqj0R0RqfvlbNq8T7pEF4JYW7Fnp19Zt2JHPeBNZZTXC1ufw= X-Proofpoint-GUID: ojFBLz7sioIdrNZ2OF37HobbJ35g__Pa X-Authority-Info-Out: v=2.4 cv=botBxUai c=1 sm=1 tr=0 ts=69dd1f72 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=hfWBbujXMTx1PmRkPVYA:9 X-Proofpoint-ORIG-GUID: ojFBLz7sioIdrNZ2OF37HobbJ35g__Pa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 adultscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.86; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099272261158500 Content-Type: text/plain; charset="utf-8" Was removed in 2c08624 but it's still useful for Windows 10 so reintroduce it there. And this time, actually make it work by reporting the hypervisor bit in CPUID. Pretend to be vmware to be able to use vmport's functionality. If the vmware frequency leaf is disabled, pretend to be KVM, with the only capability reported being X2APIC support. Signed-off-by: Mohamed Mediouni --- accel/whpx/whpx-common.c | 2 ++ include/system/whpx-internal.h | 1 + target/arm/whpx/whpx-all.c | 1 + target/i386/whpx/whpx-all.c | 63 +++++++++++++++++++++++++++++----- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c index b813a5d9d2..59be996aef 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -550,6 +550,8 @@ static void whpx_accel_instance_init(Object *obj) =20 whpx->hyperv_enlightenments_allowed =3D true; whpx->hyperv_enlightenments_required =3D false; + /* Value determined at whpx_accel_init */ + whpx->hyperv_enlightenments_enabled =3D false; } =20 static const TypeInfo whpx_accel_type =3D { diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index 5902124b63..cf782cf5f8 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -45,6 +45,7 @@ struct whpx_state { =20 bool hyperv_enlightenments_allowed; bool hyperv_enlightenments_required; + bool hyperv_enlightenments_enabled; =20 }; =20 diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c index bbf0f6be96..4019a513aa 100644 --- a/target/arm/whpx/whpx-all.c +++ b/target/arm/whpx/whpx-all.c @@ -968,6 +968,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) * as they're not needed for performance. */ if (whpx->hyperv_enlightenments_required) { + whpx->hyperv_enlightenments_enabled =3D true; hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 66f263558f..c2a78312f8 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2083,14 +2083,57 @@ int whpx_vcpu_run(CPUState *cpu) vcpu->exit_ctx.VpContext.Rip + vcpu->exit_ctx.VpContext.InstructionLength; =20 - reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRax; - reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRcx; - reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRdx; - reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRbx; - - if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 1) { - if (cpu_has_x2apic_feature(env)) { - reg_values[2].Reg64 |=3D CPUID_EXT_X2APIC; + if (whpx_is_legacy_os()) { + reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRax; + reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRcx; + reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRdx; + reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRbx; + } else { + cpu_x86_cpuid(env, vcpu->exit_ctx.CpuidAccess.Rax, + vcpu->exit_ctx.CpuidAccess.Rcx, + (UINT32 *)®_values[1].Reg32, + (UINT32 *)®_values[4].Reg32, (UINT32 *)®_values[= 2].Reg32, + (UINT32 *)®_values[3].Reg32); + } + + if (!whpx->hyperv_enlightenments_enabled) { + switch (vcpu->exit_ctx.CpuidAccess.Rax) { + case 1: + reg_values[2].Reg64 |=3D CPUID_EXT_HYPERVISOR; + break; + case 0x40000000: + /* + * Use vmware_cpuid_freq as a proxy to report VMware. + * This is to get the TSC/APIC frequency query functio= nality + * provided through vmport, as Linux doesn't use leaf + * 0x40000010 for getting those frequencies. + */ + if (x86_cpu->vmware_cpuid_freq) { + reg_values[1].Reg64 =3D 0x40000010; + reg_values[4].Reg64 =3D 0x61774d56; + reg_values[2].Reg64 =3D 0x4d566572; + reg_values[3].Reg64 =3D 0x65726177; + } else { + /* report KVM otherwise if that's disabled */ + reg_values[1].Reg64 =3D 0x40000001; + reg_values[4].Reg64 =3D 0x4b4d564b; + reg_values[2].Reg64 =3D 0x564b4d56; + reg_values[3].Reg64 =3D 0x4d; + } + break; + case 0x40000001: + if (!x86_cpu->vmware_cpuid_freq) { + /* KVM reporting of X2APIC support */ + reg_values[1].Reg64 =3D reg_values[4].Reg64 =3D + reg_values[2].Reg64 =3D 1 << 15; + } + break; + case 0x40000010: + if (x86_cpu->vmware_cpuid_freq) { + reg_values[1].Reg64 =3D env->tsc_khz; + reg_values[4].Reg64 =3D env->apic_bus_freq / 1000;= /* Hz to KHz */ + } + break; } } =20 @@ -2311,6 +2354,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; UINT32 cpuidExitList[] =3D {1}; + UINT32 cpuidExitList_nohyperv[] =3D {1, 0x40000000, 0x40000001, 0x4000= 0010}; =20 whpx =3D &whpx_global; =20 @@ -2513,6 +2557,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) } =20 if (is_modern_os && whpx->hyperv_enlightenments_allowed) { + whpx->hyperv_enlightenments_enabled =3D true; hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, @@ -2565,7 +2610,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeCpuidExitList, - cpuidExitList, + whpx->hyperv_enlightenments_enabled ? cpuidExitList : cpuidExitLis= t_nohyperv, RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32)); =20 if (FAILED(hr)) { --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099242; cv=none; d=zohomail.com; s=zohoarc; b=XVyfRrp81XoPcSFb2HR1IXgCh7/WNBu0lLU0JzvifH//94oyC2ieqkG9uXU7gB6JSXXq7Q0hdrWS9n8JK0ew4PAgsci4+KxnLpmKFMVWRFhjXTRNZgRMpU8RKfY2Jd/jjsZqCH27yFwIQUlIj8btKgZoZiD5viyZ4r+pVoxbUY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099242; 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=6tmGSEaUrE0Q7MlYX6psbx8TA0g5EcgDAZR7bSJpGEE=; b=If5dwXXNCUsmw/13OHJzuk5iJS7MbA+pQ4tuLFlm6EQEn6D/iP6I+baNdlesGKtJgjqYfP+HLwLnwnjbe42wOnGKmccCTH4d1qXSz756ClClMMl3utDZOawAFntiS7w1uLNpsZE9CjYSHyDA46L+kG+1LVkopeCNwXa7RrzNgYk= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099241668913.7436390787203; Mon, 13 Apr 2026 09: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 1wCKXC-0006r7-4u; Mon, 13 Apr 2026 12:53:14 -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 1wCKXA-0006qe-2w for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:12 -0400 Received: from p-west2-cluster3-host11-snip4-1.eps.apple.com ([57.103.69.24] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKX8-0005VX-9V for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:11 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 97ED71800CA4; Mon, 13 Apr 2026 16:53:08 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id DAD821803956; Mon, 13 Apr 2026 16:53:02 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099189; x=1778691189; bh=6tmGSEaUrE0Q7MlYX6psbx8TA0g5EcgDAZR7bSJpGEE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=OsCUxbm82gSFX1NVYlHKz3M75dhVELp/4h/jUMNZ5BvZMhpt0ZzQNbwN4EazaNRLzex28ScbGX+xInb28yWfiRJG/3HMnCts6LBuoVZzUFidT5EVMJ7AGXxiolome4rrB0a8FnTnZJBAmW90599WwKhxbx9PdfzF8R591qNP4M7qrj+MNhnq6qiX3lkJAmmp3zc6oT0nHEI7JHFqxS+++0Ag3g1mSS3Ba+eQTKd1O1nelpOTawNAwvCDM9oPSaKrQqlfGs1bxjDYIBvJdp7fgCyGsdySCKdg1/vm3Uynkw6BEdMdP0ZDsw4Q43AgRcneIgPT+PkSICnF1bDxaLSIjg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 07/15] whpx: i386: introduce proper cpuid support Date: Mon, 13 Apr 2026 18:52:09 +0200 Message-ID: <20260413165217.47105-8-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: INMbt5N92POGJfvdNgp0_etOvfUDjD0s X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX/5fnR9SszYNG js//wnqLycvu3HCr/GuRJi23BO+SeAOUJHAdQnxBV3AELgUEvyueub1Yr22XvTmg8QF6kKl9ycf KI5UXRUuKLJou8aePU8JrEcRrYqb2i2923jdHF5xpgRwHOV/ni6TizhxuVWbYAY9e7wXXMClLFs 6YKiPlfvTGVFhIrX7brsSgxKphXDDcG/7mLPW31P9RfBzyeel94XWcqTMokURmDtlrJKC4Aso6Q l2Ee/DyOllJreGnCnTicsGuQkp/uhVkz2I1r24GV5CjNGo8gqqNPW0tDxUmoaQ2vpVXKC4+MqHZ hOZqtTTrBlSq67d0qZaYXuuZEFyaPpZunz0qD4crK58AJhyG/5cXiMfo0HySt8= X-Proofpoint-GUID: INMbt5N92POGJfvdNgp0_etOvfUDjD0s X-Authority-Info-Out: v=2.4 cv=DohbOW/+ c=1 sm=1 tr=0 ts=69dd1f74 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=n8cRCUxqL_yedgTzvKUA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 clxscore=1030 mlxlogscore=999 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.24; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, 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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099244727158500 Content-Type: text/plain; charset="utf-8" Unlike the implementation in QEMU 10.2, this one works. It's not optimal though as it doesn't use the Hyper-V support for this. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 123 ++++++++++++++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 4 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index c2a78312f8..9827c93df1 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2071,6 +2071,7 @@ int whpx_vcpu_run(CPUState *cpu) WHV_REGISTER_NAME reg_names[5]; UINT32 reg_count =3D 5; X86CPU *x86_cpu =3D X86_CPU(cpu); + X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); CPUX86State *env =3D &x86_cpu->env; =20 reg_names[0] =3D WHvX64RegisterRip; @@ -2083,7 +2084,15 @@ int whpx_vcpu_run(CPUState *cpu) vcpu->exit_ctx.VpContext.Rip + vcpu->exit_ctx.VpContext.InstructionLength; =20 - if (whpx_is_legacy_os()) { + /* + * On Windows 10 we can't query features from + * the Hyper-V interface. + * + * On Windows 11, if using xcc->max_features + * just pass through what the hypervisor + * provides without any QEMU filtering. + */ + if (whpx_is_legacy_os() || xcc->max_features) { reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRax; reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRcx; reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRdx; @@ -2135,6 +2144,60 @@ int whpx_vcpu_run(CPUState *cpu) } break; } + } else { + switch (vcpu->exit_ctx.CpuidAccess.Rax) { + case 0x40000000: + case 0x40000001: + case 0x40000010: + reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRax; + reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRcx; + reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRdx; + reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRbx; + break; + } + } + + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 0x1) { + if (cpu_has_x2apic_feature(env)) { + reg_values[2].Reg64 |=3D CPUID_EXT_X2APIC; + } else { + reg_values[2].Reg32 &=3D CPUID_EXT_X2APIC; + } + } + + /* Dynamic depending on XCR0 and XSS, so query DefaultResult */ + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 0x07 + && vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 0) { + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRdx + & CPUID_7_0_EDX_CET_IBT) { + reg_values[3].Reg32 |=3D CPUID_7_0_EDX_CET_IBT; + } else { + reg_values[3].Reg32 &=3D ~CPUID_7_0_EDX_CET_IBT; + } + + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRcx + & CPUID_7_0_ECX_CET_SHSTK) { + reg_values[2].Reg32 |=3D CPUID_7_0_ECX_CET_SHSTK; + } else { + reg_values[2].Reg32 &=3D ~CPUID_7_0_ECX_CET_SHSTK; + } + + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRcx + & CPUID_7_0_ECX_OSPKE) { + reg_values[2].Reg32 |=3D CPUID_7_0_ECX_OSPKE; + } else { + reg_values[2].Reg32 &=3D ~CPUID_7_0_ECX_OSPKE; + } + } + + /* OSXSAVE is dynamic. Do this instead of syncing CR4 */ + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 1) { + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRcx + & CPUID_EXT_OSXSAVE) { + reg_values[2].Reg32 |=3D CPUID_EXT_OSXSAVE; + } else { + reg_values[2].Reg32 &=3D ~CPUID_EXT_OSXSAVE; + } } =20 hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( @@ -2324,6 +2387,45 @@ error: return ret; } =20 +static void whpx_cpu_xsave_init(void) +{ + static bool first =3D true; + int i; + + if (!first) { + return; + } + first =3D false; + + /* x87 and SSE states are in the legacy region of the XSAVE area. */ + x86_ext_save_areas[XSTATE_FP_BIT].offset =3D 0; + x86_ext_save_areas[XSTATE_SSE_BIT].offset =3D 0; + + for (i =3D XSTATE_SSE_BIT + 1; i < XSAVE_STATE_AREA_COUNT; i++) { + ExtSaveArea *esa =3D &x86_ext_save_areas[i]; + + if (esa->size) { + int sz =3D whpx_get_supported_cpuid(0xd, i, R_EAX); + if (sz !=3D 0) { + assert(esa->size =3D=3D sz); + esa->offset =3D whpx_get_supported_cpuid(0xd, i, R_EBX); + } + } + } +} + +static void whpx_cpu_max_instance_init(X86CPU *cpu) +{ + CPUX86State *env =3D &cpu->env; + + env->cpuid_min_level =3D + whpx_get_supported_cpuid(0x0, 0, R_EAX); + env->cpuid_min_xlevel =3D + whpx_get_supported_cpuid(0x80000000, 0, R_EAX); + env->cpuid_min_xlevel2 =3D + whpx_get_supported_cpuid(0xC0000000, 0, R_EAX); +} + static PropValue whpx_default_props[] =3D { { "x2apic", "on" }, { NULL, NULL }, @@ -2333,9 +2435,18 @@ static PropValue whpx_default_props[] =3D { void whpx_cpu_instance_init(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); + X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); =20 host_cpu_instance_init(cpu); x86_cpu_apply_props(cpu, whpx_default_props); + + if (!whpx_is_legacy_os() && xcc->max_features) { + whpx_cpu_max_instance_init(cpu); + } + + if (!whpx_is_legacy_os()) { + whpx_cpu_xsave_init(); + } } =20 /* @@ -2353,8 +2464,12 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_CAPABILITY_FEATURES features =3D {0}; WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; - UINT32 cpuidExitList[] =3D {1}; - UINT32 cpuidExitList_nohyperv[] =3D {1, 0x40000000, 0x40000001, 0x4000= 0010}; + + UINT32 cpuidExitList[] =3D {0x0, 0x1, 0x6, 0x7, 0x14, 0x24, 0x29, 0x1E, + 0x40000000, 0x40000001, 0x40000010, 0x80000000, 0x80000001, + 0x80000002, 0x80000003, 0x80000004, 0x80000007, 0x80000008, + 0x8000000A, 0x80000021, 0x80000022, 0xC0000000, 0xC0000001}; + UINT32 cpuidExitList_legacy_os[] =3D {1, 0x40000000, 0x40000001, 0x400= 00010}; =20 whpx =3D &whpx_global; =20 @@ -2610,7 +2725,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeCpuidExitList, - whpx->hyperv_enlightenments_enabled ? cpuidExitList : cpuidExitLis= t_nohyperv, + !whpx_is_legacy_os() ? cpuidExitList : cpuidExitList_legacy_os, RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32)); =20 if (FAILED(hr)) { --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099254; cv=none; d=zohomail.com; s=zohoarc; b=AEYDNOKZCVViVDjnn0db4gxAQwqh+5J6h9/Wje8AfEROGpb7MBm1G5W6f7j4bVtriyRUlo/0YosiHaNRcXL+OrJ1AxIk3Xpco2A3cPw2gWpaC1twkzNJw/jXolQEwGm8FiHn0TVLkml0LUoxl6vfro5JSjPOLkzAIhAkmPl+trQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099254; 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=T/ylQnS/te0fMXN5QyRAvae93avWDOZqU0zT/KgDwLQ=; b=YF4fTJ8WH3D5rY/EvpeclZ4CNHOgOBQm9q9O63l/W0/XWiRNGTxbg+Ba+LiZ0mlQvEviUq1p8U5+EKdO94BFHjsLXMM9JkmHStAMWqMUmXsiAXmtrpHpXTtbXoshSHFlRqBXXuvylf0JPFB41tX9wNHAQcMedBFbo/tIG/q4hrM= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17760992539971015.138671024657; Mon, 13 Apr 2026 09: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 1wCKXG-0006rt-Ji; Mon, 13 Apr 2026 12:53:18 -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 1wCKXE-0006rO-3l for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:16 -0400 Received: from p-west2-cluster3-host11-snip4-10.eps.apple.com ([57.103.69.33] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXC-0005W4-A7 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:15 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 4E7131800EAF; Mon, 13 Apr 2026 16:53:12 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id C36371800843; Mon, 13 Apr 2026 16:53:07 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099193; x=1778691193; bh=T/ylQnS/te0fMXN5QyRAvae93avWDOZqU0zT/KgDwLQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=CBpRPMH/yDMjN0ATuKXdftkQ99v0L1mLJJQoCsfEOMYQjdM6UEE46Mh+HZqn5lGC+nV7A8sTbChpexfPMnY8sxPqaoiTMU0pYJihNmzWPXYF0JZWvOG7M3YYhXY2sKeQZHZxa+5ymKvsqyEHUF/uWwduLJicBhpcZKWaOa8qbtBBxYg9HNJtO3l04HbCzZ/cZhKCbt1WLx/qQ7a58TCYkludrQGh/I4RCERRRKzR+6q242tWHK//yqBUONA+SL0TaYhnJDhcBBq0gkmz/XatZyYI6gmtPumHZ54vG+5R4KAnljrWqWaOK8t/vKQyGuz7ghyljC4bsBNe+ULhqZe/Cw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 08/15] whpx: i386: kernel-irqchip=off fixes Date: Mon, 13 Apr 2026 18:52:10 +0200 Message-ID: <20260413165217.47105-9-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: MeGrepLLuzY9JqL3MhR3INHZAD0IT3lV X-Authority-Info-Out: v=2.4 cv=QsdTHFyd c=1 sm=1 tr=0 ts=69dd1f78 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gP1GEkNOX-MqffGxZ4oA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX8+JnFz+38QRS rE2vP/GWgIIH/0/UZyZO+dhW8Ug1K7gthAk8KhoMyWV0EzCeQuACIFqqmltkTws1fAmPeE9qVjU rYU7ZhjNYpOIJua3Dv/7fy/aLjmjn/eqw5jvDep9IPv+Dyu0Q9mceyPiymfmEWg0EpvAxYI2aT2 guD20DJcVidD0YTEtsps1MpfvsN6iazLRcC5nSf53ABbxZ+gYlsLG2dL1jFKXj53NJSdtcsmvy0 BT66cAfYKMMzjwGb1at9kI6IwBP5XGqhGnHBlLpLdsCgYv+QpVxYoCck3d5jwzNPuhyyEyyhL2m zoQW04+Hc4RJ0XvH0bxdwxkaOzG7RrbTOpy38XEfechO7HoaBYL+vw4ba7x6Rs= X-Proofpoint-GUID: MeGrepLLuzY9JqL3MhR3INHZAD0IT3lV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 clxscore=1030 mlxscore=0 malwarescore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.69.33; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099257957154100 Content-Type: text/plain; charset="utf-8" This was really... quite broken. After fixing this, Windows boots with kernel-irqchip=3Doff. Signed-off-by: Mohamed Mediouni --- include/system/whpx-common.h | 1 + target/i386/whpx/whpx-all.c | 43 +++++------------------------------- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/include/system/whpx-common.h b/include/system/whpx-common.h index 04289afd97..3406c20fec 100644 --- a/include/system/whpx-common.h +++ b/include/system/whpx-common.h @@ -4,6 +4,7 @@ =20 struct AccelCPUState { bool window_registered; + int window_priority; bool interruptable; bool ready_for_pic_interrupt; uint64_t tpr; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 9827c93df1..62542922a4 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -22,6 +22,8 @@ #include "qemu/main-loop.h" #include "hw/core/boards.h" #include "hw/intc/ioapic.h" +#include "hw/intc/i8259.h" +#include "hw/i386/x86.h" #include "hw/i386/apic_internal.h" #include "qemu/error-report.h" #include "qapi/error.h" @@ -371,28 +373,6 @@ static int whpx_set_tsc(CPUState *cpu) return 0; } =20 -/* - * The CR8 register in the CPU is mapped to the TPR register of the APIC, - * however, they use a slightly different encoding. Specifically: - * - * APIC.TPR[bits 7:4] =3D CR8[bits 3:0] - * - * This mechanism is described in section 10.8.6.1 of Volume 3 of Intel 64 - * and IA-32 Architectures Software Developer's Manual. - * - * The functions below translate the value of CR8 to TPR and vice versa. - */ - -static uint64_t whpx_apic_tpr_to_cr8(uint64_t tpr) -{ - return tpr >> 4; -} - -static uint64_t whpx_cr8_to_apic_tpr(uint64_t cr8) -{ - return cr8 << 4; -} - void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; @@ -421,7 +401,7 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel l= evel) v86 =3D (env->eflags & VM_MASK); r86 =3D !(env->cr[0] & CR0_PE_MASK); =20 - vcpu->tpr =3D whpx_apic_tpr_to_cr8(cpu_get_apic_tpr(x86_cpu->apic_stat= e)); + vcpu->tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); vcpu->apic_base =3D cpu_get_apic_base(x86_cpu->apic_state); =20 idx =3D 0; @@ -692,17 +672,6 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel = level) hr); } =20 - if (whpx_irqchip_in_kernel()) { - /* - * Fetch the TPR value from the emulated APIC. It may get overwrit= ten - * below with the value from CR8 returned by - * WHvGetVirtualProcessorRegisters(). - */ - whpx_apic_get(x86_cpu->apic_state); - vcpu->tpr =3D whpx_apic_tpr_to_cr8( - cpu_get_apic_tpr(x86_cpu->apic_state)); - } - idx =3D 0; =20 /* Indexes for first 16 registers match between HV and QEMU definition= s */ @@ -751,7 +720,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) tpr =3D vcxt.values[idx++].Reg64; if (tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; - cpu_set_apic_tpr(x86_cpu->apic_state, whpx_cr8_to_apic_tpr(tpr)); + cpu_set_apic_tpr(x86_cpu->apic_state, tpr); } =20 /* 8 Debug Registers - Skipped */ @@ -1690,7 +1659,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) } =20 /* Sync the TPR to the CR8 if was modified during the intercept */ - tpr =3D whpx_apic_tpr_to_cr8(cpu_get_apic_tpr(x86_cpu->apic_state)); + tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); if (tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; reg_values[reg_count].Reg64 =3D tpr; @@ -1737,7 +1706,7 @@ static void whpx_vcpu_post_run(CPUState *cpu) if (vcpu->tpr !=3D tpr) { vcpu->tpr =3D tpr; bql_lock(); - cpu_set_apic_tpr(x86_cpu->apic_state, whpx_cr8_to_apic_tpr(vcpu->t= pr)); + cpu_set_apic_tpr(x86_cpu->apic_state, vcpu->tpr); bql_unlock(); } =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099269; cv=none; d=zohomail.com; s=zohoarc; b=ciAnqg777v63m8BSK0Lvtn31KbP5nOC9d1yOqrhIRmbwHtOlVK1FzUujcpVQjKgsWJgi84Gasg41N5Q/G8xIRxbGfOoK85KJHY92xqBs88yYycC46vcNeojHdWpJvIcUFIl8ekQ5yHH1zdoB+3y26Q6DV1CS9JGaQurhKmoIZGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099269; 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=9UzhbHGn3KNjJvwbSrpYXcynAdkRNKmx/7n4duVcxcA=; b=Q9Ua/ps074kQ+VAEWAGs1K4BEHcMDrNIMbzMWeIS9z0TanrBxdd11P9cbHV5alIJWWkUoC2zk1QNbAAXYeFb9jEklbHL1FvKgotFyDlCTkGlgQZfSlTe6M0pFMKuFfWoXxEbxoxhFaV/EE7tU7BS7juka3d3vMPMxMnTPC5fDoM= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099269036967.7243993904634; Mon, 13 Apr 2026 09:54:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKXN-0006se-48; Mon, 13 Apr 2026 12: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 1wCKXM-0006sP-77 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:24 -0400 Received: from p-west2-cluster2-host4-snip4-3.eps.apple.com ([57.103.68.156] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXK-0005Z1-MQ for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:23 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id EB2C918002A0; Mon, 13 Apr 2026 16:53:19 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 54C481802383; Mon, 13 Apr 2026 16:53:12 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099201; x=1778691201; bh=9UzhbHGn3KNjJvwbSrpYXcynAdkRNKmx/7n4duVcxcA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=a6prqFyxeK4Hb0foh4h7AgI/AoOx0JgmY4As6gsdhxErqfgEtyDerR3XJbwoswKI6Al9rCX4GK8+wTI6JcbjkPJywQfLmyQznqP9CgwrW7t3BC1nmZp2jKS++cPlKgI6QaB5GK65xo1sNS1VDgF/DYQw9AKylBOGnqPJ4ej0mgeKF4fZZz7D8Jfx7/JitZ4QIe5+hb6iVIgs9Gvu6SU6jigwVfKQskRgmXofqUZUBFC+LCrksZ1VpGZBAuPdT3nDVSdFt44Vj1d3fIeQaS2W4kur/RgvJRU4AisMvSoPKz6yTiTJCXuqL8G8ULP0KyzO795ZIlmIFuQW/6vHNnv8rA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 09/15] whpx: i386: use WHvX64RegisterCr8 only when kernel-irqchip=off Date: Mon, 13 Apr 2026 18:52:11 +0200 Message-ID: <20260413165217.47105-10-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX6zFErk4EPOCV +DAAWpqD8GwgfOYTwb1hOsw0rLknLex7ycVMK/3K+1gZmGlb6VwwqHoX8asDZoiHNUhkrj/WpWz UIM5lbzetpRZadGAcvchACx8qJWfwFqHEjzrx9iAUbxevePCz6DpcSU+xxo1IhJ9HtYYFQVb3qK gWQv0YBR3uwKlceeVE0aCZoxWuSRGegayzsFKaLKSjnfc3bq6FWyoHgeeoLy0PqPM3gYI//hBrr NDKiI6YGg4MHimxT8XUfYurH/CFYxAKoICYavylduiH42RXN3+/e17/pUg8jjrhEZFdPqnqa6/R IodlR9tX78wJevHPfSAfG9rMGsZuOZEokKGWAQ5MPEGQBO5Fm6r9rrL8u2GKLw= X-Authority-Info-Out: v=2.4 cv=P/43RyAu c=1 sm=1 tr=0 ts=69dd1f81 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=4IdwVP5-j8YZXVcKM5MA:9 X-Proofpoint-ORIG-GUID: r_L7CJjCsWBVSeX5kxB0QavXvxwawOTp X-Proofpoint-GUID: r_L7CJjCsWBVSeX5kxB0QavXvxwawOTp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 suspectscore=0 malwarescore=0 mlxlogscore=867 spamscore=0 adultscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.68.156; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099271901154100 Content-Type: text/plain; charset="utf-8" When kernel-irqchip=3Don, manage TPR as part of the APIC state instead enti= rely. This fixes some failure to set state errors. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 62542922a4..74b94b799e 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -95,7 +95,6 @@ static const WHV_REGISTER_NAME whpx_register_names[] =3D { WHvX64RegisterCr2, WHvX64RegisterCr3, WHvX64RegisterCr4, - WHvX64RegisterCr8, =20 /* X64 Debug Registers */ /* @@ -459,8 +458,11 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel = level) vcxt.values[idx++].Reg64 =3D env->cr[3]; assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr4); vcxt.values[idx++].Reg64 =3D env->cr[4]; - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr8); - vcxt.values[idx++].Reg64 =3D vcpu->tpr; + /* For kernel-irqchip=3Don, TPR is managed as part of APIC state */ + if (!whpx_irqchip_in_kernel()) { + WHV_REGISTER_VALUE cr8 =3D {.Reg64 =3D vcpu->tpr}; + whpx_set_reg(cpu, WHvX64RegisterCr8, cr8); + } =20 /* 8 Debug Registers - Skipped */ =20 @@ -716,11 +718,14 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel= level) env->cr[3] =3D vcxt.values[idx++].Reg64; assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr4); env->cr[4] =3D vcxt.values[idx++].Reg64; - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr8); - tpr =3D vcxt.values[idx++].Reg64; - if (tpr !=3D vcpu->tpr) { - vcpu->tpr =3D tpr; - cpu_set_apic_tpr(x86_cpu->apic_state, tpr); + + /* For kernel-irqchip=3Don, TPR is managed as part of APIC state */ + if (!whpx_irqchip_in_kernel()) { + tpr =3D vcpu->exit_ctx.VpContext.Cr8; + if (tpr !=3D vcpu->tpr) { + vcpu->tpr =3D tpr; + cpu_set_apic_tpr(x86_cpu->apic_state, tpr); + } } =20 /* 8 Debug Registers - Skipped */ @@ -1660,7 +1665,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) =20 /* Sync the TPR to the CR8 if was modified during the intercept */ tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); - if (tpr !=3D vcpu->tpr) { + if (!whpx_irqchip_in_kernel() && tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; reg_values[reg_count].Reg64 =3D tpr; qatomic_set(&cpu->exit_request, true); @@ -1702,12 +1707,14 @@ static void whpx_vcpu_post_run(CPUState *cpu) =20 env->eflags =3D vcpu->exit_ctx.VpContext.Rflags; =20 - uint64_t tpr =3D vcpu->exit_ctx.VpContext.Cr8; - if (vcpu->tpr !=3D tpr) { - vcpu->tpr =3D tpr; - bql_lock(); - cpu_set_apic_tpr(x86_cpu->apic_state, vcpu->tpr); - bql_unlock(); + if (!whpx_irqchip_in_kernel()) { + uint64_t tpr =3D vcpu->exit_ctx.VpContext.Cr8; + if (vcpu->tpr !=3D tpr) { + vcpu->tpr =3D tpr; + bql_lock(); + cpu_set_apic_tpr(x86_cpu->apic_state, vcpu->tpr); + bql_unlock(); + } } =20 vcpu->interruption_pending =3D --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099317; cv=none; d=zohomail.com; s=zohoarc; b=OsP+R+5l278gTjQ4XRT01WH+ZpSpr7oiKVl2AHm9jL+VvOhbyVW2eAMJIibGFRNEx29yaJikPQER+TISWmKCKrMYYhHEp/7raPbDozXXlTApk6B9ka+/VWZ2QIYmLC5bZcaqUFAKLCSbGPRK7yWSHCTycqOC0TH1M49B3zsgsVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099317; 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=UDUDDhSNImOkwjgegNmDYFGV0Ws4YLT0V61YNwqVXjA=; b=YVuKkx4MJiz4ta1Xyn+0ey9wlKv8kZXucTa9MuKjUztPRsdpOoccPwlysI1xk9OpNfO66exNb1vAFE2raFuZAgDZelSLcym/sVvm31xVRHqJZy64dR30YoOFkPaFLPVtjbTYsALAIbJdEHzJpW4uQaQYdqSpebnUS3+MAl7IxnE= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099317480674.8135223165856; Mon, 13 Apr 2026 09:55:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKXV-0006td-9A; Mon, 13 Apr 2026 12:53:33 -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 1wCKXS-0006tQ-SN for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:31 -0400 Received: from p-west2-cluster2-host8-snip4-5.eps.apple.com ([57.103.68.136] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXR-0005ZU-7v for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:30 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 4C117180039D; Mon, 13 Apr 2026 16:53:26 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 17EBD18003C7; Mon, 13 Apr 2026 16:53:19 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099208; x=1778691208; bh=UDUDDhSNImOkwjgegNmDYFGV0Ws4YLT0V61YNwqVXjA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=OOeOXefpZDY7Z4nQN/lKRi0eNvEZ59yY2FweFtihyvjUCRAlq5O/ph9g379jBcBDOhbDnPAaKmmwC27SVqvszDLddp2C3BwnD+0XIp3SgpzQS9vjb3a4QENEmoCtXugNhKAfArW5lHttPpXoS9QWf0J3JDC6O4b/jakG9xKw1hMfV/UvCRA8cJYeugLQu9Fjn1XpNudnXZSvk3xVphzrCWJw3V/C/0FHN/9dnqUZvtSFCsr8Ij53J/rvs/tvAlpG2/fV1mkUKl2vfv46djdY7qYAJid/3tGrLmVhk4RjFQT6vrVZrd9HR1YvqzHXot10M2YyNAAy8qskK5jrzMy8Hw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 10/15] whpx: i386: disable kernel-irqchip on Windows 10 when PIC enabled Date: Mon, 13 Apr 2026 18:52:12 +0200 Message-ID: <20260413165217.47105-11-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: ySWcCZIXJKeykKifnYAhlFZF-7g-ET9F X-Proofpoint-GUID: ySWcCZIXJKeykKifnYAhlFZF-7g-ET9F X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX97XTR/tt4q2n xWq866zTjshpC01qRlyG1m1iQmSK2j/9HIR3Sta9Rw98J2HhIo9lSQn1mPP/57HC1NRx9wSN44e 23wwjB2C4ENO0Rhg/q1wb9U2APPBE1fXirQ0Nepoky1E2ONytqe22N6uU8SSzjGxKsVg5GjUdp9 Uz7k7GCQJ9iNzuKjiOtSiShH2eE4N/VFov3+Q+3hgyG2RwtroIo6hGm3FtdBXRmrqLuWv9jMDQr MzIvuGXlvqeMcRuiIj+cn5sg77206jO6KkFrXviKBp4nLvcRDPPt2ZYZr6tbx5gPs5QS/iqjVc9 l8pFlbAw/qhN2L3GLxCTI/B55n8y9RwdjT6reqjmWVKtxwDxPli+OaYrsEbroY= X-Authority-Info-Out: v=2.4 cv=DstbOW/+ c=1 sm=1 tr=0 ts=69dd1f87 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nUl_a9z44qMLw6SsMv4A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=801 phishscore=0 malwarescore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1030 spamscore=0 bulkscore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.68.136; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099318723154100 Content-Type: text/plain; charset="utf-8" Move WHvCapabilityCodeProcessorPerfmonFeatures queries as that's how we distinguish if on a legacy OS. Now that Windows guests are booting, disable kernel-irqchip=3Don by default for Windows 10 when the PIC is enabled. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 69 +++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 74b94b799e..7c80d653d1 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2447,6 +2447,13 @@ int whpx_accel_init(AccelState *as, MachineState *ms) 0x8000000A, 0x80000021, 0x80000022, 0xC0000000, 0xC0000001}; UINT32 cpuidExitList_legacy_os[] =3D {1, 0x40000000, 0x40000001, 0x400= 00010}; =20 + X86MachineState *x86ms =3D X86_MACHINE(ms); + bool pic_enabled =3D false; + + if (x86ms->pic =3D=3D ON_OFF_AUTO_ON || x86ms->pic =3D=3D ON_OFF_AUTO_= AUTO) { + pic_enabled =3D true; + } + whpx =3D &whpx_global; =20 if (!init_whp_dispatch()) { @@ -2518,6 +2525,35 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 + /* Enable supported performance monitoring capabilities */ + hr =3D whp_dispatch.WHvGetCapability( + WHvCapabilityCodeProcessorPerfmonFeatures, &perfmon_features, + sizeof(WHV_PROCESSOR_PERFMON_FEATURES), &whpx_cap_size); + /* + * Relying on this is a crutch to maintain Windows 10 support. + * + * WHvCapabilityCodeProcessorPerfmonFeatures and + * WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks + * are implemented starting from Windows Server 2022 (build 20348). + */ + if (FAILED(hr)) { + warn_report("WHPX: Failed to get performance " + "monitoring features, hr=3D%08lx", hr); + is_modern_os =3D false; + } else { + hr =3D whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeProcessorPerfmonFeatures, + &perfmon_features, + sizeof(WHV_PROCESSOR_PERFMON_FEATURES)); + if (FAILED(hr)) { + error_report("WHPX: Failed to set performance " + "monitoring features, hr=3D%08lx", hr); + ret =3D -EINVAL; + goto error; + } + } + /* * Error out if WHP doesn't support apic emulation and user is requiri= ng * it. @@ -2530,8 +2566,9 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 - if (whpx->kernel_irqchip_allowed && features.LocalApicEmulation && - whp_dispatch.WHvSetVirtualProcessorInterruptControllerState2) { + if (whpx->kernel_irqchip_allowed && !(whpx_is_legacy_os() && pic_enabl= ed + && !whpx->kernel_irqchip_required) && features.LocalApicEmulation + && whp_dispatch.WHvSetVirtualProcessorInterruptControllerState2) { WHV_X64_LOCAL_APIC_EMULATION_MODE mode =3D WHvX64LocalApicEmulationModeX2Apic; hr =3D whp_dispatch.WHvSetPartitionProperty( @@ -2590,34 +2627,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 - /* Enable supported performance monitoring capabilities */ - hr =3D whp_dispatch.WHvGetCapability( - WHvCapabilityCodeProcessorPerfmonFeatures, &perfmon_features, - sizeof(WHV_PROCESSOR_PERFMON_FEATURES), &whpx_cap_size); - /* - * Relying on this is a crutch to maintain Windows 10 support. - * - * WHvCapabilityCodeProcessorPerfmonFeatures and - * WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks - * are implemented starting from Windows Server 2022 (build 20348). - */ - if (FAILED(hr)) { - warn_report("WHPX: Failed to get performance " - "monitoring features, hr=3D%08lx", hr); - is_modern_os =3D false; - } else { - hr =3D whp_dispatch.WHvSetPartitionProperty( - whpx->partition, - WHvPartitionPropertyCodeProcessorPerfmonFeatures, - &perfmon_features, - sizeof(WHV_PROCESSOR_PERFMON_FEATURES)); - if (FAILED(hr)) { - error_report("WHPX: Failed to set performance " - "monitoring features, hr=3D%08lx", hr); - ret =3D -EINVAL; - goto error; - } - } =20 /* Enable synthetic processor features */ WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS synthetic_features; --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099292; cv=none; d=zohomail.com; s=zohoarc; b=InVvkJ4+CAd0EMhIilKzGX3n3X0coATKnVyYFiEuM2qRnLeXTVhVu0Z26SASQqTRCtWaWspDDh1ie2sFkl0T7vE7gBNfIAXjHP6cLhFMp+oEkbpqZoBTREaATZ/yTc+74WxoxHFO7pKf5smg+u/BD4KIQJ4N4hKtYwKAb8PStUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099292; 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=G89W4sMC3YwwxzvqsgVypuGjICEkNIb9nBQsRfciAZw=; b=VD81TtLBZVKPbPxsgpKLNak8X0Vkx8F4VlUKgYlYXTKxhIDKYwI8lAo3l0iHn1CnlgqNGnXTjUzqDYQDzA+it2mo4aMzgisUW+TeF6l+g6IdLZ7IGNe4hiZ7A0HhJRjM0Iv+AmLJkihtRH92wnkhP8XVaxqNLiyGoAkituKYJpM= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099292858945.3136296647208; Mon, 13 Apr 2026 09:54:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKXa-0006ud-Kd; Mon, 13 Apr 2026 12:53:38 -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 1wCKXY-0006uF-Ow for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:36 -0400 Received: from p-west2-cluster2-host2-snip4-3.eps.apple.com ([57.103.68.196] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXX-0005Zq-8Z for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:36 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id ECAD3180039D; Mon, 13 Apr 2026 16:53:31 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 6B9E71800E80; Mon, 13 Apr 2026 16:53:26 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099213; x=1778691213; bh=G89W4sMC3YwwxzvqsgVypuGjICEkNIb9nBQsRfciAZw=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JOosQG/iUe1miASoOAvJ6OHzP8OMiGpFYsERaBVV3Y6X9DHFQk67p5lEGIfjQS//lNmj/qVoomknOba7IEgr848AwsercJRdMMWgS+1Eu4OafBmWQrrVCrJCDMMmH7Tyf/tExC1RVgJXUr53XM/UVXKOxmAaEDef7obfIDDHRVXTapMl72h1kFznHvRAhcU8T+lxF9vp78y9+BRHrIc1WZqHpFjNwXBPuKFNoqpRo4YoedchHbkFTHrMt1IffotlvtemklWe57RbBdVLDzzajB8baj1UeZBycF4+f6B7azAaKcJIBMUhgfhqKvzXY8iZckUSBa4gngYQT+pUou/1vA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 11/15] whpx: i386: IO port fast path cleanup Date: Mon, 13 Apr 2026 18:52:13 +0200 Message-ID: <20260413165217.47105-12-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: 8s6PUUeKuIQfQf4vj0EAxMA-u83ZHiyR X-Proofpoint-ORIG-GUID: 8s6PUUeKuIQfQf4vj0EAxMA-u83ZHiyR X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX3WxkAjCf8SR7 +u6yclyfL61D2VkNr9LYr7YpvnOplSouYqEzDgC62EI0PNsifK2JICzsqgBxMcuYJ8LG+l0LK93 cLgfcNTxSI8xFhGjQrRU60+tD6J7L0ueyHjjkyy8ARmPt5tKiezQIvY2d5sJUbRzGaun21wYa5l YMR7wGk5bUFRwwwPQNRxmMZgf45epBVrZ6c0maOq574Um2mJJC9TDo31yADG5TesggrxpO0hEEe +Var2A2enuMK2E5imJLZZhVRZMBHkl+2LkdQdSsg+ZSQ7ae+EioF6nRA8BY+7jQMX+0lL3yrxKi R87k8dPO+DvwapVzeMqvPiUKnn1nZobAbshlRu1JxkUou1k+WTm1NwxkdWbOso= X-Authority-Info-Out: v=2.4 cv=G5QR0tk5 c=1 sm=1 tr=0 ts=69dd1f8c cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Vrzv6M8N8vcM0KmfSJEA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 phishscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=805 adultscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.68.196; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099294320154100 Content-Type: text/plain; charset="utf-8" vmport calls synchronise_state within an I/O port read. Support that properly. What was there before worked because of a side effect of whpx_get_reg synchronising context if cpu->vcpu_dirty. Remove that whpx_get_reg call in whpx_bump_rip too as it's no longer needed now. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 7c80d653d1..61aec98e66 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -862,7 +862,6 @@ static void handle_io(CPUState *env, uint16_t port, voi= d *buffer, static void whpx_bump_rip(CPUState *cpu, WHV_RUN_VP_EXIT_CONTEXT *exit_ctx) { WHV_REGISTER_VALUE reg; - whpx_get_reg(cpu, WHvX64RegisterRip, ®); reg.Reg64 =3D exit_ctx->VpContext.Rip + exit_ctx->VpContext.Instructio= nLength; whpx_set_reg(cpu, WHvX64RegisterRip, reg); } @@ -890,13 +889,23 @@ static int whpx_handle_portio(CPUState *cpu, } else { reg.Reg64 =3D (uint64_t)val; } - whpx_bump_rip(cpu, exit_ctx); - whpx_set_reg(cpu, WHvX64RegisterRax, reg); + /* vmport calls cpu_synchronize_state on an I/O port read */ + if (!cpu->vcpu_dirty) { + whpx_bump_rip(cpu, exit_ctx); + whpx_set_reg(cpu, WHvX64RegisterRax, reg); + } else { + env->eip =3D exit_ctx->VpContext.Rip + exit_ctx->VpContext.Ins= tructionLength; + env->regs[R_EAX] =3D reg.Reg64; + } return 0; } else if (!ctx->AccessInfo.StringOp && ctx->AccessInfo.IsWrite) { RAX(env) =3D ctx->Rax; handle_io(cpu, ctx->PortNumber, &RAX(env), 1, ctx->AccessInfo.Acce= ssSize, 1); - whpx_bump_rip(cpu, exit_ctx); + if (!cpu->vcpu_dirty) { + whpx_bump_rip(cpu, exit_ctx); + } else { + env->eip =3D exit_ctx->VpContext.Rip + exit_ctx->VpContext.Ins= tructionLength; + } return 0; } =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099293; cv=none; d=zohomail.com; s=zohoarc; b=hsIRRuwC0Wnf9LV5f1ylnj+nvGUsSGw9ZbAlZJ057OTrWtiRnElH4ZG415ONluqG0rocYENEQwqMMM7WFkvQ4ZmJFeqNoITGV+Cgl3DBpG2WnENNmYmzm2qL+Pl2Uq0zPZbkFUgnKNchmki0Om2jMoB34uDYcz7wkFH2hfjQOTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099293; 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=zcmYD8sBYnUVL4imQw8BkyvhG03VGFAjf3wzcMF8rtM=; b=a19YTbFcdjr/Ih6u076191fJA2tqUDgn5+nMYeIW43Y3hataJTwQIM4mo5mp+QJzznjCnFhZ5UPzRH30m0f2cgWkOcsl33PfsAMWMtlNkuzqSbGCNkpTUbWRQEds4i7qx+T+3WbRpJq7zBffIamXQzfgqqpkux/eINlble9twkI= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099293821974.5729771987943; Mon, 13 Apr 2026 09:54:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKXd-0006vI-Qq; Mon, 13 Apr 2026 12:53:41 -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 1wCKXc-0006v7-M4 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:40 -0400 Received: from p-west2-cluster2-host7-snip4-1.eps.apple.com ([57.103.68.244] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXb-0005aI-0Q for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:40 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id B003718027C0; Mon, 13 Apr 2026 16:53:36 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 7426218003C1; Mon, 13 Apr 2026 16:53:31 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099217; x=1778691217; bh=zcmYD8sBYnUVL4imQw8BkyvhG03VGFAjf3wzcMF8rtM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=e3HwatzrwAfUkMVHb2lPLGe7Ghj+1S4lRDv7unfVpsm5uHDHvWTCdKvKy+eD66ZmluSKdKA5oEJA6uM3XVs0GLzkkQUlTuh21NzfjkfI6LBMdp+cM94osXz6Vdv/3o/wsFmHza0mtzOxVRk5aJ3dnDqLy6JxFrNtPWgdvY0uI/RUzYx2+inZb8uQ5Y3V5o4DWgo0MnTDD9Z1fC+FQswzGQ8D8K1hCCJU8KMHohfFbnnwGoOVipPQ0e3BgMirNZvt5q0IYvfPVMV76lReAu16b+bn2upjZKKyKEie9GidnvQiIgDIWawLG9eDkNc/m6dMOBsR2v5j6RCIr7UprzLzow== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 12/15] whpx: i386: disable enlightenments and LAPIC for isapc Date: Mon, 13 Apr 2026 18:52:14 +0200 Message-ID: <20260413165217.47105-13-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=c4GmgB9l c=1 sm=1 tr=0 ts=69dd1f91 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=kaNVauZA35-AGszze7oA:9 X-Proofpoint-GUID: -IUWGaGSyUMWMfYMATEnkei19uuAPT4f X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX/JfzCHRh2Bnd 2Wo114XrVYeSLEjUYzcbWVRCoORxci1ORAIILxa5pHX2/ZNPHgVxmoxKFcelkPlOR+BTaP5oTbf 1+XCh4e8h1koXJl+ii+R8vNR5GUxcSZHdUknO95xHV5a1uztZa1A+b7WTFOlLbaTceDXOf9gNfk H9PYkl/k0tBHAf+Y69xwhy5oKigiY58b1SB1HwIsxajEZ3Uygqsag+FCKl5g8Z9QodCd/sEKe90 QuRYoiOkRLr/+2NtdmydtWTNDQ96uDPo0mBznbd15aVIgqSSL3IxVJ2QmoAbv3Tx+Jdm0VGfKl2 TnYs3L27pO1ET9BEgN1GeTVTofMABYvSuUGUrAJHHYf0CbY5z7jSwXSqYTvjhA= X-Proofpoint-ORIG-GUID: -IUWGaGSyUMWMfYMATEnkei19uuAPT4f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 clxscore=1030 malwarescore=0 lowpriorityscore=0 mlxlogscore=817 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.68.244; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099296217158500 Content-Type: text/plain; charset="utf-8" The isapc machine doesn't have an APIC. And Hyper-V enlightenments don't sound too useful to have there so disable those. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 61aec98e66..7a31dc6427 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2470,6 +2470,14 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 + /* for isapc, disable Hyper-V enlightenments and LAPIC */ + if (!strcmp(MACHINE_GET_CLASS(ms)->name, "isapc")) { + whpx->kernel_irqchip_allowed =3D false; + whpx->kernel_irqchip_required =3D false; + whpx->hyperv_enlightenments_allowed =3D false; + whpx->hyperv_enlightenments_required =3D false; + } + whpx->mem_quota =3D ms->ram_size; =20 hr =3D whp_dispatch.WHvGetCapability( --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099301; cv=none; d=zohomail.com; s=zohoarc; b=eoMCah7dFZg+8bcrLLznhhSDVwBI3gv5AuDQxdHJUpWxUL+fzMbWCb6WQgK5eSHYNCX4Ta6WmUyqStNGi6eoIVIJkXWpEMzTPt6Z79gAgMAqRaTY7nL4VXOoVJHs1ciT/+fryXKXYAjUKqHS6ipweqLzo465RuRf9aA89U5v73U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099301; 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=poibcXPqvaJ8YaZ5/PTr9/BHGmofzQDktL0gBjdI+dM=; b=QgKYlcAc9x9yECOLI9Sq0inXKTbUnqNWJQzOLlNKviB8823vB2qqhPP3xpzxGZgRnsHWKTvZUAhZ7mCCy/ElqlsndIW9XBL8Q85T11Ylo8Yor3ioCZCNOI1yoXExwss/sJ7Rb4DURCrcxwjTWz7lXEwEv7egBEXzZG9qblSxrNU= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776099301454977.4107748689199; Mon, 13 Apr 2026 09:55:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKXn-0006wL-0K; Mon, 13 Apr 2026 12:53:51 -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 1wCKXi-0006w4-Oz for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:47 -0400 Received: from p-west2-cluster1-host7-snip4-10.eps.apple.com ([57.103.68.93] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXh-0005ai-A4 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:46 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 36B4618016E9; Mon, 13 Apr 2026 16:53:41 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 7C1C6180034A; Mon, 13 Apr 2026 16:53:36 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099223; x=1778691223; bh=poibcXPqvaJ8YaZ5/PTr9/BHGmofzQDktL0gBjdI+dM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=HwBOcBzhgnu1oqKLgMcuHn7whWxzBzAtpZhvHdIzx1e6+Ef/8q/4dUu2njKYtiQaL9eutYOeExMfhe7WxUqpUK08ZsKeVfDdbCoKes0vWo0jVl9CKaEuxsMosF2EyVzgQAj1eBr8RTZicTdJbBBHfBqe0zIdRLsmQ17j/vYO61W1hCHMKnE5JR4k7ZCRgUKoI/Q7uAQ08RWRIYnoIq/X6si9X9W4j4j+gFpxvqpnEpDa7n5/P62TWnSTKY5XqZfZ1g5luU+gSW/rAz6UMjTE6eSUU6uDR7LhUuPemfoo0SmHLES9hFWTKFMsrKxw9s2DepwAZqSnqix4PQ4rWUG3Aw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 13/15] whpx: i386: interrupt priority support Date: Mon, 13 Apr 2026 18:52:15 +0200 Message-ID: <20260413165217.47105-14-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX0rrVXH3b3Lvl 7BHhzMiI8i3Wvo49pNEfra3vyEn/U2tLC14ScCMmklPHNdxHx8lICqdIYa2SFoNT5aLf010IHDV 70zxfvct4GoymzMROpqy5PRgbO1RGUDrvwkn1QQUNduYYM4KPPu5Lr0bOtYRAZ6Y8Eo+Vtn6T/i 7CGQdNLp1W7RqqBHjZgMGFfdDMA5SgQ5JR5r3PtHPxEIbv3JVMS9mWNbHtxgTOFCV3QtTGqmUZn 0iEuDCFmIrz5TQaTo34JfNfQSKxpjVjQYWCqDCmEGl6EFqOnguls0mmAvqP+tnhfSx21ZkC9eQy 8nviQm4TSwnZv9iCh/ulu+yU1xvAvIPoxz6Frj6lTG6g9MGXYVScW4oQ67zA88= X-Authority-Info-Out: v=2.4 cv=P/43RyAu c=1 sm=1 tr=0 ts=69dd1f96 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=NuKELtICf0aykZwt-QIA:9 X-Proofpoint-ORIG-GUID: bpTtNxr3sD7a8ZYemr-E43X7j_byJcrs X-Proofpoint-GUID: bpTtNxr3sD7a8ZYemr-E43X7j_byJcrs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 suspectscore=0 malwarescore=0 mlxlogscore=658 spamscore=0 adultscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.68.93; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099302548154100 Content-Type: text/plain; charset="utf-8" Implement APIC IRR interrupt priorities. Even with kernel-irqchip=3Doff, Hyper-V is aware of interrupt priorities and implements CR8/TPR, with the InterruptPriority field being followed. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 7a31dc6427..8cd81fffee 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1588,6 +1588,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) UINT32 reg_count =3D 0; WHV_REGISTER_VALUE reg_values[3]; WHV_REGISTER_NAME reg_names[3]; + int irr =3D apic_get_highest_priority_irr(x86_cpu->apic_state); =20 memset(&new_int, 0, sizeof(new_int)); memset(reg_values, 0, sizeof(reg_values)); @@ -1623,10 +1624,20 @@ static void whpx_vcpu_pre_run(CPUState *cpu) } } =20 + if (irr =3D=3D -1) { + if (pic_get_output(isa_pic)) { + /* In case it's a PIC interrupt */ + irr =3D 0; + } else if (cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)) { + abort(); + } + } + /* Get pending hard interruption or replay one that was overwritten */ if (!whpx_irqchip_in_kernel()) { if (!vcpu->interruption_pending && - vcpu->interruptable && (env->eflags & IF_MASK)) { + vcpu->interruptable && (env->eflags & IF_MASK) + && (vcpu->tpr < irr || irr =3D=3D 0)) { assert(!new_int.InterruptionPending); if (cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD); @@ -1683,13 +1694,17 @@ static void whpx_vcpu_pre_run(CPUState *cpu) } =20 /* Update the state of the interrupt delivery notification */ - if (!vcpu->window_registered && + if ((!vcpu->window_registered || + (vcpu->window_priority < irr && vcpu->window_priority !=3D 0) || + (irr =3D=3D 0 && vcpu->window_priority !=3D 0)) && cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)) { reg_values[reg_count].DeliverabilityNotifications =3D (WHV_X64_DELIVERABILITY_NOTIFICATIONS_REGISTER) { - .InterruptNotification =3D 1 + .InterruptNotification =3D 1, + .InterruptPriority =3D irr >> 4 }; vcpu->window_registered =3D 1; + vcpu->window_priority =3D irr; reg_names[reg_count] =3D WHvX64RegisterDeliverabilityNotifications; reg_count +=3D 1; } @@ -1703,7 +1718,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) reg_names, reg_count, reg_values); if (FAILED(hr)) { error_report("WHPX: Failed to set interrupt state registers," - " hr=3D%08lx", hr); + " hr=3D%08lx, InterruptPriority=3D%i", hr, irr >>= 4); } } } @@ -1919,6 +1934,7 @@ int whpx_vcpu_run(CPUState *cpu) case WHvRunVpExitReasonX64InterruptWindow: vcpu->ready_for_pic_interrupt =3D 1; vcpu->window_registered =3D 0; + vcpu->window_priority =3D 0; ret =3D 0; break; =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099301; cv=none; d=zohomail.com; s=zohoarc; b=kq4wxAqTTm+UWyzKpnD8WmeZumooV/0AAy4u7bQC7mGN69TdUCHhA5zcIRT6dEpHKG0WRj+N+5zcvOwLGxI1GgmjNZBVnjjDTKjohtrznWdYTFtVvdpio3nHCfflHiuprVAHFjddT3psBarbmoXgB3R44XgO2lWc6u3F6j27x60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099301; 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=SCqUAJvB1zqKRh44vHU0QIqywz/suuWsKXqtx/ZiPkM=; b=QI1CmBljYYFM/gofq5Mgu2VmxhvDLPV3jQiKZ1K/bFFEZt+riaBwIyReN/OOVTcrY0G/U2tQ1v1QC7a+tQA/jaWHBagIHwq8NYRPHYnDpIGRM2sYc4uqrhOyo6t3aKo4Ntper7jnR5M+Yp0zrMZ1vSj9ggEHI4YANgyrSP2vdek= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17760993013471020.3373390458218; Mon, 13 Apr 2026 09:55:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKYK-0007Y0-1K; Mon, 13 Apr 2026 12:54:24 -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 1wCKXl-0006wM-74 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:50 -0400 Received: from p-west2-cluster1-host6-snip4-7.eps.apple.com ([57.103.68.60] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXj-0005bA-RA for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:53:48 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id 1F0DB1800EBA; Mon, 13 Apr 2026 16:53:44 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id 4EA1118023A5; Mon, 13 Apr 2026 16:53:41 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099226; x=1778691226; bh=SCqUAJvB1zqKRh44vHU0QIqywz/suuWsKXqtx/ZiPkM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=KM9nd+mzg2DuAAMpzJ9/tpGllWc3XQK533a1LrsD8mDgbRDK6UwCAo6A9hfWAtKYH6+Dp+S6jjJYyECFP5cjDTPYs+8MPgewGZMjPoTNx60gYi8Sv4c8/A3+T9Bcexq9w5IqpLl0NsxVabhltdVqqQB9M7niXcgtrY1Pk219/DYHqQVf3eNQPmlcw+e+T7R0GITOmcmwUg81Ge0GP8H7gIwO8k/F1hPP6fbIc80zyIyPQaOwxeqmSKXNwWEpo1ILfXzNQNy8OKYXyoRC93vpiKJZ1kLV/Zo7HiePfomEpeH56zWVMOt1V3qODq0zDyOAozx0GlNf0J4pZs4t7VodoA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 14/15] hw/intc: apic: disallow APIC reads when disabled Date: Mon, 13 Apr 2026 18:52:16 +0200 Message-ID: <20260413165217.47105-15-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: NcsbE5_Bg3kp2_1-i5uRuQEyXNbecz4D X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX43q0zF5F96mb 0HcNCH5sSnKnfk71SLJ4kUIbnqLPwWPZVS8snrG+Zqwcv5ACnOs/DzVYxJY0Bmw40KWLCXr7oEq 81rZFy3aAmoyav2R1ykUegP4kEBGJcrS4rpcgs2eTV6dyWxseEikdgKE3/18Wzm7JOmPHdPmKeH ovyU4tA1AMoYZKLb20WmqAT3UCy2Llb4uHA48bER8ZdlmRP/GDjdOUvXo91RWRGWFjw20vLV2uG 5Y7as/wMsVURBZglsKWkKItPvDob4tGmx65f5ySX5qOMsDinUK2qtT2q+DFFquUkb0m2y4FYtuJ R0cB8E0IhuIU1jDie1V0/V+0LOLpjBtZUoFLuXUJQX89z2f86qqgpNe1MR6OBY= X-Authority-Info-Out: v=2.4 cv=RpTI7SmK c=1 sm=1 tr=0 ts=69dd1f9a cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Sz3nRv2TKcqVAncp5HQA:9 X-Proofpoint-GUID: NcsbE5_Bg3kp2_1-i5uRuQEyXNbecz4D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=800 mlxscore=0 suspectscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.68.60; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099302564154100 Content-Type: text/plain; charset="utf-8" !APICBASE_ENABLE + attempting to read xAPIC registers is not an allowed com= bination. And neither is x2APIC enabled + attempting to read xAPIC registers Signed-off-by: Mohamed Mediouni --- hw/intc/apic.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/intc/apic.c b/hw/intc/apic.c index 8766ed00b9..c09dddef39 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -875,6 +875,15 @@ static uint64_t apic_mem_read(void *opaque, hwaddr add= r, unsigned size) return -1; } =20 + /* if the xAPIC is disabled, return early. */ + if (!(s->apicbase & MSR_IA32_APICBASE_ENABLE)) { + return 0xffffffff; + } + + if (s->apicbase & MSR_IA32_APICBASE_EXTD) { + return 0xffffffff; + } + index =3D (addr >> 4) & 0xff; apic_register_read(s, index, &val); =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:40:27 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1776099274; cv=none; d=zohomail.com; s=zohoarc; b=CuUnG5jcYkytcONcgHUr6a+30RM/QQ5I2XYSln3A5mAQGGz0TO96kStnJBSCkNB1pkO/tjAs3LroK5L5Xq1myHWzkBBQvckHOhLNOR7UZW0ffXbyuZvyLFUOu0lu0cE3jFAffU+Q49kdqZ0DTiOrwXobsaIwvvSOgiElTnQkOdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776099274; 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=M6AkUUrPcxLOfhXzaNmZevrpR2eORr3l/18/Pdjn4vI=; b=jkFuIdNE0zN9AmOeu6LYzJyGJ3fKdt10Kqr/4pShECy8aZj0Xs8KPHXo3HNzUuy3PhOObFBM1h0fL/9JGLV+uzNCamH3zshdIGJngq8xpT5v06INoZTXqUScjmdZhA+ixRVYMTsl36JFZmgj38Sutc+hM9dN8ltxv3zMdb36ABg= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17760992740461.9257529903239856; Mon, 13 Apr 2026 09:54:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCKYL-0007i6-99; Mon, 13 Apr 2026 12:54: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 1wCKXz-0007I8-1n for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:54:07 -0400 Received: from p-west2-cluster1-host4-snip4-10.eps.apple.com ([57.103.68.83] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCKXu-0005e3-MV for qemu-devel@nongnu.org; Mon, 13 Apr 2026 12:54:00 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPS id A0426180034A; Mon, 13 Apr 2026 16:53:56 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-1 (Postfix) with ESMTPSA id BD38E1800194; Mon, 13 Apr 2026 16:53:44 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776099237; x=1778691237; bh=M6AkUUrPcxLOfhXzaNmZevrpR2eORr3l/18/Pdjn4vI=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=OgLZx6IPu5x4SSSqvMQ1E5Du4H3PPhn+U1J/OqTruzTCFeOGa4RFgRWYTxZCpTdLFVDw2etRTgEWlvXCqYgSGYZEVoVa1INu7vqhVTRHWD+Cr6KxwPRlxUyCv8UzgZUzjvlKM8tcqJTf5AM89YdjKDSPYQZUiZZxHwjtfeTHAts+mvelmqhMIiNzSLSVByG+5aS+Dj0cDlqRQk1n7lR39HsxwX41gRO/jYaFAen+NrZS0YVzFrZTDjqCvxACybyeta0X3xY6E2ujlaDfLgl8NjQ+rvtTrkoQM7d8T5uyN6pPsumsYnUebBiIHmYZqXUohGUDfsnKvPRNWuQiCwtmaA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Pedro Barbuda , Mohamed Mediouni , Paolo Bonzini , Zhao Liu , Roman Bolshakov , Wei Liu , Phil Dennis-Jordan Subject: [PATCH v11 15/15] whpx: i386: fix CPUID[1:EDX].APIC reporting Date: Mon, 13 Apr 2026 18:52:17 +0200 Message-ID: <20260413165217.47105-16-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413165217.47105-1-mohamed@unpredictable.fr> References: <20260413165217.47105-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: PaMtK1GHS8JZ0iZKr6Stx4zKr--eHmql X-Proofpoint-ORIG-GUID: PaMtK1GHS8JZ0iZKr6Stx4zKr--eHmql X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE2NiBTYWx0ZWRfX3nS9x2FJOIM+ P+X/cl10PVZixRY+pd4yPdLPxti3eH6Rwp1Nh4u5m9K72pgs5LkhpEUSfVM4rKNxV2/9APZvE0R ZPsNBjel/GzJZS51UFBZGXyA9LFYsqzD6QcwjldW5RHb2nOY7E8t0JfXxmFnZDH7SVKaeAsa0am m4NV9InzePzTWTJM+1pHVM7tghAU4XPbB0ZANxERlAVeO7JgaZVK/hM8NxOyMBbisIeH+FKEJQ2 zo7P1yQxYdcBhdk9sBoKzp8kGfvNQxb4n6olERydFhbk1hWigUaoc/7aerrYj2aW3ng3FTJ3yJZ Ja3EbiDkPMn+UyN1EcW0xAdiH/9YpFCA+jBrju/bOFlznQCUNVpWc/e8uCkPTM= X-Authority-Info-Out: v=2.4 cv=fZqgCkQF c=1 sm=1 tr=0 ts=69dd1fa5 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=ljJ9V6m273jqBh-Cp98A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=856 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 clxscore=1030 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130166 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=57.103.68.83; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: 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 @unpredictable.fr) X-ZM-MESSAGEID: 1776099276087154100 Content-Type: text/plain; charset="utf-8" Hyper-V always has CPUID[1:EDX].APIC set, even when the APIC isn't enabled = yet. Work around this by also using the APICBASE trap for kernel-irqchip=3Don. Signed-off-by: Mohamed Mediouni --- include/system/whpx-common.h | 1 - target/i386/whpx/whpx-all.c | 34 ++++++++--------- target/i386/whpx/whpx-apic.c | 71 ++++++++++++++++++++++++++++++++++-- 3 files changed, 84 insertions(+), 22 deletions(-) diff --git a/include/system/whpx-common.h b/include/system/whpx-common.h index 3406c20fec..79710e2fb3 100644 --- a/include/system/whpx-common.h +++ b/include/system/whpx-common.h @@ -8,7 +8,6 @@ struct AccelCPUState { bool interruptable; bool ready_for_pic_interrupt; uint64_t tpr; - uint64_t apic_base; bool interruption_pending; /* Must be the last field as it may have a tail */ WHV_RUN_VP_EXIT_CONTEXT exit_ctx; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 8cd81fffee..9ce73261c2 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -139,7 +139,6 @@ static const WHV_REGISTER_NAME whpx_register_names[] = =3D { #ifdef TARGET_X86_64 WHvX64RegisterKernelGsBase, #endif - WHvX64RegisterApicBase, /* WHvX64RegisterPat, */ WHvX64RegisterSysenterCs, WHvX64RegisterSysenterEip, @@ -401,7 +400,6 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel l= evel) r86 =3D !(env->cr[0] & CR0_PE_MASK); =20 vcpu->tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); - vcpu->apic_base =3D cpu_get_apic_base(x86_cpu->apic_state); =20 idx =3D 0; =20 @@ -519,9 +517,6 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel l= evel) vcxt.values[idx++].Reg64 =3D env->kernelgsbase; #endif =20 - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterApicBase); - vcxt.values[idx++].Reg64 =3D vcpu->apic_base; - /* WHvX64RegisterPat - Skipped */ =20 assert(whpx_register_names[idx] =3D=3D WHvX64RegisterSysenterCs); @@ -556,6 +551,12 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel = level) error_report("WHPX: Failed to set virtual processor context, hr=3D= %08lx", hr); } + + if (level >=3D WHPX_LEVEL_FULL_STATE) { + WHV_REGISTER_VALUE apic_base =3D {}; + apic_base.Reg64 =3D cpu_get_apic_base(X86_CPU(cpu)->apic_state); + whpx_set_reg(cpu, WHvX64RegisterApicBase, apic_base); + } } =20 static int whpx_get_tsc(CPUState *cpu) @@ -647,7 +648,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) X86CPU *x86_cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86_cpu->env; struct whpx_register_set vcxt; - uint64_t tpr, apic_base; + uint64_t tpr; HRESULT hr; int idx; int idx_next; @@ -779,13 +780,6 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel = level) env->kernelgsbase =3D vcxt.values[idx++].Reg64; #endif =20 - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterApicBase); - apic_base =3D vcxt.values[idx++].Reg64; - if (apic_base !=3D vcpu->apic_base) { - vcpu->apic_base =3D apic_base; - cpu_set_apic_base(x86_cpu->apic_state, vcpu->apic_base); - } - /* WHvX64RegisterPat - Skipped */ =20 assert(whpx_register_names[idx] =3D=3D WHvX64RegisterSysenterCs); @@ -1997,8 +1991,7 @@ int whpx_vcpu_run(CPUState *cpu) val =3D X86_CPU(cpu)->env.apic_bus_freq; } =20 - if (!whpx_irqchip_in_kernel() && - vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D MSR_IA32_APICBAS= E) { + if (vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D MSR_IA32_APICBAS= E) { is_known_msr =3D 1; if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { /* Read path unreachable on Hyper-V */ @@ -2164,6 +2157,13 @@ int whpx_vcpu_run(CPUState *cpu) } else { reg_values[2].Reg32 &=3D CPUID_EXT_X2APIC; } + + /* CPUID[1:EDX].APIC is dynamic */ + if (env->features[FEAT_1_EDX] & CPUID_APIC) { + reg_values[3].Reg32 |=3D CPUID_APIC; + } else { + reg_values[3].Reg32 &=3D ~CPUID_APIC; + } } =20 /* Dynamic depending on XCR0 and XSS, so query DefaultResult */ @@ -2725,9 +2725,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) =20 memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.X64MsrExitBitmap.UnhandledMsrs =3D 1; - if (!whpx_irqchip_in_kernel()) { - prop.X64MsrExitBitmap.ApicBaseMsrWrite =3D 1; - } + prop.X64MsrExitBitmap.ApicBaseMsrWrite =3D 1; =20 hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, diff --git a/target/i386/whpx/whpx-apic.c b/target/i386/whpx/whpx-apic.c index f26ecaf6e8..65629ca45f 100644 --- a/target/i386/whpx/whpx-apic.c +++ b/target/i386/whpx/whpx-apic.c @@ -90,9 +90,70 @@ static void whpx_get_apic_state(APICCommonState *s, apic_next_timer(s, s->initial_count_load_time); } =20 -static int whpx_apic_set_base(APICCommonState *s, uint64_t val) +static int apic_set_base_check(APICCommonState *s, uint64_t val) { - s->apicbase =3D val; + /* Enable x2apic when x2apic is not supported by CPU */ + if (!cpu_has_x2apic_feature(&s->cpu->env) && + val & MSR_IA32_APICBASE_EXTD) { + return -1; + } + + /* + * Transition into invalid state + * (s->apicbase & MSR_IA32_APICBASE_ENABLE =3D=3D 0) && + * (s->apicbase & MSR_IA32_APICBASE_EXTD) =3D=3D 1 + */ + if (!(val & MSR_IA32_APICBASE_ENABLE) && + (val & MSR_IA32_APICBASE_EXTD)) { + return -1; + } + + /* Invalid transition from disabled mode to x2APIC */ + if (!(s->apicbase & MSR_IA32_APICBASE_ENABLE) && + !(s->apicbase & MSR_IA32_APICBASE_EXTD) && + (val & MSR_IA32_APICBASE_ENABLE) && + (val & MSR_IA32_APICBASE_EXTD)) { + return -1; + } + + /* Invalid transition from x2APIC to xAPIC */ + if ((s->apicbase & MSR_IA32_APICBASE_ENABLE) && + (s->apicbase & MSR_IA32_APICBASE_EXTD) && + (val & MSR_IA32_APICBASE_ENABLE) && + !(val & MSR_IA32_APICBASE_EXTD)) { + return -1; + } + + return 0; +} + +static int apic_set_base(APICCommonState *s, uint64_t val) +{ + if (apic_set_base_check(s, val) < 0) { + return -1; + } + + s->apicbase =3D (val & MSR_IA32_APICBASE_BASE) | + (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE)); + if (!(val & MSR_IA32_APICBASE_ENABLE)) { + s->apicbase &=3D ~MSR_IA32_APICBASE_ENABLE; + cpu_clear_apic_feature(&s->cpu->env); + } + + /* Transition from disabled mode to xAPIC */ + if (!(s->apicbase & MSR_IA32_APICBASE_ENABLE) && + (val & MSR_IA32_APICBASE_ENABLE)) { + s->apicbase |=3D MSR_IA32_APICBASE_ENABLE; + cpu_set_apic_feature(&s->cpu->env); + } + + /* Transition from xAPIC to x2APIC */ + if (cpu_has_x2apic_feature(&s->cpu->env) && + !(s->apicbase & MSR_IA32_APICBASE_EXTD) && + (val & MSR_IA32_APICBASE_EXTD)) { + s->apicbase |=3D MSR_IA32_APICBASE_EXTD; + } + return 0; } =20 @@ -235,6 +296,10 @@ static void whpx_apic_mem_write(void *opaque, hwaddr a= ddr, static const MemoryRegionOps whpx_apic_io_ops =3D { .read =3D whpx_apic_mem_read, .write =3D whpx_apic_mem_write, + .impl.min_access_size =3D 1, + .impl.max_access_size =3D 4, + .valid.min_access_size =3D 1, + .valid.max_access_size =3D 4, .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 @@ -262,7 +327,7 @@ static void whpx_apic_class_init(ObjectClass *klass, co= nst void *data) =20 k->realize =3D whpx_apic_realize; k->reset =3D whpx_apic_reset; - k->set_base =3D whpx_apic_set_base; + k->set_base =3D apic_set_base; k->set_tpr =3D whpx_apic_set_tpr; k->get_tpr =3D whpx_apic_get_tpr; k->post_load =3D whpx_apic_post_load; --=20 2.50.1 (Apple Git-155)