From nobody Thu Apr 30 00:41:16 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=1776093847; cv=none; d=zohomail.com; s=zohoarc; b=lGqtpOf1zAonMHoYso40jWez4AtAC2+LIoDyuzUK+VvP9+Li91LBt2DvYJV8CSXkiE8KE2raI9XXsevif2ygETFKYFsjqGbv8+8kpU3xetqbgPm11PocZ2ajhmuWafjI/jADEBpl11U+CNpPQNa6yaIm0pLEX2X43xM9FQW5OBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093847; 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=TYkobo2IbNL/6thxO1Eo63eaQDAmZoSwz8nIRi/25sKf1fcwQLwqq/TU8Jx4ceSHjF4PdahlG5boV4cy1MkdDy691qT4+b5MJ+lLVMJMvpSGA7CCPsRACkAD34mhyfBlwnUmpEpII54vP5olRiQxftaacsO7kEF2r93U5Ak64KY= 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 1776093846848578.845659939821; Mon, 13 Apr 2026 08:24:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8f-0005VT-7s; Mon, 13 Apr 2026 11:23:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8U-0005To-5T for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:39 -0400 Received: from qs-2001j-snip4-6.eps.apple.com ([57.103.87.99] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8Q-0000Rq-U6 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:37 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 7683718000AF; Mon, 13 Apr 2026 15:23:32 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id A5EB11800114; Mon, 13 Apr 2026 15:23:30 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093814; x=1778685814; bh=zl2db1VwfCW29E4LtwT7zz4buZdQP1VZYTXVu1kcs+o=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Y9M+UwoIVHhGtG/Ew9BzW+1nrR4Z+2TA9obqMBl2QlZyMciShGva9hiLcjkBh1qlKtZWBXO8bpOKALXaWb3LHrbR2Pqdw0TofjeBhttDoTzNW0YTALb50Q6PxbzD52F9mB9/KPBxuBGerLRGaOWGkaJ5ITcKzclt0nEse8Inge/ohf+LgN4VbBas+qE8qgGKWaJzRanNgt6cq4aZPwc2FCTcqbEJsZpNd3YgoqNiLQ/FQdf3p9foRRs5cYQ/3PrQHaXrVxwOb2c2e+ugwerTmG/jkSFw6Qsq4E3+/bVxhDWJkCN9XfE0mt255nd4nkv+hKXapY/iSW9E/Y8zpECPPA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 01/14] whpx: i386: x2apic emulation Date: Mon, 13 Apr 2026 17:23:13 +0200 Message-ID: <20260413152326.63738-2-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: EmPtBbl6b0ZZeKGLmsIdW80Bk-FSGsa6 X-Proofpoint-GUID: EmPtBbl6b0ZZeKGLmsIdW80Bk-FSGsa6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfXxe5MfbCcXDE+ lZ8Q8YVUItVPGktqdyRqDaF62A+Vg9zF5QQr2zakyX0bdZ1BQ0mg6ppRs1BFgmKPZVOW33f50dy 472s9yz5fz48GoI2g1rC9tKIbuvXDMKJBAtnrbz1uy+7m5y0hK7zaIxdJnZmZ0AVVM8XGOszjv1 kiE9uN9GvyH31ihh83cRToUHNa5IKoFKvkGeYpylWk+d9AsSHRPwCFvT8pnKW7O029btkPVrNv3 nqpPju4zORYqcJSEJ2RVwp1wKpMJleQxj18o9DgP0FUY1eiM4Xvh5p51c2Uh8t8ALGOaPXA2bNO cdZCOWSjKsII8jejdEW7Jhhm8ETkkPSf2bBXXo5xQ8sHIb9x4SBAEENkEIaIJI= X-Authority-Info-Out: v=2.4 cv=Rbidyltv c=1 sm=1 tr=0 ts=69dd0a75 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nj4AhdDZwDx412jv8JQA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 clxscore=1030 mlxlogscore=734 phishscore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.87.99; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093851732154100 Content-Type: text/plain; charset="utf-8" Add x2apic emulation to WHPX for the kernel-irqchip=3Doff case. Unfortunately, it looks like there isn't a workaround available for proper behavior of PIC interrupts when kernel-irqchip=3Don for Windows 10. The OS is out of support outside of extended security updates so this will not be addressed. The performance boost is quite visible for multicore guests. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 134 +++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index e56ae2b343..4127440c0c 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1082,6 +1082,8 @@ HRESULT whpx_set_exception_exit_bitmap(UINT64 excepti= ons) /* Register for MSR and CPUID exits */ memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.ExtendedVmExits.X64MsrExit =3D 1; + prop.ExtendedVmExits.X64CpuidExit =3D 1; + if (exceptions !=3D 0) { prop.ExtendedVmExits.ExceptionExit =3D 1; } @@ -1898,6 +1900,18 @@ int whpx_vcpu_run(CPUState *cpu) WHV_REGISTER_NAME reg_names[3]; UINT32 reg_count; bool is_known_msr =3D 0;=20 + uint64_t val; + + if (vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + val =3D ((uint32_t)vcpu->exit_ctx.MsrAccess.Rax) | + ((uint64_t)(vcpu->exit_ctx.MsrAccess.Rdx) << 32); + } else { + /* + * Workaround for [-Werror=3Dmaybe-uninitialized] + * with GCC. Not needed with Clang. + */ + val =3D 0; + } =20 reg_names[0] =3D WHvX64RegisterRip; reg_names[1] =3D WHvX64RegisterRax; @@ -1911,7 +1925,47 @@ int whpx_vcpu_run(CPUState *cpu) && !vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite && !whpx_irqchip_in_kernel()) { is_known_msr =3D 1; - reg_values[1].Reg32 =3D (uint32_t)X86_CPU(cpu)->env.apic_b= us_freq; + val =3D X86_CPU(cpu)->env.apic_bus_freq; + } + + if (!whpx_irqchip_in_kernel() && + vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D MSR_IA32_APICBAS= E) { + is_known_msr =3D 1; + if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + /* Read path unreachable on Hyper-V */ + abort(); + } else { + WHV_REGISTER_VALUE reg =3D {.Reg64 =3D val}; + int msr_ret =3D cpu_set_apic_base(X86_CPU(cpu)->apic_s= tate, val); + if (msr_ret < 0) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + } + whpx_set_reg(cpu, WHvX64RegisterApicBase, reg); + } + } + + if (!whpx_irqchip_in_kernel() && + vcpu->exit_ctx.MsrAccess.MsrNumber >=3D MSR_APIC_START && + vcpu->exit_ctx.MsrAccess.MsrNumber <=3D MSR_APIC_END) { + int index =3D vcpu->exit_ctx.MsrAccess.MsrNumber - MSR_API= C_START; + int msr_ret; + is_known_msr =3D 1; + if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + bql_lock(); + msr_ret =3D apic_msr_read(X86_CPU(cpu)->apic_state, in= dex, &val); + bql_unlock(); + reg_values[1].Reg64 =3D val; + if (msr_ret < 0) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + } + } else { + bql_lock(); + msr_ret =3D apic_msr_write(X86_CPU(cpu)->apic_state, i= ndex, val); + bql_unlock(); + if (msr_ret < 0) { + x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0= D_GPF, 0); + } + } } /* * For all unsupported MSR access we: @@ -1921,6 +1975,11 @@ int whpx_vcpu_run(CPUState *cpu) reg_count =3D vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite ? 1 : 3; =20 + if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { + reg_values[1].Reg32 =3D (uint32_t)val; + reg_values[2].Reg32 =3D (uint32_t)(val >> 32); + } + if (!is_known_msr) { trace_whpx_unsupported_msr_access(vcpu->exit_ctx.MsrAccess= .MsrNumber, vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite); @@ -1939,6 +1998,47 @@ int whpx_vcpu_run(CPUState *cpu) ret =3D 0; break; } + case WHvRunVpExitReasonX64Cpuid: { + WHV_REGISTER_VALUE reg_values[5] =3D {0}; + WHV_REGISTER_NAME reg_names[5]; + UINT32 reg_count =3D 5; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + + reg_names[0] =3D WHvX64RegisterRip; + reg_names[1] =3D WHvX64RegisterRax; + reg_names[2] =3D WHvX64RegisterRcx; + reg_names[3] =3D WHvX64RegisterRdx; + reg_names[4] =3D WHvX64RegisterRbx; + + reg_values[0].Reg64 =3D + vcpu->exit_ctx.VpContext.Rip + + vcpu->exit_ctx.VpContext.InstructionLength; + + reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRax; + reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRcx; + reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRdx; + reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRbx; + + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 1) { + if (cpu_has_x2apic_feature(env)) { + reg_values[2].Reg64 |=3D CPUID_EXT_X2APIC; + } + } + + hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( + whpx->partition, + cpu->cpu_index, + reg_names, reg_count, + reg_values); + + if (FAILED(hr)) { + error_report("WHPX: Failed to set CpuidAccess state " + " registers, hr=3D%08lx", hr); + } + ret =3D 0; + break; + } case WHvRunVpExitReasonException: whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); =20 @@ -2136,6 +2236,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; bool is_legacy_os =3D false; + UINT32 cpuidExitList[] =3D {1}; =20 whpx =3D &whpx_global; =20 @@ -2354,6 +2455,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) /* Register for MSR and CPUID exits */ memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.ExtendedVmExits.X64MsrExit =3D 1; + prop.ExtendedVmExits.X64CpuidExit =3D 1; =20 hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, @@ -2366,6 +2468,36 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 + memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); + prop.X64MsrExitBitmap.UnhandledMsrs =3D 1; + if (!whpx_irqchip_in_kernel()) { + prop.X64MsrExitBitmap.ApicBaseMsrWrite =3D 1; + } + + hr =3D whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeX64MsrExitBitmap, + &prop, + sizeof(WHV_PARTITION_PROPERTY)); + if (FAILED(hr)) { + error_report("WHPX: Failed to set MSR exit bitmap, hr=3D%08lx", hr= ); + ret =3D -EINVAL; + goto error; + } + + hr =3D whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeCpuidExitList, + cpuidExitList, + RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32)); + + if (FAILED(hr)) { + error_report("WHPX: Failed to set partition CpuidExitList hr=3D%08= lx", + hr); + ret =3D -EINVAL; + goto error; + } + /* * We do not want to intercept any exceptions from the guest, * until we actually start debugging with gdb. --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093896; cv=none; d=zohomail.com; s=zohoarc; b=O87HbhL1w7VzGWxKhrega+4XTUoOSFaqO20NgF+Qhn2RYyWjmqGHxJmSX2UjMMVWBcXNhQYv247Mn4slPRXtEIpaXJzMOnoD1E0VMFD3/GyY5Pyvk47wj8nZ3LX+Q0bvGCb8thte1WjuGLvwch3usNCIKQDt7BIMQ3npQGkyMVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093896; 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=OYYxqj6Bj3pr55PvCnCmIf7BWuzXQ/vWn2BJ8UqJPCYBizEr8tVluW9AjQ7J4ZfDIZ4VFTj5Vmb6PgZbaLNlZIGHduQlp29Uwd3/LT1pmjJBYQ7j9sEhfZ+NKhN2KHxcHOxQ359udFxd6fcGFt4S33PMhUUsuZyIow8M00qkR60= 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 1776093896347395.18530473508486; Mon, 13 Apr 2026 08:24:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8s-0005eC-59; Mon, 13 Apr 2026 11:24: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 1wCJ8V-0005UI-Rp for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:41 -0400 Received: from qs-2001d-snip4-11.eps.apple.com ([57.103.87.43] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8T-0000S0-8Z for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:39 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id D9539180013D; Mon, 13 Apr 2026 15:23:33 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 1220A18000B0; Mon, 13 Apr 2026 15:23:31 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093815; x=1778685815; bh=Ash1yi3VlTyxdP0Aar5CNwwUDY+XErFVJjyfbU7EpDA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=LYlAhFZec4npWQPmQI2jNXDZXa7i13OqC5QuVTVHltrqfQbGHsUNx9j/vwb8+bV0mShFcdAaLnh4bZZzeLOTvZQ9QeRSoNnKpBVq4yszY7o26arrYhsZA9KtIw89cwiPviqx/qoqtrXwT0HAuya2ZVyB0qslbYgjAU2TVzM1R2I++whoI8N1ozMf6/6r6BnZ8QPe9E++LZivjUhcVPh1Ji63RCoLX44ywATkkSTxvXYriysSyVqw/6D4cr//jZ5GupSOt8ADSFUr8qvJV5K4s9h9DfzAgZJTisGf8BKa+ybVj1PAlQAJJx7whKZRV1K4AoC4btMXF0LqnfXQZq1djQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 02/14] whpx: i386: wire up feature probing Date: Mon, 13 Apr 2026 17:23:14 +0200 Message-ID: <20260413152326.63738-3-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: bROYOTlNw_pXtVAZ4WrNND17gM1KUlcl X-Authority-Info-Out: v=2.4 cv=QsdTHFyd c=1 sm=1 tr=0 ts=69dd0a76 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Gr33WSPopR-aU8k7cJUA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfXxCMI6brxdMOW sW/d9Kf9v0qvOXHfYWK0D0pUoUjObu+jpIoACEekorN7QdaURonDpM8DI3YpCAKfICLUVgUlu6G 2fr4xkd7CvN9G4mwid835SIpWhDrGHLXweFG4t/RUbqybvYZ1hQSqpK0yyE0Vzvtg3RlMrh9pCx VtC4pL1zexenbbRMCVxXt0JE11u3BTOBJMt7rR0dumfcSgyBgoOwBhO7yyRRnmapb6TYmNQ9P/X +SUQN3o5EwTjKN7KdLI2vuxIbZq4l4wUEjy0dvLN+L9QqVoi+fA/S0scGMvIwK3wdUFrtXbXqiN ehth3r05v/Qh1eBkC5aGEo7cQE7iU+gkT6I33m9Y/+Zx1h3gqGMusjQZEz6yMg= X-Proofpoint-GUID: bROYOTlNw_pXtVAZ4WrNND17gM1KUlcl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=985 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 clxscore=1030 mlxscore=0 malwarescore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.87.43; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093898357154100 Content-Type: text/plain; charset="utf-8" Windows 10 doesn't have the API for this, so using this only for Windows 11. Signed-off-by: Mohamed Mediouni --- include/system/whpx-internal.h | 9 ++++ target/i386/cpu.c | 25 ++++++++++++ target/i386/whpx/whpx-all.c | 75 ++++++++++++++++++++++++++++++++-- target/i386/whpx/whpx-i386.h | 4 ++ 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 target/i386/whpx/whpx-i386.h diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index 8482901f71..5902124b63 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -73,6 +73,14 @@ void whpx_apic_get(APICCommonState *s); X(HRESULT, WHvGetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partit= ion, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 Registe= rCount, WHV_REGISTER_VALUE* RegisterValues)) \ X(HRESULT, WHvSetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partit= ion, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 Registe= rCount, const WHV_REGISTER_VALUE* RegisterValues)) \ =20 +#ifdef __x86_64__ +#define LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL_ARCH(X) \ + X(HRESULT, WHvGetVirtualProcessorCpuidOutput, \ + (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Eax, \ + UINT32 Ecx, WHV_CPUID_OUTPUT *CpuidOutput)) +#else +#define LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL_ARCH(X) +#endif /* * These are supplemental functions that may not be present * on all versions and are not critical for basic functionality. @@ -89,6 +97,7 @@ void whpx_apic_get(APICCommonState *s); UINT32 StateSize)) \ X(HRESULT, WHvResetPartition, \ (WHV_PARTITION_HANDLE Partition)) \ + LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL_ARCH(X) =20 #define WHP_DEFINE_TYPE(return_type, function_name, signature) \ typedef return_type (WINAPI *function_name ## _t) signature; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c6fd1dc00e..0000093fa3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -26,6 +26,8 @@ #include "tcg/helper-tcg.h" #include "exec/translation-block.h" #include "system/hvf.h" +#include "system/whpx.h" +#include "whpx/whpx-i386.h" #include "hvf/hvf-i386.h" #include "kvm/kvm_i386.h" #include "kvm/tdx.h" @@ -8087,6 +8089,17 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *= cpu, FeatureWord w) r =3D hvf_get_supported_cpuid(wi->cpuid.eax, wi->cpuid.ecx, wi->cpuid.reg); + } else if (whpx_enabled()) { + if (wi->type !=3D CPUID_FEATURE_WORD) { + return 0; + } + if (whpx_is_legacy_os()) { + r =3D wi->tcg_features; + } else { + r =3D whpx_get_supported_cpuid(wi->cpuid.eax, + wi->cpuid.ecx, + wi->cpuid.reg); + } } else if (tcg_enabled() || qtest_enabled()) { r =3D wi->tcg_features; } else { @@ -8168,6 +8181,18 @@ static void x86_cpu_get_supported_cpuid(uint32_t fun= c, uint32_t index, *ebx =3D hvf_get_supported_cpuid(func, index, R_EBX); *ecx =3D hvf_get_supported_cpuid(func, index, R_ECX); *edx =3D hvf_get_supported_cpuid(func, index, R_EDX); + } else if (whpx_enabled()) { + if (whpx_is_legacy_os()) { + *eax =3D 0; + *ebx =3D 0; + *ecx =3D 0; + *edx =3D 0; + } else { + *eax =3D whpx_get_supported_cpuid(func, index, R_EAX); + *ebx =3D whpx_get_supported_cpuid(func, index, R_EBX); + *ecx =3D whpx_get_supported_cpuid(func, index, R_ECX); + *edx =3D whpx_get_supported_cpuid(func, index, R_EDX); + } } else { *eax =3D 0; *ebx =3D 0; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 4127440c0c..2d527b90dd 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -36,6 +36,7 @@ #include "system/whpx-accel-ops.h" #include "system/whpx-all.h" #include "system/whpx-common.h" +#include "whpx-i386.h" =20 #include "emulate/x86_decode.h" #include "emulate/x86_emu.h" @@ -49,6 +50,8 @@ /* for kernel-irqchip=3Doff */ #define HV_X64_MSR_APIC_FREQUENCY 0x40000023 =20 +static bool is_modern_os =3D true; + static const WHV_REGISTER_NAME whpx_register_names[] =3D { =20 /* X64 General purpose registers */ @@ -1062,6 +1065,71 @@ static void whpx_init_emu(void) init_emu(&whpx_x86_emul_ops); } =20 +bool whpx_is_legacy_os(void) +{ + return !is_modern_os; +} + +uint32_t whpx_get_supported_cpuid(uint32_t func, uint32_t idx, int reg) +{ + WHV_CPUID_OUTPUT output; + uint32_t eax, ebx, ecx, edx; + uint32_t cpu_index =3D 0; + bool temp_cpu =3D true; + HRESULT hr; + + hr =3D whp_dispatch.WHvCreateVirtualProcessor( + whpx_global.partition, cpu_index, 0); + + /* This means that the CPU already exists... */ + if (FAILED(hr)) { + temp_cpu =3D false; + } + + hr =3D whp_dispatch.WHvGetVirtualProcessorCpuidOutput(whpx_global.part= ition, + cpu_index, func, idx, &output); + + if (FAILED(hr)) { + abort(); + } + + if (temp_cpu) { + hr =3D whp_dispatch.WHvDeleteVirtualProcessor(whpx_global.partitio= n, cpu_index); + if (FAILED(hr)) { + abort(); + } + } + + eax =3D output.Eax; + ebx =3D output.Ebx; + ecx =3D output.Ecx; + edx =3D output.Edx; + + /* + * We can emulate X2APIC even for the kernel-irqchip=3Doff case. + * CPUID_EXT_HYPERVISOR and CPUID_HT should be considered present + * always, so report them as unconditionally supported here. + */ + if (func =3D=3D 1) { + ecx |=3D CPUID_EXT_X2APIC; + ecx |=3D CPUID_EXT_HYPERVISOR; + edx |=3D CPUID_HT; + } + + switch (reg) { + case R_EAX: + return eax; + case R_EBX: + return ebx; + case R_ECX: + return ecx; + case R_EDX: + return edx; + default: + return 0; + } +} + /* * Controls whether we should intercept various exceptions on the guest, * namely breakpoint/single-step events. @@ -2235,7 +2303,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_CAPABILITY_FEATURES features =3D {0}; WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; - bool is_legacy_os =3D false; UINT32 cpuidExitList[] =3D {1}; =20 whpx =3D &whpx_global; @@ -2395,7 +2462,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) if (FAILED(hr)) { warn_report("WHPX: Failed to get performance " "monitoring features, hr=3D%08lx", hr); - is_legacy_os =3D true; + is_modern_os =3D false; } else { hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, @@ -2435,7 +2502,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.DirectSyntheticTimers =3D 1; } =20 - if (!is_legacy_os && whpx->hyperv_enlightenments_allowed) { + if (is_modern_os && whpx->hyperv_enlightenments_allowed) { hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, @@ -2446,7 +2513,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) ret =3D -EINVAL; goto error; } - } else if (is_legacy_os && whpx->hyperv_enlightenments_required) { + } else if (!is_modern_os && whpx->hyperv_enlightenments_required) { error_report("Hyper-V enlightenments not available on legacy Windo= ws"); ret =3D -EINVAL; goto error; diff --git a/target/i386/whpx/whpx-i386.h b/target/i386/whpx/whpx-i386.h new file mode 100644 index 0000000000..6db9a75d39 --- /dev/null +++ b/target/i386/whpx/whpx-i386.h @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +uint32_t whpx_get_supported_cpuid(uint32_t func, uint32_t idx, int reg); +bool whpx_is_legacy_os(void); --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093891; cv=none; d=zohomail.com; s=zohoarc; b=Gq7UUkEGpE7a6XB8BW6xX8frlY33c7nFsK1XQ2pIMGJnr/GqTCZklwZsGvntpVoviUp5XFzYXBX2Ss4zNXMaXilbQRrmHiLtTLcZfxLzOMMDoQs9tap5g/DrvtAm51qr8AXx95jJ4QSg4QU7PRK/AwRLZ+HkBbYPuaoBJMm7Gnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093891; 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=TxtirZh3uTIEdvJwEUyZqHS3i4jCLgzOEkBLA3uEEZWuxb86ZLbdx3/54OQvg+xwP6jBadt+X3g6uQmISpLUoyDh9hwKpdciXBiNBvLMNGmV+iyis4qNR4htKvpNZh1XPMGGD4KvEPs/Z9ctPMWNiSUHbNDppv/y3HDKVZkvPko= 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 1776093891183275.30567934774604; Mon, 13 Apr 2026 08:24:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8v-0005lB-De; Mon, 13 Apr 2026 11:24: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 1wCJ8V-0005UH-Ph for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:39 -0400 Received: from qs-2007b-snip4-8.eps.apple.com ([57.103.84.149] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8T-0000SK-TM for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:39 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 3A5161800175; Mon, 13 Apr 2026 15:23:35 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 6F2911800133; Mon, 13 Apr 2026 15:23:33 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093816; x=1778685816; bh=LeCfULzXVq8eMeXoD4HoazACVFGuCL5m06fQgObX99k=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=eu3PIITCJ8Aj+sL9zzy1o53n8+wpTCslH5lrKtkWYsYCwnBFYx6cRPpEvGxkM3cp8C1Ctn6nSHBouDINL4XK8T3saqsg3MMatW5MNtjvSzH+mXYDjox/NeubeyrRmsnDEE1gGAqVAcuW9GRSvAGFYJWOwwkcIEHQQiiMGgNEzfD/Xb3SvGWIU9ENyAzxX+9UO3fs7JF0S/GgJI/HS06Cmi7N2GQsNFbNzCm2nNUZFcUxsmg7GuyvK4KvulD0UoCxsoiBWyRc8uJpBJ6/yUZzE92mHyc6pmWY1IiPgDIr6f2IVI+GYK8FEMcPGvalA5FnqUc/o8cWMzX4xGpJ0u3mPA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 03/14] whpx: i386: disable TbFlushHypercalls for emulated LAPIC Date: Mon, 13 Apr 2026 17:23:15 +0200 Message-ID: <20260413152326.63738-4-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: _9IVXNzXR01xtAewPb6oyFeBy0jF_rhC X-Authority-Info-Out: v=2.4 cv=QsdTHFyd c=1 sm=1 tr=0 ts=69dd0a78 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Rm0zj2O9plGGl-KjdfMA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX1cfKi/9TePDK CTY50vH7dwUZrGtTM0p2lovysbdwAc1sxqN0VwSRGSLHTDnKL2S7OyXL0veZ3wt2SkFewCvGknk DDzd8UvuNBYUaQ/kd/BRIBDiC36Et4ax0t1Gw4vQfm5QkDY19rtHT81ks3hjpnWVy3zLbXoNHs3 tFSdWBLtadlo5fBTVHz5aIzkZMi0dohNWs1iatLpMehFE97T8KupwUnRRC2XhYR8NK9LkuaxuGq cApsMABkZv3CuTdFH31WICyb0YIhoPcTWWUHcFomuG6odAwu7Q+QhCfECqaqZWLI6epGi2Q1K4S cqR0OXWJbYuV2hfGx3dPGg20bYrt+uF913i4+MVjLH7Q0LeSb4Xbc7EbCPLCGo= X-Proofpoint-GUID: _9IVXNzXR01xtAewPb6oyFeBy0jF_rhC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=710 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 clxscore=1030 mlxscore=0 malwarescore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.84.149; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093894231154100 Content-Type: text/plain; charset="utf-8" AccessHypercallRegs was present twice so clean that up. Remove TbFlushHypercalls (and its extended Gva range sub-feature) from the user-mode LAPIC case as it behaves oddly there. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 2d527b90dd..0908dfd134 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2489,10 +2489,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.AccessPartitionReferenceTsc =3D 1; synthetic_features.Bank0.AccessHypercallRegs =3D 1; synthetic_features.Bank0.AccessFrequencyRegs =3D 1; - synthetic_features.Bank0.EnableExtendedGvaRangesForFlushVirtualAddress= List =3D 1; synthetic_features.Bank0.AccessVpIndex =3D 1; - synthetic_features.Bank0.AccessHypercallRegs =3D 1; - synthetic_features.Bank0.TbFlushHypercalls =3D 1; =20 if (whpx_irqchip_in_kernel()) { synthetic_features.Bank0.AccessSynicRegs =3D 1; @@ -2500,6 +2497,12 @@ int whpx_accel_init(AccelState *as, MachineState *ms) synthetic_features.Bank0.AccessIntrCtrlRegs =3D 1; synthetic_features.Bank0.SyntheticClusterIpi =3D 1; synthetic_features.Bank0.DirectSyntheticTimers =3D 1; + /* + * These technically work without the Hyper-V LAPIC + * but behave oddly for multi-core VMs. + */ + synthetic_features.Bank0.TbFlushHypercalls =3D 1; + synthetic_features.Bank0.EnableExtendedGvaRangesForFlushVirtualAdd= ressList =3D 1; } =20 if (is_modern_os && whpx->hyperv_enlightenments_allowed) { --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093915; cv=none; d=zohomail.com; s=zohoarc; b=VBkixzdI7ktZBwvz43EMy6g3IQwPFMds45KK956kJS/E/9NMGKbDvakIzbfuMF7b5/M4dCf1tyaywOnNZ+ImT8jHHgDw6lKLGpa0T9FfqG920f9KiS+fGnxwAZOLMJGBmnO+z386OytPdXE9wlHKn/UxVYAsrDc9ML/HVW15WUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093915; 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=C+BLqtH5weICAK23aq/rR1/L8GxaY0R4+nV5n3lWihxSlqTAj3HQgKYVcm7HD2NXWcbYeWmAgjkDWJ4157VXTow3dC7PmsXR9RVm8+FYdcmCnutQ4BunCE4QNtG0lwLVVvD/cjcCxlL227zkfHgDlyxlKxl/O5qNzG6JH++BLcU= 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 1776093915159607.4093593666217; Mon, 13 Apr 2026 08:25:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8t-0005gI-PK; Mon, 13 Apr 2026 11:24:03 -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 1wCJ8Y-0005Us-Ob for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:43 -0400 Received: from qs-2005b-snip4-11.eps.apple.com ([57.103.86.151] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8X-0000TH-EM for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:42 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 0F6591800133; Mon, 13 Apr 2026 15:23:36 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id CAD171800111; Mon, 13 Apr 2026 15:23:34 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093820; x=1778685820; bh=dugTy6Mycl0V8PO55M7zjkrIKW6irE2gkRf+Eg5CDxE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=CEPPCoXh7OPVwFaIF/c9LtjeZe36QQoXMujjEr/CcFAkArhnUZWZoZNKg3CDf8mFkh2N62guUoLpbhSldUvUtYsLTf/rC+4+jEtAqWNQD0uYv8/B9YP582qgtAkWnW58ob3y3FzoINGM1ztXWXECkSGfB+AjeHiMktUsBHj9YeHDURuj9I1OwWBI3rWMMYvddGvW8Uyu9ORRigDQ4Ad1NGVLrnnhy0xyPcKgCpHu+z2LaJjWAStlo2RPat+Sw2omQqR5qWBu81ObsT5fIdIxRASrdRhEgVDcFQssiF+jvTJv8lJUEZ8uU0ADE9gUer+UUY+3uTApVf14Oh+W+x/fiw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 04/14] whpx: i386: enable x2apic by default for user-mode LAPIC Date: Mon, 13 Apr 2026 17:23:16 +0200 Message-ID: <20260413152326.63738-5-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: e_sSOIKC437JNvMUbHuJ0TW8oJBH4SPG X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX9bgHxNapknnE KBv0/Hj+SSS2Xjuh4jh+cs4+hvvSkyBRqbJeEPGyRckHJaa1Xb6vQIaqlTsc0RJ0U5yGjXKOvnU Vr/RX6gMRH4VLC8i51wzyM1GwMU/XCCxcHQCU9Ire18jNyjO2hUmX6EumW3aB3SA1JMBTaLLL+h idmflseSSJyfJeibi94ED3bZ6WLfkz8plhZ5ipAxRlVbb15HcM2xVJGQ4hJzS/gwnZu6ZYJiyBG szk82D65XrEqWbiMIEu2JnikROklSd+wZdoguRKFhI4WrRWM0lV/mRH3SI4YPTIodLrC7YwiqZM 2e0Nsm5acibJ3mK5PF5SH+T1BkCN6kUVFmOLIbXA1UOXHkGYJoDKHWm1l1RYSQ= X-Proofpoint-ORIG-GUID: e_sSOIKC437JNvMUbHuJ0TW8oJBH4SPG X-Authority-Info-Out: v=2.4 cv=HdsZjyE8 c=1 sm=1 tr=0 ts=69dd0a7a cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=uAk9FrDoCeqUxh5yT_MA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 clxscore=1030 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.151; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093918984154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 0908dfd134..66f263558f 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2281,11 +2281,18 @@ error: return ret; } =20 +static PropValue whpx_default_props[] =3D { + { "x2apic", "on" }, + { NULL, NULL }, +}; + + void whpx_cpu_instance_init(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); =20 host_cpu_instance_init(cpu); + x86_cpu_apply_props(cpu, whpx_default_props); } =20 /* --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093915; cv=none; d=zohomail.com; s=zohoarc; b=QpgwtnvahrOnfFToDKNlcs97OacFcrH6zkZly5tk4luPS5QzQG0SU9lgyWaXSZBh2r+Qq9RtjkijU69eecaF7Sp7hOAO+AH9AiVDxkcUYQ5EAFrKktLeTRA5rRuF4z8vDB0Hi3JHhQ2EqqmDPEb9JWAcHB+jgIYSVSdCtjm8QSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093915; 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=MLsb9GFhjKfvBM+s9ov4EWFe89ofIgMM5DHkIxtiOgtETpeTVCHd+vArzVuCiS9UdIL6v6c3z/JSrB8lJbx9DzLJtdk5SaOQgfzgT7YPJYGeOyxBm2JVpYMjsKkboVNvTzWv4gfRkcVCFGaaLOrGQKjRtamKnUxKQ0hjF7+Z98U= 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 1776093915533653.8868387860279; Mon, 13 Apr 2026 08:25:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8t-0005fb-5M; Mon, 13 Apr 2026 11:24:03 -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 1wCJ8X-0005Uc-LN for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:43 -0400 Received: from qs-2007i-snip4-11.eps.apple.com ([57.103.84.221] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8V-0000Sh-9p for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:41 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id AC5C318001AB; Mon, 13 Apr 2026 15:23:37 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 30ACE18000A4; Mon, 13 Apr 2026 15:23:36 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093818; x=1778685818; bh=oQob0705w1vpsKwSbilmxpp8KQiyruObQqebQ5RZ0Dc=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=H43eqEf4p8P4MVZL9tvWCCVVfUd8eqpsm8U3+Y2TaTFMnWd2nY4l+PjBcH8n5AsYd0Qb9VPeviCKFrtOgXGLS1BqsWfIdVPONNO3/UCbC1PthbhvF7R2e4PMtSCTjeivmMyu+P4Qbg9SzQpmmpspz3odjL5VZmZ37jop/eAlE/Z1zozpn3UhSHZruWhWXU+E5oseUPfMwg3a77jmuS443OIQF6DWE9cnZ7Xv1h9F70EFh96pd9Yc9T2inFYo0UvCa3VSmmcBguCfJWXsyYiXLuFQ1HrF1y6ANpHpdwJdaGD8CfLEuzgCN3jAQL5Lxq7vbibOt+BbKryJSFXiy5/r8Q== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 05/14] whpx: i386: reintroduce enlightenments for Windows 10 Date: Mon, 13 Apr 2026 17:23:17 +0200 Message-ID: <20260413152326.63738-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=MLJtWcZl c=1 sm=1 tr=0 ts=69dd0a7a cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=hfWBbujXMTx1PmRkPVYA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX0damrvb1/h/Y pJ2J8edkdX4OnWS0qHK8Rr3egBL9ono4qGbo9uBLL46kBP2VIxrppftVss1A07GMru5yg+jbP0m FqJRrQKpsoSKKbIr0hC/RByw+zucP2YWbAt6N7p6iPv3WdZsVItpZpodWQHqwbSKLCfuxq4vtF3 DGHxkAu/yPF9A7q4bcj8LhD0r5ubpB5+UfeD7zUvWgc/nGYkaw/eTCTE8lt8QDMPNaVp6DsS92x NWGTSY8wZzTYKMjlTj8lnzwEQHySaCCJbFiaY5an//RoUfxPkNWgI+Jm1UW1iUPgzm+JEogZQgE CaDCwGwCJBG8epLGe7pPYscGvmvXEycz5r7Df5AENp7t5ztIHQLDcrXMzaRaUs= X-Proofpoint-GUID: PoD55ei_JwWp51GyalkpTEn46HezCVXQ X-Proofpoint-ORIG-GUID: PoD55ei_JwWp51GyalkpTEn46HezCVXQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 clxscore=1030 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.84.221; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093917299158500 Content-Type: text/plain; charset="utf-8" Was removed in 2c08624 but it's still useful for Windows 10 so reintroduce it there. And this time, actually make it work by reporting the hypervisor bit in CPUID. Pretend to be vmware to be able to use vmport's functionality. If the vmware frequency leaf is disabled, pretend to be KVM, with the only capability reported being X2APIC support. Signed-off-by: Mohamed Mediouni --- accel/whpx/whpx-common.c | 2 ++ include/system/whpx-internal.h | 1 + target/arm/whpx/whpx-all.c | 1 + target/i386/whpx/whpx-all.c | 63 +++++++++++++++++++++++++++++----- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c index b813a5d9d2..59be996aef 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -550,6 +550,8 @@ static void whpx_accel_instance_init(Object *obj) =20 whpx->hyperv_enlightenments_allowed =3D true; whpx->hyperv_enlightenments_required =3D false; + /* Value determined at whpx_accel_init */ + whpx->hyperv_enlightenments_enabled =3D false; } =20 static const TypeInfo whpx_accel_type =3D { diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index 5902124b63..cf782cf5f8 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -45,6 +45,7 @@ struct whpx_state { =20 bool hyperv_enlightenments_allowed; bool hyperv_enlightenments_required; + bool hyperv_enlightenments_enabled; =20 }; =20 diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c index bbf0f6be96..4019a513aa 100644 --- a/target/arm/whpx/whpx-all.c +++ b/target/arm/whpx/whpx-all.c @@ -968,6 +968,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) * as they're not needed for performance. */ if (whpx->hyperv_enlightenments_required) { + whpx->hyperv_enlightenments_enabled =3D true; hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 66f263558f..c2a78312f8 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2083,14 +2083,57 @@ int whpx_vcpu_run(CPUState *cpu) vcpu->exit_ctx.VpContext.Rip + vcpu->exit_ctx.VpContext.InstructionLength; =20 - reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRax; - reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRcx; - reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRdx; - reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.DefaultResu= ltRbx; - - if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 1) { - if (cpu_has_x2apic_feature(env)) { - reg_values[2].Reg64 |=3D CPUID_EXT_X2APIC; + if (whpx_is_legacy_os()) { + reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRax; + reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRcx; + reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRdx; + reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRbx; + } else { + cpu_x86_cpuid(env, vcpu->exit_ctx.CpuidAccess.Rax, + vcpu->exit_ctx.CpuidAccess.Rcx, + (UINT32 *)®_values[1].Reg32, + (UINT32 *)®_values[4].Reg32, (UINT32 *)®_values[= 2].Reg32, + (UINT32 *)®_values[3].Reg32); + } + + if (!whpx->hyperv_enlightenments_enabled) { + switch (vcpu->exit_ctx.CpuidAccess.Rax) { + case 1: + reg_values[2].Reg64 |=3D CPUID_EXT_HYPERVISOR; + break; + case 0x40000000: + /* + * Use vmware_cpuid_freq as a proxy to report VMware. + * This is to get the TSC/APIC frequency query functio= nality + * provided through vmport, as Linux doesn't use leaf + * 0x40000010 for getting those frequencies. + */ + if (x86_cpu->vmware_cpuid_freq) { + reg_values[1].Reg64 =3D 0x40000010; + reg_values[4].Reg64 =3D 0x61774d56; + reg_values[2].Reg64 =3D 0x4d566572; + reg_values[3].Reg64 =3D 0x65726177; + } else { + /* report KVM otherwise if that's disabled */ + reg_values[1].Reg64 =3D 0x40000001; + reg_values[4].Reg64 =3D 0x4b4d564b; + reg_values[2].Reg64 =3D 0x564b4d56; + reg_values[3].Reg64 =3D 0x4d; + } + break; + case 0x40000001: + if (!x86_cpu->vmware_cpuid_freq) { + /* KVM reporting of X2APIC support */ + reg_values[1].Reg64 =3D reg_values[4].Reg64 =3D + reg_values[2].Reg64 =3D 1 << 15; + } + break; + case 0x40000010: + if (x86_cpu->vmware_cpuid_freq) { + reg_values[1].Reg64 =3D env->tsc_khz; + reg_values[4].Reg64 =3D env->apic_bus_freq / 1000;= /* Hz to KHz */ + } + break; } } =20 @@ -2311,6 +2354,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; UINT32 cpuidExitList[] =3D {1}; + UINT32 cpuidExitList_nohyperv[] =3D {1, 0x40000000, 0x40000001, 0x4000= 0010}; =20 whpx =3D &whpx_global; =20 @@ -2513,6 +2557,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) } =20 if (is_modern_os && whpx->hyperv_enlightenments_allowed) { + whpx->hyperv_enlightenments_enabled =3D true; hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks, @@ -2565,7 +2610,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeCpuidExitList, - cpuidExitList, + whpx->hyperv_enlightenments_enabled ? cpuidExitList : cpuidExitLis= t_nohyperv, RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32)); =20 if (FAILED(hr)) { --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093860; cv=none; d=zohomail.com; s=zohoarc; b=mWrwH4IaG/rw3DbhIIWK3/Wq20pH/lYSZE2c7VOfpUDA6y97z5EmGFaiGcFB5jTUi+qmDPPF4eLNOBqK8uTJzEtYAEV2iFYwxfGTiFATcFWEUF1GM9pjkO//Wg4NNcUtLZZEL3S+t9k7trNoqgQyzHEr5sZBhXHWbMbyp5K88Gs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093860; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6tmGSEaUrE0Q7MlYX6psbx8TA0g5EcgDAZR7bSJpGEE=; b=SCUBlPxgkdwcXivYg20beU6YAhGaFhz9xd6GmwlUlsgkueAIIVXDYiV+EcxOIxwz9x8fQ1wv65vS70W6pNRIZqI8btOWaWWyfhDd34gAfxcxKBke5jNf/LguOBLdaJn+TnIwxbhSk/6b4bRiSQceJfjbGPcvcF7RdwIupltLwOU= 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 1776093860190656.094783967807; Mon, 13 Apr 2026 08:24:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8t-0005fi-5G; Mon, 13 Apr 2026 11:24:03 -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 1wCJ8a-0005Wt-AA for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:47 -0400 Received: from qs-2005f-snip4-2.eps.apple.com ([57.103.86.183] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8Y-0000TN-3g for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:44 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 63A581800163; Mon, 13 Apr 2026 15:23:39 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 8EEFC1800179; Mon, 13 Apr 2026 15:23:37 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093821; x=1778685821; bh=6tmGSEaUrE0Q7MlYX6psbx8TA0g5EcgDAZR7bSJpGEE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=B3aTUuLGrXQ3ppIZHJyS8VZREd+FMZUYxcPIpDMR9WUBgjl2oYoRID0xvcQkymqWzUS7TiAgNnEoTXo1hxj4T0cxWdk5dd/0y8I51AAZ0XsKSCVw6VpFHC6w7N4k10wvw/Ew1B7ZqbwP+LfFIUeGDkKUdDVCf0C1mCadSGzxAgBRoJZ+zf+qvLIVdV0nScwRnn2UAbmIJeWFwacxDX/F5MCYUimGMscFUemmvO30YPoSNoWkjW1DrMvujNcyzbigknOO9QgV3uIgWd98gvo0KdSEDrqa+9hAzO2odL7e66FwBURTCDGvRNw04AGxdk2/rq+5z5CQ+ivC0nibGNbXHA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 06/14] whpx: i386: introduce proper cpuid support Date: Mon, 13 Apr 2026 17:23:18 +0200 Message-ID: <20260413152326.63738-7-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX4pNs+/CZPtMT M5qmRcLnKrD2qL5nXVkPok7Ds6FgpNOfkDVe3CBYRvbP++kR9Bvm4RZgRu+rCtyIPZcDjbkSHxa GdYRLW9QflGjVcRNXzwYUxYTF5Y70a6W5xBnqexis4eli+okFhsyZ5vTAghUSLI+LDybTUoiqM3 MUrgfmwx3mXpv3saL08smtlA6zOOCgM14y6qyZxZ4RYcspdojYJAJcVWBkz3JkhkA8jL6tHdAjh LCY7bkxMV1lXmlNIiqG8sQ7raB0vdIMVkqoU4JSgXnWkHbwX6HVLjzOcSrvJosxXOnoIUbClK+3 Zy7X3ZbTnkI9Lo4F7riQSsdUJAEaJAvEKukCdeXvMYg4cyL391WbzkkntXkDYw= X-Proofpoint-ORIG-GUID: 99S6q3eXzvQq7vVxkg8h8aP4-s-auM0D X-Authority-Info-Out: v=2.4 cv=LaoxKzfi c=1 sm=1 tr=0 ts=69dd0a7c cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=n8cRCUxqL_yedgTzvKUA:9 X-Proofpoint-GUID: 99S6q3eXzvQq7vVxkg8h8aP4-s-auM0D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 clxscore=1030 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.183; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093862137154100 Content-Type: text/plain; charset="utf-8" Unlike the implementation in QEMU 10.2, this one works. It's not optimal though as it doesn't use the Hyper-V support for this. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 123 ++++++++++++++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 4 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index c2a78312f8..9827c93df1 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2071,6 +2071,7 @@ int whpx_vcpu_run(CPUState *cpu) WHV_REGISTER_NAME reg_names[5]; UINT32 reg_count =3D 5; X86CPU *x86_cpu =3D X86_CPU(cpu); + X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); CPUX86State *env =3D &x86_cpu->env; =20 reg_names[0] =3D WHvX64RegisterRip; @@ -2083,7 +2084,15 @@ int whpx_vcpu_run(CPUState *cpu) vcpu->exit_ctx.VpContext.Rip + vcpu->exit_ctx.VpContext.InstructionLength; =20 - if (whpx_is_legacy_os()) { + /* + * On Windows 10 we can't query features from + * the Hyper-V interface. + * + * On Windows 11, if using xcc->max_features + * just pass through what the hypervisor + * provides without any QEMU filtering. + */ + if (whpx_is_legacy_os() || xcc->max_features) { reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRax; reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRcx; reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Default= ResultRdx; @@ -2135,6 +2144,60 @@ int whpx_vcpu_run(CPUState *cpu) } break; } + } else { + switch (vcpu->exit_ctx.CpuidAccess.Rax) { + case 0x40000000: + case 0x40000001: + case 0x40000010: + reg_values[1].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRax; + reg_values[2].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRcx; + reg_values[3].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRdx; + reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRbx; + break; + } + } + + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 0x1) { + if (cpu_has_x2apic_feature(env)) { + reg_values[2].Reg64 |=3D CPUID_EXT_X2APIC; + } else { + reg_values[2].Reg32 &=3D CPUID_EXT_X2APIC; + } + } + + /* Dynamic depending on XCR0 and XSS, so query DefaultResult */ + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 0x07 + && vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 0) { + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRdx + & CPUID_7_0_EDX_CET_IBT) { + reg_values[3].Reg32 |=3D CPUID_7_0_EDX_CET_IBT; + } else { + reg_values[3].Reg32 &=3D ~CPUID_7_0_EDX_CET_IBT; + } + + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRcx + & CPUID_7_0_ECX_CET_SHSTK) { + reg_values[2].Reg32 |=3D CPUID_7_0_ECX_CET_SHSTK; + } else { + reg_values[2].Reg32 &=3D ~CPUID_7_0_ECX_CET_SHSTK; + } + + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRcx + & CPUID_7_0_ECX_OSPKE) { + reg_values[2].Reg32 |=3D CPUID_7_0_ECX_OSPKE; + } else { + reg_values[2].Reg32 &=3D ~CPUID_7_0_ECX_OSPKE; + } + } + + /* OSXSAVE is dynamic. Do this instead of syncing CR4 */ + if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 1) { + if (vcpu->exit_ctx.CpuidAccess.DefaultResultRcx + & CPUID_EXT_OSXSAVE) { + reg_values[2].Reg32 |=3D CPUID_EXT_OSXSAVE; + } else { + reg_values[2].Reg32 &=3D ~CPUID_EXT_OSXSAVE; + } } =20 hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( @@ -2324,6 +2387,45 @@ error: return ret; } =20 +static void whpx_cpu_xsave_init(void) +{ + static bool first =3D true; + int i; + + if (!first) { + return; + } + first =3D false; + + /* x87 and SSE states are in the legacy region of the XSAVE area. */ + x86_ext_save_areas[XSTATE_FP_BIT].offset =3D 0; + x86_ext_save_areas[XSTATE_SSE_BIT].offset =3D 0; + + for (i =3D XSTATE_SSE_BIT + 1; i < XSAVE_STATE_AREA_COUNT; i++) { + ExtSaveArea *esa =3D &x86_ext_save_areas[i]; + + if (esa->size) { + int sz =3D whpx_get_supported_cpuid(0xd, i, R_EAX); + if (sz !=3D 0) { + assert(esa->size =3D=3D sz); + esa->offset =3D whpx_get_supported_cpuid(0xd, i, R_EBX); + } + } + } +} + +static void whpx_cpu_max_instance_init(X86CPU *cpu) +{ + CPUX86State *env =3D &cpu->env; + + env->cpuid_min_level =3D + whpx_get_supported_cpuid(0x0, 0, R_EAX); + env->cpuid_min_xlevel =3D + whpx_get_supported_cpuid(0x80000000, 0, R_EAX); + env->cpuid_min_xlevel2 =3D + whpx_get_supported_cpuid(0xC0000000, 0, R_EAX); +} + static PropValue whpx_default_props[] =3D { { "x2apic", "on" }, { NULL, NULL }, @@ -2333,9 +2435,18 @@ static PropValue whpx_default_props[] =3D { void whpx_cpu_instance_init(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); + X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); =20 host_cpu_instance_init(cpu); x86_cpu_apply_props(cpu, whpx_default_props); + + if (!whpx_is_legacy_os() && xcc->max_features) { + whpx_cpu_max_instance_init(cpu); + } + + if (!whpx_is_legacy_os()) { + whpx_cpu_xsave_init(); + } } =20 /* @@ -2353,8 +2464,12 @@ int whpx_accel_init(AccelState *as, MachineState *ms) WHV_CAPABILITY_FEATURES features =3D {0}; WHV_PROCESSOR_FEATURES_BANKS processor_features; WHV_PROCESSOR_PERFMON_FEATURES perfmon_features; - UINT32 cpuidExitList[] =3D {1}; - UINT32 cpuidExitList_nohyperv[] =3D {1, 0x40000000, 0x40000001, 0x4000= 0010}; + + UINT32 cpuidExitList[] =3D {0x0, 0x1, 0x6, 0x7, 0x14, 0x24, 0x29, 0x1E, + 0x40000000, 0x40000001, 0x40000010, 0x80000000, 0x80000001, + 0x80000002, 0x80000003, 0x80000004, 0x80000007, 0x80000008, + 0x8000000A, 0x80000021, 0x80000022, 0xC0000000, 0xC0000001}; + UINT32 cpuidExitList_legacy_os[] =3D {1, 0x40000000, 0x40000001, 0x400= 00010}; =20 whpx =3D &whpx_global; =20 @@ -2610,7 +2725,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, WHvPartitionPropertyCodeCpuidExitList, - whpx->hyperv_enlightenments_enabled ? cpuidExitList : cpuidExitLis= t_nohyperv, + !whpx_is_legacy_os() ? cpuidExitList : cpuidExitList_legacy_os, RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32)); =20 if (FAILED(hr)) { --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093954; cv=none; d=zohomail.com; s=zohoarc; b=OmKOnsNP0YndfMz+Lbm/nQvuko0U9pGFXaBUoOwbAvermCuuFE/59fM7IZhDtCMAivXdo8fdu4UPTe2q4pH/dvnFHz/xWaEXHreSLdcZCJDODK2KostvuBv++WEZ+Z/m1I0LixwoowMHbaRnTvo9umMD+TmfQUHJnz6vBxJES34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093954; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=T/ylQnS/te0fMXN5QyRAvae93avWDOZqU0zT/KgDwLQ=; b=bknjVjdi27XzUxtumiDEfjHMryQBM5aM1RFidZo9BGAcjaSCgj4PI1EwQEsX/sLxcG4ruU4gdbYm+x9H8RuB1Qp3ZOdVdnqjNyNEOF8T4546KfWr9kZO74ixWaMVlAk/UOR6YsD4xbvqPkOQHeO4lLbTb0TYTsjHHBcI+KFX7P8= 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 1776093954314273.94746555425945; Mon, 13 Apr 2026 08:25:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8u-0005jg-Rg; Mon, 13 Apr 2026 11:24: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 1wCJ8a-0005Wo-5R for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:45 -0400 Received: from qs-2005l-snip4-11.eps.apple.com ([57.103.86.251] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8X-0000TO-Uc for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:43 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 71DBF1800114; Mon, 13 Apr 2026 15:23:40 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id EB9C918000A4; Mon, 13 Apr 2026 15:23:38 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093821; x=1778685821; bh=T/ylQnS/te0fMXN5QyRAvae93avWDOZqU0zT/KgDwLQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=b3oDEX6nITMUpVRInSigZuTKl6EaRGe0FCZYfXuh/PuzaGL5pp4SCtO6yYRnOvUUQSfZG/Nv6ADGl8uAhHhqPtzoXN/0OmOSQHJ+n6ouzcDP5tp66CU9TvNfJuMj61nypKGMXFJQHt7R2ToxeujceEyLA0yqHY6D2JryWkjHnmBJaGpmv6sLFdTubn9Toz9sXHhSfALmpQXGpE63yFfmJ5NXibeyBkEKzRC946ZgL/ZqX1kwelY+jgrrnfzr8w7Xg4Wnoidk8sFBZQnOuaECMFRUkW7gBm7NPB3IA4sgtrn4og8rMy+k1qo9mXvecQ1Iicnjup5M3AsHIh1HG/AOUA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 07/14] whpx: i386: kernel-irqchip=off fixes Date: Mon, 13 Apr 2026 17:23:19 +0200 Message-ID: <20260413152326.63738-8-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: TEOdMrv76yBEOJR5aVD2uAiK7Ert-muc X-Proofpoint-ORIG-GUID: TEOdMrv76yBEOJR5aVD2uAiK7Ert-muc X-Authority-Info-Out: v=2.4 cv=ee0wvrEH c=1 sm=1 tr=0 ts=69dd0a7c cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gP1GEkNOX-MqffGxZ4oA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfXwyfk8bPY4r2E a3mtz2kS4sylOx60G+6SgXtLcwKC1hBxaMbeQPqpjswGgxb2L01LCip1HqD6F2YFrHtoWJWbSpN W9q4ZCjZboXk7pg+W4u4tZMllTUEkimMpQVwKJp9Zv3/xp+jTVivY6RkN/1qtq6pjZy4OyN2cFX fL+bkbkdXRaw8RN8cI9/4Pg2FlgJsJsiXOqcK9DDToxT5X93KTuPkzCdRKc6au5JjsQXmsHdA0Q dOYrevdseSvci+UsSz4l6rpBiJJFrYlnRdWiLsrobkISeSUaJ93yYaILgcM7aTVJYJRQTxbiuvD inyh7DExInCnLYJfD1pguL8KzzSCW3b1qyR20no1Y9sdtHEmeJlYZp2+MLV7q4= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 suspectscore=0 phishscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.251; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093955311154100 Content-Type: text/plain; charset="utf-8" This was really... quite broken. After fixing this, Windows boots with kernel-irqchip=3Doff. Signed-off-by: Mohamed Mediouni --- include/system/whpx-common.h | 1 + target/i386/whpx/whpx-all.c | 43 +++++------------------------------- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/include/system/whpx-common.h b/include/system/whpx-common.h index 04289afd97..3406c20fec 100644 --- a/include/system/whpx-common.h +++ b/include/system/whpx-common.h @@ -4,6 +4,7 @@ =20 struct AccelCPUState { bool window_registered; + int window_priority; bool interruptable; bool ready_for_pic_interrupt; uint64_t tpr; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 9827c93df1..62542922a4 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -22,6 +22,8 @@ #include "qemu/main-loop.h" #include "hw/core/boards.h" #include "hw/intc/ioapic.h" +#include "hw/intc/i8259.h" +#include "hw/i386/x86.h" #include "hw/i386/apic_internal.h" #include "qemu/error-report.h" #include "qapi/error.h" @@ -371,28 +373,6 @@ static int whpx_set_tsc(CPUState *cpu) return 0; } =20 -/* - * The CR8 register in the CPU is mapped to the TPR register of the APIC, - * however, they use a slightly different encoding. Specifically: - * - * APIC.TPR[bits 7:4] =3D CR8[bits 3:0] - * - * This mechanism is described in section 10.8.6.1 of Volume 3 of Intel 64 - * and IA-32 Architectures Software Developer's Manual. - * - * The functions below translate the value of CR8 to TPR and vice versa. - */ - -static uint64_t whpx_apic_tpr_to_cr8(uint64_t tpr) -{ - return tpr >> 4; -} - -static uint64_t whpx_cr8_to_apic_tpr(uint64_t cr8) -{ - return cr8 << 4; -} - void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; @@ -421,7 +401,7 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel l= evel) v86 =3D (env->eflags & VM_MASK); r86 =3D !(env->cr[0] & CR0_PE_MASK); =20 - vcpu->tpr =3D whpx_apic_tpr_to_cr8(cpu_get_apic_tpr(x86_cpu->apic_stat= e)); + vcpu->tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); vcpu->apic_base =3D cpu_get_apic_base(x86_cpu->apic_state); =20 idx =3D 0; @@ -692,17 +672,6 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel = level) hr); } =20 - if (whpx_irqchip_in_kernel()) { - /* - * Fetch the TPR value from the emulated APIC. It may get overwrit= ten - * below with the value from CR8 returned by - * WHvGetVirtualProcessorRegisters(). - */ - whpx_apic_get(x86_cpu->apic_state); - vcpu->tpr =3D whpx_apic_tpr_to_cr8( - cpu_get_apic_tpr(x86_cpu->apic_state)); - } - idx =3D 0; =20 /* Indexes for first 16 registers match between HV and QEMU definition= s */ @@ -751,7 +720,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) tpr =3D vcxt.values[idx++].Reg64; if (tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; - cpu_set_apic_tpr(x86_cpu->apic_state, whpx_cr8_to_apic_tpr(tpr)); + cpu_set_apic_tpr(x86_cpu->apic_state, tpr); } =20 /* 8 Debug Registers - Skipped */ @@ -1690,7 +1659,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) } =20 /* Sync the TPR to the CR8 if was modified during the intercept */ - tpr =3D whpx_apic_tpr_to_cr8(cpu_get_apic_tpr(x86_cpu->apic_state)); + tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); if (tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; reg_values[reg_count].Reg64 =3D tpr; @@ -1737,7 +1706,7 @@ static void whpx_vcpu_post_run(CPUState *cpu) if (vcpu->tpr !=3D tpr) { vcpu->tpr =3D tpr; bql_lock(); - cpu_set_apic_tpr(x86_cpu->apic_state, whpx_cr8_to_apic_tpr(vcpu->t= pr)); + cpu_set_apic_tpr(x86_cpu->apic_state, vcpu->tpr); bql_unlock(); } =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093935; cv=none; d=zohomail.com; s=zohoarc; b=HgUiNQLfyQvQGxipugWNj00/o/6+8OlKZ8rS+Cn/x8lxEyd0qFY+FkVfDqq8d4E6BIljzszt0LQmeBzREn8dgCnpVj9NJ9bpslIo2OA4DDMji6ceXiRlInEZqkBhpCo5IEMgBFOxWRSeXkERget69le5FA+XU1dQRuKhBWuVikg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093935; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9UzhbHGn3KNjJvwbSrpYXcynAdkRNKmx/7n4duVcxcA=; b=iosC+wizaKrthzbXwOdMitlp0Mwp8ajoyzJXqNecigufPXyJV8F1iusqikyqaFIHAtDp0i3pXCr7NjN/NZHZxyMJcVOI5XteN+w757Qo7ZQ8bg1XZPmVf7cN5jADjOQ309oh3bCjpxnCI78YLfDzBJPHZ/niNx8Vj6WQcor+tCY= 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 1776093935391919.1848597076247; Mon, 13 Apr 2026 08:25:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ90-00062h-83; Mon, 13 Apr 2026 11:24:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8d-0005X3-Cv for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:49 -0400 Received: from qs-2005a-snip4-11.eps.apple.com ([57.103.86.141] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8b-0000U6-6q for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:46 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 887EE1800190; Mon, 13 Apr 2026 15:23:42 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 55B831800108; Mon, 13 Apr 2026 15:23:40 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093824; x=1778685824; bh=9UzhbHGn3KNjJvwbSrpYXcynAdkRNKmx/7n4duVcxcA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=H/EImIWWofNJ/oQKbexwojsmYODehcKiWx1+D1YO4/da+BGoqMY0AP137XniU3q9kjlcark1tCWc8PSDL/7p5TXi5L6NoRq/HOW6/3eb+CgAsVh/JVyVuOqGoIfqcbXbDvFKnqrkLfG9jN+wr29t+yVLSqNhl5qey8DzXKMj0dY60sQal75VcS8wpwwySDhIYQ8IZGwNREyzivfUpunbF5OwLc0plutHzLO0+fF8cGSrt5T3MN4HI+3UpZ+W2IFLuXAYQrKjqwDS+xup+YY1j+4NgDCikVeFYniepGOsEYJlZjunTdlto4Vn5XkEzg7nvN9Xz46/pFwxrkoqfldUig== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 08/14] whpx: i386: use WHvX64RegisterCr8 only when kernel-irqchip=off Date: Mon, 13 Apr 2026 17:23:20 +0200 Message-ID: <20260413152326.63738-9-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: QFq6oXE-GucBxWpoaDEOgcIgS6MFCzpb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX2ir0rUN0/guR p5lD/3cNAteQRsmvdQ+M2PVJ80laWdmQAJtKNQvQsTvHJeDHpsoiAEAz4oq+/Zj06cwTPoAHBuH tkdzdbmqaP5ntWsNTOX3eoGqckLm2ImqB930dgKxQg2aXejKjR+PfS/PE9AnJc3OwR9998WdCua VeLyg9ufSHGllfkSZbYt9ReQ+gv8XCRvHfEbAnXvThb/hDArTa8tVlhl0DHWUwUDroMJuBDgl77 pbWW/V1IhJz/RvEAL77Sxl1P0VQyc/Vqmwcj/gCHEPDWn9d0q/IJdlW4+Y05rA4Lwd7nTd9luYP EIIptWsLYnYpAe6VFY5O+Pyi4M9NhXYYmYEgG234ctTnJocQFy4jlDi8nmsy3Q= X-Authority-Info-Out: v=2.4 cv=Xqr3+FF9 c=1 sm=1 tr=0 ts=69dd0a7f cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=4IdwVP5-j8YZXVcKM5MA:9 X-Proofpoint-ORIG-GUID: QFq6oXE-GucBxWpoaDEOgcIgS6MFCzpb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 mlxlogscore=867 bulkscore=0 phishscore=0 mlxscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.141; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093937549158500 Content-Type: text/plain; charset="utf-8" When kernel-irqchip=3Don, manage TPR as part of the APIC state instead enti= rely. This fixes some failure to set state errors. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 62542922a4..74b94b799e 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -95,7 +95,6 @@ static const WHV_REGISTER_NAME whpx_register_names[] =3D { WHvX64RegisterCr2, WHvX64RegisterCr3, WHvX64RegisterCr4, - WHvX64RegisterCr8, =20 /* X64 Debug Registers */ /* @@ -459,8 +458,11 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel = level) vcxt.values[idx++].Reg64 =3D env->cr[3]; assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr4); vcxt.values[idx++].Reg64 =3D env->cr[4]; - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr8); - vcxt.values[idx++].Reg64 =3D vcpu->tpr; + /* For kernel-irqchip=3Don, TPR is managed as part of APIC state */ + if (!whpx_irqchip_in_kernel()) { + WHV_REGISTER_VALUE cr8 =3D {.Reg64 =3D vcpu->tpr}; + whpx_set_reg(cpu, WHvX64RegisterCr8, cr8); + } =20 /* 8 Debug Registers - Skipped */ =20 @@ -716,11 +718,14 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel= level) env->cr[3] =3D vcxt.values[idx++].Reg64; assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr4); env->cr[4] =3D vcxt.values[idx++].Reg64; - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr8); - tpr =3D vcxt.values[idx++].Reg64; - if (tpr !=3D vcpu->tpr) { - vcpu->tpr =3D tpr; - cpu_set_apic_tpr(x86_cpu->apic_state, tpr); + + /* For kernel-irqchip=3Don, TPR is managed as part of APIC state */ + if (!whpx_irqchip_in_kernel()) { + tpr =3D vcpu->exit_ctx.VpContext.Cr8; + if (tpr !=3D vcpu->tpr) { + vcpu->tpr =3D tpr; + cpu_set_apic_tpr(x86_cpu->apic_state, tpr); + } } =20 /* 8 Debug Registers - Skipped */ @@ -1660,7 +1665,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) =20 /* Sync the TPR to the CR8 if was modified during the intercept */ tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); - if (tpr !=3D vcpu->tpr) { + if (!whpx_irqchip_in_kernel() && tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; reg_values[reg_count].Reg64 =3D tpr; qatomic_set(&cpu->exit_request, true); @@ -1702,12 +1707,14 @@ static void whpx_vcpu_post_run(CPUState *cpu) =20 env->eflags =3D vcpu->exit_ctx.VpContext.Rflags; =20 - uint64_t tpr =3D vcpu->exit_ctx.VpContext.Cr8; - if (vcpu->tpr !=3D tpr) { - vcpu->tpr =3D tpr; - bql_lock(); - cpu_set_apic_tpr(x86_cpu->apic_state, vcpu->tpr); - bql_unlock(); + if (!whpx_irqchip_in_kernel()) { + uint64_t tpr =3D vcpu->exit_ctx.VpContext.Cr8; + if (vcpu->tpr !=3D tpr) { + vcpu->tpr =3D tpr; + bql_lock(); + cpu_set_apic_tpr(x86_cpu->apic_state, vcpu->tpr); + bql_unlock(); + } } =20 vcpu->interruption_pending =3D --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093865; cv=none; d=zohomail.com; s=zohoarc; b=kihbYUA5JZqd9xoMtxvHBBtlT8R2hxptjX4bHIUe9SkfWSNXXJWbZAMsbwxqa5uksNV+JKWVXdA0s0PfaqXnsTbQsOWLias6uSslWIrcF7c1VMeeX8nmb+2Ynny/eSuXuQAnaUXRPJUXIFaSJgY96mkGc6fYiCcigkBHyYw5z4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093865; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UDUDDhSNImOkwjgegNmDYFGV0Ws4YLT0V61YNwqVXjA=; b=agRVz2rg2zpu5RDS/BONaA/DUc0IzDUzkNwRxl5ctfwI4iNJv8Oe2M2JQBK2JCy9/aLqUtBfBf1i/QZYENG5KnV1FD/yv1+AIE9YQfBvHNgCEr3xRQnLo8vUINErf8fwZSDr1VBb5rxqDdgvzqHtb4Nb5zsn8c+e1KeyR0uQCu0= 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 1776093865323234.83794874816988; Mon, 13 Apr 2026 08:24:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ90-00064Y-Po; Mon, 13 Apr 2026 11:24:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8h-0005Yb-Jb for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:54 -0400 Received: from qs-2005k-snip4-2.eps.apple.com ([57.103.86.233] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8f-0000Uv-4V for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:50 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 34C4218000AF; Mon, 13 Apr 2026 15:23:43 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 0D68F180009E; Mon, 13 Apr 2026 15:23:41 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093827; x=1778685827; bh=UDUDDhSNImOkwjgegNmDYFGV0Ws4YLT0V61YNwqVXjA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Uja94aSOJEquuuQVQ8/jtaeEFPYubNBAJthoHXjuTjkH1Xq2/ZsnznO0sQuKunSBTybe/6rsxAgll+ROpEUX+divTGmCjZmqO9r10EIMx1IhtLbRthMfEIkMiKNN5qoK/C0tv/Mxud8Spkgq362PSPVrWN5Y575eOUBkQtat0O130s3EvSAka1Ob9ifRked+htop6OgjUGMjyW3xy2giWYDIN2mSS0vv7ShXGSkVrgrVg2Dhs0466anJSIWxZVr3Pdn1PgUjovVbQu6XtxzPYg4lNrsI22j7vx8Bg9Une4Ce3bcw2uOEP2fQ1Gy0DGSEip6m1ObCrdhTRxgVIlRE+g== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 09/14] whpx: i386: disable kernel-irqchip on Windows 10 when PIC enabled Date: Mon, 13 Apr 2026 17:23:21 +0200 Message-ID: <20260413152326.63738-10-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: D-4RY6il9eKIem7RH8Zju7hLiVxOme4C X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX6xeykMPdZj1u Ijp2bFt/xn/M/1pjIZJsAGqzoKnsjiXHDrCiAbKuyKgeAn9fDpSDMQfLnQh7Zu9dUsqMKgpSpNh ZAQzRAHIuaRnBrT1tB2eiYRzhp6N1MI3Slvs3U7/tT1b+OUS1HO7tYnmE9WclysbxOKQtUwNzOQ mGizs0Tl0S+QT7OtTBnlwKt+hqkDi0Yw49DQ7A0jivtJwhI5nHT/3UMt4Zi7A7ZMpxxzdMIy67a okf5yCQHF4xFcFzfiR3SyFELpB1P34S/LB1VW/60emd14MKX3afVKMoAx3QG/S4FNruSwN2T2m1 OzqOfi3GwXXzjmY461HiMmRjFAY/xWkTYuPaQcNKjsvJkyC1vV5UxeTCFOu7FI= X-Proofpoint-GUID: D-4RY6il9eKIem7RH8Zju7hLiVxOme4C X-Authority-Info-Out: v=2.4 cv=DohbOW/+ c=1 sm=1 tr=0 ts=69dd0a81 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=nUl_a9z44qMLw6SsMv4A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 clxscore=1030 mlxlogscore=801 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.233; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093867760154100 Content-Type: text/plain; charset="utf-8" Move WHvCapabilityCodeProcessorPerfmonFeatures queries as that's how we distinguish if on a legacy OS. Now that Windows guests are booting, disable kernel-irqchip=3Don by default for Windows 10 when the PIC is enabled. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 69 +++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 74b94b799e..7c80d653d1 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2447,6 +2447,13 @@ int whpx_accel_init(AccelState *as, MachineState *ms) 0x8000000A, 0x80000021, 0x80000022, 0xC0000000, 0xC0000001}; UINT32 cpuidExitList_legacy_os[] =3D {1, 0x40000000, 0x40000001, 0x400= 00010}; =20 + X86MachineState *x86ms =3D X86_MACHINE(ms); + bool pic_enabled =3D false; + + if (x86ms->pic =3D=3D ON_OFF_AUTO_ON || x86ms->pic =3D=3D ON_OFF_AUTO_= AUTO) { + pic_enabled =3D true; + } + whpx =3D &whpx_global; =20 if (!init_whp_dispatch()) { @@ -2518,6 +2525,35 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 + /* Enable supported performance monitoring capabilities */ + hr =3D whp_dispatch.WHvGetCapability( + WHvCapabilityCodeProcessorPerfmonFeatures, &perfmon_features, + sizeof(WHV_PROCESSOR_PERFMON_FEATURES), &whpx_cap_size); + /* + * Relying on this is a crutch to maintain Windows 10 support. + * + * WHvCapabilityCodeProcessorPerfmonFeatures and + * WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks + * are implemented starting from Windows Server 2022 (build 20348). + */ + if (FAILED(hr)) { + warn_report("WHPX: Failed to get performance " + "monitoring features, hr=3D%08lx", hr); + is_modern_os =3D false; + } else { + hr =3D whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeProcessorPerfmonFeatures, + &perfmon_features, + sizeof(WHV_PROCESSOR_PERFMON_FEATURES)); + if (FAILED(hr)) { + error_report("WHPX: Failed to set performance " + "monitoring features, hr=3D%08lx", hr); + ret =3D -EINVAL; + goto error; + } + } + /* * Error out if WHP doesn't support apic emulation and user is requiri= ng * it. @@ -2530,8 +2566,9 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 - if (whpx->kernel_irqchip_allowed && features.LocalApicEmulation && - whp_dispatch.WHvSetVirtualProcessorInterruptControllerState2) { + if (whpx->kernel_irqchip_allowed && !(whpx_is_legacy_os() && pic_enabl= ed + && !whpx->kernel_irqchip_required) && features.LocalApicEmulation + && whp_dispatch.WHvSetVirtualProcessorInterruptControllerState2) { WHV_X64_LOCAL_APIC_EMULATION_MODE mode =3D WHvX64LocalApicEmulationModeX2Apic; hr =3D whp_dispatch.WHvSetPartitionProperty( @@ -2590,34 +2627,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 - /* Enable supported performance monitoring capabilities */ - hr =3D whp_dispatch.WHvGetCapability( - WHvCapabilityCodeProcessorPerfmonFeatures, &perfmon_features, - sizeof(WHV_PROCESSOR_PERFMON_FEATURES), &whpx_cap_size); - /* - * Relying on this is a crutch to maintain Windows 10 support. - * - * WHvCapabilityCodeProcessorPerfmonFeatures and - * WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks - * are implemented starting from Windows Server 2022 (build 20348). - */ - if (FAILED(hr)) { - warn_report("WHPX: Failed to get performance " - "monitoring features, hr=3D%08lx", hr); - is_modern_os =3D false; - } else { - hr =3D whp_dispatch.WHvSetPartitionProperty( - whpx->partition, - WHvPartitionPropertyCodeProcessorPerfmonFeatures, - &perfmon_features, - sizeof(WHV_PROCESSOR_PERFMON_FEATURES)); - if (FAILED(hr)) { - error_report("WHPX: Failed to set performance " - "monitoring features, hr=3D%08lx", hr); - ret =3D -EINVAL; - goto error; - } - } =20 /* Enable synthetic processor features */ WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS synthetic_features; --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093956; cv=none; d=zohomail.com; s=zohoarc; b=AsJoWPunZS5/RdBAMOAGAM51oCTPBf+L2cWpte7E2k0eU3J8jtO+ncJFzYWdUyTuiqda6gr3PPTfivjtFLCpn9/7MjKPWX2PCKFJDzZ38KIxbYZQ6W5NPSk7wjwYSWUoteyuAtRC0A5T0zqVvvC2Lbn+jX06nHLCTwdZpKn/dHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093956; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G89W4sMC3YwwxzvqsgVypuGjICEkNIb9nBQsRfciAZw=; b=fK2u579cEVlwnfg+Ch4BOvfkjVJM13JPgOapWTRdyRo4776Q/QkVvwkCy9QZ9cySh4YHHqL2JNEq+exCEhKjGazEn00k5o565JyCgRGHqolu8v1hI7oX8QC2uyxb2cY/NT6NHm8Jjan8BIPryVzlC9gl58Fel2hUFghEDkxCOWc= 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 1776093956155832.33834732602; Mon, 13 Apr 2026 08:25:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8u-0005ji-RQ; Mon, 13 Apr 2026 11:24: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 1wCJ8f-0005Xl-H8 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:51 -0400 Received: from qs-2005g-snip4-5.eps.apple.com ([57.103.86.196] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8d-0000Uo-Vo for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:49 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 4097C1800135; Mon, 13 Apr 2026 15:23:45 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 6C58318000A9; Mon, 13 Apr 2026 15:23:43 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093827; x=1778685827; bh=G89W4sMC3YwwxzvqsgVypuGjICEkNIb9nBQsRfciAZw=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=R6+bE7zoj7oBfFP8RsZg6QlDDBHEMqvM6EoWDWkqWx/a8tpRS4isnHMcRsSL3Ude3uZv2pn7deopafIoXo7iIQThFOhYXWWkONN/+mFnpSNhf7ZZ/l/kzhxzwSsSFusjMOu6JCLe7uUVoJtuN8SrKvTFm5J5zZULCrAukoIYybyJS9NAFVG+dWNS/Xa7R4XwgxUIAvG70xFv6j3c2u4BRMOPO5cjR+mQyoZg9gd0Z/qsbJ60g/ppcai13dEPlvxz2MxCoQuDwLy+3WQYr2yb5mcdr+NHzWc/OAW5O22iW0cqtQz7rJsrnJ4N76DCvkF8ebjG29HXtdRVzcYYGWHXnA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 10/14] whpx: i386: IO port fast path cleanup Date: Mon, 13 Apr 2026 17:23:22 +0200 Message-ID: <20260413152326.63738-11-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfXx6LjKkf+MynM dDLk/MJBRWwfZQ8Z5Sf1vixAZ07Qp2MTPwS2zF2cQfxwaqExK/YUw5Q6nOJluHJkwIWLEFtTR0x 2KUwu2VhNxNAMn4+yt3LTyP2oupnMSI+qh7g51xZ/JkzRZaUbe9HdrcVHtQZAp/HW0wa2Zm392B BQy0T45LsbHq2KUIe1Na5VSX/xlu7E+ZARfMCu9qVBCsSJV7XMg0GekscvBxGSOCu3wUc2MItq/ EuqVecthFNKOZhBcjPywS/3UL4A53ZpcLaKxQ4Pwqsq7EUh8lPdBHUt8VVtiEAhElF4VHhOZJ1S 7kVG3FdSENKUpxQ9Ug9PJOrDmd9frXMb4UFIqKr1Y28C53IF1V7jq66FQRIZ1Y= X-Proofpoint-GUID: LDp9tnS6bRPzTsZA8uhi45_bHLsXLKmh X-Authority-Info-Out: v=2.4 cv=LNRrgZW9 c=1 sm=1 tr=0 ts=69dd0a82 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Vrzv6M8N8vcM0KmfSJEA:9 X-Proofpoint-ORIG-GUID: LDp9tnS6bRPzTsZA8uhi45_bHLsXLKmh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 lowpriorityscore=0 spamscore=0 mlxlogscore=805 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.196; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093957192154100 Content-Type: text/plain; charset="utf-8" vmport calls synchronise_state within an I/O port read. Support that properly. What was there before worked because of a side effect of whpx_get_reg synchronising context if cpu->vcpu_dirty. Remove that whpx_get_reg call in whpx_bump_rip too as it's no longer needed now. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 7c80d653d1..61aec98e66 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -862,7 +862,6 @@ static void handle_io(CPUState *env, uint16_t port, voi= d *buffer, static void whpx_bump_rip(CPUState *cpu, WHV_RUN_VP_EXIT_CONTEXT *exit_ctx) { WHV_REGISTER_VALUE reg; - whpx_get_reg(cpu, WHvX64RegisterRip, ®); reg.Reg64 =3D exit_ctx->VpContext.Rip + exit_ctx->VpContext.Instructio= nLength; whpx_set_reg(cpu, WHvX64RegisterRip, reg); } @@ -890,13 +889,23 @@ static int whpx_handle_portio(CPUState *cpu, } else { reg.Reg64 =3D (uint64_t)val; } - whpx_bump_rip(cpu, exit_ctx); - whpx_set_reg(cpu, WHvX64RegisterRax, reg); + /* vmport calls cpu_synchronize_state on an I/O port read */ + if (!cpu->vcpu_dirty) { + whpx_bump_rip(cpu, exit_ctx); + whpx_set_reg(cpu, WHvX64RegisterRax, reg); + } else { + env->eip =3D exit_ctx->VpContext.Rip + exit_ctx->VpContext.Ins= tructionLength; + env->regs[R_EAX] =3D reg.Reg64; + } return 0; } else if (!ctx->AccessInfo.StringOp && ctx->AccessInfo.IsWrite) { RAX(env) =3D ctx->Rax; handle_io(cpu, ctx->PortNumber, &RAX(env), 1, ctx->AccessInfo.Acce= ssSize, 1); - whpx_bump_rip(cpu, exit_ctx); + if (!cpu->vcpu_dirty) { + whpx_bump_rip(cpu, exit_ctx); + } else { + env->eip =3D exit_ctx->VpContext.Rip + exit_ctx->VpContext.Ins= tructionLength; + } return 0; } =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093867; cv=none; d=zohomail.com; s=zohoarc; b=Ghm/H9KgGG/o8AnGhh0fhc4EgABlXvBWvVBBdj+6QOZTyKb3xXsMGfzwOKP90IugsNNW2VUtN1sKrBpj5CzL/lHcReesU5dbik45j4jub2XIBwTJ/SMo8+/5PU5GvyLIs0bGKEmjy+LK01VGcXWe0UNkNtI0jJToipHNKyx5QFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093867; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zcmYD8sBYnUVL4imQw8BkyvhG03VGFAjf3wzcMF8rtM=; b=HEBUI1N+IY3VmjIBT9JXP+vqLaBH+lf6MaZE/jPxMz0qmRexOXxpqHwih9kIJ8cAiU4rOF6qH0bojAimiulwuDKPppCvXi0jTSI4rwaS6unDpD9/6l5eKg9u+nl3Npl1qupwV5gagum+uxMIT10Ktrj3xW2SUC2FPI53p/23gb0= 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 1776093867336637.4498819664577; Mon, 13 Apr 2026 08:24:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8t-0005gK-TA; Mon, 13 Apr 2026 11:24:03 -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 1wCJ8k-0005Z7-92 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:55 -0400 Received: from qs-2005b-snip4-7.eps.apple.com ([57.103.86.148] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8h-0000WH-5V for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:53 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 52D4E180009E; Mon, 13 Apr 2026 15:23:47 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id C765B1800110; Mon, 13 Apr 2026 15:23:44 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093830; x=1778685830; bh=zcmYD8sBYnUVL4imQw8BkyvhG03VGFAjf3wzcMF8rtM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Adyeh4NfyAgViKt453C0tTDclfCKyQM+GTM732ikFqb2WyDUon8HAcT0MoZrZE58bgGsz1GqJA7MdSrQVg/UoXkX6AKj1xF36tNgyGj1S5/LN4hjtZ2ceHgjG8jDOBcti8naAmVtDZ3fjUKPWeAhquQ+xZ9qW4VbBIl+auZnYxcnGIewn/RSEyhG2ubn09Oykv394R7JChdIYq9tda+kHtRPNNPdFHDOqtnY3k6p1oiglSVsn2uwRajiEQkTB+0MOqXYcDaZPBzI+dz+rmZEkWOvOtZ1SxGluvFulN/xzdpk48e3nbqYt1v3sKe1pSUIQhgjW/O64nlBBlYgrqo7rA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 11/14] whpx: i386: disable enlightenments and LAPIC for isapc Date: Mon, 13 Apr 2026 17:23:23 +0200 Message-ID: <20260413152326.63738-12-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: IomtRxvvHBFy-ayAdQPaVgRnqam3McJY X-Proofpoint-GUID: IomtRxvvHBFy-ayAdQPaVgRnqam3McJY X-Authority-Info-Out: v=2.4 cv=QKdlhwLL c=1 sm=1 tr=0 ts=69dd0a84 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=kaNVauZA35-AGszze7oA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX3cjP3fTcvClk F7N84gVBTHTP/jBI38d3D3cZnPpBKcgdeWp2yc5X6s3qyJGrZpwlpcK3sOO0daBpZp2pk9SJMUb nEqCAi+Yk6wZ2JMLlU2michPgPQZ+jPFDPXVEbGdYRs9JIrqvQN4+GCSzA2Lq54ovgI/zkUQBqe bw1IHC81FBu7Qw/ehu4xQZWVyMvh4Maa7Aewd6jSFGaqThb2n6BEVBGP1iubVOb1tbfh8kW6BNf ys4CMR++e85GmgG+sLkNEE9UFGYRVlnIKiSGmQWbCPmlRsShs2NzCA/D/nXy6PR5EVC+V809dUd 7HV1vYKgIGcPtH2uyH9iBrsYRKtNRz6twq/EtOCg6UC6OF+w5QHyw3zmkt2KAo= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=783 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1030 phishscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.148; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093871342158500 Content-Type: text/plain; charset="utf-8" The isapc machine doesn't have an APIC. And Hyper-V enlightenments don't sound too useful to have there so disable those. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 61aec98e66..7a31dc6427 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2470,6 +2470,14 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } =20 + /* for isapc, disable Hyper-V enlightenments and LAPIC */ + if (!strcmp(MACHINE_GET_CLASS(ms)->name, "isapc")) { + whpx->kernel_irqchip_allowed =3D false; + whpx->kernel_irqchip_required =3D false; + whpx->hyperv_enlightenments_allowed =3D false; + whpx->hyperv_enlightenments_required =3D false; + } + whpx->mem_quota =3D ms->ram_size; =20 hr =3D whp_dispatch.WHvGetCapability( --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093862; cv=none; d=zohomail.com; s=zohoarc; b=SW39CKRnqZZqHSsJXDycA3rbMi95xgL0WXl9Q1M81pOEOIngyn8NSJw47/9qrpHREaavvMyOygfMdoHDkOTs8BwvmXbnCh9EX1J+tPA3UjNoY8kH5uQKekA8RGBH2/hc4Bgez7baz9210KQ8ppHMomHUfh7QrKhpfZWy2c74yk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093862; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=poibcXPqvaJ8YaZ5/PTr9/BHGmofzQDktL0gBjdI+dM=; b=Kcj4NHiXKnhN3XDV75K03MN64asGg11DG6/DbzDkbh5upDgvH40RAYIfEBZ/HkvU0TjZlTy3NOwaYOf197P0kY6P2z6U6VLXs91KIKAnHLdLQ7ej+ZishgkiPyuAGbcpRvnUW+CI0estQgjFYHUkCzZhfXsOuGsmCxeyVdkNGz0= 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 177609386230523.62469956200414; Mon, 13 Apr 2026 08:24:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8z-00060F-Ty; Mon, 13 Apr 2026 11:24: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 1wCJ8n-0005bv-A0 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:58 -0400 Received: from qs-2005h-snip4-10.eps.apple.com ([57.103.86.210] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8j-0000Wa-Je for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:55 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id E074918001AB; Mon, 13 Apr 2026 15:23:48 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 7F4941800194; Mon, 13 Apr 2026 15:23:46 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093833; x=1778685833; bh=poibcXPqvaJ8YaZ5/PTr9/BHGmofzQDktL0gBjdI+dM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=Dy4doSrIAaaiGBDtMj3FMUohs+Xhzs8ad4/42liLLFEflYsidsY/K+A9J822bRT9w4+UPK6Ir9uz/TDatd1vMdyxB067D37u/SKSrPjoLTbM/bxqwweqFTR6HVCZaH8P+MYtvj3HTXvd1AX4TBpHW8gCWIWLQKy+TZvVUldLRPNsAJq2nbs2sQVHsbIE1IOjGAJM1LHJro0z0zeI6zW0Y4cNA5925M7R5CbnV8yg1tIgGhYAO0Ruh98QlUKNDLUaaQ4LC2phRosGjyXBQF5V2xKkHDK8VnFHBaAd+Y+6szjfvfcrsVkWLfG6Ct5Rj2uWBNsZfsOLWyQ8zJ+VN32Tyg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 12/14] whpx: i386: interrupt priority support Date: Mon, 13 Apr 2026 17:23:24 +0200 Message-ID: <20260413152326.63738-13-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX0TurWoU9AEgD 7JgXxNcf0ICH693r0gnCYqKiVyzEY7ygTNSjfXlt9DSc8fFmkmFRUEM/F1oDDg5iHMBuT/UE5eU WbWEoi+fr2Ibe/n7cBRocfNkYzBiaSrhbrAMn1BpXdouZrHe0E0eODAANcQt3TkrmIAh2fy+K7B UXZIuFRo3ni1u6+H6eMGtR+QAuTaZN2qIJrphOIZjBgWlekY7xKN8xG5bUwzP/Ya+ITnf+rqxvE n9UYgdmTz+RagQdSmH6TTFGg+I/RNoPkuPX8RsEjD/4i6OGMoSYvi215ERW6bOj0FkPCK/GdgJV 2A+3UfZclCY1ipjkwZhlmXzfK+rJ+UpY/VQoa1pboqp0Da6/AElWLCuPvXTAZI= X-Authority-Info-Out: v=2.4 cv=ILYPywvG c=1 sm=1 tr=0 ts=69dd0a86 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=NuKELtICf0aykZwt-QIA:9 X-Proofpoint-GUID: EHvMJi1tiXNi0X2JhReAPFaf4WU_FQBJ X-Proofpoint-ORIG-GUID: EHvMJi1tiXNi0X2JhReAPFaf4WU_FQBJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1030 spamscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 mlxlogscore=692 bulkscore=0 phishscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.210; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093865977154100 Content-Type: text/plain; charset="utf-8" Implement APIC IRR interrupt priorities. Even with kernel-irqchip=3Doff, Hyper-V is aware of interrupt priorities and implements CR8/TPR, with the InterruptPriority field being followed. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 7a31dc6427..8cd81fffee 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1588,6 +1588,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) UINT32 reg_count =3D 0; WHV_REGISTER_VALUE reg_values[3]; WHV_REGISTER_NAME reg_names[3]; + int irr =3D apic_get_highest_priority_irr(x86_cpu->apic_state); =20 memset(&new_int, 0, sizeof(new_int)); memset(reg_values, 0, sizeof(reg_values)); @@ -1623,10 +1624,20 @@ static void whpx_vcpu_pre_run(CPUState *cpu) } } =20 + if (irr =3D=3D -1) { + if (pic_get_output(isa_pic)) { + /* In case it's a PIC interrupt */ + irr =3D 0; + } else if (cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)) { + abort(); + } + } + /* Get pending hard interruption or replay one that was overwritten */ if (!whpx_irqchip_in_kernel()) { if (!vcpu->interruption_pending && - vcpu->interruptable && (env->eflags & IF_MASK)) { + vcpu->interruptable && (env->eflags & IF_MASK) + && (vcpu->tpr < irr || irr =3D=3D 0)) { assert(!new_int.InterruptionPending); if (cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD); @@ -1683,13 +1694,17 @@ static void whpx_vcpu_pre_run(CPUState *cpu) } =20 /* Update the state of the interrupt delivery notification */ - if (!vcpu->window_registered && + if ((!vcpu->window_registered || + (vcpu->window_priority < irr && vcpu->window_priority !=3D 0) || + (irr =3D=3D 0 && vcpu->window_priority !=3D 0)) && cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)) { reg_values[reg_count].DeliverabilityNotifications =3D (WHV_X64_DELIVERABILITY_NOTIFICATIONS_REGISTER) { - .InterruptNotification =3D 1 + .InterruptNotification =3D 1, + .InterruptPriority =3D irr >> 4 }; vcpu->window_registered =3D 1; + vcpu->window_priority =3D irr; reg_names[reg_count] =3D WHvX64RegisterDeliverabilityNotifications; reg_count +=3D 1; } @@ -1703,7 +1718,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) reg_names, reg_count, reg_values); if (FAILED(hr)) { error_report("WHPX: Failed to set interrupt state registers," - " hr=3D%08lx", hr); + " hr=3D%08lx, InterruptPriority=3D%i", hr, irr >>= 4); } } } @@ -1919,6 +1934,7 @@ int whpx_vcpu_run(CPUState *cpu) case WHvRunVpExitReasonX64InterruptWindow: vcpu->ready_for_pic_interrupt =3D 1; vcpu->window_registered =3D 0; + vcpu->window_priority =3D 0; ret =3D 0; break; =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093946; cv=none; d=zohomail.com; s=zohoarc; b=BYfyA9O/F3rpylAny9ArCvEKZGrk/rBOYS4Tyw3zLsP8mRUScoezMdCr3U3MEm8vO0HW/OQZh71tQrXHU2P9lz0bGpo6ULTzPuAPaXP5byKA8r79UgOVFxv9PutW0eG5mxiFAmLekwFWcQvSc82vlVO0+Do923gw3wEsNQwfDs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093946; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SCqUAJvB1zqKRh44vHU0QIqywz/suuWsKXqtx/ZiPkM=; b=Azgsf+6haVEwuavmdji+Of1FFVw4nAlmKXGpqLm1531R1dj1lxEN8ldlGW8OqaRVu/LC+ucNl3EOy81d8zMIaqz5nn8+AhsvA47ayuZJQRkClw/uGgm+TWLc5FDyqUcLTsiC8xAyLeDO6Oo1Kxrl/vT3tq2sbi7G5SmPmcS9wyM= 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 1776093946882384.81600575182233; Mon, 13 Apr 2026 08:25:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ90-00063a-Er; Mon, 13 Apr 2026 11:24:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8n-0005cA-Uc for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:59 -0400 Received: from qs-2005h-snip4-2.eps.apple.com ([57.103.86.203] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8k-0000Wf-2K for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:23:56 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id 2D42D1800111; Mon, 13 Apr 2026 15:23:49 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id DB9A61800103; Mon, 13 Apr 2026 15:23:47 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093833; x=1778685833; bh=SCqUAJvB1zqKRh44vHU0QIqywz/suuWsKXqtx/ZiPkM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=FZyetyY44Ph+mBFSFnmmiKimJ/NmiyZ5O+zcTbVejoorf4EEJuAXcXrC145Mp19c0kEUcAUgn6uFGwTfVAubwxMqEbPxxTwoCIOQEOTHQwCDtyDBTA21jn8+JmLAWkMzGm1275XU3eIXMeX0bls10iMp+9jo4HQlqxmsAcYVzdcYk95YsVm0VsHS4ssijXa8QDxyltt4tvxlkdJzrMnSZ3At9hI/TQBB5jf4hnYac3HHrGTO+csoMj23TWoHVC3fQR64ZtIO9LCcka+ZqEja/sD6oAMJvLBucHRLcmXh8tCIgRYW8kWvaGHoYjvDo/AVRykazZfIgjK1Zrd2/vAJjQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 13/14] hw/intc: apic: disallow APIC reads when disabled Date: Mon, 13 Apr 2026 17:23:25 +0200 Message-ID: <20260413152326.63738-14-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: jo6XZAgya5S1hpQad2hJpOZgwLCtAGsV X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX5Eq1l4INaBew OZ86TkVTmiIvuuUibuyzHNYeVBVbA3oLT7xtz2oX6j8w2HO++qiAKYPT8D69n14YRycoZBJY1WI fcxxhGa76LqGDJDkbZ2WeOhCW/Xaxt8yyIclfjH/sxlW6K3DkuRckejKWJ3Vye3Oc6Ha4Kupvdx pJeFMtEzEyRH091c9n0ba+LLc0PtM9z3gozXK8CiqHGgEO2yqVNW6WAHA9fz+qgr/87/rx845Nd sCsSSueiIh4xJChu+P/FwAQWQx3QaIYi0gCbxziVKAQ0/H5ovLK5YBs8oAcjKou33deWx+2mn75 ouU3yNv4phv6CnE8RevtVE6XQjxWUVsSCrBEY7oH1kyQCryDGjQi3yS5WvXZKA= X-Proofpoint-ORIG-GUID: jo6XZAgya5S1hpQad2hJpOZgwLCtAGsV X-Authority-Info-Out: v=2.4 cv=HdsZjyE8 c=1 sm=1 tr=0 ts=69dd0a87 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Sz3nRv2TKcqVAncp5HQA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 clxscore=1030 mlxlogscore=800 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.203; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093949015154100 Content-Type: text/plain; charset="utf-8" !APICBASE_ENABLE + attempting to read xAPIC registers is not an allowed com= bination. And neither is x2APIC enabled + attempting to read xAPIC registers Signed-off-by: Mohamed Mediouni --- hw/intc/apic.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/intc/apic.c b/hw/intc/apic.c index 8766ed00b9..c09dddef39 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -875,6 +875,15 @@ static uint64_t apic_mem_read(void *opaque, hwaddr add= r, unsigned size) return -1; } =20 + /* if the xAPIC is disabled, return early. */ + if (!(s->apicbase & MSR_IA32_APICBASE_ENABLE)) { + return 0xffffffff; + } + + if (s->apicbase & MSR_IA32_APICBASE_EXTD) { + return 0xffffffff; + } + index =3D (addr >> 4) & 0xff; apic_register_read(s, index, &val); =20 --=20 2.50.1 (Apple Git-155) From nobody Thu Apr 30 00:41:16 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=1776093958; cv=none; d=zohomail.com; s=zohoarc; b=iV8A+cTymZNdGirvF+fltgrXukajO16oOPTVZMkAdiSpzp4kjelEngKpqY75DN9qkzgOgdvE5j0bkNhXRWXbelBTraiH1EiuI3kaMwmsAe2UjPXLMAP2z+5WhtnAXdh7gVhkCDRBruyQbtmhSLOeWDzwIRw4BwQuPICMkDhwOlQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776093958; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M6AkUUrPcxLOfhXzaNmZevrpR2eORr3l/18/Pdjn4vI=; b=Zb38bXLFRn5v3CQV9IjMay9gF1twqNj3uutVnZfcvyEf+P3mRZ0FZ9qsbFPGhppad/AUX9U2B3CePG8HJYWM57gWcOrcAvvcyNP8QqfOQIZwXD/bYfbqP5L/ctbln6UoSlvlHqI3QgqDuAUrVYefaF78L8fzM8nspaImvtJ6glg= 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 1776093958903613.6233558738903; Mon, 13 Apr 2026 08:25:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wCJ8u-0005jU-Or; Mon, 13 Apr 2026 11:24: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 1wCJ8r-0005cs-4C for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:24:01 -0400 Received: from qs-2005i-snip4-4.eps.apple.com ([57.103.86.215] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wCJ8n-0000XI-33 for qemu-devel@nongnu.org; Mon, 13 Apr 2026 11:24:00 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPS id A43AF18000A4; Mon, 13 Apr 2026 15:23:51 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-10 (Postfix) with ESMTPSA id 61BB618001CB; Mon, 13 Apr 2026 15:23:49 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1776093835; x=1778685835; bh=M6AkUUrPcxLOfhXzaNmZevrpR2eORr3l/18/Pdjn4vI=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=g75zPbFX9Uvgk1RCyqoRQGzzd7WpkrEsb6FBVcpcD2lM3E8MjLQs1ba5EngMQC50k+j4rL+hRsOUyHZcrQckuGtCIrG6cRwODaBrjyod27Ugi7GlITtDYp/xO6+trRv3KK9JhLNUJ05hhbay4HLjwRQB1u6Gf/DNozBz60FNMx/X27RSrSJAffIxtWUuriNbGS2f+We7NMsjWsBHIuhCzfjMFOK9UzPjtpbMjDmGfu1PegL/us550QsYOmyCjK6LheMB669VkW2nTyJuymXO2ZwHLInBemNMYxR2ZJB2/NAwmyolDiWJpi4B64+TvBXnl6tOmrqPYgMWdpVMzyum4w== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Zhao Liu , "Michael S. Tsirkin" , Paolo Bonzini , Wei Liu , Roman Bolshakov , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v10 14/14] whpx: i386: fix CPUID[1:EDX].APIC reporting Date: Mon, 13 Apr 2026 17:23:26 +0200 Message-ID: <20260413152326.63738-15-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260413152326.63738-1-mohamed@unpredictable.fr> References: <20260413152326.63738-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: OiZfWjie1kUd0v-0ycLxZjDwKG-_b6iz X-Proofpoint-GUID: OiZfWjie1kUd0v-0ycLxZjDwKG-_b6iz X-Authority-Info-Out: v=2.4 cv=QKdlhwLL c=1 sm=1 tr=0 ts=69dd0a89 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=ljJ9V6m273jqBh-Cp98A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEzMDE1MSBTYWx0ZWRfX91lA5Jj8GUiS Lhslujwaa4G3uuzmrF17qtjeT8sVFzEQdo9Hqpgm15W2/oy3vGlUuetkVqT4XGrP/5MME1ydRJ+ KTjtR4itBHAv6PnPUOez3ELNAB3ixmIailNhJO+2dL2GM7xB0B2A8k+NiIZveI+fAhrIsUHMfT5 +Dts1DqdyBj9eq7l0n6zFtubJujTnBj8toW+sLWX2QgJFHmO1OuqEPGfrZLIBRipm3GqRsQ4hz5 kdDOSaNvogNBF0Ld6cedmE2O0nYt/aiAI+/vdCTH0JDqVajhSUPZiw1BgRuMqAMNi/79U4cko+K Oq8aFQqHc7F7CVtv9yRr9yj6qn0+3Fq9/Hoxjdoui3kKiT81XZOAxQdzvZ0xVE= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-13_03,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=856 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1030 phishscore=0 suspectscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604130151 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.86.215; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @unpredictable.fr) X-ZM-MESSAGEID: 1776093961479154100 Content-Type: text/plain; charset="utf-8" Hyper-V always has CPUID[1:EDX].APIC set, even when the APIC isn't enabled = yet. Work around this by also using the APICBASE trap for kernel-irqchip=3Don. Signed-off-by: Mohamed Mediouni --- include/system/whpx-common.h | 1 - target/i386/whpx/whpx-all.c | 34 ++++++++--------- target/i386/whpx/whpx-apic.c | 71 ++++++++++++++++++++++++++++++++++-- 3 files changed, 84 insertions(+), 22 deletions(-) diff --git a/include/system/whpx-common.h b/include/system/whpx-common.h index 3406c20fec..79710e2fb3 100644 --- a/include/system/whpx-common.h +++ b/include/system/whpx-common.h @@ -8,7 +8,6 @@ struct AccelCPUState { bool interruptable; bool ready_for_pic_interrupt; uint64_t tpr; - uint64_t apic_base; bool interruption_pending; /* Must be the last field as it may have a tail */ WHV_RUN_VP_EXIT_CONTEXT exit_ctx; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 8cd81fffee..9ce73261c2 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -139,7 +139,6 @@ static const WHV_REGISTER_NAME whpx_register_names[] = =3D { #ifdef TARGET_X86_64 WHvX64RegisterKernelGsBase, #endif - WHvX64RegisterApicBase, /* WHvX64RegisterPat, */ WHvX64RegisterSysenterCs, WHvX64RegisterSysenterEip, @@ -401,7 +400,6 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel l= evel) r86 =3D !(env->cr[0] & CR0_PE_MASK); =20 vcpu->tpr =3D cpu_get_apic_tpr(x86_cpu->apic_state); - vcpu->apic_base =3D cpu_get_apic_base(x86_cpu->apic_state); =20 idx =3D 0; =20 @@ -519,9 +517,6 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel l= evel) vcxt.values[idx++].Reg64 =3D env->kernelgsbase; #endif =20 - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterApicBase); - vcxt.values[idx++].Reg64 =3D vcpu->apic_base; - /* WHvX64RegisterPat - Skipped */ =20 assert(whpx_register_names[idx] =3D=3D WHvX64RegisterSysenterCs); @@ -556,6 +551,12 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel = level) error_report("WHPX: Failed to set virtual processor context, hr=3D= %08lx", hr); } + + if (level >=3D WHPX_LEVEL_FULL_STATE) { + WHV_REGISTER_VALUE apic_base =3D {}; + apic_base.Reg64 =3D cpu_get_apic_base(X86_CPU(cpu)->apic_state); + whpx_set_reg(cpu, WHvX64RegisterApicBase, apic_base); + } } =20 static int whpx_get_tsc(CPUState *cpu) @@ -647,7 +648,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) X86CPU *x86_cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86_cpu->env; struct whpx_register_set vcxt; - uint64_t tpr, apic_base; + uint64_t tpr; HRESULT hr; int idx; int idx_next; @@ -779,13 +780,6 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel = level) env->kernelgsbase =3D vcxt.values[idx++].Reg64; #endif =20 - assert(whpx_register_names[idx] =3D=3D WHvX64RegisterApicBase); - apic_base =3D vcxt.values[idx++].Reg64; - if (apic_base !=3D vcpu->apic_base) { - vcpu->apic_base =3D apic_base; - cpu_set_apic_base(x86_cpu->apic_state, vcpu->apic_base); - } - /* WHvX64RegisterPat - Skipped */ =20 assert(whpx_register_names[idx] =3D=3D WHvX64RegisterSysenterCs); @@ -1997,8 +1991,7 @@ int whpx_vcpu_run(CPUState *cpu) val =3D X86_CPU(cpu)->env.apic_bus_freq; } =20 - if (!whpx_irqchip_in_kernel() && - vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D MSR_IA32_APICBAS= E) { + if (vcpu->exit_ctx.MsrAccess.MsrNumber =3D=3D MSR_IA32_APICBAS= E) { is_known_msr =3D 1; if (!vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) { /* Read path unreachable on Hyper-V */ @@ -2164,6 +2157,13 @@ int whpx_vcpu_run(CPUState *cpu) } else { reg_values[2].Reg32 &=3D CPUID_EXT_X2APIC; } + + /* CPUID[1:EDX].APIC is dynamic */ + if (env->features[FEAT_1_EDX] & CPUID_APIC) { + reg_values[3].Reg32 |=3D CPUID_APIC; + } else { + reg_values[3].Reg32 &=3D ~CPUID_APIC; + } } =20 /* Dynamic depending on XCR0 and XSS, so query DefaultResult */ @@ -2725,9 +2725,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) =20 memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); prop.X64MsrExitBitmap.UnhandledMsrs =3D 1; - if (!whpx_irqchip_in_kernel()) { - prop.X64MsrExitBitmap.ApicBaseMsrWrite =3D 1; - } + prop.X64MsrExitBitmap.ApicBaseMsrWrite =3D 1; =20 hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, diff --git a/target/i386/whpx/whpx-apic.c b/target/i386/whpx/whpx-apic.c index f26ecaf6e8..65629ca45f 100644 --- a/target/i386/whpx/whpx-apic.c +++ b/target/i386/whpx/whpx-apic.c @@ -90,9 +90,70 @@ static void whpx_get_apic_state(APICCommonState *s, apic_next_timer(s, s->initial_count_load_time); } =20 -static int whpx_apic_set_base(APICCommonState *s, uint64_t val) +static int apic_set_base_check(APICCommonState *s, uint64_t val) { - s->apicbase =3D val; + /* Enable x2apic when x2apic is not supported by CPU */ + if (!cpu_has_x2apic_feature(&s->cpu->env) && + val & MSR_IA32_APICBASE_EXTD) { + return -1; + } + + /* + * Transition into invalid state + * (s->apicbase & MSR_IA32_APICBASE_ENABLE =3D=3D 0) && + * (s->apicbase & MSR_IA32_APICBASE_EXTD) =3D=3D 1 + */ + if (!(val & MSR_IA32_APICBASE_ENABLE) && + (val & MSR_IA32_APICBASE_EXTD)) { + return -1; + } + + /* Invalid transition from disabled mode to x2APIC */ + if (!(s->apicbase & MSR_IA32_APICBASE_ENABLE) && + !(s->apicbase & MSR_IA32_APICBASE_EXTD) && + (val & MSR_IA32_APICBASE_ENABLE) && + (val & MSR_IA32_APICBASE_EXTD)) { + return -1; + } + + /* Invalid transition from x2APIC to xAPIC */ + if ((s->apicbase & MSR_IA32_APICBASE_ENABLE) && + (s->apicbase & MSR_IA32_APICBASE_EXTD) && + (val & MSR_IA32_APICBASE_ENABLE) && + !(val & MSR_IA32_APICBASE_EXTD)) { + return -1; + } + + return 0; +} + +static int apic_set_base(APICCommonState *s, uint64_t val) +{ + if (apic_set_base_check(s, val) < 0) { + return -1; + } + + s->apicbase =3D (val & MSR_IA32_APICBASE_BASE) | + (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE)); + if (!(val & MSR_IA32_APICBASE_ENABLE)) { + s->apicbase &=3D ~MSR_IA32_APICBASE_ENABLE; + cpu_clear_apic_feature(&s->cpu->env); + } + + /* Transition from disabled mode to xAPIC */ + if (!(s->apicbase & MSR_IA32_APICBASE_ENABLE) && + (val & MSR_IA32_APICBASE_ENABLE)) { + s->apicbase |=3D MSR_IA32_APICBASE_ENABLE; + cpu_set_apic_feature(&s->cpu->env); + } + + /* Transition from xAPIC to x2APIC */ + if (cpu_has_x2apic_feature(&s->cpu->env) && + !(s->apicbase & MSR_IA32_APICBASE_EXTD) && + (val & MSR_IA32_APICBASE_EXTD)) { + s->apicbase |=3D MSR_IA32_APICBASE_EXTD; + } + return 0; } =20 @@ -235,6 +296,10 @@ static void whpx_apic_mem_write(void *opaque, hwaddr a= ddr, static const MemoryRegionOps whpx_apic_io_ops =3D { .read =3D whpx_apic_mem_read, .write =3D whpx_apic_mem_write, + .impl.min_access_size =3D 1, + .impl.max_access_size =3D 4, + .valid.min_access_size =3D 1, + .valid.max_access_size =3D 4, .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 @@ -262,7 +327,7 @@ static void whpx_apic_class_init(ObjectClass *klass, co= nst void *data) =20 k->realize =3D whpx_apic_realize; k->reset =3D whpx_apic_reset; - k->set_base =3D whpx_apic_set_base; + k->set_base =3D apic_set_base; k->set_tpr =3D whpx_apic_set_tpr; k->get_tpr =3D whpx_apic_get_tpr; k->post_load =3D whpx_apic_post_load; --=20 2.50.1 (Apple Git-155)