From nobody Tue Apr 21 14:38:14 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=1776681830; cv=none; d=zohomail.com; s=zohoarc; b=gxjDn6Tj2wvMdnlkOwmg7g7tRAmwOZMuk1zTQog9lJdEPd1XfjC7uLnuHzabTNP9iwN9IY186YJTvp5+BDhFUH4mmRsOLZb4LRVXnb4yDGJ0dFMkai3rC376FuIyzAZlMklVZCK9DxCvzES6GCDb5ZBH5IkAZC8fiAc79vF7IrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681830; 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=K/E+FHzvrKIMAe6BlTJolw1PGR2qTpKO759LuPFXKfi63+2od4vobUnyRTufIajeeMC6aB2jW2C4WP4FTmuNL4gdto+nEMj0yNaTfRscR4AdAoJR5pDjRvmzLE6c88AlxCf1qbAsSSza4aH1YdA/n1HZEd+2GMl0bJvbS8wBkAA= 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 1776681829623456.4446563549111; Mon, 20 Apr 2026 03:43:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm5o-0006oE-Sk; Mon, 20 Apr 2026 06:43:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5n-0006nh-Q6 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:03 -0400 Received: from p-west3-cluster3-host2-snip4-7.eps.apple.com ([57.103.72.168] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5l-0000Tv-Ix for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:03 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id AE0111800153; Mon, 20 Apr 2026 10:42:56 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id A0C241800140; Mon, 20 Apr 2026 10:42:53 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681778; x=1779273778; bh=jSFEY3OW57r5Gmf0SB6G349rIgUNCT10rXc1M/CBSww=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JQz1XccqkAxHXcW+vWvXdKNtDnZzs4C648AylqWGvrHvcWXfUh6eeV8LVa9sijF7KYg+AvXL6fbysEojORYdJCRHAAMdVNvQ+LQ9lBxIfxSWG4I7vgc+V9ZmzPwtL2sa/g230z366mMYjT31GKnN1vz2t++wGUcNY+MPhgKfuJGLOjVjB1QHEISgfH4NzyhnaKLMOuJbcfetI7FBZILbPTGhKVnT/1rs7ng/7he2Uk0tngRsI7p4BmKW9yi877YuvIC7rPzyceNsJiHFvIJ4wsTiyvYxvJGV69Oa5St4akLVBs+emjN1umTn+K6dhz27hFGsioHkMCqYpXXnoCA6yw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 01/38] target/i386: emulate: include name of unhandled instruction Date: Mon, 20 Apr 2026 12:42:11 +0200 Message-ID: <20260420104248.86702-2-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXwLXvhkoB1h9r K7F/9i6k1UyteZoYV080TLz165jzReLK4hqxqzhzWKuLL3fZsacimXoeJrO8gUvOJHJjO21rpOE ADK1hEL0jw617WxWuPi73u5h9UJlD7hfWNaKXEoZwdtNaZ9gF1/0ws/vj1kq5NQACvvrOMQL6gI 7NkB11EpRQkIh9gtgBtoN0XB2+/fOkAyK3hxfF3ix0zok4wWQrv7NJgeWuHJKAyFFzsLE5BLRnq AXVZsjnzi2uJ82j8+xbE8IBXUWRw7knWeaeG+zSpQNkrPvL2CTUSfBikSdVR03QUxSBFYcvP5oQ XEpoPISyIyIsjLqayWVdI9H6nu7mRdT19tUYih5zeX9KB5+Z1swg9RNA333dKY= X-Proofpoint-ORIG-GUID: sot_2WDoZAF2V-oijn09rKqeUHHRyLRF X-Proofpoint-GUID: sot_2WDoZAF2V-oijn09rKqeUHHRyLRF X-Authority-Info-Out: v=2.4 cv=JeGxbEKV c=1 sm=1 tr=0 ts=69e60331 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 clxscore=1030 bulkscore=0 mlxscore=0 mlxlogscore=973 malwarescore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.168; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776681832913158500 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 Tue Apr 21 14:38:14 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=1776682138; cv=none; d=zohomail.com; s=zohoarc; b=h7RGdbcA8e7Ct/GD4Tx+m4Tw7oTmEx7IBxYKTIMD6/qLtb4sd1mxZgFwbqTC9njCfpPA/bZ+Yiz3Uvgo/l0QO/88lRi4cNXKsIV+fugUHKZAMUQkXCN1idrPgw09mVeLaDx+e2pk3XnEIaU/gnU1aersYdWVHNQHc/E2leH9080= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682138; 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=bVTzEacRdJzhQMjfA8E8Hpms+Nr0Rn1BNpJ4saKSLflXXfCIDt82FTmIj6DBWKVG5fZzzgIQsFWA2vs5Bcv1AI7Ck7kwxbtLv0/Bc1VLHqYdkURqh4BfbfOjWuebgy+HE7YjGBjqmuw2Ki5fCDqZpexgqp0MINYRTRyD18HU8xI= 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 1776682138343736.3212020613585; Mon, 20 Apr 2026 03:48:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm5t-0006qV-0L; Mon, 20 Apr 2026 06:43:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5o-0006oC-Os for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:04 -0400 Received: from p-west3-cluster3-host2-snip4-10.eps.apple.com ([57.103.72.171] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5l-0000U8-Km for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:04 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 098F3180044F; Mon, 20 Apr 2026 10:42:58 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 8A72918000A3; Mon, 20 Apr 2026 10:42:56 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681779; x=1779273779; bh=zl2db1VwfCW29E4LtwT7zz4buZdQP1VZYTXVu1kcs+o=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=NEOagA2NmK4GPKF58muXyNAGkLIJZr2ItNsCaJqE1Uzh0GG9fKJ0bJQYG4gFJFcCVniqs7B4UFOJ53hLZDi6OhJBjTy3lohXof+rLHnAIgnAbCvmwytGrLu3P/Tc5ZWH9+fngjfCW5kSxaLebkE0mp5YZF0f6gSJeYnGdo34CBheJJ4dhtVWX/1KC2Uy+z6gfrl/eR4CAy72eBxrrkxfpv2OsqaXLP9Fyp6Qn/G3gf6CTofTZmaqB17lCmdu2fGbnMlsZEN9sFfDyQWY04/x5awZi9G7EATywhNSwP4iRbxIF9IsFGOrLYwGCCl5HNUKjSmKu2lD5ez7V11PdY02Lw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 02/38] whpx: i386: x2apic emulation Date: Mon, 20 Apr 2026 12:42:12 +0200 Message-ID: <20260420104248.86702-3-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=V7ZwEOni c=1 sm=1 tr=0 ts=69e60333 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nj4AhdDZwDx412jv8JQA:9 X-Proofpoint-ORIG-GUID: kN9eLcje0eagstP5YJyqq5jgsYPe0cSU X-Proofpoint-GUID: kN9eLcje0eagstP5YJyqq5jgsYPe0cSU X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX3Zm4r4fSDxU7 nqI8QGD6EM/WCm4pMTH6zJKvT1TyyUlSOuiuw/7wEeKwFlTRhUD55Lew3aypg3H/KVo2MSl1hds RrNU1QlC8fJZBbJSUYveBjZteLCIz/iiUwlohLrtGh/9U4NAa1bP4FSPk4EYoON+ClJ6L5IP6Ot OwHjqottxJewQCB1NbhZQc7yXiFOdCvP5AumP4/9icBFg3yO7u6uYrvlrLZEXxOGgUy+rxiJE0n LMPoXxER2mvWU1HSlsLK+SsMR/M2CpTl78wmJCMHKnB3dIcOrXIjX9LlJS3810TSg0lCMHk2fLE aKnFEDkrR/gWUtMyGvc7lCM9JnhYWsulqhHi0AFk8sznWKFpL+r4Vm2CFjab7w= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 phishscore=0 clxscore=1030 mlxscore=0 mlxlogscore=800 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.171; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682139997158500 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 Tue Apr 21 14:38:14 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=1776682127; cv=none; d=zohomail.com; s=zohoarc; b=myu5pbl9Jxd91o/+FUqAkOWMp7v4Vvb5Vyu+nnBfICj+mgr07GL82RBrdBPfsb37RkeVLaNH/iWtyG0hm0nGkasRt/GQhfXQ5XZrwEOO0cQl42nwU+BReZ5G/kaACN9asZU8nX6uQAuHWpwIDaLO5bYqyeSC5AXz6B7/NXWhACQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682127; 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=Vmb28QJ4pAeHJEemHWf2hvfYjet33JL8CwGehC1PYGQBinabfgcj/G9LE4I0nIm9WIu/UNtuQ0UPofFgX6dc+0NIU/nSGvgcJWL40l9hwG8tvgcFwjnofcserdDXlbpeMVRJaDIcW2q4NkgyV6d6pXN59LQ7CC2IcjMrOrwo47U= 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 177668212797499.52903412415128; Mon, 20 Apr 2026 03:48:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm5t-0006qU-04; Mon, 20 Apr 2026 06:43:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5p-0006ol-6k for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:05 -0400 Received: from p-west3-cluster3-host11-snip4-8.eps.apple.com ([57.103.72.219] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5n-0000Uj-6v for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:04 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 7AD8B180017C; Mon, 20 Apr 2026 10:43:01 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 0CF761800451; Mon, 20 Apr 2026 10:42:58 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681782; x=1779273782; bh=Ash1yi3VlTyxdP0Aar5CNwwUDY+XErFVJjyfbU7EpDA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=atH1E0vzg+TqTX4HTr4+NFf2EfDRBYor8UGg63g8VgA70OUxTyEyzF298a4JKT04S3EyxWR5gpcQ22vYV1U7fOq6Arybow4Yt508zDbFsejQOuvpU/C3y8mgya8QTRKlF3zGDbze7tEaQeU2mbN2wo5o9xD6w1d+a5bRYAlZhP9J8A73K+3rB7EimqdmkdMch+Hea99hzacBCRkAgnEtXCOq9YH9EAf5WIpD0gQ/jB1+2sonsQy1hFI8MdvfoxKjBUBAuQIHGDFZNJgqzMaB2VYxlsInrdQ6TFlNWzlWEmY1/Lp8bc8ab+aNdXy2QY9/vax59mVC41XErn6BzFwIsg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 03/38] whpx: i386: wire up feature probing Date: Mon, 20 Apr 2026 12:42:13 +0200 Message-ID: <20260420104248.86702-4-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX/vamrJfypzM3 oO6xL9zqrRfWruqyWkUM17Kzjh+b+6pUKav92O2ih3wL3JC12VTP37Kv4q2x4HhGuBORJIrVwy4 LMJ6OF4VjCyrFCH6Olt54xGZcOHvmAatpsBZX3VueasQFLW4RO9KuixJvk2PLQDBCvPN0x459BT VtjJnvH8pIzpn8Rse7l/cFydYlqLoebudqylF0J9E35QyyjxXRV5w0KsHLsVtT1IzyxvOkzICRL 4tJIEAD43gCs4aKdWEsAhu7PiiMyk2b/b5p3XSyB/qzlR5G3AAZLNrbgJq+GnHSGBWC/GtRUmII ntFGzO2gFB74LgzGn5Udwhv4XsO7qBFfTZKcXppkJ1HToiqbCOxpVw44w3qWdA= X-Proofpoint-ORIG-GUID: YMcBjQIp-p86stFWr4mV2Bn6Vz7QhoGn X-Proofpoint-GUID: YMcBjQIp-p86stFWr4mV2Bn6Vz7QhoGn X-Authority-Info-Out: v=2.4 cv=G9cR0tk5 c=1 sm=1 tr=0 ts=69e60336 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Gr33WSPopR-aU8k7cJUA: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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 clxscore=1030 spamscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.219; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682129927158500 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 Tue Apr 21 14:38:14 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=1776681817; cv=none; d=zohomail.com; s=zohoarc; b=FN/VreP3wi2ZR/nwgcU33WafSNmRmBJ5S/HuJe8MexU+kAh9dObMWCejrsKdWcwNE2RoE9EQ+xQGeta+Q9xQ5pbwIw826kJ1IFuf5YDM+L6p24Z3T4XaxrE7dxQi3EBUAmy/scI6MJPftGfvE/Q3O13d7ygsuGJ29JNtRYQEXx8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681817; 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=Fg3sDyLvvsBmhh7hv//iYrRSlea7Ttr6U0WGcBOv0ojBNl1JaES3fNNZU95IoUw7bJpGG7X13+1fBnToe6jdlgSgXDYI1YoTAimO2gQF4IZN2aj/um4AzADJJ/0FpJrqFOYeA+9T0v4YHECWi7/XG+14r31Pd6tLP9kwvTR6+vI= 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 177668181655143.70139875957136; Mon, 20 Apr 2026 03:43:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm5y-0006rd-JX; Mon, 20 Apr 2026 06:43:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5s-0006q0-CF for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:08 -0400 Received: from p-west3-cluster3-host4-snip4-10.eps.apple.com ([57.103.72.191] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5r-0000Wh-0t for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:08 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 318CF180045A; Mon, 20 Apr 2026 10:43:04 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 83EB51800466; Mon, 20 Apr 2026 10:43:01 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681786; x=1779273786; bh=LeCfULzXVq8eMeXoD4HoazACVFGuCL5m06fQgObX99k=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=eMt0dPzoXOM74HRCiK01b4PlSpyzb82oxJxRV2sQ59yAFXu/rahQKjiQGYcwYX+VmYyWpIK5mAfdnsAsk2Wu6QM/zn2ewg1QZEIVj/qPTiLXqxO1H3NmapiNa2er77Oba4+OTwnOxFvYZGIPym/4neEmtsMN5Pt67yGXwVsdb7fWRxEuKLQ+RLYxoet7raYnh7O8kSLt89vwDfHgbpqo/gBG8kn2lKVANSZj1Bd9C+ThAIo/8TvRJ5sTSPj+GzyF6/ttc/kFQL4210WstLo1kQ8OJ2UPY5AFtDbEyxtiZ3EEu4gtIkYptHvmzaQNuBaJB2v0j5kMOUOby6ls3364PA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 04/38] whpx: i386: disable TbFlushHypercalls for emulated LAPIC Date: Mon, 20 Apr 2026 12:42:14 +0200 Message-ID: <20260420104248.86702-5-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: vD2UKpINrLvOxGClEngNk6w-aaqxV7Ky X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX9PRK9R7HixMk oIXN+I2rx004icuPsv1GRzPAcbaHnBpWNkGHaRNinHPEK//VWyvdP4xj+bilgjhDvLlfvN35bc8 3V4QsH7Pv+Yh9jIO6YOjxD2Tw937F2tMwFLegG5BE5NBzAXuFiNcQ+7x8Y4nebD91uIwz/X5adE GrBvFv1ejdO2zCak74mbN4pW7ceLwArio2wEtPMRDymXgxY5oUR6sxROqaEVGFGoTeVf1NOAbWv YFzzmvNtjcO5n43t1ss+sQElZdbEc12qIoDRDm0rjOeJRpVpjJdIj4GIJyVVtepzNFP9eOi9qZt v9UTqETeqKcGPUTHyfCZgLsN9yZXuWLT70TSm64ceVKrI/Kf/+3FrNEM/YjO2g= X-Authority-Info-Out: v=2.4 cv=XaGEDY55 c=1 sm=1 tr=0 ts=69e60339 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Rm0zj2O9plGGl-KjdfMA:9 X-Proofpoint-ORIG-GUID: vD2UKpINrLvOxGClEngNk6w-aaqxV7Ky 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxlogscore=777 phishscore=0 bulkscore=0 mlxscore=0 clxscore=1030 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.191; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776681821958158500 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 Tue Apr 21 14:38:14 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=1776682023; cv=none; d=zohomail.com; s=zohoarc; b=JWfZFLv3eJ3+UAKNT6cT8JTLehsWJAUnx0eLnybYsgx9uVIxSp/dop0qS4M7BWszZ1fJqoop+WzhMZfIxgDbKgcmxvGP9fb5zpfYgiTotuc/sdYiKDQZkGW2VOEWGn2jWYIjslYdCRnDyNC5zythFZ3PjOkD854wEeqlIoJO6V0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682023; 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=ZZTZ3H77oI9FXCYS4deJZYvgFf2aMkB9a+2UBfLMTnr3NYfNbsfXCyNb/wW9H2n45nR5lZO3GNNyvIDPEXHYHUcV4yVXmgJogxqeVcXKEWLNGFNRia9wPwgnYU/Bf+gL+IPDP7FxfcYK9y+OSwAZWeZKMoB5Xipfl6k0tjQycbI= 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 1776682023936441.3592317334044; Mon, 20 Apr 2026 03:47:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm61-0006tJ-5M; Mon, 20 Apr 2026 06:43:17 -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 1wEm5w-0006rB-Ed for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:12 -0400 Received: from p-west3-cluster3-host7-snip4-4.eps.apple.com ([57.103.72.195] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5u-0000XI-MY for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:12 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id ADA551800476; Mon, 20 Apr 2026 10:43:06 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 0682518000A8; Mon, 20 Apr 2026 10:43:03 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681788; x=1779273788; bh=dugTy6Mycl0V8PO55M7zjkrIKW6irE2gkRf+Eg5CDxE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=CVgaDjcNndvu+34O+3p/0PLSTq+7lpe08YwtVhb0p7aXLVTT/gq/HxeE139hbbPrZL36ppaMcM/wXsREALmckKAMw/AXK/G9k8obL4XtMlYaNtPTj1PcELJJQnH0jCPoPGvrwDrbHy1MJrEuMAUNCx0w4LE4e85wt+nqW4snQ7gVi+C9i2qL2IwZSacXs1LzSsrHR0KrTQPbuKM6az7HzEaQZ7AadsmBJ4jM+Kf8D++UQnLWjHDVt98pSL56nO5i+b0NvCLRorzFtlu6N08ByepMPEYj7lQot8Zharay72ownHCPRZu9c9fZTiFlN0qaF8BuJALNCm22xLxm+JQa7w== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 05/38] whpx: i386: enable x2apic by default for user-mode LAPIC Date: Mon, 20 Apr 2026 12:42:15 +0200 Message-ID: <20260420104248.86702-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXxoX796Ab1mL0 6SwOnZ/YnW0ezdB7snBgtlfb0Ms8ItXUZDGsNEjqnH8OXelUhuztKXjjh+qN9mrdYRJI+/aOOib tc/uQLDU1nB6eCElgvDCvoVT29HI5AcUwEZGIbJOL+YTb+VEilbfR3cVvSq9/sBDYaO0YiCkL7x 8fh2//3ttr7Ltl9U05PSdjo4SfPb77cI3xCAZ5tztTZ2eujr9eLKiy0Or+z2iVwthRO2z7+vUiJ oL/WLQ+h2lxwlMZvoMP9YYnlQxbZ5Ky9QgkUi3zpAgypmieD8jYLfvZiBSnwf8FwXgUiu0z9Fwh Shy9kORNkerqE/bNQNCEntMEcSSm10NszQtlPUt5rxTpUuorP+XNTLNTlwW4CY= X-Proofpoint-GUID: b2OepAfrvosD1PF7HTt7wQvzUEyaz11P X-Proofpoint-ORIG-GUID: b2OepAfrvosD1PF7HTt7wQvzUEyaz11P X-Authority-Info-Out: v=2.4 cv=VuUuwu2n c=1 sm=1 tr=0 ts=69e6033b cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.195; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682025618158500 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 Tue Apr 21 14:38:14 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=1776682007; cv=none; d=zohomail.com; s=zohoarc; b=KpeCqp4EOt0vovoZfGRNDnyf12fZcLLzKKP6Kk8Nxg6GnPlVmlRB3V4Ibg+AbnPRtcC+7eHLn8scpM+y6ugIE0fZCjIKWvywmozl8g//ibMSQKxPNgUoxYkHgmEtfFt7dB+dgx/XhYGyNL/p6I3tLnikj9lPn8PPdNB4o0i3n44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682007; 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=B5ZO2ya+U8Y5mZiIVeeEomIW12TjCziwuygS6j8y3xg8aPqlQrm0tRj1oZ7i8jijvaKBhxadJXAQF/eh3do+TEyyctPcLqS5UOTFMrJA4sJsRf1WyD73QRRbrfGnZEJ0Za7mCCXdT93dhkNibFzQh9JC9c88tvajppB4NudJBOM= 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 17766820079551021.4946593674506; Mon, 20 Apr 2026 03:46:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm61-0006tj-Tb; Mon, 20 Apr 2026 06:43:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5z-0006sO-8B for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:15 -0400 Received: from p-west3-cluster5-host3-snip4-5.eps.apple.com ([57.103.72.28] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5w-0000XX-C5 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:14 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 2A4D9180044F; Mon, 20 Apr 2026 10:43:09 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 7D84F180046C; Mon, 20 Apr 2026 10:43:06 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681791; x=1779273791; bh=oQob0705w1vpsKwSbilmxpp8KQiyruObQqebQ5RZ0Dc=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=INWPRbk/4cACZ+lUK+edIuORaS8mQCUDWFrdcvvTc7CTg4pn8qFNrpM+TCwOXPueqosDtZD2QG6R7Bk/ibccWh4lgvLFWLTEbEYZmxc/WnCCQS4kZdyQTwS8y6fQqDSE+zG4UB+jUYdulzUVYk00cjeuO2iUoo0L6lVRLAw7XyZf7rkdr+PfaX1Hhn9BltMN5GJ2jXTsPKeBB9Hloz/mPb0aHhc7SJYg7eR/ODAapAKPFbNpZMQc9+3XBVmoasklQ1PiAHqXLOWrDihcm2KauEPlHEXIsoA5Mc9wGH642sNyJFJOOBp6fekSP1Z4vBGWNByOf2f4+5NvFxqanHfNFA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 06/38] whpx: i386: reintroduce enlightenments for Windows 10 Date: Mon, 20 Apr 2026 12:42:16 +0200 Message-ID: <20260420104248.86702-7-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=VvMuwu2n c=1 sm=1 tr=0 ts=69e6033e cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=hfWBbujXMTx1PmRkPVYA:9 X-Proofpoint-ORIG-GUID: -6QxFsOE3MIWiQv7CPoTwcvnKQYM29gO X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX7NHZ2Sjk+N5z NVmNTSTQscInY0at4z8i9YRfXplBQpEaqlavR4xkuJX9xi66Rtf2T9o69BwRV9XaxMibA532sIx qPi3WDcpdNfB/wVA4ZM6GPu5lFHJRALC3hw9qvnE5ppDiBPzVuuPjsloTDebmYUSDZMj4Txseku F1Ljf/Uk6ez7jg1kAe6dwu2fv5LwdGWfhK+upeiHSicL0vqZpYqnYs1YWt1bvb8z36OGUmcTpwd s8fo7q5NEtOwJCto8B4Ci645mRTuPp4uRFI1rIybpCjEbpKbvNXSGWjHHCUMixB5nlKKScdW/ig uXykEpXQO36CUeZgJm2Pz93A4TuXaK8fPiR3S460UfPGbaqC7ne+8HAHarDeVg= X-Proofpoint-GUID: -6QxFsOE3MIWiQv7CPoTwcvnKQYM29gO 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 clxscore=1030 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 malwarescore=0 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.28; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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_MSPIKE_H2=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: 1776682009336158500 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 Tue Apr 21 14:38:14 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=1776681976; cv=none; d=zohomail.com; s=zohoarc; b=Rjvf09VNS0nNQZGoF5ncCwqHHufwALeMq4nAEk14Mg99H8UDBpwSoqG2L/x7sfSzrJEmUtoASPU7W9boYeOAxo2pEa3XYb2VgjhIjd7iFxtzubucLY7VpsgLXAPUmJdrB8Uwhf8lipG405d8WFbI3b/taef1TYjo8HU0n1Ks/Qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681976; 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=rzH0nfvQx4HDQyGiqHq24GYidgrGqENXmeSSBmYWI5k=; b=TghsUKAz8x3iTZMjPaVzPhn78oiksA1N01jz29xM+FxWOIONVPlq+/v+YJo0+Q2tkExbSaU7uvHopIZRa9eqdlguQfwQFo4UqqKd+t9A7U96p03Rpy69TSI8MEWf1gUv8Rh9Qg2IHpQBK86FZurM071gDHXe561YXs2E91cwlvs= 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 177668197638218.300348297571418; Mon, 20 Apr 2026 03:46:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm64-0006ts-DB; Mon, 20 Apr 2026 06:43:20 -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 1wEm61-0006tN-I0 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:17 -0400 Received: from p-west3-cluster5-host2-snip4-10.eps.apple.com ([57.103.72.83] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm5z-0000YJ-6B for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:16 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id D5373180045B; Mon, 20 Apr 2026 10:43:11 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id F344618000BF; Mon, 20 Apr 2026 10:43:08 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681794; x=1779273794; bh=rzH0nfvQx4HDQyGiqHq24GYidgrGqENXmeSSBmYWI5k=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=HdahSLQ1zfFN3gh+ng+3cEn1UkgkUMdxQfeGHE/bhKxDSvYRQocB8nUaeMMhIPt7OB3TezKOIG9NlM/DguZ6ma0rNBf1LITMWMBBEnM/4SrEAeBNfGkDErQ14PaRmncezsjxLHRTGfCJVE2KBo9tURmEVqpoNEOkP3f5pQuhnXYZhqEuz0x49PjJ7Bn4H7FQ+8GhHp/6VLOtQxpxJ6ffFK/C3WYiDeMPt6DA1xQkmL8/QE4pntM6FIE6Cki/7qSdCn8rc/x87DIJyYbehYZLNOt8/Ju3iX753LDmIUtIk3GF6upZXP8OSoc2Lt7pycTfJovGOil5H3TBXh1t+eidoA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 07/38] whpx: i386: introduce proper cpuid support Date: Mon, 20 Apr 2026 12:42:17 +0200 Message-ID: <20260420104248.86702-8-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: vu_J19aCgQGVGpabYkC0JeAqTSqn076t X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX0e7DAY3dG/+c gCopN9cDCM8nxw2YexQT1jtv5Io3pj29IYT+wje1Bb4m0WPpM/pFzVo5BUwSUZ/wtcqyYsk9oNr dZK3+pPyVpa2r+T5upXEz7rZdtbZ2ZEBOMWhTB3f7+s/11/rJeF/a3/yNCtH8S6YqmoAx0uUzS0 6ibA4u131UTq62PMqnMMC4Ba76Prmp47099hoQLU9A53kRvcqGU2jHjYGGjwFpd/ObV2/cgMKta qZ9EcVe+lHrmmw/MqzX2SNIBZPJsEho3cV7PxV7d/otADBYZNWK2+RKiR5EBWfrSu5CQwJECNrn 6hAHOL9xEByp2od5vJ6JxM9IBQab5Eke9SS4CDOYNe+teoSgiAyOrQE3UcctvA= X-Authority-Info-Out: v=2.4 cv=LaIxKzfi c=1 sm=1 tr=0 ts=69e60341 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=n8cRCUxqL_yedgTzvKUA:9 X-Proofpoint-GUID: vu_J19aCgQGVGpabYkC0JeAqTSqn076t 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=999 clxscore=1030 suspectscore=0 phishscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.83; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776681977441154100 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..53b59a98b9 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 Tue Apr 21 14:38:14 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=1776681982; cv=none; d=zohomail.com; s=zohoarc; b=Gy4bO4OUw1Dqc4Yj407JpeEFRhzmetxKsAXgPMunt/YZqlacqO7/Dhma4jrrCvZMvZPvYRzZmnIese185zt1q1iNrvbYMd13ZFZJqmUJ2Yd8O+68CITnG2od933mKKHLJH0CRJ5g8aKlBlKm8vLU/yoHL0vTXjpxdek9NPF1XdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681982; 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=Dqy8GVOg6Vy5Bj3rQXQsRJvMspD1oQZRo/6wY+UsQGM=; b=M+IvbeqxxMcpx58A5Vslaq5cfoXwYEMe2Mqrx/LNZXCQ/w4TUAbNktMlOrZah/wISbtwHU8nPL7hahfJiIj07IRUmSGeb8M5FDTdpCE+z8R4PAv/O+UVZl295Xp0ujFN/Onmf2gzWu8EAzfkTiOqGq6BJCpJ7i6zwwYhtSipUGE= 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 1776681982268774.5655151824919; Mon, 20 Apr 2026 03:46:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm68-0006vJ-2V; Mon, 20 Apr 2026 06:43:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm62-0006tu-RW for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:20 -0400 Received: from p-west3-cluster5-host7-snip4-10.eps.apple.com ([57.103.72.13] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm61-0000Yd-9h for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:18 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 3E20F18000BF; Mon, 20 Apr 2026 10:43:14 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 74CB1180045A; Mon, 20 Apr 2026 10:43:11 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681796; x=1779273796; bh=Dqy8GVOg6Vy5Bj3rQXQsRJvMspD1oQZRo/6wY+UsQGM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=MTjclywa8EtPxqcnPTCarbM9eQbGRsNC7jwOrYiKcpCXRau/JXMwmg3vQB44+A8iBwYCphvTZtXBrR/ATc3NxyPFpGRKtCx4wFypUnONJDBP8iX9VIKJrvCplBiOdzVyzMg3E8sanHsd2ynbXldDMW4tWK7kUV8MPmrYtB/+NmPylUZVCUcF2yParUpmBFGF6DXE7Y63e60GxV+t+Lx7GTTfZWdkAl90gcLR2Gcp8Qo9AmHR9q2nkHkDSV5i2nWpmgb6FxDRNeW4poNhZIlzSaZXVbkk/RTZw0CVvxz0ejS5BAUgiSBKh9n0+7KaPJDaVjreE5wiyG8FFcFJIamzpQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 08/38] whpx: i386: kernel-irqchip=off fixes Date: Mon, 20 Apr 2026 12:42:18 +0200 Message-ID: <20260420104248.86702-9-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXx9aIsiqqI6lN ADEtxzJT/hu8yMPBS/hZjHW4R2CmsdfPKSy1RDJxxd32DER2u3wyMEDn9OFvhhkOL2mqrbzKYBo nX8y7pcJmDz4sCh4Z2seeMJjK9LBdVkE4Xad/50lM0JxggTMRWnUFuCFdDN/ldcnBcsv3kP7Ciw gtxKXJ/onHCzLXh+7Jt5GOBAua6nsr24jsCDiNjUvDAkFSKF24dZB8RplUVgpRedLwTaXyjKLlb ijhu2A/rfV5bUaOR44/AyrwmgIAjyrsX/OX/7QwZxgRAh/+Xv2TkAyrG+iE8OEWGOEo8+jBmqG1 pMZOavYDvxrV5NcVAEfF7ioXS0pXVEhNYTUHwz9gf6TO0lupzkAjSkSTmLkNdU= X-Authority-Info-Out: v=2.4 cv=Z+zh3XRA c=1 sm=1 tr=0 ts=69e60343 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gP1GEkNOX-MqffGxZ4oA:9 X-Proofpoint-ORIG-GUID: urpzqvhhtQKdSFRZTyFW5-ZcPxvVL6c_ X-Proofpoint-GUID: urpzqvhhtQKdSFRZTyFW5-ZcPxvVL6c_ 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 spamscore=0 phishscore=0 clxscore=1030 adultscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.13; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776681983593154100 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 53b59a98b9..1d99003a4a 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 Tue Apr 21 14:38:14 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=1776681824; cv=none; d=zohomail.com; s=zohoarc; b=C663xvmfPJ7u9zipE1rT+rSuM/VzmyZGSdXNQJr3qsy6orFgVdnKbI2IZJuvscyDgdgPbXpJi3cJIjsNslUrXKy0oXeXt0LIkfzdRDiTXb/uOYq2d/pRQbwxoGfdX6tio0S20Gm8A28l+hR+17IpI8hNB7YzmlWEV945e86iZTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681824; 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=8EZPZlRm+WeBpG+PY8ABc8ic+4NnvhCRuAoI2d7ubQQ=; b=HU+jmf2aJhg2WIsUr8JsJgf7YP303+vhK/zvIDUw2jFmfST4sCBbNFh00VbSISa9ojTndaN8IGya3MHkSPLmvg0a66mfDm/laFd+Y2Rfn4mlSmJ6DVvwRcj8n6hPsVybcVK0YwQ7p+w9OOiWUP9cFpS+c6E8SZG8l5020t5u3CQ= 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 1776681824593934.2484697589023; Mon, 20 Apr 2026 03:43:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6B-0006wL-Oh; Mon, 20 Apr 2026 06:43: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 1wEm65-0006ue-GU for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:21 -0400 Received: from p-west3-cluster5-host6-snip4-10.eps.apple.com ([57.103.72.63] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm63-0000Z9-JV for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:21 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id BB6341800153; Mon, 20 Apr 2026 10:43:16 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id E9B4E180046C; Mon, 20 Apr 2026 10:43:13 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681798; x=1779273798; bh=8EZPZlRm+WeBpG+PY8ABc8ic+4NnvhCRuAoI2d7ubQQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JkNGgePt9hWl3xJZXXELW3Lsju6fSFRMyafumllrZF5Ea3+sAkkKCof8jUPHG2IicOyuH15u9GKb1+I5IYGafK6QOQhPHRumzNB6dMSyijZuj6oeSmlFGBqOE/g7hreaGYvU321ByHxUD1vDmp1Os0j5AndoPX6PgZ1xVJy+be8/EUQqmRG3o40o8cyxnvowlacRWHNQeJqRuRDG+9oH2P19JQd4bSj/I/1Y+t8Z2ZvpY4Io6XiiVjhEXrFK4i3716AkySw5KPfP3DUs0WvqGFwJnMMSPuKcxc+3MFkbGRL/oPjKj5npo3aihSTVnJ2VIfqcQHfuYKotz1iEp5XICA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 09/38] whpx: i386: use WHvX64RegisterCr8 only when kernel-irqchip=off Date: Mon, 20 Apr 2026 12:42:19 +0200 Message-ID: <20260420104248.86702-10-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: _bWqKoJBba5jE8kleKPErwnbgiDW4ykN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX5YXtWIleJh5W bRRofCprt5DTSdifwoZ3cONOrzniOtcyjrYjGEnUCO0VBj8EA5vrp6KanQ4V28zVNjwvjfZqD5v RvVrqsa+yDzf51ywZTkQ+mr9YnclkGsri1uBQHKV3k1YILH1y0CLSAUrpeebugt7fcUgCT8bxfo CReY0tgo+r9CSqO3dMCxiTPbetaAMhYuav4GCEEUB2/daz9ekGXgFopdsKevHj11NYOabKGkQgx zgs2+dxlHFFWMFh2DQeVrMfHVcMU4LOLofir86msseezkjec/I/dMluAYL+byBjHgPsgM7vfWCV ucVH8x6VeHJJejBJKQUtjYFtpO78QXyoD87A1UJp6lmi880xU369K1F/KYBG/A= X-Proofpoint-ORIG-GUID: _bWqKoJBba5jE8kleKPErwnbgiDW4ykN X-Authority-Info-Out: v=2.4 cv=TtzrRTXh c=1 sm=1 tr=0 ts=69e60345 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=934 lowpriorityscore=0 adultscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.63; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776681827393154100 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 1d99003a4a..03f490804b 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 Tue Apr 21 14:38:14 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=1776682101; cv=none; d=zohomail.com; s=zohoarc; b=lcSQ27JwPtg7n3rui1hV8bljoyo65S6i88/UflqGQq85VzDU0AeHRKmljYVi2xLSg7nv/qJYSUg4nDA02gDSx/9xw/2UM24D9Qt//hLMchp+NRdpTd4to+64J345e2Wt+GYr3vG/7RwiE/TWgW3GA/qawswIpcnhGOj7iuKQ67k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682101; 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=HdVAIoica2OqP4cKWuMYnvVU1VqaziOIo3sBb38zdzU=; b=hjZatxFpPd6ltUwuzvnm749cLsw5ZkPshx6hbXUMa5Fdt7EmLl0D/+tOFemrNCuECBBH+CJLZ0XHhXoDsPAXlvt0XkGqTxZS63C9swppn6OkXgDsHZW5fQ3QHM6PeAe4RdaqysNr8l+S6V4zM8W9X6YJ3fVBrsiqXNFtEUDCyLI= 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 1776682101678136.023886808396; Mon, 20 Apr 2026 03:48:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6K-0006xh-1H; Mon, 20 Apr 2026 06:43:36 -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 1wEm68-0006vR-6M for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:24 -0400 Received: from p-west3-cluster5-host12-snip4-10.eps.apple.com ([57.103.72.123] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm66-0000Zd-Id for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:23 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 51A9E180045B; Mon, 20 Apr 2026 10:43:19 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 6EF2D18000A3; Mon, 20 Apr 2026 10:43:16 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681801; x=1779273801; bh=HdVAIoica2OqP4cKWuMYnvVU1VqaziOIo3sBb38zdzU=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=ZbRfhmxbkJKbDvi4kV/Cvrzkz0UGSR6WbHSOuN6U7Xz8Iy/FMgpFR8bOHv1y7V00OQSqQomECxBdxQ9ObNDKwJ5ETIpvvo729PNJIlYTcUr5q+A5bjf7j4OeOACpVvzGMAdPcqok9MIZEWp/i3q6Sjo18XAdmoEavCtQ8t+/xVuuRy4VtpwxcGb8UGoS786jGIiKUkNy/1xnd6HV9sFSQ1Ia/yjZ42aYiBYPUAeyQUZpkvnmiCGCHB9D+A+EgB/Tz/t46oHf8b2HYXFoOCHObJRFitcWnJQIPKg+wHrMXQc07OUCHOEjwyGdU47HudrUE3Pjz9uurPSerpgdT622TA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 10/38] whpx: i386: disable kernel-irqchip on Windows 10 when PIC enabled Date: Mon, 20 Apr 2026 12:42:20 +0200 Message-ID: <20260420104248.86702-11-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXzxGCLb8ASQoQ SYU71lPx4nmuOcMfWAB1tx6aCdCg6L1NDmSNCirQ4tV2BaytKUjE9aXfWWOLTqBoMlL3z1HhNeo kYKhFztiagk3QxcEdC7ikZp4fPg2uxigkaqdoXVNfmRyA7psK7GtH3yMyyApco31FrkP1Ak/Rbr Rt5VDqjosQGcd4kdGl3NVmSvz5iPiXLEQukDWcgYe1xcEabO0QLX8Va+XIgO5lnLM0XiHvjDqol QNxGLaxq3U2dIQ/drT/U7W9PQnNEK7rJkj48QZTUT0zTBxsN0hWV93CMHQvqQ79ag38iO11bTy8 SwQ878cWW3RFYqnUHfxdKi+y13pNoYNKfM7HTjijTm5df68Oyg0bsOHHJ+a8CU= X-Authority-Info-Out: v=2.4 cv=Dbcaa/tW c=1 sm=1 tr=0 ts=69e60348 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nUl_a9z44qMLw6SsMv4A:9 X-Proofpoint-GUID: znvfjnvsgZKLosfzKUnJ4GMbCvMv_mcD X-Proofpoint-ORIG-GUID: znvfjnvsgZKLosfzKUnJ4GMbCvMv_mcD 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1030 adultscore=0 malwarescore=0 suspectscore=0 mlxlogscore=867 mlxscore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.123; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776682103740158500 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 03f490804b..4d1a151db5 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 Tue Apr 21 14:38:14 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=1776682082; cv=none; d=zohomail.com; s=zohoarc; b=BIVMGApazaRkgKjkkBv8f3y03EHOQEInUl16XLEOiSciFBF7PGmjUW40vZpzWmsxM4BwIratBKfzeuhtd7QIt63sussC30DyHKJhYJRuvzgKhdKFTjHgeeSJd1uu/juX3kH/LwAjdwpBuAEURa6FEeQ/wHHDejKtsACdRTvZRDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682082; 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=nQndBaUP3p2GZXyo2M9Kbvf88ZtsTTUcXFr9tOFWW7A=; b=aMglaJPiEGm5YeqBWCYqRf6dyE/UhA7q3h0wEm1+yiPHtL6HV5vNBwC3fAvfsfnLUcqleCDmylJUxJuDmglvAQigwv8W4it2/OxDhdANPn6kMumRoEBh/CVgtJ/bArNRcVVsDLTpdDTzMNncCrGoHnO0CkNXVB62hSUmXKEVh8k= 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 1776682082270970.0019850532898; Mon, 20 Apr 2026 03:48:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6L-00073H-A2; Mon, 20 Apr 2026 06:43: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 1wEm6B-0006wf-Pc for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:27 -0400 Received: from p-west3-cluster5-host1-snip4-10.eps.apple.com ([57.103.72.73] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm69-0000a2-Pr for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:27 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id C346618000A3; Mon, 20 Apr 2026 10:43:21 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id E26C11800451; Mon, 20 Apr 2026 10:43:18 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681804; x=1779273804; bh=nQndBaUP3p2GZXyo2M9Kbvf88ZtsTTUcXFr9tOFWW7A=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=IdWxXi1zVZXv44s4zRRsjVx2FHvC9BYFG5DB70W98TBCe1Fn9J7IPKpacB8+jQfxwUwHtIYfG6BRZcLMAoosvl/hvxL+xRJ2sxOeDPtiUP90wh61FoWHggg4xbTJEDd1BIr/77+zuG7/XuqzhFkLPgxQ7z3p1XoFA5Ls/2JtrsYbGvntw3Ars5Wdqz0BWUjBZQw66gX1uS1LwFHVcZOdQk9wvRkpbu1ZF/dmlyc4/1H1Z4sOaHxszP1LrWlSam7h/bssTjwAZdwnsIwYxtojeuUI6MIylGFs69PDEFV8ZCxA6bz4MNnu0reD6l6LbPp0UcTiBe+NjYr50LbGhaf8ow== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 11/38] whpx: i386: IO port fast path cleanup Date: Mon, 20 Apr 2026 12:42:21 +0200 Message-ID: <20260420104248.86702-12-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: w0YYqtkw1NyWm0C125HfF_BDCgCCAIVx X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX3xTYq0JAgDqw 3sywa5JekA6elTiW8T8gjzu2uTO/XbFZRkgCz0hhcvEjsRcMQuAoRMhikosba4Ci3io5cV+QZi3 DfkdBrVakNnBUpDG3JXlc00uYmgi1qF1YP+QgaeDY5mj3mPYGlep2TS8jmKtci6qpVrAVlFMnks QqKK8lOG55nd8+QghhiAA3Ygb9zWhUDfkcXu30eVUxGDNTBMFP/VebttxwcRORCYQ2H/6tcZtq2 FPjm/ub6TUjlDhOsaD/wverweDU/4Jh46/omxJvvXP9yv8FnGGewzMJ8Fxci38ly1oMDHPABF6D aILm6TwExQ/9Qu6+AvF0GJCSN+cNSG8zs3uOfxoErTcntE0h2ZUyuWMZok8o9Q= X-Proofpoint-ORIG-GUID: w0YYqtkw1NyWm0C125HfF_BDCgCCAIVx X-Authority-Info-Out: v=2.4 cv=TtzrRTXh c=1 sm=1 tr=0 ts=69e6034b cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=873 lowpriorityscore=0 adultscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.73; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, 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: 1776682085072154100 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 4d1a151db5..4deeffbcfc 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 Tue Apr 21 14:38:14 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=1776682097; cv=none; d=zohomail.com; s=zohoarc; b=M37wh/57FwU5tZlhVSCpJwxuQESovW/2xMQJpS+DMJLlznb0RX8Y74AOHD3R4DXAp7rW8qnfXxYLdP8ag+4871lD/7bE/QjRDDAPN7c3P2olz7I3f2sAGy6+vSm2Ogij0G2aNdA+PuiUH4wBkSeMmOtmPHfJEWHD9HmOZcX/reQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682097; 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=oAkt/0X2iO3/a4xMYFMpgz9ibOxymnsHVlwLVxvLdU8=; b=SiCFozqT22vgI2v2VU/2t+NFI9Dj4xPvhS+8+jRyx7aKMq7UQt8rKnKwdLLEqw6UPWZnloGrnftF+RANvQvqq+ARIeAv1zWcGs6San5QmkNGLPtlE3p8e8PE2mg/FfIgZYKVAqE8yWcVaAgWi6PSEGj89/VryVbEzyVFGICfkFw= 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 1776682097324714.134902480354; Mon, 20 Apr 2026 03:48:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6M-00076F-Dq; Mon, 20 Apr 2026 06:43:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6D-0006xd-BZ for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:31 -0400 Received: from p-west3-cluster5-host4-snip4-2.eps.apple.com ([57.103.72.35] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6B-0000aK-LB for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:28 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 2E58F1800140; Mon, 20 Apr 2026 10:43:24 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 5E0FA1800442; Mon, 20 Apr 2026 10:43:21 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681806; x=1779273806; bh=oAkt/0X2iO3/a4xMYFMpgz9ibOxymnsHVlwLVxvLdU8=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=gZFvQfOtTG728Aiqh3Pxs+7eq2aA57ZZU/Egy1Y+k7Ux9i+eKytga4f+WS6bmGIdbIRFog5+nqKeEw1gEKIvBpyAhQG7u4A7Kc6zrPjTxvk4B77aGecuXxijBV6MVANNnuZqst74pR57zqOywL0huNJEiUxAgiZnUOA1/dhm86wN6/vSOy+OlT0It6YfsKUIYA58grHWh9PbLsTdI1Ny7Y7YfKyIYteTG8IraDGWuQkWW+ePC/Ppr9w9KbIBIoEdSrwZcws0aj7DF7GH8SymAS7VJ4/WD9hj8IcvlvA5v+BXT7k5AfJVPes/C3zlpFxT9IuGrm/t1GTHXd+jWedu8g== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 12/38] whpx: i386: disable enlightenments and LAPIC for isapc Date: Mon, 20 Apr 2026 12:42:22 +0200 Message-ID: <20260420104248.86702-13-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXxjvbCepagAjn ZdMVIr4oj3Snew99sTCdX+R4pAd8RUzhrxURYc3GAKlwjDb6npkQeOi4ux+CRQZrldl3UY45Bhj 8M5ilmpJ8ayKheufeK8rEpR79gxizl7ZkahRX/gJt2euzblbYPP5hUr1IKZiUMbPu4AQmHUL7JS EtjY45v8xrSxYQTnjX2Aot/IBCPzTCSl4u5ilElkW6B05XmeAMocSq4Ptu1FtswIIKDOzj+4iAr bnHvSdQbxnJLH9G1Nw9xJO6Y6vDQuihnMT3sqO/tc5KzP3fy1N5Zf4yPbYctP2QIDz1kMaOZT0H T4VH0zE8Kh6qd5iuOSQlXba1jMsI7xTqE/Ao3DyDYjH34x/JmhmOcWz6hjRrGw= X-Authority-Info-Out: v=2.4 cv=Z+zh3XRA c=1 sm=1 tr=0 ts=69e6034d cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=kaNVauZA35-AGszze7oA:9 X-Proofpoint-ORIG-GUID: dHfS9Sf_op2BC3kfYYMOpZIEm8yd27jN X-Proofpoint-GUID: dHfS9Sf_op2BC3kfYYMOpZIEm8yd27jN 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=891 spamscore=0 phishscore=0 clxscore=1030 adultscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.35; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682099453154100 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 4deeffbcfc..d38b83d274 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 Tue Apr 21 14:38:14 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=1776681959; cv=none; d=zohomail.com; s=zohoarc; b=CnWJMKrIwURqcNE2VZHLD1CNpPoWOF26kc6zFlu+5PPcWmbuHwidTfdWAq+Yx/Bv89a2F0ODYYc5ySzypzPMJN9K03wpMLDqWzNGoiyCdMZdSUCbL9J+hi1dhNJF2YRpD+85PdC3n2nT++jZxjMkoot40hP+tIr9U3PzJSib4eI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681959; 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=3V2AbGdIbRhzhb8qduzZPT33vmWH+5zkQKA9bxE3tcA=; b=Kfh2aH0q7WsOpgonXYqb0UMW1cUzVd+V3DV6RTUtHT4zbaviIIWDfICA+qXVR9MXLzjf6To9wKjGwX+z95LZWNdvjELdsTYN+MWsBr34UnMpsoS8v2GgXghD6+GLYUsf59aSC5nKqaX/1PpS0p+ETN3hLvbyF2+nciiwmH4m7O8= 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 1776681958926513.8805590955883; Mon, 20 Apr 2026 03:45:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6Q-00079X-H8; Mon, 20 Apr 2026 06:43:42 -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 1wEm6E-0006xj-QG for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:31 -0400 Received: from p-west3-cluster5-host11-snip4-5.eps.apple.com ([57.103.72.108] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6C-0000ao-SF for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:30 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 7177918000BF; Mon, 20 Apr 2026 10:43:26 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id D3B251800453; Mon, 20 Apr 2026 10:43:23 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681807; x=1779273807; bh=3V2AbGdIbRhzhb8qduzZPT33vmWH+5zkQKA9bxE3tcA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JgWCaSVEugXlN49xCAIBBThh2GbMf0C2o4t3BXF6rIFK64sazePCyhM+yMZQYRsW09f2xUM/ILHbd1LM9UvAE/LThGSvj83cEDL9WuSZikWtgFzAbQHpsUo1CEoewxdtIN5WCHSZZVFkKGPOSI9HjXIhnrpTGCZIW3joZBYUun2BxTUqAV7otF+adMaGE8ZXDFmD88s4kZAxOEEWWkhxdT2P5iMDAwkuvXC5E13TxFiurNScj5Zj/OTDKjUbiKW042WX6hdXVuA/+moUdRIuiQ4brl1O9nvE0zlgWnbjkczvkVWRjmNdY7ZpsJnNpnGP4QYO7SWdnVOGHk80zBCqtQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 13/38] whpx: i386: interrupt priority support Date: Mon, 20 Apr 2026 12:42:23 +0200 Message-ID: <20260420104248.86702-14-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: -SxLM4dJTJev-AiykB4STG2w6MD6DZ2D X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX3XW3xQb9Sawf Tg+P5z5Rk9A7r1oWnc+UMoM6rGN9bQ8azLXr87OKJMuJa1mnJBqOW/euElhCBIHorP77aK9leJ/ qf/ubyItpyQfrKpi8sKTF8l0U+3k8Hmdcm83d/PsQIQPVH99rF7XgqOC8rZkva1OMSm7zJ+1Dnl BndrJ6h7QV4ckod3IGuLduBDuNsxjsKMehDrOPCJX0DCTLgrY8N/8cy09/C6fEcbZn2uP0RHI48 vDqn2W0yv39OGfq4xKj/Hb3bp83u1GZViNsvCFQTQaYibGGL+vsiaXe2J6AWFRhKqwtcGfyVk1f qyFuhohJ037yOCni4WVpllI13p7QiYkzJcDC8KNIW3ZLK7ODvA0y5xhB0jZenM= X-Proofpoint-ORIG-GUID: -SxLM4dJTJev-AiykB4STG2w6MD6DZ2D X-Authority-Info-Out: v=2.4 cv=ce7fb3DM c=1 sm=1 tr=0 ts=69e6034f cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=687 bulkscore=0 adultscore=0 mlxscore=0 suspectscore=0 clxscore=1030 phishscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.108; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776681961473158500 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 d38b83d274..930731e4bf 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 Tue Apr 21 14:38:14 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=1776682129; cv=none; d=zohomail.com; s=zohoarc; b=eoWalNgfa/ou92TKLYDVcZdLioKjZBUWCw8pqyQ7WmhoFP47QC8gjjZ810zn4PzlI4hw8fhR6cdmXDvTAMH3FKFyxsscChGeKINp2gtPNze8AwJxppUKWPvIRy2iehWrIPZ/Wl1aH8UCujlK47G1EBbriKLvihG68St8UMM9DtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682129; 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=ZKPoujWieITU4lFOoYMwoz+Ev2hRigYtFeWxrkrjtmk=; b=Ll0s/78fYfbt+pehWZSKSSrbyV5M/+CR11heRxMcJEdQo5cOdXq8ObAEDaYVZn/MKNXIIdnjrLjHEwRbIrNGwCk0r8diOrSO+MwFjg45SS8UCaWcEGjW75sihQOXUreaFPCOsbiR/FHPOj8/3WJ/WEA7hKr/RVzslBB9KGyN9HA= 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 1776682129392452.8865933674276; Mon, 20 Apr 2026 03:48:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6N-00077e-DY; Mon, 20 Apr 2026 06:43: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 1wEm6H-0006y0-R5 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:35 -0400 Received: from p-west3-cluster5-host11-snip4-4.eps.apple.com ([57.103.72.107] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6F-0000bk-SW for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:33 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 21E2918000BC; Mon, 20 Apr 2026 10:43:28 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 564EF18000A8; Mon, 20 Apr 2026 10:43:26 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681811; x=1779273811; bh=ZKPoujWieITU4lFOoYMwoz+Ev2hRigYtFeWxrkrjtmk=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=fC41+bjobamaLoNii7j/C1lXIHx+syO6jSROHnplmk1IwNbxSKguUZxL3T/uE3+C+a7Zwpq9HsiPvU1HvNrCEHz7hlyhkR+1IPyrA7fslgev8rSGXq2gRhkGG8/22LD6BLWfY+1CNrakLsBtTBG81l/Boi5PWw2RkYZshKXCE8vgzalbSvkBRaoduKZLJtE9PqdY+j4qfvILrhYPBBjXF8aDwVBqb3s8a1f9fV3hze53UbZM3PnkGVjhQFu6ZsTNwtrA2rwmbBUPVN6hSZ2tHzUbZW5hB1zc2Y/DpGYA5LNWhUxi/w88uTAIgszr6Jtrh70t51YWCT/bhxlDFoc0wA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 14/38] hw/intc: apic: disallow APIC reads when disabled Date: Mon, 20 Apr 2026 12:42:24 +0200 Message-ID: <20260420104248.86702-15-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=b4e/I9Gx c=1 sm=1 tr=0 ts=69e60352 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=JYwUPf56aOQolOdNqfgA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX9DgcYt0tomOa ARX49ThUrj3kbjjlvxp+slIiNlI4M8YQYqmuv/RkrA+VjzTw8SXn7x86HVygB2rKxSzJkI2rfrd VOfbaJZ8cy1Uq5/CDlUk0Aip9+x/E7mS/40XQhn0IL6zedyIU0c+ltvBggM7STo/gsgWATA2cnc jl6ar+mMnS9EByhIeJd5tek7qE0NCtlH6vOu7b3ACVxh71qDeOqo087ntdPvh2VuFmY5r6uoGXo lmEvg7mgKEH6ksVz7tDzeUIrqGnPtYfcX7/BMaxaSlDKCpqj0GL+1yy8AyKddJyE9pcEyl1v19M ouN4DoaIpPGOQAMQ5u01LGZN2XgXDHyOjH33z6OQXuxegCNKJF1VG+tZV+Ercw= X-Proofpoint-GUID: BDxHLjnW0i30Vvh8xCView2pLlXS9wfB X-Proofpoint-ORIG-GUID: BDxHLjnW0i30Vvh8xCView2pLlXS9wfB 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=821 phishscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxscore=0 malwarescore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.107; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776682129794158500 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..e5ea831261 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 (is_x2apic_mode(s)) { + return 0xffffffff; + } + index =3D (addr >> 4) & 0xff; apic_register_read(s, index, &val); =20 --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682100; cv=none; d=zohomail.com; s=zohoarc; b=kuCj+boM+i1e6z/PZL+SyjIRmq5Vko8jav0Z+9j6MIGX6dWg82SLPqr3qsONJ4pQoQ+DCgWfIPds4LLU0XgLlr7Wi07wM1vAQ3FYIw5KKLPJ0mpIlokmYAzSsCMvCwPhtl10K+0t1ycbC5PkyJOPXJ+sTQxUbP4fWYVogxXgdR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682100; 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=hYF1YTmYdf5ICiuf6ALK6IwLbtpP7J/JdnQnOFIIsbo=; b=hPPjwRZOYqbqgHk+YC1G/dinF1KPsE3nGEA1mTQu2xGHRxUa02MSubECmMENfT3lZImV4SVYoeh3g1XUOTrw7TDgjchUit7FkQJkaT7YQxLdl4nN6p8WSLFdnDh05Fn6+lTZ1Nk3W1bJJkn4h9eMJAceuNc1Tc2RDC2rP4N6PPo= 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 1776682100582482.9054125876039; Mon, 20 Apr 2026 03:48:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6M-00076S-J8; Mon, 20 Apr 2026 06:43:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6L-00073G-6h for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:37 -0400 Received: from p-west3-cluster5-host2-snip4-10.eps.apple.com ([57.103.72.83] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6I-0000cP-V7 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:36 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id B20691800453; Mon, 20 Apr 2026 10:43:31 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id CF79D1800475; Mon, 20 Apr 2026 10:43:28 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681814; x=1779273814; bh=hYF1YTmYdf5ICiuf6ALK6IwLbtpP7J/JdnQnOFIIsbo=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Iv6mZeb/lN/CVrKJYpZFmxjaYyPrMFE5zfXl9c9PgI7EPoOm5cpa7sWtORFChz1SrBok+UDY/3HNtLwRUJ+uHOzxZPVEAPmsRV47Mh0dLQsIoiQXXD4FQSFqD1S7lT7D20KXF6X7512Ip6jIpvh4ODXayQNdmPTgQg5Hkv1d6Gn42ASBj3aXoYYcY/dAzdy26KzLWvECLFtmNf0mCly83pZi+lgynURoJeasCmpqaIYcq7ZwWEXKItQRWPb2IjPFeZHR2cxgGNCA4tsVVK6WEn4F+XsWj1V1BuO8ncsq4Rp05caHu6JWxhb47fFrp66GySLgRg+K+dmrNjjUotfnxg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 15/38] whpx: i386: fix CPUID[1:EDX].APIC reporting Date: Mon, 20 Apr 2026 12:42:25 +0200 Message-ID: <20260420104248.86702-16-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: gK4Fzyvc9Py-pGYvUxxz2EwOwKt40q8h X-Proofpoint-ORIG-GUID: gK4Fzyvc9Py-pGYvUxxz2EwOwKt40q8h X-Authority-Info-Out: v=2.4 cv=Ct2ys34D c=1 sm=1 tr=0 ts=69e60355 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=ljJ9V6m273jqBh-Cp98A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX1gYefjI6ooO9 f2HnPeK/tMaC3rLWYpu/VUZLVU3GOaPNOQJ9IgRK2CjP9TCukxk6B3MSltbPGb3QhNwRKDIo1mq lXYLKnYM12Bv8gf+2EmRRKf/Oghd5pFtK7cUoNIoGwUC2la/JLuaXKG/rwl+V/i6TLi6O6wIzC7 ClJevMpDo3VYatTTsjkzMgn3Qn1jkmi+InouFwwpqTCZYnfGdWxE4TavEo63aJ0vGC6EAQOWghU MxS3+Y606bmg5yPXUlGDw/zDZwebXmXFUv9HISum3IqwxD3L+DhCqH0HWdoojsHNtNyhnYvAAgp tYgAhN+yVQbiiJOjzUaOizxg1c/PJNBXO7Xr6fPlnfcveVnaWU3k6FAzz8KBwA= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=922 bulkscore=0 phishscore=0 clxscore=1030 suspectscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.83; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776682102096158500 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 930731e4bf..c6f4041515 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) From nobody Tue Apr 21 14:38:14 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=1776682019; cv=none; d=zohomail.com; s=zohoarc; b=S74ub5Bodlh2agRQLMesalec/kWSthuTEr7EMGxo3W2TLzoDfGP+eb2AB8BPGqTS7ddXXBVJVZfdCGRC102Co1gvIf8LPAdx66eZ5tUovgzqwEDswGS2+rPttXzE7+upJOAKF95acysPrHG7KxQmgLNoptyQHihFEVe5vzGGuPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682019; 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=4624USsR0p7NklevhZpyiOMKAkWt2GrauvKzkoCskVE=; b=PIaj4l/5T0B03pIwn1+NocWfcpgeNqMdqe6G/X5jKOIULBt6750vZ4ynJCB6zgAuKKTsJesQVfxRwLgGoPU6rdvyCfT5tJfmMU9PNDhP7YqxhanNZcPZLl7BlEcsDIdPQ26qT6wf+Cnplyv4gkkVpoCvbzvkulr7EVb0xRgpZbI= 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 1776682019303703.1947809293098; Mon, 20 Apr 2026 03:46:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6O-00077o-0d; Mon, 20 Apr 2026 06:43: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 1wEm6M-00076E-CQ for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:38 -0400 Received: from p-west3-cluster5-host8-snip4-8.eps.apple.com ([57.103.72.21] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6K-0000cj-Tr for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:38 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 2517E1800475; Mon, 20 Apr 2026 10:43:33 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 564A518000BF; Mon, 20 Apr 2026 10:43:31 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681815; x=1779273815; bh=4624USsR0p7NklevhZpyiOMKAkWt2GrauvKzkoCskVE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JBz6ZtwebDTWn1xVfEGEcZ0hNkLBAd/m7ahsmQ+sD6CsAQPjJUf5x2SCeum8+/CCGBgDVayWXoaAJNUdGWxkuaPUjiGtFsPRbieIEtFUQePpb/jL6O5iJatXd+mqYb6Obr3/DsPSGwwJ+zWuLvu/mQsQezARBcbQDbpWG+gF6yEyI5wgMa18MXzhIF2BCjOCvrsR3l/KDrkLxy1pe28bCC6cujNam/6ZOJtjPg8ZDmWRBstkZwXceAG9pbNZtjvRjoDl1jVdIphJ+kqM85MsgkEcmjl3fq1yk9v3wO57LvvSFYfF59LckwULBw0A0glw9x2woQNKfiIvZZSlxBmeSw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 16/38] whpx: i386: set apicbase value only on success Date: Mon, 20 Apr 2026 12:42:26 +0200 Message-ID: <20260420104248.86702-17-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX6neWATxSasTX sM0vWdIYo0ObuPKOGHYQor4CQxyZ4fXLnGz1i+3kcdnwwsgpH12+vmoMXQxt5NAnzicG94BN4+B pYPMBZZq4XVSd8K3mAZ05ibfgv9FekjRDDxx1Jp6lF7ZNvVtfzRSB5zXkoQutVzXv1Ofjk3KaMw ojxTxxMKVgLS6d3PEeVsmlK9Hf7A9SHPEfUFa4mv/gxmh2GxG4wfVf8hP8vbXVT819/TqPUUvbn r40PcyA+9oRoLiXFOul8dhIl0tkztn1Yw8eAqjNyaogv7UtfkSUiLa0AfCjVNhO0KaEB3J1YKWc a3gkN1znnoxdU5p9aAq2kyKAVpVtTvRF5wVwwBF9EEw22K0k+zcfn3YxjkV/D0= X-Proofpoint-GUID: qmSC2HbiSG6G-dnwftkoqlY5O-ThVt1D X-Authority-Info-Out: v=2.4 cv=J6enLQnS c=1 sm=1 tr=0 ts=69e60357 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=uh2sygq7LFHjsVUyvz4A:9 X-Proofpoint-ORIG-GUID: qmSC2HbiSG6G-dnwftkoqlY5O-ThVt1D 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=676 clxscore=1030 suspectscore=0 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.72.21; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682020085154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index c6f4041515..0d72e93621 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2001,8 +2001,9 @@ int whpx_vcpu_run(CPUState *cpu) 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); + } else { + whpx_set_reg(cpu, WHvX64RegisterApicBase, reg); } - whpx_set_reg(cpu, WHvX64RegisterApicBase, reg); } } =20 --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682123; cv=none; d=zohomail.com; s=zohoarc; b=BNhAOQQfcqinbNscFjMOXs9uJFh4zVCsmSXlpxxE4dF/BoQi6tat5KdXoSBgYGr/jh5lpZbCn1QhQfP1VYVBkoz98R+jns0jatBMLis16YYhkTDpqmV9FRq1OZdpwLVN8enKvAhMM3kprm4GUpwmyqVVIcqgrnCDg3DiU1JATzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682123; 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=6dRDJ5VEmS78xsRk6kMHBpp9Wu7kQoHjBWY816Egd9Q=; b=oDlXv//sFEy0wjgBr4h7vn72u4eG060z80PetJt0c/aQx4pvIMxHFoJu2S92CZ4I8uImWGUwS8s5iPifQEpaxD5uAXV6fQwVjEwZOWhZATNTldMwr/9Ix40BQuW9LAHES9sPUyXNvmgfZIweV53ibi1KMEQspBusVli1nrkNBds= 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 1776682123964531.4767512681013; Mon, 20 Apr 2026 03:48:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6T-0007An-7Q; Mon, 20 Apr 2026 06:43:45 -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 1wEm6Q-00079Z-KB for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:42 -0400 Received: from p-west3-cluster6-host4-snip4-10.eps.apple.com ([57.103.75.23] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6O-0000dj-RV for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:42 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 66B97180045A; Mon, 20 Apr 2026 10:43:36 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id D21F21800478; Mon, 20 Apr 2026 10:43:33 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681818; x=1779273818; bh=6dRDJ5VEmS78xsRk6kMHBpp9Wu7kQoHjBWY816Egd9Q=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=ZiqMaEhERnaCG8BBDaSaBRanydfmEXgOfWTwKXKrYtbhDEoGSzDKpRIjO36TBOG5pPHEJeBws2HhjHjt+uIQQ+pAV6bNFTTP0G1sa3Aw2X1lKur9SFJhx1mfJwSj4RXmi7dZlZDHg9d3/0lTKo686wTVdA7Ml8MjnoPxADNYBbax5A8GyIIVYxMdVwlzQaA3IzKoOsS+035LImh1rQF9R3jNUjUVL0wrv07aTcrMCFeOu/iI/I+HDRqtF0iHkoHNWEoBiPYIEcPYu5AFKrXK1aIAciK1z6M5ialSCxJ3lU5wrt0UbLWHkUX3qAIVHZfCcglFyIUMB/yYgQCuGzb1QQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 17/38] whpx: i386: unknown MSR configurability Date: Mon, 20 Apr 2026 12:42:27 +0200 Message-ID: <20260420104248.86702-18-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: PDCmDiPyhYelfMhsgCs4mxLsG49E4L6c X-Authority-Info-Out: v=2.4 cv=DOGCIiNb c=1 sm=1 tr=0 ts=69e60359 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=9z_AL-2ZILZrMqfKHsQA:9 X-Proofpoint-ORIG-GUID: PDCmDiPyhYelfMhsgCs4mxLsG49E4L6c X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX9Zq935l7r8mP vlaUDFA3GpOv4YI3ojqIp7m3nXUhBecmS38s/+K7J9Cd6QT6Es5ZaRdSsYFWtn4dQKBsUmfUQcx N0G4e7MnRvx2W9Zd3L7VHfMzO3o0NHiRcYo+BVtZxvUpCESjNi+79HBuFai56uMpvflSx1BtYy7 GAqp523lUjnBh3twSWTbsBAnZzZFaf5amr8xtgkUhKbVIy9MhwH4f0lSgExvHj4zqgp6fBwNyvK 2RAmkN/sYGD0xd01mtV4lx92WKr0Ip6b6UsngLF7DV9wdG0k4Z0m16XFbgY30iZAPJVJwKgMgVt iRpQ+U+M45w73RK6+PWHifpZLCguFPukGyvcZvfu8+tmQKdUaXRJRcMTlk8T1g= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.23; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776682126083158500 Content-Type: text/plain; charset="utf-8" Add an option to inject back a GPF for unknown MSRs. Keep it on by default for now as Linux expects accesses to some AMD-specific MSRs to always succeed when on an AMD host. Signed-off-by: Mohamed Mediouni --- accel/whpx/whpx-common.c | 38 ++++++++++++++++++++++++++++++++++ include/system/whpx-internal.h | 1 + target/i386/whpx/whpx-all.c | 4 ++++ 3 files changed, 43 insertions(+) diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c index 59be996aef..706871f138 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -505,6 +505,38 @@ static void whpx_set_hyperv(Object *obj, Visitor *v, } } =20 +static void whpx_set_unknown_msr(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + struct whpx_state *whpx =3D &whpx_global; + OnOffAuto mode; + + if (!visit_type_OnOffAuto(v, name, &mode, errp)) { + return; + } + + switch (mode) { + case ON_OFF_AUTO_ON: + whpx->ignore_unknown_msr =3D true; + break; + + case ON_OFF_AUTO_OFF: + whpx->ignore_unknown_msr =3D false; + break; + + case ON_OFF_AUTO_AUTO: + whpx->ignore_unknown_msr =3D true; + break; + default: + /* + * The value was checked in visit_type_OnOffAuto() above. If + * we get here, then something is wrong in QEMU. + */ + abort(); + } +} + static void whpx_cpu_accel_class_init(ObjectClass *oc, const void *data) { AccelCPUClass *acc =3D ACCEL_CPU_CLASS(oc); @@ -538,6 +570,11 @@ static void whpx_accel_class_init(ObjectClass *oc, con= st void *data) NULL, NULL); object_class_property_set_description(oc, "hyperv", "Configure Hyper-V enlightenments"); + object_class_property_add(oc, "ignore-unknown-msr", "OnOffAuto", + NULL, whpx_set_unknown_msr, + NULL, NULL); + object_class_property_set_description(oc, "ignore-unknown-msr", + "Configure unknown MSR behavior"); } =20 static void whpx_accel_instance_init(Object *obj) @@ -552,6 +589,7 @@ static void whpx_accel_instance_init(Object *obj) whpx->hyperv_enlightenments_required =3D false; /* Value determined at whpx_accel_init */ whpx->hyperv_enlightenments_enabled =3D false; + whpx->ignore_unknown_msr =3D true; } =20 static const TypeInfo whpx_accel_type =3D { diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index cf782cf5f8..86639627b3 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -47,6 +47,7 @@ struct whpx_state { bool hyperv_enlightenments_required; bool hyperv_enlightenments_enabled; =20 + bool ignore_unknown_msr; }; =20 extern struct whpx_state whpx_global; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 0d72e93621..550f30d50a 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2048,6 +2048,10 @@ int whpx_vcpu_run(CPUState *cpu) vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite); } =20 + if (!is_known_msr && !whpx->ignore_unknown_msr) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0= ); + } + hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( whpx->partition, cpu->cpu_index, --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776681908; cv=none; d=zohomail.com; s=zohoarc; b=JsOvn64hzo6aWHg7oMt+6xPX4b6yZyK30dssUeT2HUo7DuWSvGENQnjoPq0VZqYAwf2E6hhsvwvx0JCqFALUTpV9z8FQfxZ35nQd4UrQmvPw4jDUwXUMzC4k4ifNyTnhvti8Jq3WfFNSTETopFoSD6eN118EGAJPseXDKWuh++c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681908; 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=IShay1Ni0PZxOVHY3UdoELgY8h3uyJIPv2UhTb9vE4s=; b=LZv1UsEyqOzgeJPRpplfkHZJLnIhfUqOjyNdgJB6CuAN1+5A98k/KC5sRSBp2c0DHKjZh2F3G5i0ifQvv4wWdzwiXT+d5YAyCfi91gP8DxTxN+aSG6EjKmD7/AR5bkTU14HmWF9Q1RszTmzgP2QaTOI6okBjmfybJF6KQUjHxqQ= 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 1776681908699875.9841487362044; Mon, 20 Apr 2026 03:45:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6V-0007F8-II; Mon, 20 Apr 2026 06:43:47 -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 1wEm6S-0007Am-5Y for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:45 -0400 Received: from p-west3-cluster6-host12-snip4-5.eps.apple.com ([57.103.75.38] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6Q-0000dv-NJ for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:43 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 3311F180047E; Mon, 20 Apr 2026 10:43:39 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 4D6111800451; Mon, 20 Apr 2026 10:43:36 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681821; x=1779273821; bh=IShay1Ni0PZxOVHY3UdoELgY8h3uyJIPv2UhTb9vE4s=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=GJ0RwysjOTKv/0vN81m9a1Xte54h1czZpPevEmUKm7EATlxZOSuJyR4GYisLnKrrPmA7zXSh1esoOI4gNck8aZ5sLywfh8gLdrZY/LcYkKY0RvZJfl0BXVmsr3qWon02gIb1TYGF2fw/ktc2rOC+XV7OCMRp6lnaX+z3H+q6Y3SVSDGeQxO32rMFEvzR2w0xTe4wFLlWNpzpC1KKtVZStsVtIyEuLH5HWf+Y/LBnA2RBUSnALbK8YNjUhrVijFeGLoFsu3e13zXZiLeqfT3t+ANJLynaWQCx0N2dBpcPxlTq/SI5qldWfxYjjq70TmmcwEcuLyZzHfwZe/aaNGKQIQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 18/38] whpx: i386: enable GuestIdleReg enlightenment Date: Mon, 20 Apr 2026 12:42:28 +0200 Message-ID: <20260420104248.86702-19-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: fuvp5F2VI2h6Nxc3O-HE1SZDUDLubjzx X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX/YMFW4KNNdDF rHO76IAGCx1rNYSZjFGP1hRvSg345ds5l1AyI46uHColpi69WyxOs4wW9RTwRfwpuvWXqbOwwud c3OFI7F5W3eGPHhzN6KscK5LhFcKwk9DVCEcDYcCz1tgkeVotyoheDUvwMBHpWMGSuEFTxy91rB g8MZg2uLdvINifW4jVuPEROjo+vkx0AlFDaYzEduvMyW3DP2v+tYJe/ZOZV9TaMleBaJm2j2htd jvRI+C+se5KRD+SkhwDKa+hGwXgdycDHCmuZ8+Nl1I83IjKQWrMspbQSTtleiCch5JcVrIWdZah cj4fcjR4UJ0jA8DYhPECWGcyxz4vBPD/NJheg4E2jd7eLIJrhCGet4guFmd764= X-Proofpoint-ORIG-GUID: fuvp5F2VI2h6Nxc3O-HE1SZDUDLubjzx X-Authority-Info-Out: v=2.4 cv=TtzrRTXh c=1 sm=1 tr=0 ts=69e6035c cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=givlr1pFTcEyfNb0yRoA: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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=982 lowpriorityscore=0 adultscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.38; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776681912799158500 Content-Type: text/plain; charset="utf-8" This corresponds to HV_X64_MSR_GUEST_IDLE (0x400000f0). This enlightenment is only available by the HV when using the Hyper-V LAPIC. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 550f30d50a..f856022a87 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2686,6 +2686,7 @@ 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; + synthetic_features.Bank0.AccessGuestIdleReg =3D 1; /* * These technically work without the Hyper-V LAPIC * but behave oddly for multi-core VMs. --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776681858; cv=none; d=zohomail.com; s=zohoarc; b=izOz4y3XBjRL/jJGSnmcPUlC7auYCLdek8pBot1fjfiyVXjfGZB+305KZtaObFV+8XslMt3UUKC/llZYiEQBJeB+VWdPNb2OuZ5HpJ7kHG4cB5HwIqCrMpWuoqEd/7ZPwsVj58U16wDsdIQsg4bTQXQuyArfnJVyNnBFZnU4xjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681858; 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=XYfcVLNP4XKUf3qEh2m3HXpH6E0h6AgTscZ6AUjxiTg=; b=QJqkg+jkZcoqXDuMB+UOmFZSqZZSJjthxM9HcR4LTR7snQ7RMrt5Kxf9tJhoNe5Rc0zB5gNnXaqp9avIK2Shz1/s6P8ByU5QpRzdtT+r/jevKwf79KX5jlibr5veX0DWez45X6fJaVj0OGt4gXC9fCu0QMOjbm5rmXKny2C/hfw= 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 1776681857767709.4346779804524; Mon, 20 Apr 2026 03:44:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6W-0007FD-3t; Mon, 20 Apr 2026 06:43:48 -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 1wEm6U-0007E1-MT for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:46 -0400 Received: from p-west3-cluster6-host6-snip4-10.eps.apple.com ([57.103.75.123] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6T-0000eZ-2w for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:46 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 95AFF1800EC0; Mon, 20 Apr 2026 10:43:41 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id C208218000BF; Mon, 20 Apr 2026 10:43:38 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681823; x=1779273823; bh=XYfcVLNP4XKUf3qEh2m3HXpH6E0h6AgTscZ6AUjxiTg=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=U3pfQA/p0xR8TOyeE/jQ7D5DsHrBu6W3B0JdQLYkPGf2I61C6oE6WX4WJvarPcRVWUe9oHrc+VL/yAfB6J5rm7E/sneheGDOKxtnh5EX0kdTkH8oD2aA0m6L6IWbvNvOvjKTf+kVFZzRTkLnMXDuwiZ6IbkgzsZFL/LHslAb0pgyKDOkXQ/O03qa98mBmpJjucOv/zY/J5R98+fbdZBKh+DYEq5akuYwM4NohUVxVEdtiPLxyZRcAGxO7D21YmGv6cSSEXErfDGS3juqGvpgFRoKnXZ7r2KyV4vznJmrXwqy+CiR+V/uKGE38noDO6h5sW3zcMH6bNG++o8AbWuawg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 19/38] whpx: i386: tighten APIC base validity check Date: Mon, 20 Apr 2026 12:42:29 +0200 Message-ID: <20260420104248.86702-20-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=ftDRpV4f c=1 sm=1 tr=0 ts=69e6035e cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=uh2sygq7LFHjsVUyvz4A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX1FHoEmDpH7V/ VFmEFeUuTITSMP0wWMp4OOtooFBEOzv8E8lDXCVrcG5wLgyI6i6qKURP9pj/jBw/dIpO3MHlFqD fhgGdW1GZOKB+3Cv5W6CrzgWFKEbZLzceEpDsXaYqpG6CdkQ55LFjXiT0TriWy0wCCl1XtkGq/Q JlIbZ1q7l3ngg5RoRByCtWkpIh2A1aUkww36s2I+oU837JMfjYPOF0eaeASwBJEVsXmMCMpKIwf 2GXxOeV0wCOHyn95gso3IRrvfxvf+04eFmVpga4MpOvM+PQ6GB4ekrOA+qOsvqjpRGOljz86yGT tyOA40RxM02qvllPBj2lOHQHWfDyA58dfc1W3TNeoG28nag/NfMh9E1bM8cwqE= X-Proofpoint-GUID: bI-YLqzpCtIXz5yr_ePGPk888FbikWDV X-Proofpoint-ORIG-GUID: bI-YLqzpCtIXz5yr_ePGPk888FbikWDV 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 suspectscore=0 spamscore=0 clxscore=1030 mlxscore=0 mlxlogscore=687 lowpriorityscore=0 bulkscore=0 malwarescore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.123; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776681860616158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index f856022a87..f31eabce37 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1993,6 +1993,9 @@ int whpx_vcpu_run(CPUState *cpu) =20 if (vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D MSR_IA32_APICBAS= E) { is_known_msr =3D 1; + if (val & MSR_IA32_APICBASE_RESERVED) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GP= F, 0); + } if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { /* Read path unreachable on Hyper-V */ abort(); --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776681890; cv=none; d=zohomail.com; s=zohoarc; b=Xrtf5AWSdKUpWmjpKWLi/lG2lj0apQzEu7uvbuauRruIqyMN49BKWdIcC6oTdnhTMM9b/I+Ej5U8AVjs1OTonndLj+aLhs7mbLAXdvAYzyqMBFXTyqTtIPq8LW2SVW4N5ya/IHRAIEz3vG0ywEyDlWnMYHV2hKtiOyVw/nBBTYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681890; 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=shO+Mw/9k0xyNmUmIAPxgO00PEUmcfuq7ZIwrGpWZBo=; b=aJzoa70wD34wqYRvTbHeTRjt2A5+Mx4uG/W/0gVT7jb7PN0+CTu9zaXnj5OWp/4B36n2xg8FrjkXCbvNRcToKWpmUce23LhEdQscYxlxqsAjahUcS9ZooGSRW8BY17MRwTJdddrD/uo5CXcA0K9gjkJChS0YhXqPofsCct/sDc8= 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 1776681890277853.0642725143753; Mon, 20 Apr 2026 03:44:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6Y-0007JP-K5; Mon, 20 Apr 2026 06:43:50 -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 1wEm6W-0007FF-9W for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:48 -0400 Received: from p-west3-cluster6-host9-snip4-6.eps.apple.com ([57.103.75.89] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6U-0000et-Tk for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:48 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id D057F1800451; Mon, 20 Apr 2026 10:43:43 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 3A08B18000BC; Mon, 20 Apr 2026 10:43:41 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681826; x=1779273826; bh=shO+Mw/9k0xyNmUmIAPxgO00PEUmcfuq7ZIwrGpWZBo=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=NCBBg+/i1VrdTr2Wl/nRuZP8CDUUhwgqxRh1QMxiYtbCjJajg9tVZeepbXlooul4Jd314+60OfXf0QqWnPDDJXL/vTOcdysPv7l6w8dQUl/UJphkJBx+Rl5I20lldlkCK2N8dtHuucN8fbzm1jNpyIrc413/LVh0lSDTTnN9/ry9krn2HIzdT0LXV0tW/2B6nrPP6rSwFbMSuXzxVWxuxpaY77h4q4nkc0rnfUnYih0M9CKEsMI5cued/C71YHS2YSH+qs9IF2SQrFUaNX1Mr0iP3gwBNWecmscsjpsEiqh86YMJyWQTsI2HmSvNU7kWCcMqbg1ia/JbjDK39fXwzg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 20/38] whpx: i386: ignore vpassist when kernel-irqchip=off Date: Mon, 20 Apr 2026 12:42:30 +0200 Message-ID: <20260420104248.86702-21-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXxXZDVTjV9PDw AzFXFt01KBczUo966IMt8gD8NgpnZ+r9XEkh4+iyCA4fz4Z0QlIbjbXViXMbMgznwJyYeLvZ5i1 /3Yh8xal579oDkg0phx1AvDGw3Yq2/JAQR4m2hoHyICkCJ8JHpM6TKu0ohGH2l3XgTgJXb+rTot bHT87LalwIwkg/vMwNmirBtpgyWliP3F/o29eauYwLhDJdNC8uxW/QSaeUNRhKWhd3f8LsAvs2o 8GzRQ3ZXa5hAnD1gxpqbljDF7Inbltx/V/NIrRR8mlCuG7uJqwl0yLPOtuW0MIEIWFo2nxxdd/g 5O16qEzTkFQN3Dx0NnLNq5BBrGG0SxxJU1l1vHKbvHmR7GIUakj6WbDTDs2eYw= X-Proofpoint-GUID: L0hv3xy8QT-c52lr9bVOXfFmy1Idvtek X-Authority-Info-Out: v=2.4 cv=CeMFJbrl c=1 sm=1 tr=0 ts=69e60360 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=HmN67jXOOwgiugJlUbgA:9 X-Proofpoint-ORIG-GUID: L0hv3xy8QT-c52lr9bVOXfFmy1Idvtek 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 clxscore=1030 bulkscore=0 suspectscore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.89; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776681891184158500 Content-Type: text/plain; charset="utf-8" Linux tries to set vpassist even when none of the enlightenments using it are available. So ignore the page it sets. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index f31eabce37..3af5f936d4 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -51,6 +51,7 @@ #define HYPERV_APIC_BUS_FREQUENCY (200000000ULL) /* for kernel-irqchip=3Doff */ #define HV_X64_MSR_APIC_FREQUENCY 0x40000023 +#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073 =20 static bool is_modern_os =3D true; =20 @@ -2033,6 +2034,18 @@ int whpx_vcpu_run(CPUState *cpu) } } } + + /* + * Linux tries to use it anyway even when not exposed.=20 + * Ignore the write as the VP assist page is not used. + */ + if (vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D HV_X64_MSR_VP_AS= SIST_PAGE + && vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite + && !whpx_irqchip_in_kernel() + && whpx->hyperv_enlightenments_enabled) { + is_known_msr =3D 1; + } + /* * For all unsupported MSR access we: * ignore writes --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682132; cv=none; d=zohomail.com; s=zohoarc; b=Hn3DU5QhbRHBZsDT+d85C/D70U68EGKDWivNdg/RRLlPfURsP6RubTq7u1/oRWbwbmM4Z1wpH4c1BvDkh5KhMYI6z5HzlDh5ktRK7e91VtrZOlHuUjyQqO7lAZMwnoXvX/XCq0Uyy3eNDYA6w3kdLCVVIDE7j4Xt3BO/2Smg4SI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682132; 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=tT4F++bSuONbY+c7bgtCCb6QKbPZ19v7x1ehrozqyHo=; b=S4qY79VdvjGjrZu9y8UlCPd+1LvtD+OFKC99uVKtget+93NU6RFc5q2/VoC3th2rgzdkE9tdiUhog5hSkg/F4WM+gIuusI8hzi/oTWJdW74S+rZruJcHyv0Q2YVWX6s8tR6b3QWDU6DH7muETzBdjXfbYolmGmI8Ezzcq26+hww= 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 1776682132294286.77654664750594; Mon, 20 Apr 2026 03:48:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6a-0007K4-0x; Mon, 20 Apr 2026 06:43:52 -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 1wEm6Y-0007Jc-Qk for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:50 -0400 Received: from p-west3-cluster6-host3-snip4-10.eps.apple.com ([57.103.75.13] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6X-0000fg-BB for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:50 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 518AA18000BC; Mon, 20 Apr 2026 10:43:46 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id B58E81800468; Mon, 20 Apr 2026 10:43:43 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681828; x=1779273828; bh=tT4F++bSuONbY+c7bgtCCb6QKbPZ19v7x1ehrozqyHo=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Y5lN968rPsdG4YhoFc9+bJeWXAP8pirP8325pvD6E3skje7SoyXLlzonmF2+I4HKDy5LkcM/CBQWHtPJleSYdLKYrz7S/spuZnZL/arNSc3NKA4CCdxGTn5UB9usHrBJ22IHqbrCdfuD6H6VHBJamaByR/Z74cD9xVI6MaDZarnrY/PdfGlmgywJqa9UhYWYQR0ltJsxuLIwA7DQyb1mEz54O6PcN+7droBlp0lgeFbZ2QF/97JavT5ID+NdD5hheGrJ3/c+69RMPuYkkDm7qLQHiAodEXFCW+uCIlhrGGoDCvKaWRs47W/0lzRcu/GKqqLqlaU1o7a2aIowDzEVvg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 21/38] target: i386: HLT type that ignores EFLAGS.IF Date: Mon, 20 Apr 2026 12:42:31 +0200 Message-ID: <20260420104248.86702-22-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: BUSIVBVpXyOejyGnf0nikFQ2625_67KS X-Authority-Info-Out: v=2.4 cv=DICCIiNb c=1 sm=1 tr=0 ts=69e60362 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=ZtXhj7NgbhMgH__AbsQA:9 X-Proofpoint-GUID: BUSIVBVpXyOejyGnf0nikFQ2625_67KS X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX2YcaoG8wkDlD pOJ2Wkw596+tBK9FsCKZXoMkU2AvQzfbgS3yYWv1l9yOpvRAE93K7Cg5+umt0Hry3lD9k037Fkx d0C2VTtAVES2d1mWodbBP+5CbgPjn8ogRoy88fZI0Xu9CXJiZ9y5NQAyJ1AYHaOINaNOaCKssLn 8q1nKVgt80RF8t3y16kbraDF/mIYur+KsAu9BceUuN2kYlVyIWtwR6iSlCO/hvwHNIp99zpSt47 Dj5O9ugHNtE7aZ41HVc0SFjfhWStyDhn0LgPzPGs95pz0UU8fxAW9Ksj1aqFg3/tbMlH0rPl57V 9y7IWzDp8MyhtcZKjkDMyiqE6QJcS6KFGbQQXXdD/Y4YKIcO5WSztpn2RyxLy4= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 malwarescore=0 mlxlogscore=958 phishscore=0 adultscore=0 lowpriorityscore=0 clxscore=1030 suspectscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.13; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776682133891158500 Content-Type: text/plain; charset="utf-8" The TLFS says: > A partition which possesses the AccessGuestIdleMsr privilege may trigger > entry into the virtual processor idle sleep state through a read to the > hypervisor-defined MSR HV_X64_MSR_GUEST_IDLE. The virtual processor will > be woken when an interrupt arrives, regardless of whether the interrupt > is enabled on the virtual processor or not. Meanwhile, Windows 24H2+ calls this MSR anyway without the privilege being = set. Add the infrastructure to support it on the generic QEMU side. Signed-off-by: Mohamed Mediouni --- target/i386/cpu.c | 10 ++++++---- target/i386/cpu.h | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0000093fa3..b18e40666e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -10482,13 +10482,15 @@ int x86_cpu_pending_interrupt(CPUState *cs, int i= nterrupt_request) (((env->hflags2 & HF2_VINTR_MASK) && (env->hflags2 & HF2_HIF_MASK)) || (!(env->hflags2 & HF2_VINTR_MASK) && - (env->eflags & IF_MASK && - !(env->hflags & HF_INHIBIT_IRQ_MASK))))) { + ((env->eflags & IF_MASK && + !(env->hflags & HF_INHIBIT_IRQ_MASK)) + || env->hflags2 & HF2_HYPERV_HLT_MASK)))) { return CPU_INTERRUPT_HARD; } else if (env->hflags2 & HF2_VGIF_MASK) { if((interrupt_request & CPU_INTERRUPT_VIRQ) && - (env->eflags & IF_MASK) && - !(env->hflags & HF_INHIBIT_IRQ_MASK)) { + ((env->eflags & IF_MASK && + !(env->hflags & HF_INHIBIT_IRQ_MASK)) + || env->hflags2 & HF2_HYPERV_HLT_MASK)) { return CPU_INTERRUPT_VIRQ; } } diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 0b539155c4..67f508dc10 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -225,6 +225,7 @@ typedef enum X86Seg { #define HF2_NPT_SHIFT 6 /* Nested Paging enabled */ #define HF2_IGNNE_SHIFT 7 /* Ignore CR0.NE=3D0 */ #define HF2_VGIF_SHIFT 8 /* Can take VIRQ*/ +#define HF2_HYPERV_HLT_SHIFT 9 /* Hyper-V HV_X64_MSR_GUEST_IDLE */ =20 #define HF2_GIF_MASK (1 << HF2_GIF_SHIFT) #define HF2_HIF_MASK (1 << HF2_HIF_SHIFT) @@ -235,6 +236,7 @@ typedef enum X86Seg { #define HF2_NPT_MASK (1 << HF2_NPT_SHIFT) #define HF2_IGNNE_MASK (1 << HF2_IGNNE_SHIFT) #define HF2_VGIF_MASK (1 << HF2_VGIF_SHIFT) +#define HF2_HYPERV_HLT_MASK (1 << HF2_HYPERV_HLT_SHIFT) =20 #define CR0_PE_SHIFT 0 #define CR0_MP_SHIFT 1 --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682140; cv=none; d=zohomail.com; s=zohoarc; b=Jgi+M52UFqLCPqHqOv+uZu4UV8xpwCzR8ZF8ixFn/wcPS+rBSI5pUOxsX7oFuD8zPxhedw5QCI1/yoNWSCUPSTqdHKZ0EetezE+1CMjjxdMdvZWCcG/u39MGUNBZt6l6P8Hsw1wgrNPz/WhKr9nWfU87iinh32fIcMDxL9jsyfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682140; 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=35AwHuK3FNutlfTTq4p+Vg27ixeNuT9FvPY378EVDsQ=; b=C3Vr3wqy+uZbE31V1vkt/9P6OoEaBE4rFaUuqIpxhSSU3M8z3sU3tfJgiFpVP0c1IWM46MOp82zOaZyTFhp7yVrQsBmqGoCwIffmYNJ0NB4QESn6BroyVldL3E1ashaxMnkDlip7+n8va2FajHYL7AwqZq+L5BmdYB2lC2wx02s= 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 1776682140237627.3032193203126; Mon, 20 Apr 2026 03:49:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6d-0007LR-B7; Mon, 20 Apr 2026 06:43:55 -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 1wEm6b-0007Ki-IV for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:53 -0400 Received: from p-west3-cluster6-host11-snip4-10.eps.apple.com ([57.103.75.33] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6a-0000gC-0M for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:53 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id C36E51800EC2; Mon, 20 Apr 2026 10:43:48 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 3860218000A8; Mon, 20 Apr 2026 10:43:46 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681831; x=1779273831; bh=35AwHuK3FNutlfTTq4p+Vg27ixeNuT9FvPY378EVDsQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=g9dcsIzNLY+BJW6ySRkk7+o5tgxBqmVyDVPwi+qJaipyJZvst/WVPmngY1NI7elYXTYxGjayco4peUbdNExH23Kgxw8hN6E+6neNpFGm6ZG8IYNtwyQMtRAYIyQRsM8fWk5KJaRNvvSqOmjidJvhVR2lzBRa7F4zk5rdde7eUBwR/K26+W3oIQKMwh88DMkq4Mlestn20YuKwSpXqSeLNvuQqB7kTs3Rav4KajDhUb0TOfpCJLaIetSttyJ8KWKjGfyW9JZuiGgPxZqG2W8wViqKSTTIaONy8C5f0WGpRvxioPUIs+GsSgLb8QTc8+S2ixghzdoGwYq3gZmDTvSn7A== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 22/38] whpx: i386: add HV_X64_MSR_GUEST_IDLE when !kernel-irqchip Date: Mon, 20 Apr 2026 12:42:32 +0200 Message-ID: <20260420104248.86702-23-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: dE6Sy28pQ6v8HPLMu6rOC2g_RSQ33-4c X-Authority-Info-Out: v=2.4 cv=DOGCIiNb c=1 sm=1 tr=0 ts=69e60365 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=mSEN7FZ2dYRJNo9PPvgA:9 X-Proofpoint-ORIG-GUID: dE6Sy28pQ6v8HPLMu6rOC2g_RSQ33-4c X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX/7s1U1iEpY8u ZJ2HMCKQaIoxG9HSWTjkfi5jX7O3mzViV6jBElXOxoBTyurbtq+LN/WgjirDgGQxJkIzTSB1U2J Rb6XaLeljwlP5V8WSRjrGAwBa25rbFzhBAksOW7VOAJITE5H9ZFHWYTDZeylu05nsV+nIGrqKMQ xIOqI6mTbBzxTWejXf+cIZnoZfxQEodb4HJXWu+KG1ktiD7Xk7BpyN3p7Cci8fKv0cdtr1/U/rF NJrRChgr61UTrYYIZLYaKxrIFs/oYmSLlnOL/nCTE06LAzVRVhr5KI7dHkdTY8dEv9Xn9DYk8xh xe4PHvaTz6HNxO/IyYImGhROQotso7+Brh2uHL69Fze17sQxglxo7IIlJibkkY= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.33; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776682141974154100 Content-Type: text/plain; charset="utf-8" Add support for an oddball HV_X64_MSR_GUEST_IDLE not-quite-an-HLT that wakes the vCPU even if EFLAGS.IF is set. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 46 ++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 3af5f936d4..4dc4030d87 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -52,6 +52,7 @@ /* for kernel-irqchip=3Doff */ #define HV_X64_MSR_APIC_FREQUENCY 0x40000023 #define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073 +#define HV_X64_MSR_GUEST_IDLE 0x400000f0 =20 static bool is_modern_os =3D true; =20 @@ -1543,13 +1544,16 @@ static vaddr whpx_vcpu_get_pc(CPUState *cpu, bool e= xit_context_valid) } } =20 -static int whpx_handle_halt(CPUState *cpu) +static int whpx_handle_halt_generic(CPUState *cpu) { + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + int ret =3D 0; =20 bql_lock(); if (!(cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD) && - (cpu_env(cpu)->eflags & IF_MASK)) && + ((cpu_env(cpu)->eflags & IF_MASK) || env->hflags2 & HF2_HYPERV_H= LT_MASK)) && !cpu_test_interrupt(cpu, CPU_INTERRUPT_NMI)) { cpu->exception_index =3D EXCP_HLT; cpu->halted =3D true; @@ -1560,6 +1564,27 @@ static int whpx_handle_halt(CPUState *cpu) return ret; } =20 +static int whpx_handle_halt(CPUState *cpu) +{ + int ret =3D 0; + + ret =3D whpx_handle_halt_generic(cpu); + + return ret; +} + +static int whpx_handle_hyperv_guestidle(CPUState *cpu) +{ + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + int ret =3D 0; + + env->hflags2 |=3D HF2_HYPERV_HLT_MASK; + ret =3D whpx_handle_halt_generic(cpu); + + return ret; +} + static void whpx_vcpu_kick_out_of_hlt(CPUState *cpu)=20 { WHV_REGISTER_VALUE reg; @@ -1763,9 +1788,10 @@ static void whpx_vcpu_process_async_events(CPUState = *cpu) } =20 if ((cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD) && - (env->eflags & IF_MASK)) || + ((env->eflags & IF_MASK) || env->hflags2 & HF2_HYPERV_HLT_MASK)) = || cpu_test_interrupt(cpu, CPU_INTERRUPT_NMI)) { cpu->halted =3D false; + env->hflags2 &=3D ~HF2_HYPERV_HLT_MASK; } =20 if (cpu_test_interrupt(cpu, CPU_INTERRUPT_SIPI)) { @@ -2035,6 +2061,20 @@ int whpx_vcpu_run(CPUState *cpu) } } =20 + /* + * Windows and Linux both use this MSR. + * Windows 11 25H2 uses it even when not advertised. + */ + if (vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D HV_X64_MSR_GUEST= _IDLE + && !vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite + && !whpx_irqchip_in_kernel() + && whpx->hyperv_enlightenments_enabled) { + is_known_msr =3D 1; + whpx_bump_rip(cpu, &vcpu->exit_ctx); + ret =3D whpx_handle_hyperv_guestidle(cpu); + break; + } + /* * Linux tries to use it anyway even when not exposed.=20 * Ignore the write as the VP assist page is not used. --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682000; cv=none; d=zohomail.com; s=zohoarc; b=DmihurLIx28Unq/lfO6WH368VvuOqX3ugaiJuAeH54ak5766m8MLg3OT/n/8dXTE/blHRBfh5cq5nl0IlKN6sW+aF/eZSIIemFAXGRG4yz3/zwfjQbDsU9w53xXWkxzN7j8K5zUW0/IqcyTWW/GPgdKwOGBPBRmJkw9+l4uo7BA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682000; 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=Sw+c1/Szq2U+GFUwZJhzpKe2Oxhd+T8qz2/AUdFCjpA=; b=lekewOfdpMVt6qja92Mo1gZvM15L8TEQTKK1QScLpdiX5W8vv8PW0AkMhwtDdD+OTpLzEDVArhebXGDuBcLFuroK/FQnus+fp2DF91aUZtzCsic9BENNjzD3iOCFliGlSBMQ7cbezgV6tRjEib2fVHPC9L6aOW2Pya9pyZx+HnU= 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 1776682000576708.8834172703108; Mon, 20 Apr 2026 03:46:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6h-0007bm-NJ; Mon, 20 Apr 2026 06:43:59 -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 1wEm6d-0007Ll-R2 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:55 -0400 Received: from p-west3-cluster6-host7-snip4-1.eps.apple.com ([57.103.75.44] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6c-0000gd-BR for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:55 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 4AC8E1800153; Mon, 20 Apr 2026 10:43:51 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id A2D631800EC1; Mon, 20 Apr 2026 10:43:48 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681833; x=1779273833; bh=Sw+c1/Szq2U+GFUwZJhzpKe2Oxhd+T8qz2/AUdFCjpA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=B+pp0bXZBdoi9Tun0jHDKvLCzgiRbAviydrZ0/fwZ3GFLunizE0eh8VkQL0GAcsTsJUtEcr/uOC8CfChhDiHHGz05h5qf9k89DzNYqe8PUai3cdxXtF2mLRR5HoiH/ZFhRaETmvVlnYF5NoO/120vb+oZKAEmhqpl9wh29LIMSw0i2Hhgv2OYljhSSPJvc4svrFkA/fQT0GHJDkxXOreLsKkkKNeKjk+H5kmrSrQItGZLg2N5s73fSnImFg3+b15IF8UcP/Wp1Hd2Z1cWkHeqfnsDguVZyjabE5nPw5v8qVMcQlzCOI/fPCHs8qGyrR3BTP3bDrEZ/q9TR+AgESE7A== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 23/38] whpx: i386: one more CPUID Date: Mon, 20 Apr 2026 12:42:33 +0200 Message-ID: <20260420104248.86702-24-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: TB9HfKJq5B6oZnLys3hsxi-hPRL35pjp X-Proofpoint-GUID: TB9HfKJq5B6oZnLys3hsxi-hPRL35pjp X-Authority-Info-Out: v=2.4 cv=d7D4CBjE c=1 sm=1 tr=0 ts=69e60367 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=zJD0qBlfmizEQV4F3ZsA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX+vkFGbyzu0Xz 4yweAC2jiJUJpco9tegdk2kkdrI/AZ/UzzPD7cRPvFtFnlzOYBTyYWa3PsXTfQGyFUIl+AbRRjg Fi4BPxaCp+qGHRfMGzt0sg5wCIOZ1SsK8yq7HlISeaYVUpylzappXHoY8jxFZBxGlA4E97fDej4 evnXUwZutDJlzfJw9LIJ6ZRgK/zTy9W9eClUdqF8XvjB9RM8/M1WthTf1nNQnbpGQbYgPivMmcs ft7dskEgXn7pSLBjYboe/Oinq5hfdeX5HlYh8dEQB2LbDW+6rgQgulh64Qwag0QHKwkRzs9hHCN DPwZvbDqg5Uoo6g7mCAMsoZcrhs5MgO7rCJ44DTzL8j5uZBK9JCnhm+s+JUe+Y= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=821 adultscore=0 clxscore=1030 suspectscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.44; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776682001756154100 Content-Type: text/plain; charset="utf-8" Trap cpuid_0xb as it has x2APIC topology information. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 4dc4030d87..5c2a9bb8ad 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2527,7 +2527,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; =20 - UINT32 cpuidExitList[] =3D {0x0, 0x1, 0x6, 0x7, 0x14, 0x24, 0x29, 0x1E, + UINT32 cpuidExitList[] =3D {0x0, 0x1, 0x6, 0x7, 0xb, 0x14, 0x24, 0x29,= 0x1E, 0x40000000, 0x40000001, 0x40000010, 0x80000000, 0x80000001, 0x80000002, 0x80000003, 0x80000004, 0x80000007, 0x80000008, 0x8000000A, 0x80000021, 0x80000022, 0xC0000000, 0xC0000001}; --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776681922; cv=none; d=zohomail.com; s=zohoarc; b=epbsEggU7HoMkMRT2SBoCPphpz7kKccgJCcshgi3ZgMfNIDIQpOyW7QqKtzfdzVwlZ5v7ZQX2UfB3TOwgJFvHlEVxVgRY6TBl36fjc2GUneHw9TbyetVbMtdl+ZtqId4zTGUpuTjgE9br734fagLwHShQnMHlVd+/a6ywcgmWcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681922; 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=9xbxyGGfjNH/HWQDHlAQCg/qgFyvlvlu7VNj5bZOFog=; b=JhWy/RACDEFzVGvNhzK7iQSV2XsuZQy2zA5B8bei79oyJtq3/TxCeSB3rG8NmVFbuwFMd2iqiFc81zFSedeYm9Ax1R0Lgb38uI5rYcj374Gz/cmhx6kL8PQM94dgl5Nx/No9u42KBV+RSuwdw04dozo1bl46KtIMPxSn0AWxb9Y= 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 1776681922832616.495156551542; Mon, 20 Apr 2026 03:45:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6k-0007l0-Hd; Mon, 20 Apr 2026 06:44:02 -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 1wEm6g-0007XF-8e for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:58 -0400 Received: from p-west3-cluster6-host4-snip4-10.eps.apple.com ([57.103.75.23] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6e-0000h2-O2 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:43:58 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id B3E09180045A; Mon, 20 Apr 2026 10:43:53 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 250B318000A8; Mon, 20 Apr 2026 10:43:50 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681835; x=1779273835; bh=9xbxyGGfjNH/HWQDHlAQCg/qgFyvlvlu7VNj5bZOFog=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=ZDboLL+djex1IduTIdz8d49gH5k5FKkgkCssuVNc/TArt80cS7v2HeYvPp2/RL/Eh8g0PNbjipId2Gdx83mfOIo6yWDY0Kwnogi+vSYhYtiEtzIRf/5+ELcYFW5ZtJn5KQx/n3BNrqbYBgAAaYqwy/LMmeVLlrQM35waEnG/T4qCEGDzZGYkNNuOWWTWQZYIJSrPaA2fUEvb47ZGdx+lUy33jo5QOgCrrQ/2UKtDGCVDcWHbJ2UEhD8kdZlSWBwcz4Qxrg6+/zq95RfnSApyEGVP1hxEp67p3j0jRXtI/x9Splj8miTrrLUqxXzPQXZ+WIf+fDF0/crN+rv3ImsioA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 24/38] whpx: i386: some x2APIC awareness Date: Mon, 20 Apr 2026 12:42:34 +0200 Message-ID: <20260420104248.86702-25-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=KoZAGGWN c=1 sm=1 tr=0 ts=69e6036a cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=IZZkQHPJHa8VUPCOrf4A:9 X-Proofpoint-GUID: 88Rl_vVb61SYe0h_4wUCxkPjSJ-cfK2m X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX63VY2be2Slrk ZwiUY3TRWbawwFxFY284uiz8mm+/D8CCQUsUk/n7StXUeuHkQ3Qdt3DNDWpK1JNqpO4CUuDex1o L6UXkBo4yqwyZEG0IzRBV2OTGYNpBjpYm6GsDOwM1SS6FK1YBEmcyrmu33Az33Q7u4eOEE5ZRzD Ls5ROHlMfzRCmvZ1EmejrgQi1qLn2J2Mb3lX4QP1jueLe41h2HbNg5/oQbTeK5jQAWJUFJ+WTMQ 7LC6YDCUtjXgmKQRj46TN6Yp4OVyB53S4KgWSjiKqKdZSbd+Vm8PebHaldwwJDf9GdSdxbP0IIF 8HciFJHm+MYuUJjchI/hpSzDftp2Pu8JMXAgu2hPzxycbHt/kjoYGPEG5tYBs4= X-Proofpoint-ORIG-GUID: 88Rl_vVb61SYe0h_4wUCxkPjSJ-cfK2m 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 phishscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.23; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776681925145158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-apic.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/target/i386/whpx/whpx-apic.c b/target/i386/whpx/whpx-apic.c index 65629ca45f..cc272f82a5 100644 --- a/target/i386/whpx/whpx-apic.c +++ b/target/i386/whpx/whpx-apic.c @@ -33,7 +33,11 @@ static void whpx_put_apic_state(APICCommonState *s, int i; =20 memset(kapic, 0, sizeof(*kapic)); - kapic->fields[0x2].data =3D s->id << 24; + if (s->apicbase & MSR_IA32_APICBASE_EXTD) { + kapic->fields[0x2].data =3D s->initial_apic_id; + } else { + kapic->fields[0x2].data =3D s->id << 24; + } kapic->fields[0x3].data =3D s->version | ((APIC_LVT_NB - 1) << 16); kapic->fields[0x8].data =3D s->tpr; kapic->fields[0xd].data =3D s->log_dest << 24; @@ -61,7 +65,11 @@ static void whpx_get_apic_state(APICCommonState *s, { int i, v; =20 - s->id =3D kapic->fields[0x2].data >> 24; + if (s->apicbase & MSR_IA32_APICBASE_EXTD) { + assert(kapic->fields[0x2].data =3D=3D s->initial_apic_id); + } else { + s->id =3D kapic->fields[0x2].data >> 24; + } s->tpr =3D kapic->fields[0x8].data; s->arb_id =3D kapic->fields[0x9].data; s->log_dest =3D kapic->fields[0xd].data >> 24; --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682087; cv=none; d=zohomail.com; s=zohoarc; b=Vub8Z2ewGREKwQJo79te/zOHytNCJevCgeF85iGtnbRdB6MTn5dM6F6VGx4R9cB+AY1C+DAkZf4T8KrlMlurB/cyBUGubUZEslw8wRJOWlzFw3p/cFiEUaG4QQrL942KcG8nebSanEsnIGertyhy8Gry8ZM0WVO+sHNZDcskQs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682087; 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=cbyw4J9p3BxQsYUbbf+71GgW3JjwCzY5skdqOd0TL1w=; b=ihJni24g8YZ0mBY6jcbLrAtt9J9sC9zHpEkNIgtHb0JJa9qyiIcfi3LsB3j0QKcsPoC/KVICqHFKAGzQ7B2aR5ktcGs5J8wua8eYTFMH2b2Ac1rxXrrPB+idsCKWDNVD6kPd4wGxF4tYClKBVu5Ofv6SasCT0JIjrlkeT+0pkOA= 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 1776682087247154.86867007687113; Mon, 20 Apr 2026 03:48:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6m-0007rz-56; Mon, 20 Apr 2026 06:44:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6j-0007if-88 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:01 -0400 Received: from p-west3-cluster6-host1-snip4-9.eps.apple.com ([57.103.75.72] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6h-0000ho-MU for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:01 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 43C55180047D; Mon, 20 Apr 2026 10:43:56 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 9BFBD1800442; Mon, 20 Apr 2026 10:43:53 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681838; x=1779273838; bh=cbyw4J9p3BxQsYUbbf+71GgW3JjwCzY5skdqOd0TL1w=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=B9wLozO1FpNLnw5CtSvE4l2pIaKQGUVqN4DMQRrg50EMWi/rOnkh85kLFbV+Ervi2zA4k7417PxPoSQo2MEIX3/6gUlEcEmry5N+nfcDuanM6zKMRuI5ocNbiu9ci+wogeziggsQOU1Hl9oQGpVl7WaU9c1OgD86pxVijPROuAif8x3S7o6CaLCC8OTuNsJQIWOuiyT0Z/tr+TCaDgjDP3EgNCFmypMjAKkA4wTduIcNmOp5GXDLmyU+L0Fht3w5elXVlZ0uhGvPpvumZw7grRUad7ZW0ykHdz7AoE+fMXE5djZKLI1uywm/h6kB0Vr/5FnfCGuUVByPvp2fqSmF3Q== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 25/38] whpx: i386: set WHvX64RegisterInitialApicId Date: Mon, 20 Apr 2026 12:42:35 +0200 Message-ID: <20260420104248.86702-26-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: a_TvRe2NSjKDywicjhKezEHGYUEThNt0 X-Authority-Info-Out: v=2.4 cv=DOGCIiNb c=1 sm=1 tr=0 ts=69e6036c cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=DsSKBDvzyVHF_5agjq4A:9 X-Proofpoint-ORIG-GUID: a_TvRe2NSjKDywicjhKezEHGYUEThNt0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX/siFRm009wgs b5ZmpeRrU/PUjUmdE1AnNkvv+e7ox1aaxa5oZArEUjo+FHqx6FE3viJURRZgbUcZANt+9CTpxos HTPL3C5rkCIlc7JPzX1kw6RB9bOUfU6ys9waJpM1rAiL5AYV1x6GILS+ut0cuCgUBrge3oqCBot vbN/qwp9owBEaoM0og3LExpip8ekW9EHcYry4ibA/qpGKkgc08khSwREArm5cKoyLnuA3HY1xTm UhpXvHceSlqL1/dBEzAm/NmSUj7RSDOQb/jR9jXF4zExxcO+8JKX/rwKfHVYxrGF2vn2EDwH1kI Si5QpjhF7b/EyAMap+b+0yZi1Jhe48kmUf65nd7kYQgH0Zx1raogoCxq+HySoI= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 mlxlogscore=985 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.72; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682089786158500 Content-Type: text/plain; charset="utf-8" Keep Hyper-V aware of the initial APIC ID chosen. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 5c2a9bb8ad..a7282eb96a 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2398,6 +2398,11 @@ int whpx_init_vcpu(CPUState *cpu) goto error; } =20 + if (!whpx_irqchip_in_kernel()) { + WHV_REGISTER_VALUE apic_id =3D {.Reg64 =3D x86_cpu->apic_state->in= itial_apic_id}; + whpx_set_reg(cpu, WHvX64RegisterInitialApicId, apic_id); + } + /* * vcpu's TSC frequency is either specified by user, or use the value * provided by Hyper-V if the former is not present. In the latter cas= e, we --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682133; cv=none; d=zohomail.com; s=zohoarc; b=jADIgId8GIcEjPIVBSIOVPy0RjC6tglFfrVoNtkyvqQDU/NSbjE+a/1VX61VBtYvdknIiVAFwNX3yscq0C3cne4LX2oyT6Oq8F3ZkO/RPktSTwsbWYA8QJRTJvauyjD78yIiSrBM3AFMiXFzkObDnOQXVlzzAaQvo1hZDHKrhJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682133; 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=3N10hCGUapdzhuKA3NU8ZhsH65avZvazfJzRL/H4ESk=; b=caXWPTts4muzwDpabWG5mPlHQuElYNrnWJf1ZvDrteXCH4lSgZFtRJtVpj0QU+6b+xaYoDL4zQamX6H7SQ0I2ZyM7qX0EljYP1qU+8dknraz/9uXuhD9r4mXnjbd4gUFEOkXRQFxmAJEhdr3hXc5A75QFldbheTGdcXYU4e9Cqg= 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 1776682133576226.01571096691077; Mon, 20 Apr 2026 03:48:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6n-0007z7-4E; Mon, 20 Apr 2026 06:44:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6l-0007pA-Oc for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:03 -0400 Received: from p-west3-cluster6-host4-snip4-1.eps.apple.com ([57.103.75.14] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6k-0000iB-0c for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:03 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id B77A71800474; Mon, 20 Apr 2026 10:43:58 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 25AEE180045B; Mon, 20 Apr 2026 10:43:56 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681840; x=1779273840; bh=3N10hCGUapdzhuKA3NU8ZhsH65avZvazfJzRL/H4ESk=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=NXyr/s44izelOMuWl8Ttey2HwhsAEhR/GVqgodBKvo0VsneXCrMpmnvvP1Sv9IRow8mg53WrgvFnj3AX+XEZ0501Gfnki37Wrz8rnbJZvB7jotrKxz0++GES1scq6COOT+2KeMFOeAHX+Vvuu5i17V2Pv4IguW8jgloe7Q0vYwkSFcNSKIAsIiDXypxkSED0w6kwjwTve64vC5SsJiaUnrSQa1Tzbl2BQfzbFpE69srjc5B6prAPyTu5PWpHCvNPWfoRZa1QZ5K19gWJkosC2QQARumH9Jc5Nds2DZP132n/xgoH8InjsMVHQ6C5KCN8x9ZfwBtiSgGW7sds6V/STg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 26/38] whpx: i386: Pause VM on fatal exception to be able to inspect state Date: Mon, 20 Apr 2026 12:42:36 +0200 Message-ID: <20260420104248.86702-27-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX8TH5H5JbKpLw Avsi2elB4AoM8nz1+wWJPIXeBKD16Hh6JIxmJdVXA+hsF4FMycUSC0bGI5AN4raQUgn6xYoEq5Q GE/ziop0o3F2s5yKfZ3TltZDhGe1FBOzjvQ/2DV8iRjMi/k8Fvzje249g/Mv/tUFZvW3LTAC/TB +g5CvA/7gZwJCUpcnaq4ZsVdtLfEKeUvbxSP19PJqANqcPnEgzxi83rUQ7rA6GkVHkX79tC0DlY 9q1QEy2NX9jUY0a9vCjuTIjVBGsld04Rv1hCJiExU/iTCDToR8mRrWAWTeh5kjz/FpgeVKtMlBH uQCuGtx4HxGBZr72KStwM0Q6epu7Cfgladjbu7nsL7Ellf8lccVy94biO5elvs= X-Proofpoint-GUID: mgceeyAzTnvKd9DTkjYzRUEf5xShhGwS X-Authority-Info-Out: v=2.4 cv=CeMFJbrl c=1 sm=1 tr=0 ts=69e6036f cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=CGn8axfqn9I_s65QuTEA:9 X-Proofpoint-ORIG-GUID: mgceeyAzTnvKd9DTkjYzRUEf5xShhGwS 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=795 clxscore=1030 bulkscore=0 suspectscore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.14; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682133863158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index a7282eb96a..dee2a203b2 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2310,7 +2310,7 @@ int whpx_vcpu_run(CPUState *cpu) vcpu->exit_ctx.ExitReason); whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); bql_lock(); - qemu_system_guest_panicked(cpu_get_crash_info(cpu)); + vm_stop(RUN_STATE_PAUSED); bql_unlock(); break; } --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776681932; cv=none; d=zohomail.com; s=zohoarc; b=NWXMBMQGt3epmnsYRO1mTVHliTMtuAcBtflRTuRAqWa5W6yNUp4cES00aAorQIkkmhonYJQZ+H32qTcOkBUi7FcZAIsuoD1tPGrAxj4t6uQ7vr4YK5T2jfE9y/ABuXZ23Qk+Ld7IExhdQfGkIdZk/K3MAVbuttC6iOt1jeX+iDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681932; 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=MoioDyw9WNCdgAnpil2qVwmsqi0G9SAnV0FrCmNrGIk=; b=jHGqu6nRusMtRO+NpgyT6vkC4gSRqHhJxGXtkcrg+VqBFIXEJQCaFS8NuAQz4dSXWwyPlP0cHr7NCKW92ezR9WWxTmmpB3ojLChTImtFu2Wngo7KsxVURl0EOzBgn4mXDP9Djnpo95pimDfLSfUiyUofbY5iur1jPjGEzUJTLeM= 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 1776681932302101.15983566324451; Mon, 20 Apr 2026 03:45:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6p-00089a-Bk; Mon, 20 Apr 2026 06:44:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6n-00082U-Nh for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:05 -0400 Received: from p-west3-cluster6-host2-snip4-1.eps.apple.com ([57.103.75.74] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6m-0000id-32 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:05 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 29EA11800449; Mon, 20 Apr 2026 10:44:01 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 9B4C71800444; Mon, 20 Apr 2026 10:43:58 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681843; x=1779273843; bh=MoioDyw9WNCdgAnpil2qVwmsqi0G9SAnV0FrCmNrGIk=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=CpGxLNp+HrrHZjrXUYKhg5ImOfQCEqfbrtnyeywqfnsgAyCOjtHN3s2y3a6vkft/ugUeldHFLi4yp4kWmgRX3rvJfK8xe/2wJ/oxQwm4XfPoEEy0jWUCZ9hWwAJm4fsnYboCOv+roDFmaMuVexuVVbBAS39t2p9Z4bHz4IEk7+Syb26JmRev8FOfhTNfsJSWqnDsMOBd6T9Xf1dUHIgDeI1c4cJzXksWhegDQDwpvOpqgKwnCDjLa3QAgtZcGdZB6oVQ3yA/RwAk8HuJ/KIwNNtHZBpkJh/y/WOG8S9wtzoGDfZlCa7+XQSgz7dlyfy0gWGEFJfw6q3wR0CnD6YhIw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 27/38] target/i386: emulate: use exception_payload for fault address Date: Mon, 20 Apr 2026 12:42:37 +0200 Message-ID: <20260420104248.86702-28-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: BPMrr2-a9WCluFEdNc9SHbK75xQBDyzG X-Proofpoint-GUID: BPMrr2-a9WCluFEdNc9SHbK75xQBDyzG X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXys5FbfJnfK3e x9TqOurviAq3YtlJO0AJiVtwlug7JWSBXVwTzO9TkPN2IZtXaBbg2IvkzchOR6nmd7+9wEXbAGN SO/43X4GJ9zVu4M7U+2ZHPJryF5Z5fpGVl96/Ho74JdE1Rbk0z+qmDvtSQAL/it7sNbA/5bQce0 d+bnF+6RFRriibdNQeoFXpwLWrw0Fi/kcA1p886VqY0xdfcIHKugkJTqZpeGMvVH+vVM85Iapxt qbyK1AbIzBNuP+VghE8uAUpGn356m+E1hfevUBXhlmyCMKWOtT/SZrijf5T71T2npga5aFG3x2/ w97Mxx2b1drBGMBQ4jY4cWBFqye3Xhq6RPJonUdH7y1fLZzg1LhCqqdW1PvLtQ= X-Authority-Info-Out: v=2.4 cv=d7b4CBjE c=1 sm=1 tr=0 ts=69e60371 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=YcyI-53RcdBlrF1VUN8A: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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=791 suspectscore=0 bulkscore=0 phishscore=0 adultscore=0 spamscore=0 malwarescore=0 clxscore=1030 lowpriorityscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.75.74; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776681932906158500 Content-Type: text/plain; charset="utf-8" Instead of directly putting it in cr[2], put it in exception_payload. Signed-off-by: Mohamed Mediouni --- target/i386/emulate/x86_mmu.c | 3 ++- target/i386/whpx/whpx-all.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/target/i386/emulate/x86_mmu.c b/target/i386/emulate/x86_mmu.c index 007de582de..8d4371467f 100644 --- a/target/i386/emulate/x86_mmu.c +++ b/target/i386/emulate/x86_mmu.c @@ -277,7 +277,8 @@ static MMUTranslateResult x86_write_mem_ex(CPUState *cp= u, void *data, target_ulo translate_res =3D mmu_gva_to_gpa(cpu, gva, &gpa, translate_flags); if (translate_res) { int error_code =3D translate_res_to_error_code(translate_res, = true, is_user(cpu)); - env->cr[2] =3D gva; + env->exception_has_payload =3D 1; + env->exception_payload =3D gva; x86_emul_raise_exception(env, EXCP0E_PAGE, error_code); return translate_res; } diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index dee2a203b2..02235d5391 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1818,11 +1818,11 @@ static void whpx_inject_exceptions(CPUState* cpu) WHV_REGISTER_VALUE reg =3D {}; reg.ExceptionEvent.EventPending =3D 1; reg.ExceptionEvent.EventType =3D WHvX64PendingEventException; - reg.ExceptionEvent.DeliverErrorCode =3D 1; + reg.ExceptionEvent.DeliverErrorCode =3D env->has_error_code; reg.ExceptionEvent.Vector =3D env->exception_nr; reg.ExceptionEvent.ErrorCode =3D env->error_code; - if (env->exception_nr =3D=3D EXCP0E_PAGE) { - reg.ExceptionEvent.ExceptionParameter =3D env->cr[2]; + if (env->exception_has_payload) { + reg.ExceptionEvent.ExceptionParameter =3D env->exception_paylo= ad; } whpx_set_reg(cpu, WHvRegisterPendingEvent, reg); } --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682140; cv=none; d=zohomail.com; s=zohoarc; b=dmnlsBuruxOvoPaJSrbQnQPuqajmkyYry3jgfEmOk6OQEVeW2i1aUBuZHL433CrARB8UxM/4xe9NGfImWV36BK+nwUyrrvTq63S9supMScAhJZNjHepTFtrQyRizn9naI/A1OdwpYVQAK2F9BG4u9ZOgH8E0c0cX7x3bwRh75aA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682140; 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=FjknWeXX453ZkdimgET5qsOfRjRd950mgDj8NKv+vI4=; b=kJSKfcvsSpisg9AWVc/bjzWV49Pm3HZDd9tUZra6zFq3a4yIzxBq4dcpDSaT1S8VndL7E9aUS+DhaXm8s7NdVAardcnw0Daec7oYHb6Ry4EJg4c5JSxB3CEld1q7IzFXa8CqmsPi3CYRd9ksPSMjTaKPUpdJkfYsI4F0P+k0XWk= 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 177668214029151.88536560144871; Mon, 20 Apr 2026 03:49:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6t-0008Dv-PI; Mon, 20 Apr 2026 06:44:11 -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 1wEm6s-0008DT-Dz for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:10 -0400 Received: from p-west3-cluster4-host7-snip4-10.eps.apple.com ([57.103.74.141] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6p-0000jn-Q6 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:10 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id E81E01800097; Mon, 20 Apr 2026 10:44:03 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 117B918000BF; Mon, 20 Apr 2026 10:44:00 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681846; x=1779273846; bh=FjknWeXX453ZkdimgET5qsOfRjRd950mgDj8NKv+vI4=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=WjxOkqnT6BYcEYghIml7QL5elXP1nICipH6tp0q11gTIZ5N2uiUU/1iip5tlAVK6nkK9yQaZ0r0aeDNYbadzeTki5PGUQRz0umBgz9DxQBMGirqKymceiQNLoHVgdu9TBD2gLIS2bNob5rO6gSu+oAqCyHMLPKxbFZAYPrxH7Ztln3wQFHUH36m0wGmDdLLolhypKTbjSM3on9y2axrbEw2WSGbhmh2DuhnHQxpRkvX4+v+qtIDLh86b+bSIANg4i9wMtF6F8vjhsd9EzRnaB/SulX01Ak1MG0p8+TwyhjLUDGtyNQTZiKpIeXUCQOK7Bg3CYesjqTeCS9ZGAs2SUw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 28/38] whpx: i386: CPU features support for Windows 10 Date: Mon, 20 Apr 2026 12:42:38 +0200 Message-ID: <20260420104248.86702-29-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=MK9tWcZl c=1 sm=1 tr=0 ts=69e60375 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=mDV3o1hIAAAA:8 a=_S2v2Z1saO19s7bx6VoA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXwrsj3Z7EXcXk I9fsIzwlp0yO5cN5k2aYwiF19k+LSRfIwaxClZrkiSmwvX64gBiro/9Twh5UODQCLa9Sv10MzZH HU1H6Sg850six0E/KI+s288qCVw1oYmY/hCKLYfbREGK8DcqSvBCt9menXrXIiiT7reIRg86NFI U7DakHPEdvfw9puku6/xojJHoHfgtzWXF7uVXXeN06qk9yFWZXI54YBVJryYg6R9ttjvCov2ADt xuGbSHyR6aXLDaViYjIV85d3IgvTN1RuKNFPN1eV4nJNFYvAODboMSJeqr0i5nHMEWWWgHAsd4y Vn2IzjZWf+NnUiGSz+YP5cd0Uj5IplTijbpPAaRI5KrL2+0s2ojxRB5FePrdVM= X-Proofpoint-ORIG-GUID: UtvCed5Z_R3D996j83iiKzD5vQsDHJkw X-Proofpoint-GUID: UtvCed5Z_R3D996j83iiKzD5vQsDHJkw 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 clxscore=1030 mlxlogscore=999 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.141; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682142062154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/cpu.c | 18 +-- target/i386/whpx/meson.build | 1 + target/i386/whpx/whpx-all.c | 38 ++++++- target/i386/whpx/whpx-cpu-legacy.c | 171 +++++++++++++++++++++++++++++ target/i386/whpx/whpx-i386.h | 7 ++ 5 files changed, 215 insertions(+), 20 deletions(-) create mode 100644 target/i386/whpx/whpx-cpu-legacy.c diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b18e40666e..8f090782bd 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8092,9 +8092,6 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *c= pu, FeatureWord w) } 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, @@ -8182,17 +8179,10 @@ static void x86_cpu_get_supported_cpuid(uint32_t fu= nc, uint32_t index, *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); - } + *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/meson.build b/target/i386/whpx/meson.build index c3aaaff9fd..1c6a4ce377 100644 --- a/target/i386/whpx/meson.build +++ b/target/i386/whpx/meson.build @@ -1,4 +1,5 @@ i386_system_ss.add(when: 'CONFIG_WHPX', if_true: files( 'whpx-all.c', 'whpx-apic.c', + 'whpx-cpu-legacy.c' )) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 02235d5391..045dbdfdc8 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -270,11 +270,30 @@ typedef enum WhpxStepMode { static uint32_t max_vcpu_index; static WHV_PROCESSOR_XSAVE_FEATURES whpx_xsave_cap; =20 -static bool whpx_has_xsave(void) +bool whpx_has_xsave(void) { return whpx_xsave_cap.XsaveSupport; } =20 +bool whpx_has_xsaves(void) +{ + return whpx_xsave_cap.XsaveSupervisorSupport; +} + +static bool whpx_rdtsc_cap; + +bool whpx_has_rdtscp(void) +{ + return whpx_rdtsc_cap; +} + +static bool whpx_invpcid_cap; + +bool whpx_has_invpcid(void) +{ + return whpx_invpcid_cap; +} + static WHV_X64_SEGMENT_REGISTER whpx_seg_q2h(const SegmentCache *qs, int v= 86, int r86) { @@ -1057,6 +1076,11 @@ uint32_t whpx_get_supported_cpuid(uint32_t func, uin= t32_t idx, int reg) bool temp_cpu =3D true; HRESULT hr; =20 + /* Legacy OSes don't have WHvGetVirtualProcessorCpuidOutput */ + if (whpx_is_legacy_os()) { + return whpx_get_supported_cpuid_legacy(func, idx, reg); + } + hr =3D whp_dispatch.WHvCreateVirtualProcessor( whpx_global.partition, cpu_index, 0); =20 @@ -2147,7 +2171,7 @@ int whpx_vcpu_run(CPUState *cpu) * just pass through what the hypervisor * provides without any QEMU filtering. */ - if (whpx_is_legacy_os() || xcc->max_features) { + if (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; @@ -2507,11 +2531,11 @@ void whpx_cpu_instance_init(CPUState *cs) host_cpu_instance_init(cpu); x86_cpu_apply_props(cpu, whpx_default_props); =20 - if (!whpx_is_legacy_os() && xcc->max_features) { + if (xcc->max_features) { whpx_cpu_max_instance_init(cpu); } =20 - if (!whpx_is_legacy_os()) { + if (whpx_has_xsave()) { whpx_cpu_xsave_init(); } } @@ -2536,7 +2560,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms) 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 X86MachineState *x86ms =3D X86_MACHINE(ms); bool pic_enabled =3D false; @@ -2700,6 +2723,9 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 + whpx_rdtsc_cap =3D processor_features.Bank0.RdtscpSupport; + whpx_invpcid_cap =3D processor_features.Bank0.InvpcidSupport; + if (whpx_irqchip_in_kernel() && processor_features.Bank1.NestedVirtSup= port) { memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.NestedVirtualization =3D 1; @@ -2808,7 +2834,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeCpuidExitList, - !whpx_is_legacy_os() ? cpuidExitList : cpuidExitList_legacy_os, + cpuidExitList, RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32)); =20 if (FAILED(hr)) { diff --git a/target/i386/whpx/whpx-cpu-legacy.c b/target/i386/whpx/whpx-cpu= -legacy.c new file mode 100644 index 0000000000..477429b460 --- /dev/null +++ b/target/i386/whpx/whpx-cpu-legacy.c @@ -0,0 +1,171 @@ +/* + * i386 CPUID helper functions + * + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2017 Google Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + * + * cpuid + */ + +#include "qemu/osdep.h" +#include "qemu/cpuid.h" +#include "host/cpuinfo.h" +#include "cpu.h" +#include "emulate/x86.h" +#include "whpx-i386.h" + +static bool cached_xcr0; +static uint64_t supported_xcr0; + +static void cache_host_xcr0(void) +{ + if (cached_xcr0) { + return; + } + + if (whpx_has_xsave()) { + uint64_t host_xcr0 =3D xgetbv_low(0); + + /* Only show xcr0 bits corresponding to usable features. */ + supported_xcr0 =3D host_xcr0 & (XSTATE_FP_MASK | + XSTATE_SSE_MASK | XSTATE_YMM_MASK | + XSTATE_OPMASK_MASK | XSTATE_ZMM_Hi25= 6_MASK | + XSTATE_Hi16_ZMM_MASK); + if ((supported_xcr0 & (XSTATE_FP_MASK | XSTATE_SSE_MASK)) !=3D + (XSTATE_FP_MASK | XSTATE_SSE_MASK)) { + supported_xcr0 =3D 0; + } + } + + cached_xcr0 =3D true; +} + +uint32_t whpx_get_supported_cpuid_legacy(uint32_t func, uint32_t idx, + int reg) +{ + uint32_t eax, ebx, ecx, edx; + + cache_host_xcr0(); + host_cpuid(func, idx, &eax, &ebx, &ecx, &edx); + + switch (func) { + case 0: + eax =3D eax < (uint32_t)0xd ? eax : (uint32_t)0xd; + break; + case 1: + edx &=3D CPUID_FP87 | CPUID_VME | CPUID_DE | CPUID_PSE | CPUID_TSC= | + CPUID_MSR | CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | + CPUID_SEP | CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | + CPUID_PAT | CPUID_PSE36 | CPUID_CLFLUSH | CPUID_MMX | + CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS | CPUID_HT; + ecx &=3D CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSSE3 | + CPUID_EXT_FMA | CPUID_EXT_CX16 | CPUID_EXT_PCID | + CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_MOVBE | + CPUID_EXT_POPCNT | CPUID_EXT_AES | + (supported_xcr0 ? CPUID_EXT_XSAVE : 0) | + CPUID_EXT_AVX | CPUID_EXT_F16C | CPUID_EXT_RDRAND; + ecx |=3D CPUID_EXT_HYPERVISOR; + ecx |=3D CPUID_EXT_X2APIC; + edx |=3D CPUID_HT; + break; + case 6: + eax =3D CPUID_6_EAX_ARAT; + ebx =3D 0; + ecx =3D 0; + edx =3D 0; + break; + case 7: + if (idx =3D=3D 0) { + ebx &=3D CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 | + CPUID_7_0_EBX_HLE | CPUID_7_0_EBX_AVX2 | + CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_BMI2 | + CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_RTM | + CPUID_7_0_EBX_RDSEED | CPUID_7_0_EBX_ADX | + CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_AVX512IFMA | + CPUID_7_0_EBX_AVX512F | CPUID_7_0_EBX_AVX512PF | + CPUID_7_0_EBX_AVX512ER | CPUID_7_0_EBX_AVX512CD | + CPUID_7_0_EBX_CLFLUSHOPT | CPUID_7_0_EBX_CLWB | + CPUID_7_0_EBX_AVX512DQ | CPUID_7_0_EBX_SHA_NI | + CPUID_7_0_EBX_AVX512BW | CPUID_7_0_EBX_AVX512VL | + CPUID_7_0_EBX_INVPCID; + + if (!whpx_has_invpcid()) { + ebx &=3D ~CPUID_7_0_EBX_INVPCID; + } + + ecx &=3D CPUID_7_0_ECX_AVX512_VBMI | CPUID_7_0_ECX_AVX512_VPOP= CNTDQ | + CPUID_7_0_ECX_RDPID; + edx &=3D CPUID_7_0_EDX_AVX512_4VNNIW | CPUID_7_0_EDX_AVX512_4F= MAPS; + } else { + ebx =3D 0; + ecx =3D 0; + edx =3D 0; + } + eax =3D 0; + break; + case 0xD: + if (!supported_xcr0 || idx >=3D 63 || + (idx > 1 && !(supported_xcr0 & (UINT64_C(1) << idx)))) { + eax =3D ebx =3D ecx =3D edx =3D 0; + break; + } + + if (idx =3D=3D 0) { + eax =3D supported_xcr0; + } else if (idx =3D=3D 1) { + eax &=3D CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XGETBV1; + if (!whpx_has_xsaves()) { + eax &=3D ~CPUID_XSAVE_XSAVES; + } + } + break; + case 0x80000001: + /* LM only if HVF in 64-bit mode */ + edx &=3D CPUID_FP87 | CPUID_VME | CPUID_DE | CPUID_PSE | CPUID_TSC= | + CPUID_MSR | CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC= | + CPUID_EXT2_SYSCALL | CPUID_MTRR | CPUID_PGE | CPUID_MCA | = CPUID_CMOV | + CPUID_PAT | CPUID_PSE36 | CPUID_EXT2_MMXEXT | CPUID_MMX | + CPUID_FXSR | CPUID_EXT2_FXSR | CPUID_EXT2_PDPE1GB | CPUID_= EXT2_3DNOWEXT | + CPUID_EXT2_3DNOW | CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPU= ID_EXT2_NX; + if (!(whpx_has_rdtscp())) { + edx &=3D ~CPUID_EXT2_RDTSCP; + } + ecx &=3D CPUID_EXT3_LAHF_LM | CPUID_EXT3_CMP_LEG | CPUID_EXT3_CR8L= EG | + CPUID_EXT3_ABM | CPUID_EXT3_SSE4A | CPUID_EXT3_MISALIGNSSE= | + CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_OSVW | CPUID_EXT3_XO= P | + CPUID_EXT3_FMA4 | CPUID_EXT3_TBM; + break; + case 0x80000007: + edx &=3D CPUID_APM_INVTSC; + eax =3D ebx =3D ecx =3D 0; + break; + default: + return 0; + } + + 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; + } +} diff --git a/target/i386/whpx/whpx-i386.h b/target/i386/whpx/whpx-i386.h index 6db9a75d39..9dc6837574 100644 --- a/target/i386/whpx/whpx-i386.h +++ b/target/i386/whpx/whpx-i386.h @@ -2,3 +2,10 @@ =20 uint32_t whpx_get_supported_cpuid(uint32_t func, uint32_t idx, int reg); bool whpx_is_legacy_os(void); + +uint32_t whpx_get_supported_cpuid_legacy(uint32_t func, uint32_t idx, + int reg); +bool whpx_has_xsave(void); +bool whpx_has_xsaves(void); +bool whpx_has_rdtscp(void); +bool whpx_has_invpcid(void); --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682127; cv=none; d=zohomail.com; s=zohoarc; b=K/zVxwbjJhk0dMxy7kf3IPScYHejY3sji0PYXU1EKJKC139ViFXhgkXteBQ3Cdg3Hejm1mlAw85nTfn04LJBpNr42Iy+O3JNoVkaEx8vK9wlfewIHZLFHFfrpvMT16HM6heui/ytMMVPdjTrO8y2uH01frKmTsaTJ265SfQxfYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682127; 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=nflalHNpsd+cwF/uF35esRRPVFTNfgzM4VSaQ5bZG+E=; b=aZd/avZ0PyzS4g4XDpbmoJXZQWB4Q5xSpvTD5vAA94Wt9OgIWTPkv81dTM/en4R9Lm4nUQ6k+nxGWSZrMwsWnA7MFc9L1zpOpxrrpy7nDqsVq2OHytFhZ+jpjpyXXXBU5t8p4ncS7tJE4qS3L3g6xJFkPFrHPAU+KeJnayQ3XnQ= 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 177668212783482.98768423584568; Mon, 20 Apr 2026 03:48:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6v-0008FP-4R; Mon, 20 Apr 2026 06:44:13 -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 1wEm6t-0008Do-KX for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:11 -0400 Received: from p-west3-cluster4-host11-snip4-3.eps.apple.com ([57.103.74.214] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6r-0000kJ-6J for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:11 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 16264180045A; Mon, 20 Apr 2026 10:44:05 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 7C7D41800471; Mon, 20 Apr 2026 10:44:03 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681848; x=1779273848; bh=nflalHNpsd+cwF/uF35esRRPVFTNfgzM4VSaQ5bZG+E=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=FNMbmroCvTzrII/NtwJLiAaUqELDTL3wAvZteIi6CtOkgPsVpnIv3USlkB3qRe33IB1MVZEa9T8PeNSsDWpm2OfyVSMP0tn5fpEXVHoFBslUOj823k3dJGuwCu5o2/9zNChs5zNiq21LuxP+qaezhFzvcdw51LG2n95zqwiswNy9f2/4vrmeNiL/YP0vPi7n6pfEuCyVmCFmKhz3yFLWxuoLFprEitKNxMM5apqTe62RzW2/xZExsekouLdLZTyA8ZmfqfY7xjj94J/6NPLGS7wDnadp1KVdo6EZWJxOk5zyn8VRLr1x8ddWgJOXC5HQgzp8y68dvNMcbWpBTcaiYQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 29/38] target/i386: make xsave_buf present unconditionally Date: Mon, 20 Apr 2026 12:42:39 +0200 Message-ID: <20260420104248.86702-30-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX6jJ8bPlrBLRt 426J8yTRL/At65uSWfwkfRL3yaqGSeYMVG2HHdCgC6udYTfUHVSZqUzD/OiY0pbuqtH8ZFU/Fo7 gROA0ATdd3hMzh8lIz/TTMJaHbHJJy8gcC1SaK0hWy68IXkGYsUZkyjbof/5gto06CLltdA2EiH nMRi9f0XDwo0+AejcNRv6xZV2ykEIGa0hJ+J0Xw8vnxLEo09g6aE3z/oxlBNRoQfN+hPKdeVQRq tWpKFWXkPelj/+IkTJwFJ3ytDNVHKx2RIhcia8D1oJDVhKDJub4BBq3RallrK5KGCzz8dY6T/hL trKne8vpPumG5LHGpj01eeWfwSDyuN4mkE1SoWIr09NsHAgj7K32cejM/cEa2s= X-Proofpoint-GUID: x1IlCGvlfwUAWhMOXOr0_Vft11f2yvtZ X-Authority-Info-Out: v=2.4 cv=CeMFJbrl c=1 sm=1 tr=0 ts=69e60376 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EWkIHKX3_8ZzwOJz1Y8A:9 X-Proofpoint-ORIG-GUID: x1IlCGvlfwUAWhMOXOr0_Vft11f2yvtZ 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=873 clxscore=1030 bulkscore=0 suspectscore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.214; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776682129799158500 Content-Type: text/plain; charset="utf-8" This is necessary for the xsave_helper helpers to compile. Signed-off-by: Mohamed Mediouni --- target/i386/cpu.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 67f508dc10..0af7bdf85a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2269,10 +2269,8 @@ typedef struct CPUArchState { int64_t user_tsc_khz; /* for sanity check only */ uint64_t apic_bus_freq; uint64_t tsc; -#if defined(CONFIG_KVM) || defined(CONFIG_HVF) void *xsave_buf; uint32_t xsave_buf_len; -#endif #if defined(CONFIG_KVM) struct kvm_nested_state *nested_state; MemoryRegion *xen_vcpu_info_mr; --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776681970; cv=none; d=zohomail.com; s=zohoarc; b=Z0cH02wOncWsaE5jL8ovDZIRjRIKl+gp6RPCeWJOqIae24mGyT+mDBlx0BxDophFR0wkRTnu9tL30G7D5Ysl23zoIBg0ajEb7SQ+TO7byopaplET92tdxb6aZjAHacq1FM20MFqJVwHYfwhMALYwdURFyBN4H5zHtIZeMKssScE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681970; 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=IUjKb0cE7ZzdVrzQoDPD3eOQWmDC4LH15sqwoM3HWHE=; b=bt0Zfz0ymWNRlry5DvxKFLVEUDQOrpRv7N8N/kGcHfTIaT7AQhRsLyFbpSoiCeQwOJTUR3lVbRBQH8DAGaiSwZVKUiypqcQsE7N11scyKU49ThOnYMhvyagQvmZr1rKsbhBVK4mWN93D5MRIdSf0sIHEP+8zIQwtPnqG+g92x+E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776681970322173.1702585595549; Mon, 20 Apr 2026 03:46:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm6x-0008Gd-Oh; Mon, 20 Apr 2026 06:44:15 -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 1wEm6w-0008Fx-5J for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:14 -0400 Received: from p-west3-cluster4-host4-snip4-10.eps.apple.com ([57.103.74.171] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6t-0000lC-Tp for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:13 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id ABCD01800449; Mon, 20 Apr 2026 10:44:08 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 019CB1800451; Mon, 20 Apr 2026 10:44:05 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681850; x=1779273850; bh=IUjKb0cE7ZzdVrzQoDPD3eOQWmDC4LH15sqwoM3HWHE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=KeSI/XervqlsUhvkHyUP27jToHvUeWnvaEbqrnonDlG7BgPxux0WyAWdmDTn5jwTTOW4gtzO8SXyHu+bPeIT8JWKpQk+jkUtlQPJ2Tza1wh5/DPj/TXu8bROIGhUcpz/Jel2F/mXvGT0y2C4LZ6EyzZAT9zcn9jMdpGu1yyWtC7u9gosdhM/P2ZW3ixhDk8UMQjj6LUEk3aPIqbd2FVDi8rhAyqZa4SPefrcLH0wQcZhFDMUCoLJIBk7ai0SCxv1Lmp+SR+0uZYgTOrifP0mZXFZahjc2UihRMrEyS2jiTE4IRbjemvMvGyAfZtA854MmAJEvLkjh6iZ6/7KD6Fa8A== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu , Magnus Kulke Subject: [PATCH v2 30/38] target/i386: add de/compaction to xsave_helper Date: Mon, 20 Apr 2026 12:42:40 +0200 Message-ID: <20260420104248.86702-31-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: vu1BWl4H15wgxyAfxwVxW8TtrW4bWnb1 X-Proofpoint-GUID: vu1BWl4H15wgxyAfxwVxW8TtrW4bWnb1 X-Authority-Info-Out: v=2.4 cv=cKftc1eN c=1 sm=1 tr=0 ts=69e60379 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yMhMjlubAAAA:8 a=SWS4GvfA19jorXXodEoA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXw5U+D8tUHNss tyloSrQMvvSxmFx8WDIMIIrJc6G3h5GmDA2FFOeKCAFHDbLbY+YQHhrTJ9xhXR7H3A/IWOZxJlX 3ZLs0b5AqxoJZ7SxYDrEWM3hDxWDjVW42gJoLMayiWzwrOB/+xVbjG1sAgIfgEA46ZG1FfZqgkD aBxivy5yOUzmjLRJXJh1/XrRdMQic1mg5A+8YBwbBVC5xctaBTQF7wMcoLQXyMWDO1QqJZECpJr Ey7V0VT2LnZhgSs+LhWqbfmLQClhak35/JxqPK3qQ2XVkrE6iGRQBFWbH0Or3yUQsDGHXEnSdfO paX0MJv7/wQn7TqxybEbAlpnHpz8R6oNin7UCHRn1KtpdqBmT1mnDVnq2wCL38= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1030 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.171; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776681971523154100 Content-Type: text/plain; charset="utf-8" From: Magnus Kulke HyperV use XSAVES which stores extended state in compacted format in which components are packed contiguously, while QEMU's internal XSAVE representation use the standard format in which each component is places at a fixed offset. Hence for this purpose we add two conversion fn's to the xsave helper to roundtrip XSAVE state in a migration. - decompact_xsave_area(): converts compacted format to standard. XSTATE_BV is masked to host XCR0 since IA32_XSS is managed by the hypervisor. - compact_xsave_area(): converts standard format back to compacted format. XCOMP_BV is set from the host's CPUID 0xD.0 rather than the guest's XCR0, as this is what the hypervisor expects. Both functions use the host's CPUID leaf 0xD subleaves to determine compone= nt sizes, offsets, and alignment requirements. There are situations when the host advertises features that we want to disable for the guest, e.g. AMX TILE. In this case we cannot rely on the host's xcr0, but instead we use the feature mask that has been generated in as part of the CPU realization process (x86_cpu_expand_features). Signed-off-by: Magnus Kulke [Fixup: made xsave_offset a size_t to fix macOS and OpenBSD builds] Signed-off-by: Mohamed Mediouni --- target/i386/cpu.h | 2 + target/i386/xsave_helper.c | 256 +++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 0af7bdf85a..80cdc1cb2a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -3023,6 +3023,8 @@ void x86_cpu_xrstor_all_areas(X86CPU *cpu, const void= *buf, uint32_t buflen); void x86_cpu_xsave_all_areas(X86CPU *cpu, void *buf, uint32_t buflen); uint32_t xsave_area_size(uint64_t mask, bool compacted); void x86_update_hflags(CPUX86State* env); +int decompact_xsave_area(const void *buf, size_t buflen, CPUX86State *env); +int compact_xsave_area(CPUX86State *env, void *buf, size_t buflen); =20 static inline bool hyperv_feat_enabled(X86CPU *cpu, int feat) { diff --git a/target/i386/xsave_helper.c b/target/i386/xsave_helper.c index bab2258732..625bae103a 100644 --- a/target/i386/xsave_helper.c +++ b/target/i386/xsave_helper.c @@ -3,6 +3,7 @@ * See the COPYING file in the top-level directory. */ #include "qemu/osdep.h" +#include "qemu/error-report.h" =20 #include "cpu.h" =20 @@ -293,3 +294,258 @@ void x86_cpu_xrstor_all_areas(X86CPU *cpu, const void= *buf, uint32_t buflen) } #endif } + +#define XSTATE_BV_IN_HDR offsetof(X86XSaveHeader, xstate_bv) +#define XCOMP_BV_IN_HDR offsetof(X86XSaveHeader, xcomp_bvo) + +typedef struct X86XSaveAreaView { + /* 512 bytes */ + X86LegacyXSaveArea legacy; + /* 64 bytes */ + X86XSaveHeader header; + /* ...followed by individual xsave areas */ +} X86XSaveAreaView; + +#define XSAVE_XSTATE_BV_OFFSET offsetof(X86XSaveAreaView, header.xstate_b= v) +#define XSAVE_XCOMP_BV_OFFSET offsetof(X86XSaveAreaView, header.xcomp_bv) +#define XSAVE_EXT_OFFSET (sizeof(X86LegacyXSaveArea) + \ + sizeof(X86XSaveHeader)) + +/** + * decompact_xsave_area - Convert compacted XSAVE format to standard format + * @buf: Source buffer containing compacted XSAVE data + * @buflen: Size of source buffer + * @env: CPU state where the standard format buffer will be written to + * + * Accelerator backends like MSHV might return XSAVE state in compacted fo= rmat + * (XSAVEC). The state components have to be packed contiguously without g= aps. + * The XSAVE qemu buffers are in standard format where each component has a + * fixed offset. + * + * Returns: 0 on success, negative errno on failure + */ +int decompact_xsave_area(const void *buf, size_t buflen, CPUX86State *env) +{ + uint64_t compacted_xstate_bv, compacted_xcomp_bv, compacted_layout_bv; + size_t xsave_offset; + uint64_t *xcomp_bv; + size_t i; + uint32_t eax, ebx, ecx, edx; + uint32_t size, dst_off; + bool align64; + uint64_t guest_xcr0, *xstate_bv; + + compacted_xstate_bv =3D *(uint64_t *)(buf + XSAVE_XSTATE_BV_OFFSET); + compacted_xcomp_bv =3D *(uint64_t *)(buf + XSAVE_XCOMP_BV_OFFSET); + + /* This function only handles compacted format (bit 63 set) */ + assert((compacted_xcomp_bv >> 63) & 1); + + /* Low bits of XCOMP_BV describe which components are in the layout */ + compacted_layout_bv =3D compacted_xcomp_bv & ~(1ULL << 63); + + /* Zero out buffer, then copy legacy region (FP + SSE) and header as-i= s */ + memset(env->xsave_buf, 0, env->xsave_buf_len); + memcpy(env->xsave_buf, buf, XSAVE_EXT_OFFSET); + + /* + * We mask XSTATE_BV with the guest's supported XCR0 because: + * 1. Supervisor state (IA32_XSS) is hypervisor-managed, we don't use + * this state for migration. + * 2. Features disabled at partition creation (e.g. AMX) must be exclu= ded + */ + guest_xcr0 =3D ((uint64_t)env->features[FEAT_XSAVE_XCR0_HI] << 32) | + env->features[FEAT_XSAVE_XCR0_LO]; + xstate_bv =3D (uint64_t *)(env->xsave_buf + XSAVE_XSTATE_BV_OFFSET); + *xstate_bv &=3D guest_xcr0; + + /* Clear bit 63 - output is standard format, not compacted */ + xcomp_bv =3D (uint64_t *)(env->xsave_buf + XSAVE_XCOMP_BV_OFFSET); + *xcomp_bv =3D *xcomp_bv & ~(1ULL << 63); + + /* + * Process each extended state component in the compacted layout. + * Components 0 and 1 (FP and SSE) are in the legacy region, so we + * start at component 2. For each component: + * - Calculate its offset in the compacted source (contiguous layout) + * - Get its fixed offset in the standard destination from CPUID + * - Copy if the component has non-init state (bit set in XSTATE_BV) + */ + xsave_offset =3D XSAVE_EXT_OFFSET; + for (i =3D 2; i < 63; i++) { + if (((compacted_layout_bv >> i) & 1) =3D=3D 0) { + continue; + } + + /* Query guest CPUID for this component's size and standard offset= */ + cpu_x86_cpuid(env, 0xD, i, &eax, &ebx, &ecx, &edx); + + size =3D eax; + dst_off =3D ebx; + align64 =3D (ecx & (1u << 1)) !=3D 0; + + /* Component is in the layout but unknown to the guest CPUID model= */ + if (size =3D=3D 0) { + /* + * The hypervisor might expose a component that has no + * representation in the guest CPUID model. We query the host = to + * retrieve the size of the component, so we can skip over it. + */ + host_cpuid(0xD, i, &eax, &ebx, &ecx, &edx); + size =3D eax; + align64 =3D (ecx & (1u << 1)) !=3D 0; + if (size =3D=3D 0) { + error_report("xsave component %zu: size unknown to both " + "guest and host CPUID", i); + return -EINVAL; + } + + if (align64) { + xsave_offset =3D QEMU_ALIGN_UP(xsave_offset, 64); + } + + if (xsave_offset + size > buflen) { + error_report("xsave component %zu overruns source buffer: " + "offset=3D%zu size=3D%u buflen=3D%zu", + i, xsave_offset, size, buflen); + return -E2BIG; + } + + xsave_offset +=3D size; + continue; + } + + if (align64) { + xsave_offset =3D QEMU_ALIGN_UP(xsave_offset, 64); + } + + if ((xsave_offset + size) > buflen) { + error_report("xsave component %zu overruns source buffer: " + "offset=3D%zu size=3D%u buflen=3D%zu", + i, xsave_offset, size, buflen); + return -E2BIG; + } + + if ((dst_off + size) > env->xsave_buf_len) { + error_report("xsave component %zu overruns destination buffer:= " + "offset=3D%u size=3D%u buflen=3D%zu", + i, dst_off, size, (size_t)env->xsave_buf_len); + return -E2BIG; + } + + /* Copy components marked present in XSTATE_BV to guest model */ + if (((compacted_xstate_bv >> i) & 1) !=3D 0) { + memcpy(env->xsave_buf + dst_off, buf + xsave_offset, size); + } + + xsave_offset +=3D size; + } + + return 0; +} + +/** + * compact_xsave_area - Convert standard XSAVE format to compacted format + * @env: CPU state containing the standard format XSAVE buffer + * @buf: Destination buffer for compacted XSAVE data (to send to hyperviso= r) + * @buflen: Size of destination buffer + * + * Accelerator backends like MSHV might expect XSAVE state in compacted fo= rmat + * (XSAVEC). The state components are packed contiguously without gaps. + * The XSAVE qemu buffers are in standard format where each component has a + * fixed offset. + * + * This function converts from standard to compacted format, it accepts a + * pre-allocated destination buffer of sufficient size, it is the + * responsibility of the caller to ensure the buffer is big enough. + * + * Returns: total size of compacted XSAVE data written to @buf + */ +int compact_xsave_area(CPUX86State *env, void *buf, size_t buflen) +{ + uint64_t *xcomp_bv; + size_t i; + uint32_t eax, ebx, ecx, edx; + uint32_t size, src_off; + bool align64; + size_t compact_offset; + uint64_t host_xcr0_mask, guest_xcr0; + + /* Zero out buffer, then copy legacy region (FP + SSE) and header as-i= s */ + memset(buf, 0, buflen); + memcpy(buf, env->xsave_buf, XSAVE_EXT_OFFSET); + + /* + * Set XCOMP_BV to indicate compacted format (bit 63) and which + * components are in the layout. + * + * We must explicitly set XCOMP_BV because x86_cpu_xsave_all_areas() + * produces standard format with XCOMP_BV=3D0 (buffer is zeroed and on= ly + * XSTATE_BV is set in the header). + * + * XCOMP_BV must reflect the partition's XSAVE capability, not the + * guest's current XCR0 (env->xcr0). These differ b/c: + * - A guest's XCR0 is what the guest OS has enabled via XSETBV + * - The partition's XCR0 mask is the hypervisor's save/restore capabi= lity + * + * The hypervisor uses XSAVES which saves based on its capability, so = the + * XCOMP_BV value in the buffer we send back must match that capabilit= y. + * + * We intersect the host XCR0 with the guest's supported XCR0 features + * (FEAT_XSAVE_XCR0_*) so that features disabled at partition creation + * (e.g. AMX) are excluded from the compacted layout. + */ + host_cpuid(0xD, 0, &eax, &ebx, &ecx, &edx); + host_xcr0_mask =3D ((uint64_t)edx << 32) | eax; + guest_xcr0 =3D ((uint64_t)env->features[FEAT_XSAVE_XCR0_HI] << 32) | + env->features[FEAT_XSAVE_XCR0_LO]; + host_xcr0_mask &=3D guest_xcr0; + xcomp_bv =3D buf + XSAVE_XCOMP_BV_OFFSET; + *xcomp_bv =3D host_xcr0_mask | (1ULL << 63); + + /* + * Process each extended state component in the host's XCR0. + * The compacted layout must match XCOMP_BV (host capability). + * + * For each component: + * - Get its size and standard offset from host CPUID + * - Apply 64-byte alignment if required + * - Copy data only if guest has this component (bit set in env->xcr0) + * - Always advance offset to maintain correct layout + */ + compact_offset =3D XSAVE_EXT_OFFSET; + for (i =3D 2; i < 63; i++) { + if (!((host_xcr0_mask >> i) & 1)) { + continue; + } + + /* Query host CPUID for this component's size and standard offset = */ + host_cpuid(0xD, i, &eax, &ebx, &ecx, &edx); + size =3D eax; + src_off =3D ebx; + align64 =3D (ecx >> 1) & 1; + + if (size =3D=3D 0) { + /* Component in host xcr0 but unknown - shouldn't happen */ + continue; + } + + /* Apply 64-byte alignment if required by this component */ + if (align64) { + compact_offset =3D QEMU_ALIGN_UP(compact_offset, 64); + } + + /* + * Only copy data if guest has this component enabled in XCR0. + * Otherwise the component remains zeroed (init state), but we + * still advance the offset to maintain the correct layout. + */ + if ((env->xcr0 >> i) & 1) { + memcpy(buf + compact_offset, env->xsave_buf + src_off, size); + } + + compact_offset +=3D size; + } + + return compact_offset; +} --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682109; cv=none; d=zohomail.com; s=zohoarc; b=IOVa7BHWYdGna8kOdEUjt/9/fb+/x/wQD9Nsoo04OQzqIrb88sIqY3iQuFng2tsy9+uw5sgRpfE+e0j+VbrLB7Z8nE5Hnq38ktACAWUi74No8AbjcpIYEfQ3yk3utisl2Qow5RFttL6X56t+myBIirlrQWg2B8cpsll3xsML8uo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682109; 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=tbMliXtkqk8dPHBK0hLkGecREvcpTdLtake6KyI3WL8=; b=N0I/9hOrECBvY1o2rqugtFMmt2JaauHVfRMgkNqbetmvGHOExxMy2JLHOFmsXIiTWeEDtPA5JUQCM6QpLU+bHeB6zOAGwdY1HVnDvTYhGmhMTF7agEnnVHyTao52Zqcej720B/JrT65LMDDmys+KJEBEhqnXgC7hlEfEdblJMqM= 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 1776682109744111.48203377654306; Mon, 20 Apr 2026 03:48:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm71-0008LP-5Q; Mon, 20 Apr 2026 06:44:19 -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 1wEm70-0008Ko-6p for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:18 -0400 Received: from p-west3-cluster4-host11-snip4-10.eps.apple.com ([57.103.74.221] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6w-0000m2-7s for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:17 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 251371800451; Mon, 20 Apr 2026 10:44:11 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 9669D1800159; Mon, 20 Apr 2026 10:44:08 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681853; x=1779273853; bh=tbMliXtkqk8dPHBK0hLkGecREvcpTdLtake6KyI3WL8=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=V7XdVDc1+XTOwx6v5+f57H3xAUMNtmfBwphIFmv8pOhEmEaS3VOHBOTJSsrpaxAUdzwQdaEJqqEtgbl/3L+kCJ+qOXlbuxzfznTqfMLomzEAITFM7eJzEgGEhvaoHOLJC07l7/mbVymCgzqfcxy7Acfkva859Dp+6sjusij+lOcVgLF+6BLHKEjRLovxmnRzICOL/F//ffvmYFQa9b7vENBb8jECvYJ0wGGfeXtGrqFGVvddcvkr4VgxBOcmoHNMellPPzCTotMoiQfDdt0rioRXzGxlAH8UMrQiW4swZ1zVzenYu6wX5/xPhS/7lJUO6PalDSbBApTfG2j3ylkR8A== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 31/38] whpx: xsave support Date: Mon, 20 Apr 2026 12:42:41 +0200 Message-ID: <20260420104248.86702-32-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: bO-wrEJn44fpQzUefPwBq6egDJYePCFq X-Proofpoint-GUID: bO-wrEJn44fpQzUefPwBq6egDJYePCFq X-Authority-Info-Out: v=2.4 cv=cKftc1eN c=1 sm=1 tr=0 ts=69e6037b cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=pIzSZyhXsI4QXQPOM_AA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXxELx/m+9X/Ic Q9UioB4ugv0c07Qj2JgxzQUo2Z4YKyEy7nycL/uX3WjK2YSzB3OGfJmr+hcO9xVnhLwsjOLcIIs m2vdwg2jcrun/33wLp3ImmdhNuIcT2K37wLIzGNjnu1ohal5ws6/2aJOZgZ9AZZSUwA0vp53pAA MHofpj2BzA4nkmXWSu8lTkGOtuNHIS2z2XTO/UxRKPs3ULb/ZItADrA1QEtbH16Eb/diBdUKNIQ +4qFlzlhhufIioUO5rd9SMC7155sRVR1P3KK0S/aIFQaLY5GNJqUhmymIXyDH05C1zoV6M1DSYa XxqVAB5UX5C6t9vgffnGvc1NpH6T+xNX5bAHc7jwszu0oE1s8o655zQ8XevM2Y= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1030 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.221; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776682111618154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- include/system/whpx-internal.h | 16 ++ target/i386/whpx/whpx-all.c | 379 ++++++++++++++++++++++++--------- 2 files changed, 292 insertions(+), 103 deletions(-) diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index 86639627b3..0aae83bd7c 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -99,6 +99,22 @@ void whpx_apic_get(APICCommonState *s); UINT32 StateSize)) \ X(HRESULT, WHvResetPartition, \ (WHV_PARTITION_HANDLE Partition)) \ + X(HRESULT, WHvGetVirtualProcessorXsaveState, \ + (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, \ + PVOID Buffer, \ + UINT32 BufferSizeInBytes, UINT32 *BytesWritten)) \ + X(HRESULT, WHvSetVirtualProcessorXsaveState, \ + (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, \ + PVOID Buffer, \ + UINT32 BufferSizeInBytes)) \ + X(HRESULT, WHvGetVirtualProcessorState, \ + (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, \ + WHV_VIRTUAL_PROCESSOR_STATE_TYPE StateType, PVOID Buffer, \ + UINT32 BufferSizeInBytes, UINT32 *BytesWritten)) \ + X(HRESULT, WHvSetVirtualProcessorState, \ + (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, \ + WHV_VIRTUAL_PROCESSOR_STATE_TYPE StateType, PVOID Buffer, \ + UINT32 BufferSizeInBytes)) \ LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL_ARCH(X) =20 #define WHP_DEFINE_TYPE(return_type, function_name, signature) \ diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 045dbdfdc8..9b2488b801 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -10,6 +10,7 @@ =20 #include "qemu/osdep.h" #include "cpu.h" +#include "qemu/typedefs.h" #include "system/address-spaces.h" #include "system/ioport.h" #include "gdbstub/helpers.h" @@ -20,6 +21,7 @@ #include "system/cpus.h" #include "system/runstate.h" #include "qemu/main-loop.h" +#include "qemu/memalign.h" #include "hw/core/boards.h" #include "hw/intc/ioapic.h" #include "hw/intc/i8259.h" @@ -108,34 +110,6 @@ static const WHV_REGISTER_NAME whpx_register_names[] = =3D { * WHvX64RegisterDr7, */ =20 - /* X64 Floating Point and Vector Registers */ - WHvX64RegisterXmm0, - WHvX64RegisterXmm1, - WHvX64RegisterXmm2, - WHvX64RegisterXmm3, - WHvX64RegisterXmm4, - WHvX64RegisterXmm5, - WHvX64RegisterXmm6, - WHvX64RegisterXmm7, - WHvX64RegisterXmm8, - WHvX64RegisterXmm9, - WHvX64RegisterXmm10, - WHvX64RegisterXmm11, - WHvX64RegisterXmm12, - WHvX64RegisterXmm13, - WHvX64RegisterXmm14, - WHvX64RegisterXmm15, - WHvX64RegisterFpMmx0, - WHvX64RegisterFpMmx1, - WHvX64RegisterFpMmx2, - WHvX64RegisterFpMmx3, - WHvX64RegisterFpMmx4, - WHvX64RegisterFpMmx5, - WHvX64RegisterFpMmx6, - WHvX64RegisterFpMmx7, - WHvX64RegisterFpControlStatus, - WHvX64RegisterXmmControlStatus, - /* X64 MSRs */ WHvX64RegisterEfer, #ifdef TARGET_X86_64 @@ -182,6 +156,36 @@ static const WHV_REGISTER_NAME whpx_register_names_for= _vmexit[] =3D { WHvX64RegisterR15, }; =20 +static const WHV_REGISTER_NAME whpx_register_names_legacy_fp[] =3D { + /* X64 Floating Point and Vector Registers (non-xsave) */ + WHvX64RegisterXmm0, + WHvX64RegisterXmm1, + WHvX64RegisterXmm2, + WHvX64RegisterXmm3, + WHvX64RegisterXmm4, + WHvX64RegisterXmm5, + WHvX64RegisterXmm6, + WHvX64RegisterXmm7, + WHvX64RegisterXmm8, + WHvX64RegisterXmm9, + WHvX64RegisterXmm10, + WHvX64RegisterXmm11, + WHvX64RegisterXmm12, + WHvX64RegisterXmm13, + WHvX64RegisterXmm14, + WHvX64RegisterXmm15, + WHvX64RegisterFpMmx0, + WHvX64RegisterFpMmx1, + WHvX64RegisterFpMmx2, + WHvX64RegisterFpMmx3, + WHvX64RegisterFpMmx4, + WHvX64RegisterFpMmx5, + WHvX64RegisterFpMmx6, + WHvX64RegisterFpMmx7, + WHvX64RegisterFpControlStatus, + WHvX64RegisterXmmControlStatus, +}; + struct whpx_register_set { WHV_REGISTER_VALUE values[RTL_NUMBER_OF(whpx_register_names)]; }; @@ -392,6 +396,123 @@ static int whpx_set_tsc(CPUState *cpu) return 0; } =20 +static bool whpx_is_xsave_enabled(CPUState *cpu) +{ + CPUX86State *env =3D &X86_CPU(cpu)->env; + return env->cr[4] & CR4_OSXSAVE_MASK; +} + +static size_t whpx_get_xsave_max_len(void) +{ + return whpx_get_supported_cpuid(0xd, 0, R_ECX); +} + +static int whpx_set_xsave_state(const CPUState *cpu) +{ + struct whpx_state *whpx =3D &whpx_global; + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + HRESULT hr; + void *xsavec_buf; + size_t page =3D qemu_real_host_page_size(); + size_t xsavec_buf_len; + + /* allocate and populate compacted buffer */ + xsavec_buf_len =3D whpx_get_xsave_max_len(); + xsavec_buf =3D qemu_memalign(page, xsavec_buf_len); + + /* save registers to standard format buffer */ + x86_cpu_xsave_all_areas(x86cpu, env->xsave_buf, env->xsave_buf_len); + + /* store compacted version of xsave area in xsavec_buf */ + compact_xsave_area(env, xsavec_buf, xsavec_buf_len); + + if (!whpx_is_legacy_os()) { + hr =3D whp_dispatch.WHvSetVirtualProcessorState( + whpx->partition, cpu->cpu_index, + WHvVirtualProcessorStateTypeXsaveState, + xsavec_buf, + xsavec_buf_len); + } else { + hr =3D whp_dispatch.WHvSetVirtualProcessorXsaveState( + whpx->partition, cpu->cpu_index, + xsavec_buf, + xsavec_buf_len); + } + + qemu_vfree(xsavec_buf); + if (FAILED(hr)) { + error_report("WHPX: Failed to get virtual processor context, hr=3D= %08lx", + hr); + } + + return 0; +} + +static void whpx_set_legacy_fp_registers(CPUState *cpu, WHPXStateLevel lev= el) +{ + struct whpx_state *whpx =3D &whpx_global; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + struct whpx_register_set vcxt; + HRESULT hr; + int idx =3D 0; + int i; + int idx_next; + + assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu)); + + /* 16 XMM registers */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterXmm0); + idx_next =3D idx + 16; + for (i =3D 0; i < sizeof(env->xmm_regs) / sizeof(ZMMReg); i +=3D 1, id= x +=3D 1) { + vcxt.values[idx].Reg128.Low64 =3D env->xmm_regs[i].ZMM_Q(0); + vcxt.values[idx].Reg128.High64 =3D env->xmm_regs[i].ZMM_Q(1); + } + idx =3D idx_next; + + /* 8 FP registers */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterFpMmx0); + for (i =3D 0; i < 8; i +=3D 1, idx +=3D 1) { + vcxt.values[idx].Fp.AsUINT128.Low64 =3D env->fpregs[i].mmx.MMX_Q(0= ); + /* vcxt.values[idx].Fp.AsUINT128.High64 =3D + env->fpregs[i].mmx.MMX_Q(1); + */ + } + + /* FP control status register */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterFpContr= olStatus); + vcxt.values[idx].FpControlStatus.FpControl =3D env->fpuc; + vcxt.values[idx].FpControlStatus.FpStatus =3D + (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; + vcxt.values[idx].FpControlStatus.FpTag =3D 0; + for (i =3D 0; i < 8; ++i) { + vcxt.values[idx].FpControlStatus.FpTag |=3D (!env->fptags[i]) << i; + } + vcxt.values[idx].FpControlStatus.Reserved =3D 0; + vcxt.values[idx].FpControlStatus.LastFpOp =3D env->fpop; + vcxt.values[idx].FpControlStatus.LastFpRip =3D env->fpip; + idx +=3D 1; + + /* XMM control status register */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterXmmCont= rolStatus); + vcxt.values[idx].XmmControlStatus.LastFpRdp =3D 0; + vcxt.values[idx].XmmControlStatus.XmmStatusControl =3D env->mxcsr; + vcxt.values[idx].XmmControlStatus.XmmStatusControlMask =3D 0x0000ffff; + idx +=3D 1; + + hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( + whpx->partition, cpu->cpu_index, + whpx_register_names_legacy_fp, + idx, + &vcxt.values[0]); + + if (FAILED(hr)) { + error_report("WHPX: Failed to set virtual processor context, hr=3D= %08lx", + hr); + } +} + void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; @@ -491,45 +612,11 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel= level) */ whpx_set_xcrs(cpu); =20 - /* 16 XMM registers */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterXmm0); - idx_next =3D idx + 16; - for (i =3D 0; i < sizeof(env->xmm_regs) / sizeof(ZMMReg); i +=3D 1= , idx +=3D 1) { - vcxt.values[idx].Reg128.Low64 =3D env->xmm_regs[i].ZMM_Q(0); - vcxt.values[idx].Reg128.High64 =3D env->xmm_regs[i].ZMM_Q(1); - } - idx =3D idx_next; - - /* 8 FP registers */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterFpMmx0); - for (i =3D 0; i < 8; i +=3D 1, idx +=3D 1) { - vcxt.values[idx].Fp.AsUINT128.Low64 =3D env->fpregs[i].mmx.MMX= _Q(0); - /* vcxt.values[idx].Fp.AsUINT128.High64 =3D - env->fpregs[i].mmx.MMX_Q(1); - */ - } - - /* FP control status register */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterFpControlStat= us); - vcxt.values[idx].FpControlStatus.FpControl =3D env->fpuc; - vcxt.values[idx].FpControlStatus.FpStatus =3D - (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; - vcxt.values[idx].FpControlStatus.FpTag =3D 0; - for (i =3D 0; i < 8; ++i) { - vcxt.values[idx].FpControlStatus.FpTag |=3D (!env->fptags[i]) = << i; + if (whpx_is_xsave_enabled(cpu)) { + whpx_set_xsave_state(cpu); + } else { + whpx_set_legacy_fp_registers(cpu, level); } - vcxt.values[idx].FpControlStatus.Reserved =3D 0; - vcxt.values[idx].FpControlStatus.LastFpOp =3D env->fpop; - vcxt.values[idx].FpControlStatus.LastFpRip =3D env->fpip; - idx +=3D 1; - - /* XMM control status register */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterXmmControlSta= tus); - vcxt.values[idx].XmmControlStatus.LastFpRdp =3D 0; - vcxt.values[idx].XmmControlStatus.XmmStatusControl =3D env->mxcsr; - vcxt.values[idx].XmmControlStatus.XmmStatusControlMask =3D 0x0000f= fff; - idx +=3D 1; - /* MSRs */ assert(whpx_register_names[idx] =3D=3D WHvX64RegisterEfer); vcxt.values[idx++].Reg64 =3D env->efer; @@ -662,6 +749,110 @@ static void whpx_get_registers_for_vmexit(CPUState *c= pu, WHPXStateLevel level) x86_update_hflags(env); } =20 +static void whpx_get_legacy_fp_registers(CPUState *cpu, WHPXStateLevel lev= el) +{ + struct whpx_state *whpx =3D &whpx_global; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + struct whpx_register_set vcxt; + HRESULT hr; + int i; + int idx; + int idx_next; + + assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu)); + + hr =3D whp_dispatch.WHvGetVirtualProcessorRegisters( + whpx->partition, cpu->cpu_index, + whpx_register_names_legacy_fp, + RTL_NUMBER_OF(whpx_register_names_legacy_fp), + &vcxt.values[0]); + + if (FAILED(hr)) { + error_report("WHPX: Failed to get virtual processor context, hr=3D= %08lx", + hr); + } + + idx =3D 0; + /* 16 XMM registers */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterXmm0); + idx_next =3D idx + 16; + for (i =3D 0; i < sizeof(env->xmm_regs) / sizeof(ZMMReg); i +=3D 1, id= x +=3D 1) { + env->xmm_regs[i].ZMM_Q(0) =3D vcxt.values[idx].Reg128.Low64; + env->xmm_regs[i].ZMM_Q(1) =3D vcxt.values[idx].Reg128.High64; + } + idx =3D idx_next; + + /* 8 FP registers */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterFpMmx0); + for (i =3D 0; i < 8; i +=3D 1, idx +=3D 1) { + env->fpregs[i].mmx.MMX_Q(0) =3D vcxt.values[idx].Fp.AsUINT128.Low6= 4; + /* env->fpregs[i].mmx.MMX_Q(1) =3D + vcxt.values[idx].Fp.AsUINT128.High64; + */ + } + + /* FP control status register */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterFpContr= olStatus); + env->fpuc =3D vcxt.values[idx].FpControlStatus.FpControl; + env->fpstt =3D (vcxt.values[idx].FpControlStatus.FpStatus >> 11) & 0x7; + env->fpus =3D vcxt.values[idx].FpControlStatus.FpStatus & ~0x3800; + for (i =3D 0; i < 8; ++i) { + env->fptags[i] =3D !((vcxt.values[idx].FpControlStatus.FpTag >> i)= & 1); + } + env->fpop =3D vcxt.values[idx].FpControlStatus.LastFpOp; + env->fpip =3D vcxt.values[idx].FpControlStatus.LastFpRip; + idx +=3D 1; + + /* XMM control status register */ + assert(whpx_register_names_legacy_fp[idx] =3D=3D WHvX64RegisterXmmCont= rolStatus); + env->mxcsr =3D vcxt.values[idx].XmmControlStatus.XmmStatusControl; + idx +=3D 1; +} + +static int whpx_get_xsave_state(CPUState *cpu) +{ + struct whpx_state *whpx =3D &whpx_global; + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + int ret; + HRESULT hr; + void *xsavec_buf; + const size_t page =3D qemu_real_host_page_size(); + size_t xsavec_buf_len =3D whpx_get_xsave_max_len(); + UINT32 bytes_written; + + xsavec_buf =3D qemu_memalign(page, xsavec_buf_len); + memset(xsavec_buf, 0, xsavec_buf_len); + + if (!whpx_is_legacy_os()) { + hr =3D whp_dispatch.WHvGetVirtualProcessorState( + whpx->partition, cpu->cpu_index, + WHvVirtualProcessorStateTypeXsaveState, + xsavec_buf, + xsavec_buf_len, &bytes_written); + } else { + hr =3D whp_dispatch.WHvGetVirtualProcessorXsaveState( + whpx->partition, cpu->cpu_index, + xsavec_buf, + xsavec_buf_len, &bytes_written); + } + if (FAILED(hr) || bytes_written =3D=3D 0) { + error_report("failed to get xsave state: %s", strerror(errno)); + return -errno; + } + + ret =3D decompact_xsave_area(xsavec_buf, xsavec_buf_len, env); + qemu_vfree(xsavec_buf); + if (ret < 0) { + error_report("failed to decompact xsave area"); + return ret; + } + x86_cpu_xrstor_all_areas(x86cpu, env->xsave_buf, env->xsave_buf_len); + + return 0; +} + void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; @@ -758,40 +949,11 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel= level) */ whpx_get_xcrs(cpu); =20 - /* 16 XMM registers */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterXmm0); - idx_next =3D idx + 16; - for (i =3D 0; i < sizeof(env->xmm_regs) / sizeof(ZMMReg); i +=3D 1, id= x +=3D 1) { - env->xmm_regs[i].ZMM_Q(0) =3D vcxt.values[idx].Reg128.Low64; - env->xmm_regs[i].ZMM_Q(1) =3D vcxt.values[idx].Reg128.High64; - } - idx =3D idx_next; - - /* 8 FP registers */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterFpMmx0); - for (i =3D 0; i < 8; i +=3D 1, idx +=3D 1) { - env->fpregs[i].mmx.MMX_Q(0) =3D vcxt.values[idx].Fp.AsUINT128.Low6= 4; - /* env->fpregs[i].mmx.MMX_Q(1) =3D - vcxt.values[idx].Fp.AsUINT128.High64; - */ - } - - /* FP control status register */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterFpControlStatus); - env->fpuc =3D vcxt.values[idx].FpControlStatus.FpControl; - env->fpstt =3D (vcxt.values[idx].FpControlStatus.FpStatus >> 11) & 0x7; - env->fpus =3D vcxt.values[idx].FpControlStatus.FpStatus & ~0x3800; - for (i =3D 0; i < 8; ++i) { - env->fptags[i] =3D !((vcxt.values[idx].FpControlStatus.FpTag >> i)= & 1); + if (whpx_is_xsave_enabled(cpu)) { + whpx_get_xsave_state(cpu); + } else { + whpx_get_legacy_fp_registers(cpu, level); } - env->fpop =3D vcxt.values[idx].FpControlStatus.LastFpOp; - env->fpip =3D vcxt.values[idx].FpControlStatus.LastFpRip; - idx +=3D 1; - - /* XMM control status register */ - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterXmmControlStatus); - env->mxcsr =3D vcxt.values[idx].XmmControlStatus.XmmStatusControl; - idx +=3D 1; =20 /* MSRs */ assert(whpx_register_names[idx] =3D=3D WHvX64RegisterEfer); @@ -1525,6 +1687,9 @@ void whpx_arch_destroy_vcpu(CPUState *cpu) X86CPU *x86cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86cpu->env; g_free(env->emu_mmio_buf); + qemu_vfree(env->xsave_buf); + env->xsave_buf =3D NULL; + env->xsave_buf_len =3D 0; } =20 /* Returns the address of the next instruction that is about to be execute= d. */ @@ -2393,6 +2558,9 @@ int whpx_init_vcpu(CPUState *cpu) Error *local_error =3D NULL; X86CPU *x86_cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86_cpu->env; + X86XSaveHeader *header; + size_t page_size =3D qemu_real_host_page_size(); + size_t xsave_len; UINT64 freq =3D 0; int ret; =20 @@ -2469,6 +2637,15 @@ int whpx_init_vcpu(CPUState *cpu) qemu_add_vm_change_state_handler(whpx_cpu_update_state, env); =20 env->emu_mmio_buf =3D g_new(char, 4096); + /* Initialize XSAVE buffer page-aligned */ + xsave_len =3D whpx_get_xsave_max_len(); + env->xsave_buf =3D qemu_memalign(page_size, xsave_len); + env->xsave_buf_len =3D xsave_len; + memset(env->xsave_buf, 0, env->xsave_buf_len); + + /* we need to set the compacted format bit in xsave header for Hyper-V= */ + header =3D (X86XSaveHeader *)(env->xsave_buf + sizeof(X86LegacyXSaveAr= ea)); + header->xcomp_bv =3D header->xstate_bv | (1ULL << 63); =20 return 0; =20 @@ -2628,10 +2805,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms) error_report("WHPX: Failed to query XSAVE capability, hr=3D%08lx",= hr); } =20 - if (!whpx_has_xsave()) { - printf("WHPX: Partition is not XSAVE capable\n"); - } - memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.ProcessorCount =3D ms->smp.cpus; hr =3D whp_dispatch.WHvSetPartitionProperty( --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682034; cv=none; d=zohomail.com; s=zohoarc; b=Q1rdJ6HDhuh1LPddWE7m9D5i9rM5b2kikZD1DU0GlZ25Wg+Lb9WeZ+S3xrl9eNd3zYUkEeMPkVWAavCUeTG3KEiYCwA1HdLdbWF0Wgy20m0EnnwWaLB6TqiaVZyPkgY1gWrpP8OYSWyFCzJFQHZESjmbsrCUDzrxu48hAJZGAkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682034; 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=T2c1vi1orOgNlAefb2YumNTYjXQUvJQ0cgUZeOpqxeQ=; b=MqhaWK2bOA8wWBC4LdmOlZ9/upOM5Fs+eQ882EJ2lDAncS5e/4GTVVF5J6RsbrbaeCfMU4k/9tp/Zc8QdcbJzwlmhKBeUVpO0pjHRENsycOANsvNkEpjnwqvucuyIl74zGoRmneKYC2WxAO4kV+jTR1Z1EK11C0pVICF2HDqBxg= 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 1776682034063889.6893202682704; Mon, 20 Apr 2026 03:47:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm70-0008LJ-N0; Mon, 20 Apr 2026 06:44:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm70-0008Kj-3q for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:18 -0400 Received: from p-west3-cluster4-host11-snip4-7.eps.apple.com ([57.103.74.218] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm6y-0000mg-Lb for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:17 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 930691800444; Mon, 20 Apr 2026 10:44:13 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 0FB071800097; Mon, 20 Apr 2026 10:44:10 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681855; x=1779273855; bh=T2c1vi1orOgNlAefb2YumNTYjXQUvJQ0cgUZeOpqxeQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=IE3ERr53wRt0r1c9hk9FgfduZQSH+mfkT2svuhC537X/BPtssWhuLxWzH7uuGiuDyJYgh+uJ23xYmNpEq1zrfcoaV5f+NRG8on46M5/7jgr3AwAA1DkI1ymqpawmcR9tSS/5mcRU9smsIqHJOe0VJgtJJrUz69Niw6bMPALM4dRwTiMM1XBJMvXzn04cyrCefoCeZQJdf0V/itqU1P+EZ+UfbFzUoQQlts4dr8OAtvCtNlNlf+uRBOMflTnuJ2AdpIch6qcgonhN8fFXD3BOSu0VFHAMR24PKClSb8kl/Rd/0Q3L5ZHUYByczRwJVNFlgpRL4c+JEIgtmrDAR1sbFQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 32/38] whpx: i386: set APIC ID only when APIC present Date: Mon, 20 Apr 2026 12:42:42 +0200 Message-ID: <20260420104248.86702-33-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 6wbyipIUSGzcTJlbeTorfLvI1b_v6fKL X-Proofpoint-GUID: 6wbyipIUSGzcTJlbeTorfLvI1b_v6fKL X-Authority-Info-Out: v=2.4 cv=d7D4CBjE c=1 sm=1 tr=0 ts=69e6037e cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=WHe3jrWR342bzmf78BwA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXxZ4DzG1liJuo uzckocHi6TGpzztisN9mp4wN6GeikMF754/h5aQi0Jnob0gDgCs7f4Bmra85TrN/E99kVShCg05 H5WCzy++53hQyL63s+sNaUu1jHjgn+cEkZmJUWK3QiqOLTDCIAZQuEeU65a8KBaLg87vlJW6yF/ 1+H2F8HJAB6R/3e0wFVG0DVhxzexyxdAVLK6hZk54vMfUESh2XovGS7uQ9FDddvbpJlqLA1dsqg CgDU38cy3rLVrXuTSEIxz9zGkvYkHNlFOfbljXz5LlxEmsgFvHHpHdEQmwPeEUkPelfa6aJZlHc B5/Mzf91mTLi6uo+hTCXCaoN6aJPTAGOGUjSfWsGg/14tjdbKyLcTRl1Ouz8AU= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=870 adultscore=0 clxscore=1030 suspectscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.218; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682036291154100 Content-Type: text/plain; charset="utf-8" -M isapc doesn't have an APIC Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 9b2488b801..208ff0c35c 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2590,7 +2590,7 @@ int whpx_init_vcpu(CPUState *cpu) goto error; } =20 - if (!whpx_irqchip_in_kernel()) { + if (!whpx_irqchip_in_kernel() && x86_cpu->apic_state !=3D NULL) { WHV_REGISTER_VALUE apic_id =3D {.Reg64 =3D x86_cpu->apic_state->in= itial_apic_id}; whpx_set_reg(cpu, WHvX64RegisterInitialApicId, apic_id); } --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682077; cv=none; d=zohomail.com; s=zohoarc; b=LWgqGer2i7TTueGKloHIBDuVEC7EX7PHpV9lROHg2QBKkenWaCNcJluimLT3mOMvcaz3o5Vggfn+Otg5KiLKKtV5sxS+YFRr+qJd2mZ8XAmk9oqsqG9wj2p5Yrq32rbwUgly5V3CkejXpGns6SmlIv4ndipxm4r/iuO32rZxBMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682077; 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=rb0GOIlqaOFPi1Yf1WKY/tBOvMMic05yErCimlciyYU=; b=avTDQtARWUhHFAz4vuOJY2MSys56AY9FezeOUumpv/rMVCi2zz4tr89rUxaNNiRht4utn1MQN6eOkQio3nTR6f79DCmiwxJopKguKMk1G+a5dJxoE9CWjg94dONsYDH6+jGnwEnd+0Ueo8LBWLt5Owf676MJitsss3UOooP8hKg= 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 17766820775917.096083021568347; Mon, 20 Apr 2026 03:47:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm74-0008OF-7p; Mon, 20 Apr 2026 06:44:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm72-0008MG-5C for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:20 -0400 Received: from p-west3-cluster4-host1-snip4-10.eps.apple.com ([57.103.74.181] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm70-0000nC-QD for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:19 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 3856C1800151; Mon, 20 Apr 2026 10:44:16 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 7E3E0180017C; Mon, 20 Apr 2026 10:44:13 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681857; x=1779273857; bh=rb0GOIlqaOFPi1Yf1WKY/tBOvMMic05yErCimlciyYU=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=VIJ6loHicV/QUogjLDzv2jEqHtGMmcwUXZjaboHXkkXFhK0xhtnEBV5QQfv6jU+OOrgTdBSZinB7fKOz/3WvOLcxd8oUOPEdEmC0PjjSAAcb8Bm20Ujf5hCr9MyeZAcVya8Wm3mqbvL7LKIDS7DwakNTDo6HRX6h29AwnEI2pXvpN0MOfxDzIkjYneSi+PPMFsMPcgdbBUHFmmfKEcEDhiFn+zT6d2vssiUBHXCJuwU7HTkRKay3eGyKpDKcitpPbrq6UpjjbAhC4rcINF7Dc6dV9pFcirF9kdggju21qA9CU3h20DjppGaHUgNNORrj0taqO8v51lE5TcTApsq4Xw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 33/38] whpx: i386: update migration blocker message Date: Mon, 20 Apr 2026 12:42:43 +0200 Message-ID: <20260420104248.86702-34-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: E8NtGfp6P629HAHk1EOEx-hDxvGJFgR_ X-Proofpoint-ORIG-GUID: E8NtGfp6P629HAHk1EOEx-hDxvGJFgR_ X-Authority-Info-Out: v=2.4 cv=GJUF0+NK c=1 sm=1 tr=0 ts=69e60381 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=0IeqtQ1xXW1zzRo-U5sA:9 a=ZXulRonScM0A:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX/h8CLLLw0T+4 yd/ODz8AZaE3tNjqh7+L8MlJdPlzFu5H0gTMh5T5DCjbwjUqrp7dzF9t9GttG+uyUp7oihs37Db McSMb4jPAf4Bc37gujTjaTBse2YMDdZfTenY3pSa+6f/Aq05bcbnVV7Q5xi2pnbOZqSj9KrAYHa jCzVx9DxtHAoL3WFKT4tQLMyeArYjIxAasNpKDixPROf/MtpwA1aHkAL4jNCKN44YBh4fz6cZJv IX+fK9FF8t6JHF2kHiqyk1FeZkIwrxDMVzUajv7vwgFsB2v8CeHFj/gYHkieYfYuzunKriYvJmb 98mZP16oQxkyfDg54l++5OdNto6DxD/Blbzb5hkVC646jmawhfnytRzDb0mSz0= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 adultscore=0 clxscore=1030 mlxlogscore=637 bulkscore=0 malwarescore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.181; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776682079557158500 Content-Type: text/plain; charset="utf-8" Quite a part of it is from older times... Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 208ff0c35c..f9f12484c9 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2569,8 +2569,8 @@ int whpx_init_vcpu(CPUState *cpu) */ if (whpx_migration_blocker =3D=3D NULL) { error_setg(&whpx_migration_blocker, - "State blocked due to non-migratable CPUID feature support," - "dirty memory tracking support, and XSAVE/XRSTOR support"); + "State blocked due to missing dirty memory tracking support= ," + "And some system register/state save-restore "); =20 if (migrate_add_blocker(&whpx_migration_blocker, &local_error) < 0= ) { error_report_err(local_error); --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682112; cv=none; d=zohomail.com; s=zohoarc; b=RKDQxH2FN2cg7+89W4CHLac+eqyK8FagbfNzrP7qehVXmM/sKILuS6oTLs9/p0BvUEpLNCV5GiDRZpdlN5ccugukZmcA5msTQBzTNWJGNQ5/NDZ1ZQz3RHK7p1wPquDP6Xf+TQ+cjghXl6n7FKH1zqo+1UnAKX6mS7dkNXcXpRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682112; 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=rPSPa9QNEGa/mspx8muwq7AvyIqsfM0CKqiZ0OTwje8=; b=S7NOOXjXw4LJPrwHkVrogJN8vJeOnIXeibzaTsWAKHFsHKngThkv/OCMSVe4WWSgb33MjoPflGKferRVQ86NqZxrldAZh+NRVSeOgSjY76uC/Z6B3gCFsQQxf6VvYKlqFJuPtY6TtodjUohW2X45PMy34Q5nePSUEtrCVRRpmpI= 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 1776682112032206.14347449010438; Mon, 20 Apr 2026 03:48:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm77-0008RV-1F; Mon, 20 Apr 2026 06:44: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 1wEm74-0008PV-Sy for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:22 -0400 Received: from p-west3-cluster4-host9-snip4-3.eps.apple.com ([57.103.74.234] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm73-0000nf-Dn for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:22 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id B3BAA1800449; Mon, 20 Apr 2026 10:44:18 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 00DA2180014D; Mon, 20 Apr 2026 10:44:15 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681860; x=1779273860; bh=rPSPa9QNEGa/mspx8muwq7AvyIqsfM0CKqiZ0OTwje8=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=gMeNcNdvmjD9YpMasB5IE3dRDlj+B2WRGE9GEj9KyX7LoQSQp+lCeaJVvjp4KD/YFqLONkxgCFUDenyRh4WOQwVs4qRFlxTuATeGZGlTE0gShE2gwy1/VIfnZaX5LqlL/n8tIjSn/Ff9TXcNHHGU0YjCoXE8tq8Kh50QCFbIBMqD5oWMca0vk5G/I33tOr6Y2+6fuDjZJXw8x1Z1foMaNnrrdEAbFtS7PfcyBkdTPZY2mO3cB+j9t8En98zd6RDehtXAaMnDUTN+A5KdFFgG2Ntetj816FvDk7Xbm1u9XmOEoUfw0ZL0PZ4+6YcqKo2CGT5z2502NyGsU6dsGcf+CA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 34/38] whpx: i386: don't increment eip on MSR access raising GPF Date: Mon, 20 Apr 2026 12:42:44 +0200 Message-ID: <20260420104248.86702-35-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=IqQTsb/g c=1 sm=1 tr=0 ts=69e60383 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=N0YEvnU7VqbRQIRMxcMA:9 X-Proofpoint-GUID: YxoqcTplDF3fAxDC33PbX8kwXAxpEfLf X-Proofpoint-ORIG-GUID: YxoqcTplDF3fAxDC33PbX8kwXAxpEfLf X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX4FBRlfBWzUCe ZhE+GPTlE8Oo4ykYyP6S5rm0z0HSvXqV+PuJr+Wg5mrGSkyO6+7QzC0u38Zt5wo9uEZByFePMg5 gOmRv0BtCiQ3XmH+IQr+Xg7Axa44foryHGLgTWrrkNHNp3IAN40fm+WtMLS+extfSm3fQIYAMci GKpyDyrrcPdaA5I8nAKMOm16/DZ7nE2K3ee/aX0vZkQkWEn/OoPl/En2O6grs5VEugsJxT28mCE 1mOcUNFja0zDbyLM2A1DgHiLj1p1CAmosKh8DxvkEWHM3PNYDnPfwaDMAgeWlBEvFony22r7vmU TrnYr20Hmlg5z4/AVZkXt3npmWwTtMFaLw/D1SJnqFMo88IwTKEFPoP5dZWqu8= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 spamscore=0 adultscore=0 suspectscore=0 clxscore=1030 mlxscore=0 mlxlogscore=757 malwarescore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.234; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776682113755158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index f9f12484c9..b0692935e7 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2179,6 +2179,7 @@ int whpx_vcpu_run(CPUState *cpu) WHV_REGISTER_NAME reg_names[3]; UINT32 reg_count; bool is_known_msr =3D 0;=20 + bool raises_gpf =3D false; uint64_t val; =20 if (vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { @@ -2211,6 +2212,7 @@ int whpx_vcpu_run(CPUState *cpu) is_known_msr =3D 1; if (val & MSR_IA32_APICBASE_RESERVED) { x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GP= F, 0); + raises_gpf =3D true; } if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { /* Read path unreachable on Hyper-V */ @@ -2220,6 +2222,7 @@ int whpx_vcpu_run(CPUState *cpu) 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); + raises_gpf =3D true; } else { whpx_set_reg(cpu, WHvX64RegisterApicBase, reg); } @@ -2239,6 +2242,7 @@ int whpx_vcpu_run(CPUState *cpu) reg_values[1].Reg64 =3D val; if (msr_ret < 0) { x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + raises_gpf =3D true; } } else { bql_lock(); @@ -2246,6 +2250,7 @@ int whpx_vcpu_run(CPUState *cpu) bql_unlock(); if (msr_ret < 0) { x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + raises_gpf =3D true; } } } @@ -2295,6 +2300,13 @@ int whpx_vcpu_run(CPUState *cpu) =20 if (!is_known_msr && !whpx->ignore_unknown_msr) { x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0= ); + raises_gpf =3D true; + } + + /* When a GPF is raised, do not change Rip. */ + if (raises_gpf) { + reg_values[0].Reg64 =3D + vcpu->exit_ctx.VpContext.Rip; } =20 hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682028; cv=none; d=zohomail.com; s=zohoarc; b=dkgngivwmU2i4GNUW972l2F8pYbVFHtpHvtFVolGJyslsYx7QMmLbAEJyserwXeB74GeLma8UdSfh1DB4wktejuXPjF0qE0VSD+49i97JHTXjLBOlb5qesIXCaYdA7XABDYRRlTCOnpcsJe3w/KYSypxihsQPj266Ag66r9qRmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682028; 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=IdjugA9xaHsg2nQQQ2yDxOQbJO+pfnS1V2J1m3byuQQ=; b=nqlXX2WUW1/yRXjsVYg8pGOvPB/acPxykX5y4o+nzZgC9jHOuIbwawNf7HU1dLxGkNfe4BZE81YPSIPFECwgONAqCm/mhfZ/QDs9vdKofKcq1ZPBoo2Uq2HBUoGIy3RDjVponGrJbCzGyxMyrcXV0x4E7/G0fWnC6dOmQAOIJW8= 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 1776682028579664.0671184798455; Mon, 20 Apr 2026 03:47:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm78-0008Sf-Hw; Mon, 20 Apr 2026 06:44:26 -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 1wEm77-0008Rx-LO for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:25 -0400 Received: from p-west3-cluster4-host2-snip4-10.eps.apple.com ([57.103.74.191] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm76-0000o2-1Y for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:25 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 1481418000A8; Mon, 20 Apr 2026 10:44:20 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 7AA7E1800097; Mon, 20 Apr 2026 10:44:18 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681863; x=1779273863; bh=IdjugA9xaHsg2nQQQ2yDxOQbJO+pfnS1V2J1m3byuQQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Y4APNMHI8lrLheuTzlQECpUx0gB1wYDEygpQ9sQX7gRHR/lsXp3RzIK1l+DxWBKxDPEwu29O8Zfna0T6pxW2Jv1W/74S5ltzXNwi57PI2NKrDVEE3TqlMGRZM+M2xWW0uJScuhQqATPSTPT5a7/TFq6adHcdSdd86zoGsfRU9ng8w8YjKvYIegyeT4U6PO0q1OJFeW+BkpMTcjIy4DTnhaZPUzi3QsDFyzQ0jAkjsdnxZutD1QP44vuOf/4cz28iUzeoD4qqAEpJa1UrTcVVTr7HnteefAqm/lNrx550sJT3zD524g4OowlYmxT2XrwSoKz14udaqiUfOEjvLuCYDQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 35/38] target/i386: emulate, hvf: rdmsr/wrmsr GPF handling Date: Mon, 20 Apr 2026 12:42:45 +0200 Message-ID: <20260420104248.86702-36-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 4dx0tQky0FyRJ8etG-ROFUMLSj2qtuUc X-Proofpoint-GUID: 4dx0tQky0FyRJ8etG-ROFUMLSj2qtuUc X-Authority-Info-Out: v=2.4 cv=d7D4CBjE c=1 sm=1 tr=0 ts=69e60385 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=183X19KWV2qSZiVN73EA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX5moUkBXcARtm iUyAwV7jxo0KKe1iO+NnUujp3m65SxV8r/J7qYBJAuM2pTqOdrkEDhWF/sonW0Al/Rl2rwhhipC sI4nDTZHdA1PWz99R6t7aLsPgdnAAQWZPJEw7WL1JtX4vr64+fk7qv59WaESRLMYjlnnIBrtMdn mawfWoFp7jBy7k1hjnepKFmpVWpvAIlAhzWywjbpgwJ0V9QasBl/EjltqRP3SFqPw1EjUC+IQdZ 38oOQ42uah3IKF3+gEudw0efqHh8UqBhfBwCjxB7rQzpsudLKzBcAJQHi9kgUoVEkacQAzOTGv3 kzYnCd/lvxkNWtEDC3BDcV/K/Er+XJdc9nTjwZBNQ4mADUTub7HRftKoPYqVnM= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=697 adultscore=0 clxscore=1030 suspectscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.191; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776682029322158500 Content-Type: text/plain; charset="utf-8" In that case, the instruction pointer mustn't be incremented. Signed-off-by: Mohamed Mediouni --- target/i386/emulate/x86_emu.c | 10 ++++++---- target/i386/emulate/x86_emu.h | 4 ++-- target/i386/hvf/hvf.c | 9 +++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/target/i386/emulate/x86_emu.c b/target/i386/emulate/x86_emu.c index c2da1a133f..c6ea854290 100644 --- a/target/i386/emulate/x86_emu.c +++ b/target/i386/emulate/x86_emu.c @@ -792,15 +792,17 @@ void x86_emul_raise_exception(CPUX86State *env, int e= xception_index, int error_c =20 static bool exec_rdmsr(CPUX86State *env, struct x86_decode *decode) { - emul_ops->simulate_rdmsr(env_cpu(env)); - env->eip +=3D decode->len; + if (!emul_ops->simulate_rdmsr(env_cpu(env))) { + env->eip +=3D decode->len; + } return 0; } =20 static bool exec_wrmsr(CPUX86State *env, struct x86_decode *decode) { - emul_ops->simulate_wrmsr(env_cpu(env)); - env->eip +=3D decode->len; + if (!emul_ops->simulate_wrmsr(env_cpu(env))) { + env->eip +=3D decode->len; + } return 0; } =20 diff --git a/target/i386/emulate/x86_emu.h b/target/i386/emulate/x86_emu.h index a8d4c93098..b985240b90 100644 --- a/target/i386/emulate/x86_emu.h +++ b/target/i386/emulate/x86_emu.h @@ -31,8 +31,8 @@ struct x86_emul_ops { target_ulong (*read_cr) (CPUState *cpu, int cr); void (*handle_io)(CPUState *cpu, uint16_t port, void *data, int direct= ion, int size, int count); - void (*simulate_rdmsr)(CPUState *cs); - void (*simulate_wrmsr)(CPUState *cs); + bool (*simulate_rdmsr)(CPUState *cs); + bool (*simulate_wrmsr)(CPUState *cs); bool (*is_protected_mode)(CPUState *cpu); bool (*is_long_mode)(CPUState *cpu); bool (*is_user_mode)(CPUState *cpu); diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index c0d028b147..dfe7500010 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -536,7 +536,7 @@ void hvf_store_regs(CPUState *cs) macvm_set_rip(cs, env->eip); } =20 -void hvf_simulate_rdmsr(CPUState *cs) +bool hvf_simulate_rdmsr(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; @@ -557,6 +557,7 @@ void hvf_simulate_rdmsr(CPUState *cs) ret =3D apic_msr_read(cpu->apic_state, index, &val); if (ret < 0) { x86_emul_raise_exception(env, EXCP0D_GPF, 0); + return 1; } =20 break; @@ -639,9 +640,10 @@ void hvf_simulate_rdmsr(CPUState *cs) =20 RAX(env) =3D (uint32_t)val; RDX(env) =3D (uint32_t)(val >> 32); + return 0; } =20 -void hvf_simulate_wrmsr(CPUState *cs) +bool hvf_simulate_wrmsr(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; @@ -657,6 +659,7 @@ void hvf_simulate_wrmsr(CPUState *cs) r =3D cpu_set_apic_base(cpu->apic_state, data); if (r < 0) { x86_emul_raise_exception(env, EXCP0D_GPF, 0); + return 1; } =20 break; @@ -668,6 +671,7 @@ void hvf_simulate_wrmsr(CPUState *cs) ret =3D apic_msr_write(cpu->apic_state, index, data); if (ret < 0) { x86_emul_raise_exception(env, EXCP0D_GPF, 0); + return 1; } =20 break; @@ -746,6 +750,7 @@ void hvf_simulate_wrmsr(CPUState *cs) g_hypervisor_iface->wrmsr_handler(cs, msr, data); =20 printf("write msr %llx\n", RCX(cs));*/ + return 0; } =20 static int hvf_handle_vmexit(CPUState *cpu) --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776681889; cv=none; d=zohomail.com; s=zohoarc; b=LnCChUbcw0jzJwPY9rjnBa5yvGZ0XKtacoe32Xv36xpIzZeeLR7QGUKNyF270WXEjNjoCsB4HQIQghmrgIUomnsI/e5jr4w3xWNhuZffi0wSRosEZOlW/57JryEkWUmGukAy1gB1D+vf9jk/aN4NpPJDpLCjy4zlFyvciOJG2mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776681889; 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=wP73mLT6dqDsimwGfoQspMT04K7Opz+I97Zfylk4p8A=; b=H3kqVtvYN9YyK4iKDui45FRpneSDwoEgQdLh2FpQamJnkIHXLWDixaCHiANzqdlAmGA4z+YJM3tirvkyXs97glXGJ8HxZEBH7qxfevUv8s6YVHai9yKW/rUo4/sKNJA0tnX+ODvzRur1Wzowd55x6YTaYqIA8Rp4/R4m6tDAl3w= 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 1776681889908199.90359330635715; Mon, 20 Apr 2026 03:44:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm7C-00005n-2i; Mon, 20 Apr 2026 06:44: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 1wEm7A-0008Th-9c for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:28 -0400 Received: from p-west3-cluster4-host3-snip4-10.eps.apple.com ([57.103.74.161] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm78-0000oP-6A for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:28 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 953CA1800478; Mon, 20 Apr 2026 10:44:23 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id EAC7B18000A3; Mon, 20 Apr 2026 10:44:20 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681865; x=1779273865; bh=wP73mLT6dqDsimwGfoQspMT04K7Opz+I97Zfylk4p8A=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=KbY2Hv5Mtc2EhyarNqc5CXsWgTp/gLHopB7IL11jL+Duoz9fZvS/9IeDx9mNBw71JQ4dZMLvANDfZYUN1Wz8OPmATlOMnW3LUnM3unbytDnGr82ssI1fs6hDlhEwWeuM6FunAf8fOCk9P3sTJWN+cvcIYxW+nv2OjbBTt41IvdXfdOyhh8eIuHuzG0hnGM1yTwn2tBLs7LAAzHwOtYyjB24x/KM7bjIv63bhIcPzHn9CuGxQ18PNIA9s/z7uG+8BO7t7AEpbXUk7W7sr2YyUQxBiI8YjSu3afDk/WWz790slLGjTaCHQiSgJ0TtWgZuZAuZTSXCuAw0ZNvs3p16Pag== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 36/38] whpx: i386: add feature to intercept #GP MSR accesses Date: Mon, 20 Apr 2026 12:42:46 +0200 Message-ID: <20260420104248.86702-37-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfXx2HLrfU447RX Hv6+Fz5zy9Lh/GI6mr55kEI+LjYP+e+G4/9hfLAGPbyfX12CCw1vqrxvUxSPSTyg2q6Vi7rsay3 wOJZbbBQ1yhaAaM0LIRhIC7RinwhNgekRxkMoSuIv9RNMNdarXcFej/X1ubVn3HhqbMM/pBqjMA IwCXM9pAOG1eTgjPFYfP5q6dY4itFoRc+EFC5HD1E9NiKW2DpgxWIPO82Gj+QqnqgvLIERgAcS6 2cBrT8m3J6/UGXNeTr51Jha76UzNL0DHbiif7WGVqUuCWhgRK7sWeQTngCwdDmM2XoSZY6gwBPP H1jlDydRct/iBO4dfUVBJ5n4iXoi6+qs4iNL7cNhYbVFBjxGtZ5lF9yVUkQcI0= X-Proofpoint-GUID: H6ayxpqCdwk7575Kt4oLT4BlwuX-egpC X-Proofpoint-ORIG-GUID: H6ayxpqCdwk7575Kt4oLT4BlwuX-egpC X-Authority-Info-Out: v=2.4 cv=Ef3FgfmC c=1 sm=1 tr=0 ts=69e60388 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=CoAbg4nstuYx8jGKVk0A: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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1030 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.161; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1776681892774154100 Content-Type: text/plain; charset="utf-8" It turns out they're not that uncommon, so have a feature around to log those. Signed-off-by: Mohamed Mediouni --- accel/whpx/whpx-common.c | 38 +++++++++ include/system/whpx-internal.h | 1 + target/i386/whpx/whpx-all.c | 146 ++++++++++++++++++++++++++++----- 3 files changed, 166 insertions(+), 19 deletions(-) diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c index 706871f138..8f28b1d617 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -537,6 +537,38 @@ static void whpx_set_unknown_msr(Object *obj, Visitor = *v, } } =20 +static void whpx_set_intercept_msr_gp(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + struct whpx_state *whpx =3D &whpx_global; + OnOffAuto mode; + + if (!visit_type_OnOffAuto(v, name, &mode, errp)) { + return; + } + + switch (mode) { + case ON_OFF_AUTO_ON: + whpx->intercept_msr_gp =3D true; + break; + + case ON_OFF_AUTO_OFF: + whpx->intercept_msr_gp =3D false; + break; + + case ON_OFF_AUTO_AUTO: + whpx->intercept_msr_gp =3D false; + break; + default: + /* + * The value was checked in visit_type_OnOffAuto() above. If + * we get here, then something is wrong in QEMU. + */ + abort(); + } +} + static void whpx_cpu_accel_class_init(ObjectClass *oc, const void *data) { AccelCPUClass *acc =3D ACCEL_CPU_CLASS(oc); @@ -575,6 +607,11 @@ static void whpx_accel_class_init(ObjectClass *oc, con= st void *data) NULL, NULL); object_class_property_set_description(oc, "ignore-unknown-msr", "Configure unknown MSR behavior"); + object_class_property_add(oc, "intercept-msr-gp", "OnOffAuto", + NULL, whpx_set_intercept_msr_gp, + NULL, NULL); + object_class_property_set_description(oc, "intercept-msr-gp", + "Intercept #GP to log erroring MSR accesses."); } =20 static void whpx_accel_instance_init(Object *obj) @@ -590,6 +627,7 @@ static void whpx_accel_instance_init(Object *obj) /* Value determined at whpx_accel_init */ whpx->hyperv_enlightenments_enabled =3D false; whpx->ignore_unknown_msr =3D true; + whpx->intercept_msr_gp =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 0aae83bd7c..15027a7d52 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -48,6 +48,7 @@ struct whpx_state { bool hyperv_enlightenments_enabled; =20 bool ignore_unknown_msr; + bool intercept_msr_gp; }; =20 extern struct whpx_state whpx_global; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index b0692935e7..bda8c484e2 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1008,6 +1008,27 @@ static int emulate_instruction(CPUState *cpu, const = uint8_t *insn_bytes, size_t return 0; } =20 +static int emulate_msr_instruction(CPUState *cpu, + const uint8_t *insn_bytes, size_t insn_len) +{ + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + struct x86_decode decode =3D { 0 }; + x86_insn_stream stream =3D { .bytes =3D insn_bytes, .len =3D insn_len = }; + + whpx_get_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE); + decode_instruction_stream(env, &decode, &stream); + + if (decode.cmd !=3D X86_DECODE_CMD_RDMSR + && decode.cmd !=3D X86_DECODE_CMD_WRMSR) { + return 1; + } + + exec_instruction(env, &decode); + whpx_set_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE); + return 0; +} + static int whpx_handle_mmio(CPUState *cpu, WHV_RUN_VP_EXIT_CONTEXT *exit_c= tx) { WHV_MEMORY_ACCESS_CONTEXT *ctx =3D &exit_ctx->MemoryAccess; @@ -1022,6 +1043,45 @@ static int whpx_handle_mmio(CPUState *cpu, WHV_RUN_V= P_EXIT_CONTEXT *exit_ctx) return 0; } =20 +static int whpx_handle_msr_from_gpf(CPUState *cpu) +{ + WHV_VP_EXCEPTION_CONTEXT *ctx =3D &cpu->accel->exit_ctx.VpException; + int ret; + + ret =3D emulate_msr_instruction(cpu, ctx->InstructionBytes, ctx->Instr= uctionByteCount); + if (ret =3D=3D 1) { + /* Not an MSR instruction */ + return 1; + } + + return 0; +} + +static void whpx_inject_back_gpf(CPUState *cpu) +{ + WHV_VP_EXCEPTION_CONTEXT *ctx =3D &cpu->accel->exit_ctx.VpException; + WHV_REGISTER_VALUE reg =3D {}; + + if (ctx->ExceptionInfo.SoftwareException) { + /* TODO */ + warn_report("Was asked to inject software exception."); + return; + } + + if (ctx->ExceptionType !=3D EXCP0D_GPF) { + warn_report("Was asked to inject exception other than GPF."); + return; + } + + reg.ExceptionEvent.EventPending =3D 1; + reg.ExceptionEvent.EventType =3D WHvX64PendingEventException; + reg.ExceptionEvent.DeliverErrorCode =3D ctx->ExceptionInfo.ErrorCodeVa= lid; + reg.ExceptionEvent.Vector =3D ctx->ExceptionType; + reg.ExceptionEvent.ErrorCode =3D ctx->ErrorCode; + reg.ExceptionEvent.ExceptionParameter =3D ctx->ExceptionParameter; + whpx_set_reg(cpu, WHvRegisterPendingEvent, reg); +} + static void handle_io(CPUState *env, uint16_t port, void *buffer, int direction, int size, int count) { @@ -1210,13 +1270,54 @@ static target_ulong read_cr(CPUState *cpu, int cr) return val.Reg64; } =20 +static bool whpx_simulate_rdmsr(CPUState *cs) +{ + X86CPU *cpu =3D X86_CPU(cs); + CPUX86State *env =3D &cpu->env; + uint32_t msr =3D ECX(env); + uint64_t val =3D 0; + + switch (msr) { + default: + error_report("WHPX: unknown msr 0x%x", msr); + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0); + return 1; + break; + } + + RAX(env) =3D (uint32_t)val; + RDX(env) =3D (uint32_t)(val >> 32); + + return 0; +} + +static bool whpx_simulate_wrmsr(CPUState *cs) +{ + X86CPU *cpu =3D X86_CPU(cs); + CPUX86State *env =3D &cpu->env; + uint32_t msr =3D ECX(env); + uint64_t data =3D ((uint64_t)EDX(env) << 32) | EAX(env); + + switch (msr) { + default: + error_report("WHPX: unknown msr 0x%x val %llx", msr, data); + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0); + return 1; + break; + } + + return 0; +} + static const struct x86_emul_ops whpx_x86_emul_ops =3D { .read_segment_descriptor =3D read_segment_descriptor, .handle_io =3D handle_io, .is_protected_mode =3D is_protected_mode, .is_long_mode =3D is_long_mode, .is_user_mode =3D is_user_mode, - .read_cr =3D read_cr + .read_cr =3D read_cr, + .simulate_rdmsr =3D whpx_simulate_rdmsr, + .simulate_wrmsr =3D whpx_simulate_wrmsr }; =20 static void whpx_init_emu(void) @@ -1295,6 +1396,18 @@ uint32_t whpx_get_supported_cpuid(uint32_t func, uin= t32_t idx, int reg) } } =20 +static UINT64 whpx_get_default_exceptions(void) +{ + struct whpx_state *whpx =3D &whpx_global; + UINT64 intercepts =3D 0; + + if (whpx->intercept_msr_gp) { + intercepts |=3D 1UL << WHvX64ExceptionTypeGeneralProtectionFault; + } + + return intercepts; +} + /* * Controls whether we should intercept various exceptions on the guest, * namely breakpoint/single-step events. @@ -1317,7 +1430,7 @@ HRESULT whpx_set_exception_exit_bitmap(UINT64 excepti= ons) prop.ExtendedVmExits.X64MsrExit =3D 1; prop.ExtendedVmExits.X64CpuidExit =3D 1; =20 - if (exceptions !=3D 0) { + if (exceptions !=3D 0 || whpx_get_default_exceptions() !=3D 0) { prop.ExtendedVmExits.ExceptionExit =3D 1; } =20 @@ -1332,7 +1445,7 @@ HRESULT whpx_set_exception_exit_bitmap(UINT64 excepti= ons) } =20 memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); - prop.ExceptionExitBitmap =3D exceptions; + prop.ExceptionExitBitmap =3D exceptions | whpx_get_default_exceptions(= ); =20 hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, @@ -1342,6 +1455,8 @@ HRESULT whpx_set_exception_exit_bitmap(UINT64 excepti= ons) =20 if (SUCCEEDED(hr)) { whpx->exception_exit_bitmap =3D exceptions; + } else { + error_report("WHPX: Failed to set exception exit bitmap, hr=3D%08l= x", hr); } =20 return hr; @@ -2477,6 +2592,15 @@ int whpx_vcpu_run(CPUState *cpu) break; } case WHvRunVpExitReasonException: + if (vcpu->exit_ctx.VpException.ExceptionType =3D=3D + WHvX64ExceptionTypeGeneralProtectionFault) { + if (whpx_handle_msr_from_gpf(cpu)) { + whpx_inject_back_gpf(cpu); + } + ret =3D 0; + break; + } + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); =20 if ((vcpu->exit_ctx.VpException.ExceptionType =3D=3D @@ -2985,22 +3109,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 - /* Register for MSR and CPUID exits */ - memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); - prop.ExtendedVmExits.X64MsrExit =3D 1; - prop.ExtendedVmExits.X64CpuidExit =3D 1; - - hr =3D whp_dispatch.WHvSetPartitionProperty( - whpx->partition, - WHvPartitionPropertyCodeExtendedVmExits, - &prop, - sizeof(WHV_PARTITION_PROPERTY)); - if (FAILED(hr)) { - error_report("WHPX: Failed to enable extended VM exits, hr=3D%08lx= ", hr); - ret =3D -EINVAL; - goto error; - } - memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.X64MsrExitBitmap.UnhandledMsrs =3D 1; prop.X64MsrExitBitmap.ApicBaseMsrWrite =3D 1; --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682024; cv=none; d=zohomail.com; s=zohoarc; b=fQ4t2MRQESM4p5WOE6opxU0fqHRBblS+cv3odSyDR55KO2+JC3Nx5QW67fQTgpZfYzha53PdgC/iNzdejJgDV+/7UcuqRFuPgcf8ZK4zt4fYwfzLilcRd/kKEWLpu18GtzbGzCQAISOLRrD+HwPcI58IGGUqSL0Skz0GjcUITvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682024; 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=H5E2yg8wjRMIBLHacxbEUpLeU4XPrgmC3oFHhxyAG2I=; b=Aq+GQd59/I+1wzhiyRkr1ovBImzJcXhwKvjXyNXFQTQZ/vn3lILL3J1OLN6FMh4hU1h6fNeEbpgqqHczjabDNPWPbdqAPih9vOla8QWOxcOiol3JdAQU3G6/RH7suZJynQJ3nqpPzcee2xEY1Wox6is8woUtUBgYTFBaC9gZu3k= 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 1776682024267794.7851439043783; Mon, 20 Apr 2026 03:47:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm7G-0000U0-2w; Mon, 20 Apr 2026 06:44:34 -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 1wEm7D-00009u-Io for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:31 -0400 Received: from p-west3-cluster4-host12-snip4-4.eps.apple.com ([57.103.74.225] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm7C-0000pA-4Z for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:31 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 291ED18000BC; Mon, 20 Apr 2026 10:44:25 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id 6340E1800475; Mon, 20 Apr 2026 10:44:23 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681869; x=1779273869; bh=H5E2yg8wjRMIBLHacxbEUpLeU4XPrgmC3oFHhxyAG2I=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=bnPyKZktpJ7aSKDPdE01Ol97vUYQ8MSVkEEuwt2UO9l3ytpSmCb71bjcbZMGHH7BLJOfgZ63W+03tCJlq4Zwm2pRTh7ddJYre1D3g3UpQMsM7u3YvuvkBSdpwr6LJEBCsMSjc2HNSo0ea6BmJ7OQMMh5N9NmRgKJ0NEoHZz+9fvcq/BR6O6QU1aUdtRR9Q74ze6YVFR4daMrnkmklWfgmYmlEtmKI0Jw0OQgVXOeBzFsDXz+86O7iCyXlekjzee0GBTuKKYkxv5NiFeecyeO5jZNIuvrsmXUvd8DTqGkIYPzejBKM/C6Pk2mVV5sVWPoO7JL1Z5FpMpVZcPnymG2bA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 37/38] whpx: i386: intercept CPUID 0xD too Date: Mon, 20 Apr 2026 12:42:47 +0200 Message-ID: <20260420104248.86702-38-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX2APGd6PVC26J y6B4RWCkdJeCjB968ajh4ar/8MttcBEfx4+vWRwMs41502+vMHeVzVLdYbeic40YDOVyJ3U6zeU e/nyy8AicXJE8pjSmmGHTsyV7mDHMYVha5Ysm8npqrdxwTFzMWDf15PmuFSDW77zt0DSKzWFQuw 6F4TcjQ0LGDv/GnNuN5yeyksqNJgXmZriBoBNPyoY4O6DYeoBPHPj3aUuu+B/YP90cOAVxwd4Z1 sUptHL/NFRaekDZ9WqmpMsytVkH3pCF6lRhDUcwnp/SAa6cZPA2Uq8GKP2YQXWxRNzb+29z9/FE SqUpD4RCOGrMRQ7JMCV+dX/NFOwUFeIgBCGe2O82PwgOUlAiaErjRynttbxgMc= X-Authority-Info-Out: v=2.4 cv=RoLI7SmK c=1 sm=1 tr=0 ts=69e6038b cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7r31mvdhAh4OVJ8YR2QA:9 X-Proofpoint-ORIG-GUID: tvBvNp-TfAhgrBY-IOsOkoDTPNgQUMal X-Proofpoint-GUID: tvBvNp-TfAhgrBY-IOsOkoDTPNgQUMal 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 mlxlogscore=869 suspectscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.225; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.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, 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: 1776682026439154100 Content-Type: text/plain; charset="utf-8" To have a more accurate CPU model. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index bda8c484e2..26647671f4 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2568,6 +2568,14 @@ int whpx_vcpu_run(CPUState *cpu) } } =20 + /* CPUID[0xD,{1,2}].EBX are dynamic depending on guest feature= s. */ + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 0xd) { + if (vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 1 + || vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 2) { + reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRbx; + } + } + /* OSXSAVE is dynamic. Do this instead of syncing CR4 */ if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 1) { if (vcpu->exit_ctx.CpuidAccess.DefaultResultRcx @@ -2869,7 +2877,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; =20 - UINT32 cpuidExitList[] =3D {0x0, 0x1, 0x6, 0x7, 0xb, 0x14, 0x24, 0x29,= 0x1E, + UINT32 cpuidExitList[] =3D {0x0, 0x1, 0x6, 0x7, 0xb, 0xd, 0x14, 0x24, = 0x29, 0x1E, 0x40000000, 0x40000001, 0x40000010, 0x80000000, 0x80000001, 0x80000002, 0x80000003, 0x80000004, 0x80000007, 0x80000008, 0x8000000A, 0x80000021, 0x80000022, 0xC0000000, 0xC0000001}; --=20 2.50.1 (Apple Git-155) From nobody Tue Apr 21 14:38:14 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=1776682131; cv=none; d=zohomail.com; s=zohoarc; b=igwGRb1TkDbG0Z60co1Ss4XGdeSAbuIbdnBSpuCRzAXLZ/tSsv31NgPovm1VB64IwVQSLs11q7w2J0iNSe289CMLbJvIXwqCK6GrWcAQsFfxmMOgUfN6vHq25BGK/IJwKwpyYwV4YBWZh7gU5s2QefqXfhQ0dxnO9+Te6OLuAkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776682131; 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=aRSWuZJ+0O4EI30ImauiiaFewa0d6ZTDxWu6Xb9/aUo=; b=CBJm9wwPAuOuXgRhIzwrKn2u4FnKKa/R9e5PLlX35YhDHYbc3h/e+SH0+tC4R0BSmr+jCkpVHgoszNSamw8MJuuN3jwrdDHvDEndIXUHwerWBV0ta/7eU+8K9PHZ23vRDgH2OGrTm+5n9OxdtsoGXE70sg+h5BEfcuzmq0A+M+M= 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 1776682131458999.3568828256581; Mon, 20 Apr 2026 03:48:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEm7I-0000nZ-MX; Mon, 20 Apr 2026 06:44:36 -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 1wEm7G-0000a8-LJ for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:34 -0400 Received: from p-west3-cluster4-host12-snip4-10.eps.apple.com ([57.103.74.231] helo=outbound.ms.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEm7E-0000r8-T8 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 06:44:34 -0400 Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPS id 94429180014D; Mon, 20 Apr 2026 10:44:28 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-1 (Postfix) with ESMTPSA id B0FCE1800151; Mon, 20 Apr 2026 10:44:25 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776681871; x=1779273871; bh=aRSWuZJ+0O4EI30ImauiiaFewa0d6ZTDxWu6Xb9/aUo=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=bBR1Tk3wovzThNLzZejOST9s2HHaLcMZsFhOjpc2pij77JYr/aZ0GlQnhhBO6ch0KCM/MmHmGWwLCi/IiIVULN6/31qAMsoRapU6scCqwrCRF899LOceVznS6zUo89LvA7qZEcfsF7JDeVAovPYf9jmLIqMfJyU93qA2ufAzydKK34M+rMRG/zuE9xcVAU5me/gg158O3S8jcITQ5D/D5D85Ojz8evgA3wIThzLlul9hKLPUqyJjdzRSQCOo8G+IBW/SbzeBR/frBJVgfY0wcB9wz4uSMJlYH6ZMmoKqBR/qc/KEp0/T1/1KEUWa1DMOv8Eo+r0drEfSbjgY6SJwng== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Mohamed Mediouni , Paolo Bonzini , Phil Dennis-Jordan , Roman Bolshakov , Pierrick Bouvier , Pedro Barbuda , Wei Liu , "Michael S. Tsirkin" , Peter Maydell , Zhao Liu Subject: [PATCH v2 38/38] whpx: i386: documentation update Date: Mon, 20 Apr 2026 12:42:48 +0200 Message-ID: <20260420104248.86702-39-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260420104248.86702-1-mohamed@unpredictable.fr> References: <20260420104248.86702-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: K6H8eRIvVlEItfTGK27ckSJegMdQQonL X-Authority-Info-Out: v=2.4 cv=QJVlhwLL c=1 sm=1 tr=0 ts=69e6038e cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=w2p0zGFWpCDavkAFAbUA:9 X-Proofpoint-ORIG-GUID: K6H8eRIvVlEItfTGK27ckSJegMdQQonL X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDEwNCBTYWx0ZWRfX0JuxT9pQ6Def ELEfCojMXbmuukJBg6lx7/erIvqqQfF1NXw7lFt+0/HVNRGkUFqppTAiWJVpM9Nkq5R2qnP4j9C syIEBVctNzpY4oAYvoX1kqLG2m7R/8u41gSRyZImuCfXuG5TQhr3irQ4/s3NG38deBSMyQgFc2/ rEWDCQDYFKTlIynPT6cIQZZyTyh2TCu6rHkrAztysGZJrvDW0SOMIlNLvzJISXxgFS6A00S39Sq +qtKnqW2P3gneYRUnX5bY9pBoBewrj7ciMDy05+etD0/PtqkQT3ME+WjGB4whek0GjlyQhQa7gQ /gQluy2tnMfQxxUdMGXEi/FYSXi6gzuiPsRmCK9dTIZ29GqEHa0su8qYCWwChU= 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-20_02,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 clxscore=1030 lowpriorityscore=0 spamscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=690 malwarescore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604200104 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.74.231; envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1776682131823158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- docs/system/whpx.rst | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/docs/system/whpx.rst b/docs/system/whpx.rst index 3e1979028c..b7006f6c2e 100644 --- a/docs/system/whpx.rst +++ b/docs/system/whpx.rst @@ -96,38 +96,18 @@ MMX, SSE or AVX instructions for access to MMIO memory = ranges. Attempts to run such guests will result in an ``Unimplemented handler`` warning for MMX and a failure to decode for newer instructions. =20 -``-M isapc`` -^^^^^^^^^^^^ - -``-M isapc`` doesn't disable the Hyper-V LAPIC on its own yet. To -be able to use that machine, use ``-accel whpx,hyperv=3Doff,kernel-irqchip= =3Doff``. - -However, in QEMU 11.0, the guest will still be a 64-bit x86 -ISA machine with all the corresponding CPUID leaves exposed. - -gdbstub -^^^^^^^ - -As save/restore of xsave state is not currently present, state -exposed through GDB will be incomplete. - -The same also applies to ``info registers``. - -``-cpu type`` ignored -^^^^^^^^^^^^^^^^^^^^^ - -In this release, -cpu is an ignored argument.=20 - PIC interrupts on Windows 10 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ =20 On Windows 10, a legacy PIC interrupt injected does not wake the guest from an HLT when using the Hyper-V provided interrupt controller. =20 -This has been addressed in QEMU 11.0 on Windows 11 platforms but -functionality to make it available on Windows 10 isn't present. +As such, on Windows 10, using the Hyper-V interrupt controller is +disabled by default. You can enable it via ``-M q35,pic=3Doff`` which +disables the PIC. In that configuration, using a UEFI is recommended. =20 -Workaround: for affected use cases, use ``-M kernel-irqchip=3Doff``. +On this release, ``-M kernel-irqchip=3D`` is not expected to be manually +set during normal operation. It remains as a debugging option. =20 Known issues on Windows 11 ^^^^^^^^^^^^^^^^^^^^^^^^^^ --=20 2.50.1 (Apple Git-155)