From nobody Thu Apr 30 00:40:29 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=1776113562; cv=none; d=zohomail.com; s=zohoarc; b=jvBclChCpGAOgg/4Pu1bvjSQsK0BQHwWquKZR+aYOQsMQ9xqoGyQz2yuavLsWRREeO9881GYDQq+QgRzW8L23BJttT+RqHVM2CAE2wqW+wbGyL6W3WGDz2R2lF2CowkaADA6tJipGvp35KXINDaHUQuSFM4py9C7sMwjo3WxMNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113562; 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=c07K0RY9joX/G91v2zv8VXBENA3PZC1ucnR3rSwGiBvH1Nu103bj6rsIZNxe+Dlvyav77TpTJ8UbKeHTNWsscKIdAPo4ccr9x46fdJo8UIkVQ0+82hs7H9ddHI4kM0XOXfBideV9ej5rOE3aok6rJBayw5dbkWTe1aN//kGRmQY= 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 1776113561796276.1284685624097; Mon, 13 Apr 2026 13:52:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGe-0007Mi-Js; Mon, 13 Apr 2026 16:52: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 1wCOGZ-0007LW-RU for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:19 -0400 Received: from ci-2007e-snip4-11.eps.apple.com ([57.103.88.53] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGY-0007tp-5W for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:19 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 7C3EC180016F; Mon, 13 Apr 2026 20:52:14 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 7A2821800206; Mon, 13 Apr 2026 20:52:12 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113537; x=1778705537; bh=jSFEY3OW57r5Gmf0SB6G349rIgUNCT10rXc1M/CBSww=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=UYw3IAS8ndwoCx3n0WEgDoCzqTCJ8txe9uVnnCUIgzMbC5dpjHhXaN/diBIcIbFTtQ/UqCqoF6C0FKZy4Bt+kCbK88YPBQeCqhPERqkwKPBfe8L+TD3Ydbt1E0JP6aRIj2LMfONVuJvYWRfGxt0NmcDLmBy/OIrCLIgmk7YwRakWz9OziZgwHLOyvU0nZf33wlk/liKKNLKEFveMlD0p1raCgNl4891C3DI6dgpyxw3bgSIARXQYtwwZxuVeT613kDVZE3I1lUbB4WtSx/CIlWzRqqZLXWseshyWo2GMgYThsKPKImCscRj9JxenSgqVqTPJDpOGnzvH0OEOV9KuGQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 01/15] target/i386: emulate: include name of unhandled instruction Date: Mon, 13 Apr 2026 22:51:53 +0200 Message-ID: <20260413205208.50643-2-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: CYG-t-37XGIgiOmn8q8rFbJkxRSmFyj5 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX6zaM1b+F8x5E AAF4SIc6iQBX3kJpl3H+wHMhY/FOneXGHqzXME/d55ea+ejC273l5ySHhBfoGO2S5UCajN64uiE XRCIEv4CU81QM/CNFTwLKQ9BdXOEqRTR9kdazRee1rNrZOXL65U8IrQnExChJk/+FF4VhcVrtc7 0sIdfntHFU6GNCr4fAccCr6B6X1ABD5GkC4gcvkqq/x2K5VIlZKI2dyIVedLhljsWH/datPzP3G 8l5CuX1UK2k46AR7vK/MwhLnUShuaDrrVQwYYmazjBKerE9KU3X8MujcMgRC2ltbkjOhiCI79I0 SAKI+kyZSMgyyyQbNLuGrNaVPT1BI7juuwi9OZTgwWO3Fr2GQ2rZ8tvIVeI6JE= X-Proofpoint-GUID: CYG-t-37XGIgiOmn8q8rFbJkxRSmFyj5 X-Authority-Info-Out: v=2.4 cv=DohbOW/+ c=1 sm=1 tr=0 ts=69dd577f cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==: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-2604130205 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.88.53; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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_H5=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: 1776113566793154100 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:29 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=1776113572; cv=none; d=zohomail.com; s=zohoarc; b=dq7bYonf/hPQ33+wTY0y8g9UamrWFvuQ/n/IhNjVgLFVlCWbBBtxpBZSwyKTbgq11vknXoEEoQj06koxxJBja8+u5qBOKrqtJbhT7sLmE1p1D9BZM0IN6MGqEWMOGrLtsokrUu0GQnMdG/rK1fjPoBYW5NO9BNXQzcZAipNb1x4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113572; 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=JkUrC0TetvtuWl7QDZ9bivu3rC/HPb6eVACqWQxl9+mSaKDu3NN8Ytx5nEgRUPAYXjdnHa4Kg9eomWFI+15wks7GYmT1Rj8HI+q+kQF6n46lvpM8B5ZbtMZ22rHcfYRA9jFpT59Oa6JIW5ZMfg1GXrh1bxK88AgFGU3iwAiOn70= 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 1776113571787156.27220082042754; Mon, 13 Apr 2026 13:52:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGc-0007MB-UU; Mon, 13 Apr 2026 16:52:23 -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 1wCOGa-0007Li-Ka for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:20 -0400 Received: from ci-2007f-snip4-1.eps.apple.com ([57.103.88.54] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGY-0007to-8z for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:20 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 9EC621800178; Mon, 13 Apr 2026 20:52:15 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 04FBE1800165; Mon, 13 Apr 2026 20:52:13 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113537; x=1778705537; bh=zl2db1VwfCW29E4LtwT7zz4buZdQP1VZYTXVu1kcs+o=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=XtfUQaIuYteIDC0aZVXHLC2lN5tz51zg3RY86fq9pzN5csSJhyhZ60olDjhFZUXUafhDXrjdrvo9j+7LN3LiRtFlEPbN2uVJsRHIzfaUzCAM3hn0/C/0VJo9wQAAW0LspOtd7zFn52X/DUii213pUApO4Mfz3Pz5v+CRgjk6RvsbHPFQS2Fa3cU7gaFqa6gRO2DeRjSa4nj10ZJ1FVSZ1guEo6vuym/VA2iyi06o5Vn/ZpzcxtN9W7FnYYFVguwYkQKqynYKRTdvFjRTEvKgPd1uYJQSh/f4MsBZttBZvnZo610QfsjSQo9B/NHcRfxoFx8DQNYe1aQQsK8KdSurvg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 02/15] whpx: i386: x2apic emulation Date: Mon, 13 Apr 2026 22:51:54 +0200 Message-ID: <20260413205208.50643-3-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: h3ZS0o0cFPiNUC7A843hrtN8U4PF8yo4 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX9M0Obmo4G2b1 NGUVRS7avlgtk8tHdovUg4DFPo0LPbiFcK+Z5DSm2OPCQgxML6E6wi/bDiZ268YcLIcrZEQMq24 BbINUfM9QKf7bBZChPerLn40SfQORZSDe+FIHp3h6BPQKq/irTFJqU37IlYpduCvAPAjZQ9Z0ai 7vha19926iQo8kKdGIcWfDB9FrndaXZjamKUoHZ6JYBkv9FPKjAwABhBbR7e7xtpFBNYxCsQFrS gk3IAHwgJzM0O2nvVpPqskqt+OJY9QAmXfYX/578FuoD0XeQKAz2U15Wm1sxtY/CAH8fHT2tSYi Mmpbphp74fMXfIvfA8IovYRiyxtgOm8TE0zpbHQqqFr+xeY3piteBmZntUQyVE= X-Authority-Info-Out: v=2.4 cv=L4cQguT8 c=1 sm=1 tr=0 ts=69dd5780 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nj4AhdDZwDx412jv8JQA:9 X-Proofpoint-GUID: h3ZS0o0cFPiNUC7A843hrtN8U4PF8yo4 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 bulkscore=0 spamscore=0 clxscore=1030 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=734 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.54; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113575128158500 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:29 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=1776113627; cv=none; d=zohomail.com; s=zohoarc; b=ZU3trk88iVPHiii9NGJXRxQG1+aMjGBGVfLhQA/ssroiWsJn109dXcliqPPFv+gjX2BKBuT5m6QHf8f+8vvZQtTK33QQQqn/EPq5CxkIhJKrwA0ijMuxAmEKOq3hiiDfS4BEEQ2lLszrlwGObxB5NXHljNXTpWiI2yyxT5qur5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113627; 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=Bkt0o9ryOPBh9g1nTo4lxwK/iYw7N74KyFeFW/PQ2xdwZmyv8hkNFM6wuYv2sIGyXisI2Zw9Mr5s6poNSX7RmSRhuDR2a5dvXwui97HjKknn7U9WF97AgjzhK8KW4KScEIbiSvnTeaFxVRe+nsDcxKPoMhLBbW6sJHWuozI1vvg= 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 1776113627452272.53302678307716; Mon, 13 Apr 2026 13:53:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGf-0007NF-DY; Mon, 13 Apr 2026 16:52: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 1wCOGc-0007MA-Ax for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:22 -0400 Received: from ci-2007a-snip4-2.eps.apple.com ([57.103.88.5] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGa-0007u8-CF for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:22 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 8A551180014C; Mon, 13 Apr 2026 20:52:17 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 824121800167; Mon, 13 Apr 2026 20:52:15 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113539; x=1778705539; bh=Ash1yi3VlTyxdP0Aar5CNwwUDY+XErFVJjyfbU7EpDA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JdJiR1ST+AYlf1CnHTprZEco84Dv0XFHLSyHjvBnJ1PRrtK6BhV8eEQTiQxpYtl4gQmBgPAWYyg45qwxhZ8RvKw9m0rO9DlI7Uho3Gr2NysScOlKflU7Z6tNiW0cp2T1oZoBAeYVidp2vPbDwPFOTLKplpssl1uKUFT9BKctlKKlvnNv5MkjLZ0pFF7Y8VWkuHdGeCptOwbfaSAjrQK29CakCyANCybZalUSs0DnMTcPK1mhGeCcx9gfG23dXgkSotz9GUjL1lU6rpRdLvxG2Yt0+/hB6JYuGncwmPAL0b4fum+tdOsg7WO/LZ0O9jcfz7aDquW926yq6H80y61OZA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 03/15] whpx: i386: wire up feature probing Date: Mon, 13 Apr 2026 22:51:55 +0200 Message-ID: <20260413205208.50643-4-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 07dG4wjafw9-7E62iZAK4epn35sBgK1r X-Proofpoint-GUID: 07dG4wjafw9-7E62iZAK4epn35sBgK1r X-Authority-Info-Out: v=2.4 cv=QKdlhwLL c=1 sm=1 tr=0 ts=69dd5782 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Gr33WSPopR-aU8k7cJUA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX3/aibxZE5Ekv DQcYEgQulM6BtCDclyJztKGS84WBkwuaoi2Hd9y31WVSyu1itT2ffdneoEaIZLfwIZWKQ178qOg MZZRRHhT02ieLrXrsS2tn191QTriq4xhKPOMqSzxDgCMim+kdVkQzfsR1cvyVUoXGKWojwfccTY 0gKsi/ZeDAQ43HQfXw7nyvl/t5zTGdS1KxnijbFhVSYS+7M0QC613ENlGhq3ZJdfIlJjBNeP/SE L6A/QKFWD7puiDStL+BCAR4lqNuXzMEJHoZi0F9tL7p7AoChcwkKWJb4HFTtYtBlNX7/PCAE2si SMMj1ayjrJqpdDQIcXi8E1PXhd/nKAKMlkLyISsh/vCNIieEGQtGraJy3rZ3PA= 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=985 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1030 phishscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.5; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113630775154100 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:29 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=1776113642; cv=none; d=zohomail.com; s=zohoarc; b=l6uoDW7wMBjh+50TkBgga1iJHN4bQGyIxVG8axiC2omPRavS/CLHjA2t/SyM62UrNJQI3AUPL82wuKa5mY9W5P/Jn44j++EpdRPoFnAwFuPbR659xd2Sz6AXjFXAfNODd+pvgPL8WoWXhwzTylQXVB0Ex3g5q95npYoO5E7Id20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113642; 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=Vtz1IFhQtqJQcFppHQfdCOo9MXWoIhmzCh3ryzAmTR4OQFum/G0Ep9oglj2rN5OoshFi+V6Nsi92bIeme0S8DkVphUuIjUxe1DfqNuUzLM7s2QD7O5ZkGF/jlMnBYSMUcrvt3yYFmhHRmgFzMfTfNtANmJgfWLjFeJ8eGyl63Ec= 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 1776113642556737.865242359659; Mon, 13 Apr 2026 13:54:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGj-0007OS-FU; Mon, 13 Apr 2026 16:52:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGd-0007Mc-J4 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:23 -0400 Received: from ci-2007f-snip4-1.eps.apple.com ([57.103.88.54] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGb-0007uP-Vq for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:23 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 250BB1800147; Mon, 13 Apr 2026 20:52:18 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 0E1F01800211; Mon, 13 Apr 2026 20:52:16 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113541; x=1778705541; bh=LeCfULzXVq8eMeXoD4HoazACVFGuCL5m06fQgObX99k=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=gzgkuZPTnQ5n6PXJEZE9sp5kL19ZdfGQjSAl3i9gAzu6jSCdnDnKmVN4sFqnhGZC8uC4ASPComF4UalYPOWUUTqm9Z0fJc1g+xcorjFyk4vAH+HRyh4ZCIx4iGImgFXZiP0jnX5HvuX7I+Gs5qwksTs0V4055eSoXuloynnFWSRAWOsX1eDW/jnmG0oQDfaP/DKeRngR8GKv6TY2B128VlmoC9+MEEykCm7Vz3W0Dk3vx+DztSPl1WbgheAUyDHfaIqwxT1r139v8iDktW/G29+F4UNbi4iZGqg0c6X3vYSx64kc4ULwAdSai+bi/98fc37QcDAelyP1wNicaZth1g== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 04/15] whpx: i386: disable TbFlushHypercalls for emulated LAPIC Date: Mon, 13 Apr 2026 22:51:56 +0200 Message-ID: <20260413205208.50643-5-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: bYvnuCF5BLA837qfaaJdOrj9fOb6L6ol X-Proofpoint-GUID: bYvnuCF5BLA837qfaaJdOrj9fOb6L6ol X-Authority-Info-Out: v=2.4 cv=QKdlhwLL c=1 sm=1 tr=0 ts=69dd5784 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Rm0zj2O9plGGl-KjdfMA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX3J23nd5bMFi3 pdKNWQenNvlRzOJZpxjIj+XS9gJ0pfDzkkYaVKMV2KWnkq2bGswoQLRnTjCMru0Gm4dSUnOmdpZ db/lVXGzZ3u8lCvGDcgGhnesrz8iVzDDguSEhlWio9sbfAvbSBeGWARy5pydy8f81HcC6dJUHjA Sf2uoIkH9gcj+U5sV+RLlxEOJ/MDO0NO01i59xamXbaXGiHg6I3JpgDNx/dyiVd8OzQ8vRMFWtP r+KtpxM0DwKonAAVnhrV0GdtTAhvxUmDkGlzC8kPr48dxPt2dUfeWJZDRQNyjhj54IzxA5rWtxh NSBrijviEFxBi4bimP0YO12qt2n0RtfylKnZABw1bMwcn4TVmCXMvYotpru1Xk= 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=710 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1030 phishscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.54; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113644612154100 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:29 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=1776113602; cv=none; d=zohomail.com; s=zohoarc; b=m6olSwA0Sh0TV4jQilAZY+YP0zV93Vp4uMUBfHlTU1zSgPDAtjXpRUgzxRLPmFsKgcCd+CakoCn6Dbj+/cbOOo01nimOGoB00pxEkXBYekL3akrfQ4QMOWAg7n1kyGiFnYbMLAYygl/j7thd7rhG68XsQYJKlqVP4lJzpBqRvDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113602; 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=OQeWBHgvIlXGwyv5Ur1g4VqTkpWq0CTegjWSQf1+jIpXfuYBF2P2RS5T5xPoO//1GGKmhDCAIqjy8DHJUf1K5PQiSh9MK6zp0f63MCRXcGSeUprfEU2E47jZvfw8sZElHY9aGTcJHFhIV0pDVuv4agdM74TmkBTpiuEZXqTPZw0= 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 1776113602079594.0367950108979; Mon, 13 Apr 2026 13:53:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGh-0007Nu-Fw; Mon, 13 Apr 2026 16:52:27 -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 1wCOGf-0007NA-52 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:25 -0400 Received: from ci-2007i-snip4-7.eps.apple.com ([57.103.88.90] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGd-0007ua-5Y for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:24 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 7EA061800206; Mon, 13 Apr 2026 20:52:20 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 8E7D0180015F; Mon, 13 Apr 2026 20:52:18 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113542; x=1778705542; bh=dugTy6Mycl0V8PO55M7zjkrIKW6irE2gkRf+Eg5CDxE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Y2MT6ejife1jhSJrpzwK9WzEvOzCzVvmCG/KZj+MB1IKT5xzEzb2dELH9LXqOXkBb+arxGyG9nIgHMC8zsy13jGaMe3PpFDflPTW6TEvb5eC3zyBBv/MNIq9AnxqzINl4rJJTR2btbYTF/B186m44bZ0eAKKm7PuIG29hMqNtRTI+1fFdcfY8Hq8SgGwjVPKNGGYbxID+/CyocPIei+VrHr6kd8R4/wRsMiBRlMuo0XIdy9yrr+BveUy0H9STCSizGRUPGwytlJ9ZvQgvIYkK28cF/PX9bwiEvohKeQlDyC7MfJgTkR2bHPgl0u7xpWidL1SMKEnmylCBxx49DgCZg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 05/15] whpx: i386: enable x2apic by default for user-mode LAPIC Date: Mon, 13 Apr 2026 22:51:57 +0200 Message-ID: <20260413205208.50643-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: dAP6Isrp7E3nh5ntkGQSpLu9qTJ3Ty6X X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfXyWHGE5ckei5l b+mrXv4pdyU96VL5Hpe4s1RhgKXVGjJTo7PnTKqg/hBRPli4LV8U2MMsbQgwu/OmwXfnBYl8mC6 vori+fErZvWE6Fkz1PzaP1te0Gq42W+ZRFKictmnhw3cMjVa/YcmB3RvOd4MjXC+hm/u51KWxy0 OgC1gTli6sV785jB4AW+ld55Y9hPrwEFLu0dthB2LG3x7KWMzXNvby0ThbDEqWGw5qh4avF4IaT VjoKq2IYq2eeIbXTPL0Opa4JO86A+z5bxIrEQEPlwQb7L6ZdzH/W2QHXFNXoeFlQcSOgLkaLq7z qz0scTFTQrN/Uz1JY/RLBtRanfFujHNpB5IVZPsKy2CYsCRuk+zzYq3M6XlYLk= X-Proofpoint-GUID: dAP6Isrp7E3nh5ntkGQSpLu9qTJ3Ty6X X-Authority-Info-Out: v=2.4 cv=DohbOW/+ c=1 sm=1 tr=0 ts=69dd5785 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=uAk9FrDoCeqUxh5yT_MA: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-2604130205 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.88.90; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113602814158500 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:29 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=1776113640; cv=none; d=zohomail.com; s=zohoarc; b=M9NAduZNA4Y6haWUrS+qdo2yiuPNVnI1TiF2fXLRnM0HQpyCx6yFkqwVdcqE+hBmh7gpI3FEL6SKiyScP1rBoa79ryAPz8hnF8aOQsIs83B4HQjhN0CApYd9Hdm0h83YsOPZHBE2UhUo4tCNLDyLi8C6AumkFEF2uAyT61P2ZJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113640; 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=VjOtuRI1M8ba4okLW2M4dVE7+RIJupnzCQjQ7/RZ6ZOWWrl9dO3SXS9kpIgeab6t2RS6oW/ZTe+uIE4JplYigylTsLsR++A3ijPfPXPSH2v5qxxhVWPE1niXJ3sg0Xl/FiQU10fBUPj/WKlD+omlynCdiUOws+SAdtZddN6GfRo= 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 1776113640854947.6494239417082; Mon, 13 Apr 2026 13: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 1wCOGj-0007Ol-K2; Mon, 13 Apr 2026 16:52:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGi-0007OD-25 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:28 -0400 Received: from ci-2007h-snip4-8.eps.apple.com ([57.103.88.81] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGg-0007v1-Bu for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:27 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 09AC7180020D; Mon, 13 Apr 2026 20:52:21 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 2625518000B4; Mon, 13 Apr 2026 20:52:20 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113543; x=1778705543; bh=oQob0705w1vpsKwSbilmxpp8KQiyruObQqebQ5RZ0Dc=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=bBLLG90P4n96ANwvqgosJqidyYxI+5hWZoM8gPccXx9Cd5BGJJRGpNkUTDvq9dpCosc/Tj0+vL4P1JjxPq9hmY1IvEfUd7klvMZlNpXDTEQWD0TzfHacHhErUdFysBfMkijDTn5Q/S0kLE5CeHv60npygrYWclKXLGOuC42GvMgai7umqB+XLDxiaoy6+cN6V1XGD6H2waPE+HhHD62lcKo7WOwrKBwFsjFyE1uErRtDMiATDVwE0EKx9NFgrIj2hHyGMBBco9Yarsm2fqaZVVwGJHsl3TPxOsH890KHjXSPrvDVw1nu2O4gXSRy/sYXeQCBMdMdnuZy1mwezXY3ZQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 06/15] whpx: i386: reintroduce enlightenments for Windows 10 Date: Mon, 13 Apr 2026 22:51:58 +0200 Message-ID: <20260413205208.50643-7-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: urkTktMEzh8xMB3venT2IX1F64fTmL06 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX1G+ZaxGUjTkB /N0gHbSc3jwZqVEdT+HbvDCGPXzIRdTP0Zm3LtSQEF4Qz5RnnTXbQ1mQoYjq85GmSMbwxl2Bd1b MDYRsxu/Kph+7kqsg9IauVQDu3foW6wcB4UOZCTiupZQ7eI8qpSg1jlR4L8VeC05p71CJN7KiXA tAx7jqMhADlvrv/BJCuIiJUCJVsjPAmqvWakkwMGEmMRnekh3jKBdAEy4aOYBU/+YSRVsEHV5bH Shq8V6yjFDoXuhDH+mv6k0A4AbiS8RAgNyLjBo0SB8Pk5zyikTdI9ASXjWd2Swd0Gl6Cq4Pr2J1 3GdpAjanmgRRkllk23Ib0zo5aFk5xDgCscA1EytZDT6IoI9hWTGFr7PVXAb73k= X-Authority-Info-Out: v=2.4 cv=Cu2ys34D c=1 sm=1 tr=0 ts=69dd5786 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=hfWBbujXMTx1PmRkPVYA:9 X-Proofpoint-GUID: urkTktMEzh8xMB3venT2IX1F64fTmL06 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=999 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.81; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113642662154100 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:29 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=1776113602; cv=none; d=zohomail.com; s=zohoarc; b=Kbdd46DRF6rxMKtJQ/MtSBbc1Su8Qz0rvka65sLPdEZCoDpMXyGHjHI7YbBywIcfdLYrN3Mfq5XlD3IaaA3VczDUa22wuPiD76//vNIY58zshbTJe22BdUJtVP18wDxAhr1ifTD7IrLAh2zJoVWq/T90HTBCcmaFCyTYlFaqxDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113602; 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=EVk7bE2V+VmjfYzeC4rcEHUVjAAr1DCyfjwIKPR2nw95ctqcBanzVdVEV5fDR9NNifIQ1GS4QJaG5OT5LURtfZUY4qxIU1hBWUZBdIwlPE84NzpPRtFCRtV/t9Pk3cySA4U85jvGEPnKBXTCjFTwXGwhkgpHESWMdw86cd7AyJE= 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 1776113601829472.6769180220515; Mon, 13 Apr 2026 13:53:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGk-0007PJ-9j; Mon, 13 Apr 2026 16:52:30 -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 1wCOGj-0007Oe-Cq for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:29 -0400 Received: from ci-2007l-snip4-2.eps.apple.com ([57.103.88.115] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGh-0007vK-BO for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:29 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id A506E180020A; Mon, 13 Apr 2026 20:52:23 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id A6A94180020C; Mon, 13 Apr 2026 20:52:21 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113546; x=1778705546; bh=6tmGSEaUrE0Q7MlYX6psbx8TA0g5EcgDAZR7bSJpGEE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=XPdXk5QxhRBdaRL+Cfl0tr1WtaZt1fgM1880yu61MXk8pPduwQhjHn3dmC+RDsp7YeKU3FnR651+ISMZRSE6EG1aB6OC505c3DAIQ4bxyke9W/hQdmaTGUg3lZ+fVl2/7toSDjw80zosnjrP+TggDWOLubDi6y7Pe3G3OtT5fuZiUGHz5wt6DvSLmRgA1J458bUW/KKGKknqg5ueYtfjAevri2u3/UmY2tetjsd0NIpUiDE5BcJt+2bbnspiuJ+IXNQILdj0o0RfDrWfx0Vh9zYbRbQpRLtkHZ1IcaQ52zeJuGz29ZrAt0+vZA87mQz29Z/njGDmJI3eilJmi5qNew== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 07/15] whpx: i386: introduce proper cpuid support Date: Mon, 13 Apr 2026 22:51:59 +0200 Message-ID: <20260413205208.50643-8-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX4r1ysznE3swW Z1HL25+KL3+zNNzipa4/ClDvW89ok5iEVACVsjHOMtalxF8z/1sXgzhlAIa8FI4s7GAzg8fhWBX LfV/URXLEhOc3DyqjZTJYDtzPxOd+8ZZbv+81KNy0EosHbeLOlElhBmPQaz06kVyf4DcdAKUl3c oqWYDFoZ9eWu0UMQDiVCHRUBi/9AwmQQFdblDqA4GDoaKi21N8/JGLHXoAY/p44RGppnWMnoCtJ 3UqOgT+wByqxIP9gc+gR3udGU2IcW7FGAoKWN5G8RlH+KxVaNp2vTdXtIdNRNdS9shxUe5axt0Q 1b6qsld/RJa02fLHA+TAxEWMdbNqN50N9+oObraAK28GxjciesWIVqGuxyIIO0= X-Authority-Info-Out: v=2.4 cv=YLySCBGx c=1 sm=1 tr=0 ts=69dd5788 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=n8cRCUxqL_yedgTzvKUA:9 X-Proofpoint-GUID: nu8tEGSjeS4bV4oz1WyStvAurSENOWVn X-Proofpoint-ORIG-GUID: nu8tEGSjeS4bV4oz1WyStvAurSENOWVn 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 phishscore=0 malwarescore=0 bulkscore=0 clxscore=1030 mlxlogscore=999 spamscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.115; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113604186154100 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:29 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=1776113613; cv=none; d=zohomail.com; s=zohoarc; b=dQqowxeQysHpEaXD+XsWA/b99fOHbQLM418a11d606+T6KmKfn41IAJze+ggpzHlbra7TRoWN4GCU27UNEROj713tuHgAtY4txmkWjDpLr1PAzWAKvaxjKLfaDtbUSjtlDQsMD5nxHzc9x2+uK6vZ4OEA+aXpiftHpKDKJLZzXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113613; 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=V7OBekPn/hhDyJzHaUwS9N5XjpsyB5in6iL6ivbVBqJmm2W0TP3GHr0kTLQImSmC6JZPqO0FonCy7SRLKOxBfsTGG2VFna34cFqv6EnR0Q4k8jKjQNzzCaJzU1vJy8K2NYANPCVMySGMc39CTAdkXWbJ4NGdFHrOSQp0RF6LtzM= 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 1776113613264842.2024780414187; Mon, 13 Apr 2026 13:53:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGl-0007Pi-DZ; Mon, 13 Apr 2026 16:52:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGj-0007Of-Ev for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:29 -0400 Received: from ci-2007c-snip4-11.eps.apple.com ([57.103.88.33] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGh-0007vU-Rd for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:29 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 2AE551800173; Mon, 13 Apr 2026 20:52:24 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 317981800163; Mon, 13 Apr 2026 20:52:23 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113547; x=1778705547; bh=T/ylQnS/te0fMXN5QyRAvae93avWDOZqU0zT/KgDwLQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=D5Z3Y2j2XpxaxGvx+FFzK3Qk4+H1LBHMJw5IWzxuSd+plApyh5uF5CTVGhIV0oJIR13v7KtinO8ERT/EX/J9nAkfUVeQQ3olJQHF/qJDCzd0bjJK0Nm71xps/jALANhTSaZycuXz5v6IxRp1OYnxzE1j5Ezaa8l+EOxia2o8fNrUmM0PE+nWTmO1YZ9pdN346u8dGnq0mAVluRBK48iuI+fx4lVu/2JLnQxPNGcXKugFh1Pzsam8FneQxmmAuJOdRJBFdFXUHfrZshNyqoI1DlPWpRUvFdz3dOzVI9vw4wHkXoOZMF4kCQuNnhZAnpVcuxjIhbS0sfLhNb985lGA5A== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 08/15] whpx: i386: kernel-irqchip=off fixes Date: Mon, 13 Apr 2026 22:52:00 +0200 Message-ID: <20260413205208.50643-9-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: -AoHmE8lNTu1OBS9NuBWbcAipxXXwB-N X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX7oGGQcnAPHa/ WVOGLnPaN9FHfMhJWoOPzpeUBTeECk7aIJOxzaaHVagya8LuyPnorIY0TAO2mNT22SnlGLB1QZI UeN1Y+lWpKmBhpzT/ebRZcAWY/EjQj0CeQcazACBDP0lfqr2Ld4Hfer0ruOmKKBeBVrZ7muCnwY oX8IGf/SgiLcrwobfHF7bLckNTiSaI8O0V/wTghpv4iR/Er4ejobRdiWQE8aMGsM7ZA0LzvD6Vs OWpv5Pv0U+PevvwfpxwrQdMSF16fS6iZ4EDwYXlNqIm41BzwZ8xpkfstzlyClKU2iDxEFc6kOSr ZtsQEjMHUP1B2oOfgjMKuWWmicGgSMNAqdipB4z5d38DSAptQq2QzoU8mUeOng= X-Proofpoint-ORIG-GUID: -AoHmE8lNTu1OBS9NuBWbcAipxXXwB-N X-Authority-Info-Out: v=2.4 cv=HdsZjyE8 c=1 sm=1 tr=0 ts=69dd578a cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gP1GEkNOX-MqffGxZ4oA: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 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 clxscore=1030 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.33; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113616176154100 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:29 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=1776113635; cv=none; d=zohomail.com; s=zohoarc; b=BAqFAUNFL/dRG+SBLkKeR68u/6YwurX6Qw190/KAbw/tk5rThBt7ntHYRrq77sKmN4x5BFvfjWt5oYIYuwl049z13FuCtYID4WtoBK2qa8a4MegH/6qiHhpN5tgh/4oEY3Di0r/jPHYCflNTjfj8PO904V9fy1cw8O7zNE9Bzw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113635; 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=Brnt7C+zhooEJCx5zTLikNxKTseZioaiADu/kOSDHYVesu8ah53jwa2H2kIg7Naz0RG5eWUQv829gt4doy20Q4r8MLx0U19M00xkZmHx0M7ULX6ieJ3meIkQeho7QEr33HxvE/R2BW8/5wZbKcJgdh63wesf25eE1hNN2Bu0uO8= 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 1776113635059649.1607367555542; Mon, 13 Apr 2026 13:53:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGm-0007QO-Qn; Mon, 13 Apr 2026 16:52:32 -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 1wCOGk-0007PL-Ns for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:30 -0400 Received: from ci-2007i-snip4-11.eps.apple.com ([57.103.88.93] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGj-0007vm-6V for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:30 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id A353E180016E; Mon, 13 Apr 2026 20:52:26 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id B0E38180014C; Mon, 13 Apr 2026 20:52:24 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113548; x=1778705548; bh=9UzhbHGn3KNjJvwbSrpYXcynAdkRNKmx/7n4duVcxcA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JNaoxQSilmi4kkuhmnStSPZFFhRJsOPiNNr3TR2eA6GfupDd1DKOhsHnYFAINf5X9P1cvBEVh3MMEWMoDcsEOkef/5E8L2tl9Mgn4LXUEGXgdwalLZhFVPUtmmI5R94iQHYUA53Opv25pu3kZpK/PTgD/bBWVZf0TfNx3uYVBVPgdj5NoFaYm7BxVGzs3IpvKTOAMuTpEO460oxUJKL4XJdCNU2eogpSV+3HD1EtpSjSUzQrKPiJrFTAstmauNOYp1caYeUt5Y5xxGdKKjJ8A7bwpSlT1UIWxisfQXOEVttOnMhee3+ZqoztzqOu0A+ZN6b4R5DvinnDR8cRevHSKg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 09/15] whpx: i386: use WHvX64RegisterCr8 only when kernel-irqchip=off Date: Mon, 13 Apr 2026 22:52:01 +0200 Message-ID: <20260413205208.50643-10-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: twY6px5apYOlygPMUkXsDbKgBbBOMRoP X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfXzq391JiiHXbA ulrvH7DWomGBj4aEz9l7TwzoPKJFPLEknZfcyirBXMjgQ0BrTfrh7cLhEmxuio5rtCvrJ3/UWea wqd1RFWvb+ERGIj3e0KIEjXc20CbscXUcFApnBwjeGvDx/P47YaFqC1y2I6AM+9GXROJ6gxbQby jk783OypLDUJLkrtfYaJ5+qSAeNQYGmDhTNkqTO2bThCM33Lhj2LojTTB6JiXAaNBqjybgSeUkK sea/uAZGes4GrwPnxr8df3N6hieMDcvTm7SVWu+ed4iol5uVzJBa5rhaWx70rRPMKYlwS5ch/RG /ibzrV7EM7SDJC1O2AuaJM6Qk/2xhyvKnL39dw0Tk70AGw3lH5d5jZ8fL4nm8g= X-Proofpoint-ORIG-GUID: twY6px5apYOlygPMUkXsDbKgBbBOMRoP X-Authority-Info-Out: v=2.4 cv=HdsZjyE8 c=1 sm=1 tr=0 ts=69dd578b cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=4IdwVP5-j8YZXVcKM5MA: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 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 clxscore=1030 mlxlogscore=867 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.93; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113637094158500 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:29 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=1776113646; cv=none; d=zohomail.com; s=zohoarc; b=SiUScKt18R50fYwJ2UjphDYalDQ+8wBvKhZ7Q/yvWHzGYtfXiLdTusoWUGqyZasXOAPv/ZqTOlq38R5eYLM8l4avXE8BrZlsmg7L7HjWsGi8NauhEMPImGs00Ut3nFL8T8/v3m6g9pRFmlQyc5+fkEFRwMKxVWLU9sQ0h2bhmqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113646; 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=fPVMUyrggzru1Arl7rnmJG+EEeiibqn134IURIa5Kq82jKouUktQKOaInLT0JCSv9N/sZMY4BqryAmigpv1UT0KyVucTYqdqgnf/KyZZyjC507rNK/DPnC6x7EID5C4SikzoD43K/gGu3T+Efx2jlzYBVt95GdpnrIR0CAjHK8g= 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 1776113646457752.4046372106321; Mon, 13 Apr 2026 13:54:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGn-0007QP-78; Mon, 13 Apr 2026 16:52: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 1wCOGm-0007Pn-5Z for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:32 -0400 Received: from ci-2007c-snip4-4.eps.apple.com ([57.103.88.27] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGk-0007w2-GL for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:31 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 1FBFE180017C; Mon, 13 Apr 2026 20:52:27 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 3B3CB18000B4; Mon, 13 Apr 2026 20:52:26 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113549; x=1778705549; bh=UDUDDhSNImOkwjgegNmDYFGV0Ws4YLT0V61YNwqVXjA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=ETB+HxkbskVjvhwmcV62cBFlST/oPod1G7vByTb/YFpZ1H0YH9uLYcY0yvLqJtjV0YXlcACcveBdb+kAkcd0oGUJw3e2OH+ROVrjCibfQpVJ4TtCJf/ZxdbEBKo0DFACU8uz71qdSZtJyFrkjA8e59mki2L1rFihoUsW7QQQ3QE2CS6hgRRaYwlZaSQacgaCHx0liq2rk7/5DclQIUxltbW+R/y9wVYxheOktXUyfCnayEMnSA8PGvT898UcZGDQmpWT56hYflOHZxoF+DjKHjVF1adxobNjbbW2I4c6ikYjybLyCfR4NiRvknVWX2CtFMXSjpfn6e8WMTKt+oVw1Q== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 10/15] whpx: i386: disable kernel-irqchip on Windows 10 when PIC enabled Date: Mon, 13 Apr 2026 22:52:02 +0200 Message-ID: <20260413205208.50643-11-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX8oLNtJglNxxL iyiDhfrVf8ru/EFh39lXFP9HEipPVCNVqnX8VQg2rWGnCr+WefClake0dxBaHO4txGX1VVenNtY T6wm1ID42z6nu8qhKpYMKPMkmB7M6X2tFvZNgs0olSM/MbFht9KBtBKlSie6WMtaR9O1RhtSQT3 N6BYXbxumrsITRngJepEh+EQ3mHgUw1IA++JZ+TAZXxCmAB6ICou4DYZsX4ssuXYJTHp8ivw+c7 mfmauvEkyVA7w1HOW4ordDMdBEQ3MazO6hBAYjkJ5DcdbAE52Kuid249rEeOHu12Vr8DBXMlp6x s5cYXdyeMaPkZAGsljhaB/BrQfDJZTkYLNa+lyPlzcPzpBlNoI+Nl1YVv94fKs= X-Proofpoint-ORIG-GUID: hnHiS7ByUdoszPJNpqPTpIm3iWzC2RIZ X-Authority-Info-Out: v=2.4 cv=d4/4CBjE c=1 sm=1 tr=0 ts=69dd578c cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nUl_a9z44qMLw6SsMv4A:9 X-Proofpoint-GUID: hnHiS7ByUdoszPJNpqPTpIm3iWzC2RIZ 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=801 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-2604130205 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.88.27; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113647003158500 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:29 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=1776113612; cv=none; d=zohomail.com; s=zohoarc; b=OSvRqW6HePWseOI3IbyTEsPhoedPe9Lx2unn9uoqOyhUfd8ACxPhTKgxjszJXdV/FsLSzN9m8X7/XVeDK3+SisReF/d9Jbm0rgaawLHLBR75m1Ert7e8eXiuc1EJz9J1PSr17Z83u3yvHPE8gRE8w4NeFtstP+B+u0Elt4HKeJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113612; 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=naR27QxYpyOMiqjGF2crLZmMsYQBWz+nRK7oD6IQCm44NbBd7s98D3m9f8PybyV3FPCj3SLDcIw3vgTPuFejP61DwjeJ4aEthQYb26i9xIyY8GnKT3Bi1vLauVWkj04BeErtiNcxeyA+DDE+T037i+dP111BG8YzScYVllOo+cQ= 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 1776113612511451.0206497905009; Mon, 13 Apr 2026 13:53:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGp-0007Se-NP; Mon, 13 Apr 2026 16:52:35 -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 1wCOGn-0007Qh-Lv for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:33 -0400 Received: from ci-2007j-snip4-3.eps.apple.com ([57.103.88.96] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGm-0007wF-7C for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:33 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id B626E1800154; Mon, 13 Apr 2026 20:52:29 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id BBDD518000BE; Mon, 13 Apr 2026 20:52:27 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113551; x=1778705551; bh=G89W4sMC3YwwxzvqsgVypuGjICEkNIb9nBQsRfciAZw=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=BN5RoA2qSzPfCSLSAX58XQKjEqvoRNj/ubVtwl76c4EiM/DHBWdE+mrVNG/Rps88sPRaSsEByWTP/plqBLX0AOlQmV1smZi0bmQ7g/yLaD8FxNiN7xt9dFEXjct/3NSvfo0SeMy/eDxpWIX8yoCbJZIUxTDRafKJPpP1n9yF1l9RUK5LSBJ+usjzBSxWnvMLbH7OMy2aRTMURjqF4UrjXUaADoYqvqfsyzvjRnk1xaZvNpv0/j40OUdozjo7+5G0hhnBBrkTUaV87zRxtP5JtnXoLXOiF9BgfD82lAehWO6lRnwV5iwZbZ5bQoYMh1N5pNHLDrGJsPbkl966fhVvrg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 11/15] whpx: i386: IO port fast path cleanup Date: Mon, 13 Apr 2026 22:52:03 +0200 Message-ID: <20260413205208.50643-12-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: 5M1NNjFva0r69B9_lemNMw1FGEO4D0JQ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfXxT6mNi3ozEMl rWYZIT3eDy3/XEMx/b65zIAFqmMooSVkgY/DlBif+tbXk7U8UBUC8chFLZ/kc0wozotYQb2W/Sj uI3VPxf8Aj43MrSfDHr3eNzdFT/AIHSmzxDe8cMnXKt9G6YHZU+2L32DDBst8MrXl8vjrlhuTsw 6E2h6cSku/xm4c3z3xF9u7U2sKKJVseslLwQJOl0tOG1a3zSdtMcd0K1tG8WPlQJLQtsqmcLg+Q HzwLaBVm26S36BZguR4NUYqP0UBsCT7jo1d1qpdSaP6p0PW+4Q9/p35GeguIwuQzmwu7CoVstax 86kcTXoOyna2qtcOzBwHITIPqfQomZ2TvNFcRIcrtJz36B8IpYSisCjRQZ6GUU= X-Proofpoint-ORIG-GUID: 5M1NNjFva0r69B9_lemNMw1FGEO4D0JQ X-Authority-Info-Out: v=2.4 cv=HdsZjyE8 c=1 sm=1 tr=0 ts=69dd578e cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==: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 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 clxscore=1030 mlxlogscore=805 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.96; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113614193154100 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:29 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=1776113575; cv=none; d=zohomail.com; s=zohoarc; b=UPAxEOIT8EScM2uNef69dtUfLOJyfyb/Px7mHcYu8ha1ModC6VHFFmKnLCGmdzK+cFuteGKjG52NMfPGVzWdPiwzR/boSXCv1kEiLnIHlEsq+OmNhEx1sq7u6EGVnV7zKumgJHlXWZC/pSiOBJks67td5/vcyaGxG4vqlblfYqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113575; 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=MeXVzOQ4bK4j2DXqaH9jxGLt8I5taUsMYT5l1socJlnzGAOTTrExA752VU1IRBYo1VrZfO5mUD+RQJwKtLvzBhSfBc+wy5OcL9wbQ63Lf28Q9p9GlARP/8u0+c5mr43R8WAD9o/iNgewMJ39PQJMrGwPSMxOzk7afBUllEnG3qA= 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 1776113575517924.96937719807; Mon, 13 Apr 2026 13:52:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGr-0007U9-MY; Mon, 13 Apr 2026 16:52:37 -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 1wCOGo-0007SS-Ru for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:34 -0400 Received: from ci-2007b-snip4-2.eps.apple.com ([57.103.88.15] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGn-0007wQ-Ii for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:34 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 2C5A718000A7; Mon, 13 Apr 2026 20:52:31 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 487C4180020D; Mon, 13 Apr 2026 20:52:29 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113552; x=1778705552; bh=zcmYD8sBYnUVL4imQw8BkyvhG03VGFAjf3wzcMF8rtM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=E3Ei+eHN/PQRV9i6AIzAuY0ubvDQYKAnbBuPGPI/umXMbM65g20EUAoR1JbZEqL4/Vp90zGvUbLiaKvk9vdXIbO+u51lRh8AJ/cTDPS0Wc5leY00K70ZlJwp8n9vNCY0cxAQ8LtV1xtPXYGE2ZAYRZTqA3oBJ0WQ3DQiUdk7RV+2XCk1uDs6P2q9523TNhSVZy1ESQDHurdXzsa75YTZ70E5FhNkgxWh8Avynm3RxLyA6iNJol1cmB7arS34KPVHDKl0tbjcXgKaFA4us/z0mvcV+d2Vz8W41hM3FKrPgQnpSi1w6tu5mI7f324H0eRYqGaUgR+lmHX1rOntFLIosQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 12/15] whpx: i386: disable enlightenments and LAPIC for isapc Date: Mon, 13 Apr 2026 22:52:04 +0200 Message-ID: <20260413205208.50643-13-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX3YpmqBYtqwnU rhxwaC7bpQImC/qRL++4QoiNkO3ibeFqUmmJYNjAg4EOFiFy9FaBZmPQzZFXF94Wm1H4v2onqu6 kXqTVYPF+WcER2qtBd34pj3YGDbdJV2iRwGDTisWXUBvwIRJBUF7tUJa1PD8C4fcRs5fX8Xwyel cJOhPbogaUtbQCqNnU7RQXu2Wf3psT9EKFnsPV4yV4DD6jSgLVtkkBuUEypu6HDgQSIWwukpqNT 1BLlEq39lamqb5JTAB6SdAdzCJv3F4DeV1QaqC/3OZwhlRenjwbpEZJP6U1g3hZ/bt9mWLGplgW tOl/i87hgUCxfNgmW48Fkz3ab6Ee4xaSSx4UpFf29S/cFYyZdXzj78zmuXr9+M= X-Authority-Info-Out: v=2.4 cv=HMrO14tv c=1 sm=1 tr=0 ts=69dd5790 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=kaNVauZA35-AGszze7oA:9 X-Proofpoint-GUID: 2c1Kx3gmVl8zu5KFrkzTs4ZRu8kMSX7M X-Proofpoint-ORIG-GUID: 2c1Kx3gmVl8zu5KFrkzTs4ZRu8kMSX7M 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=817 lowpriorityscore=0 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.88.15; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113579256158500 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:29 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=1776113625; cv=none; d=zohomail.com; s=zohoarc; b=cNjicIKTwrnXAfNLeFy/oD9DO4x/DYkILd28TyfkdWzCOGrLSx7hK9YpVrm5qgS5vnuscDAwcaiQpOE7iDH2/0BLwrBy9qhjbI4x5MnjWo7srLjjRGmReL5bGk6efLl15RJrDadEGTQ5KnG2CqJOIkErbKtGF2KL+qPVZrem8OM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113625; 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=zvIfYiWHwTxnV4KpRpM414Hk+noi+RK5kzhb+FHpHGM=; b=OJgDUwHPdtJIKh0q36halKY8fcRY++/vLCsp5wbe2hhGeFw9K30wkQxg4wucksR5qILqiWkAfL/RR2pJsP3Y4ziYe7Oduc9001ifaMJYvRTO326pop9Bkddkvk9hejJ43mGhp4EfJpyovPUpU0A3fKdpcdms3b1wgSXBzIpUVm8= 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 1776113625678717.878802191684; Mon, 13 Apr 2026 13:53:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGt-0007Uh-7m; Mon, 13 Apr 2026 16:52:39 -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 1wCOGr-0007UB-Lx for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:37 -0400 Received: from ci-2007j-snip4-4.eps.apple.com ([57.103.88.97] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGp-0007xH-8k for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:37 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id ABBF81800144; Mon, 13 Apr 2026 20:52:32 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id C88421800169; Mon, 13 Apr 2026 20:52:30 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113554; x=1778705554; bh=zvIfYiWHwTxnV4KpRpM414Hk+noi+RK5kzhb+FHpHGM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=gxoZouze6/JuXv73tdpaCz1QJk+CcSmOuWTuuINZ08WSv9rY/d3V29A8GWSHNvH4z9cp+J0DEwiFMGsr6E7OGG8rLOqF/+paAQCLkZkxx85Y+hV8aMIQfDBSnQmRCnPAT5ANvDAJ9u6kn+zxNTN5Gjm2kF6Zpo/wqCSHsKe293wiEM5goH9HgvFgkYnqe7LIXjsZ9K78kCEwAXfOcH7U4UwsoOdYoRyHIKPzQedYlRY8ctDQwDUF65FcjblUj1aYXtMHA06WJ4OfWkwkegL0ssn+YFreGAG3vROY24bt+vrI045NmIkEeu8+WysIhfMKbgypTfcF461zurY+Pd5WKQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 13/15] whpx: i386: interrupt priority support Date: Mon, 13 Apr 2026 22:52:05 +0200 Message-ID: <20260413205208.50643-14-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: cSCQRa8c86lX2ENfa65_AeIdoota3O6t X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX08vP5GdyYELX tEuCZXsMF5tIph3b4TAjKkK+caPfdlDPQQ3Fc0YlIyV7c6zLIDxtZ4+a+AesLNqHxygOAnwLeJ4 KuuEQRLbCXfTZoVLAnzNDaMwhdA87chGW3C3llttnQHs4X3iyW1FYVFBo/dI0NkvNJlnz32h9mr 9RRzzlV8MZOwJIcHlXpnNr3B8HuOCrs3hKxwCbOEIkfwY2TJAZ4T3a4cdE4xcYySiQYY1GJa4vE vhjuGjUhkW36ZOkP/l7/8Cl7ROnyPM97qFo3ymohf1VJ1KHnYIr/3lqYXnsvD6sNEd97Yl3MVW0 s9R7E5Xt+T2Mp3c9zIH7qyPGsTynl/RAsSmOGC2019JP+YFKaC4Omv2palxzMg= X-Proofpoint-GUID: cSCQRa8c86lX2ENfa65_AeIdoota3O6t X-Authority-Info-Out: v=2.4 cv=DohbOW/+ c=1 sm=1 tr=0 ts=69dd5791 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=NuKELtICf0aykZwt-QIA: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=620 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-2604130205 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.88.97; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113630689154100 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..ae15fced0a 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 (isa_pic !=3D NULL && 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:29 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=1776113638; cv=none; d=zohomail.com; s=zohoarc; b=cJkP+yZgiyT7utueH4i6GfVoyEaNB7rD3DjA48XanxBOfthfLDSXSOqKAk6AjOrRNOfEO8n+1qR148qfppWbcK4RobWy3fUNBQblJPs6fp9wcXHYJZD3Vu4VxqtiohgT4b3c94kJG12ZzA3l5oT2rx43t3Y8oel/a/uvP5W5dfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113638; 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=EjjiXX8tHkxrHUcGcDIhxE0MroYGJNytUHR7tzYMOIYKtmvmEAJ6ZAzoA8tawaPaX0KZj/Dy6Vgg7DeY0HZT3dCLy7uAvRhBlf0WhmYJR5wnfXIOysea19xCw9smeEnMy8IHMH1SRYL1U//UI6nBtq/jIDuXh0GyYbldwEsg/m8= 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 1776113638574741.1509750805841; Mon, 13 Apr 2026 13:53:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGu-0007V6-M7; Mon, 13 Apr 2026 16:52:40 -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 1wCOGs-0007UY-Pi for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:38 -0400 Received: from ci-2004c-snip4-8.eps.apple.com ([57.103.89.31] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGr-0007xb-6J for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:38 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id 4C161180016F; Mon, 13 Apr 2026 20:52:34 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id 5E19218000A1; Mon, 13 Apr 2026 20:52:32 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113556; x=1778705556; bh=SCqUAJvB1zqKRh44vHU0QIqywz/suuWsKXqtx/ZiPkM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Ay7pzWdc0PbCCWNrFy4wiemZN55xXOzSmmphEeKdeUEzOGCAvG0Lma4EfSWNlR2u1Pn3FyXlVlQRhL8jqAMk4pBmqCZ08CkswD79jgbZuwxdEtpSnuAywaO73gipHrcPhcXqU04oknnvFg06SNITekHNzjqwun2CKZUEcVGlKqlkF72v/PK4QoWbYLYKyDU+q4pL81tkE9Wrsed0ShWRNM+GegkUbU81CgWoDIpxcLEYD1DaX6ki7pooMxCrJ1YNLppZFPtZFvk67leLN3l9naMpqIsw/V0BMy28NgIbo9inz0xKFOfh72JkJPCz0MA62u815vYeH7KCvs+2LvxTZg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 14/15] hw/intc: apic: disallow APIC reads when disabled Date: Mon, 13 Apr 2026 22:52:06 +0200 Message-ID: <20260413205208.50643-15-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: biXfL_zXGr4ZH8jeq-6SRLVgXCw7NV4Q X-Proofpoint-GUID: biXfL_zXGr4ZH8jeq-6SRLVgXCw7NV4Q X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX6pLSp6DvRl7E hEvnDoGmY+DjKU0vZ2o0M4BNYvN2UTJ2E/4nZsq5wr/iZhoTGb1mXw7UDewNalQZqsH87GPWMHy IAo5yBU1fJiYmuaXP4oyg1OOqH5VWlDs+GghL5NfACCNGY3KwtFMFDxRLomtOsY5kq2mgvW1L25 4ruAexlIeAi/U2NJ/ZJ0rWPvHWPwSEcmlifCnkZE2Okn67F7jln/EceNtrF/8ZF3nDR9YEeO0X1 XR5pRxY9b8J6f0PSqClUHUhJUY4zLDKs0u4WnNvGMZASyQi76XG5YWzOqeOTtEg1HmSOc3xk8+2 i1JIFpqjROwbo61Z5yot3JTPGR9Jf5f5gNBuJuvQ9joyrnVjt02VlycvU+UNiU= X-Authority-Info-Out: v=2.4 cv=Rbidyltv c=1 sm=1 tr=0 ts=69dd5793 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Sz3nRv2TKcqVAncp5HQA: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 suspectscore=0 spamscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 clxscore=1030 mlxlogscore=800 phishscore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.89.31; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113640519154100 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:29 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=1776113578; cv=none; d=zohomail.com; s=zohoarc; b=DNS27CvYHogRv3c7blNlrxYwTItl9qVX7dJE3bZVH6d4114nbmhbgBpoUYQErUfhB3LOWXbyX2fk+CdvIo4N/sBug5d6I0NdlkcsOtqKkp678uMBXhfqbUtEeCD80ZCsaTJV77OjsIV2h/jM/Hhfhk+xynpFnZMX1ecZDIHYaKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776113578; 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=+LbJHsmhuS5y0C5rroKlzdtEDgQkUZ4oJj6RDO2tfJY=; b=PrlPnen+blIJa7miSp7T8CpukksKJosa9/AysFQiMfLvQRqMyjNUjrLpW5wDBuCMoU+WR0RoiAebp4A416El5pfCraI9EWXItDLDYC4hQNwMYPcRmw9YGnYDzIw8IPKwS5kjNnkmJJvdnFXHPlofzImJUyaySCufxKCcXb86F54= 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 177611357776297.98821263509183; Mon, 13 Apr 2026 13:52:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCOGx-0007Ye-AC; Mon, 13 Apr 2026 16:52:43 -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 1wCOGu-0007V5-IY for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:40 -0400 Received: from ci-2004k-snip4-1.eps.apple.com ([57.103.89.104] helo=outbound.ci.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCOGs-0007yU-86 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 16:52:40 -0400 Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPS id C94FD18000A7; Mon, 13 Apr 2026 20:52:35 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-10-percent-2 (Postfix) with ESMTPSA id E4855180016A; Mon, 13 Apr 2026 20:52:33 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776113557; x=1778705557; bh=+LbJHsmhuS5y0C5rroKlzdtEDgQkUZ4oJj6RDO2tfJY=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Ja2/Fl96Yrz1tTC8S8Au6ZckYTs1KhOP7VfCZATUQ7QqSNMqzra+tC7wTG5dJ8+dZqCL9SMRF3OzWOdaNio7GkPgWXkWQuUSF4E4Ak2nEbVjV3hKNy3AUEZWvu3caJNy7K9onlGH2mK1HNQbzI9LlTYPOGHxBcgqxN4lMEXGsS4ouj3CCHfHORTzTD/fv3MNzxmtOxQ9F1D2/Kp1HXENgYojN9xC4p4mMjb9pAf6GPe32L19Ti3HSb9+3idYHEc8sleFGsxvwm+S/WDVTCxAF3A5dKWZ1UMI2jqc/hYHKJLJKs42P2z3voyVMVajxzZ+272SI3vkvJwmrYA9eXRH5w== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , Pedro Barbuda , "Michael S. Tsirkin" , Wei Liu , Paolo Bonzini , Roman Bolshakov , Mohamed Mediouni , Zhao Liu Subject: [PATCH v12 15/15] whpx: i386: fix CPUID[1:EDX].APIC reporting Date: Mon, 13 Apr 2026 22:52:07 +0200 Message-ID: <20260413205208.50643-16-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413205208.50643-1-mohamed@unpredictable.fr> References: <20260413205208.50643-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: D4PZjPIDk0AMf5yTHBFwxq1BOAcdr63P X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDIwNSBTYWx0ZWRfX3eVfRCkA+qNn uqFQqvEDK92JiIefhCAK/+fr8SYbeIThhVEKHaYxrAKFMKj87jOLiwxNg8t4sEMDBdWx95UhaXV PGJRHD9AViMNmfshYCPiYpcaUpZFsDMzl/690OtCkl6jeTkyxcglfjU3zoFXau/DlCIXB9wENhh lj1YxJIpb2yTUKqotacYp7Djf80kX93vKp+YMRmrDUBxD+Qd/aDDNJKxmnVrLyGCahP9+EC0nNF evQ0WQL6r3E9IrFwdSK2k1BntR6FcxPoD3RxtKyp9uwDYVFT+DA9//daPNQ09JWjjH7BHYMeUE+ JElW5fzsa5NYxemAuFC01CafjyutwgDB1bmpSxQnD9QUUDr6LsilDVaT/kVlB0= X-Authority-Info-Out: v=2.4 cv=Cu2ys34D c=1 sm=1 tr=0 ts=69dd5794 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=ljJ9V6m273jqBh-Cp98A:9 X-Proofpoint-GUID: D4PZjPIDk0AMf5yTHBFwxq1BOAcdr63P 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=856 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130205 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.89.104; envelope-from=mohamed@unpredictable.fr; helo=outbound.ci.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: 1776113581985154100 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 ae15fced0a..86d2dc1df8 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)