From nobody Sun Apr 5 18:07:49 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=1774305427; cv=none; d=zohomail.com; s=zohoarc; b=I1i3wies6lhcBF/1gihbYXzq1ukXDzdXmsZCxxY+6W54+0kCmmZU0FwxN6xhCCX5kV4eXzVtvSN9O4rA60t7mE1ZrjE3qG/yEKJwS1Lsz6cBM3537IetKO8NzRXvX4ctWxic6lv8xbXcIviM2tptXmGQalCF9oWnFGPflic6hCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774305427; 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=PdT7IERfl0p/CeTQ+XFKTtOdCZ5WIYKOrnKXReIT4Ds=; b=mL5xgwPaH9KRmEmZyuNFpFrr0s7kgkiFhNfXtOh4L7/4U2UvFV5TvUkJiv0aF+p4RQitGAveuHbs2MXZPQkIgp5wnKtBrWiOa+YsRBOT+tTu3OVexmMvZypnscRb4MDoPKDGYH6ua0tzggNtB2oHT+dtBkMRNEr7lAkSb6zFev4= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774305427600446.24739383572444; Mon, 23 Mar 2026 15:37:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4nre-00061R-GY; Mon, 23 Mar 2026 18:35:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w4nrd-00060y-QG for qemu-devel@nongnu.org; Mon, 23 Mar 2026 18:35:13 -0400 Received: from qs-2007e-snip4-10.eps.apple.com ([57.103.84.180] 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 1w4nrb-00038m-Oc for qemu-devel@nongnu.org; Mon, 23 Mar 2026 18:35:13 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-60-percent-6 (Postfix) with ESMTPS id 4723218000B8; Mon, 23 Mar 2026 22:35:10 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-60-percent-6 (Postfix) with ESMTPSA id A41D41800276; Mon, 23 Mar 2026 22:35:08 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1774305310; x=1776897310; bh=PdT7IERfl0p/CeTQ+XFKTtOdCZ5WIYKOrnKXReIT4Ds=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=I8NdINj1hpOQlipGfw+u4r3efecuiPt3HSDyTom2aBr6U5osvf2mYKlSfEIjfsttmyv7sdQMRFdvpi7Fm4/DC5WOCWZUAv9WJeRlBPkizOr/jsgGohsNDG78zhcNyY1N1cjxhKaUAEW3Ct0ROT4uW3QMnP+8AJVUSAsbvmNTN7StZKQTWgqUlfkmvAw0ernrRwUV4kykYDBhf0HgFLJNB08viCLOEA1pQIXEDHjZoXQTTdqt4CeurwFUsRi1ldRThmSVKoIU6ip0ZyHqLJ8pT/60lOdTjveRW2CRiW/XFEy+iMv/fEPl0M75ZK5q+8bNs1rAKXI7orAiA+iSKUu3YQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Roman Bolshakov , Wei Liu , Pedro Barbuda , Mohamed Mediouni , Phil Dennis-Jordan Subject: [PATCH v2 13/13] whpx: i386: fast runtime state reads Date: Mon, 23 Mar 2026 23:34:34 +0100 Message-ID: <20260323223434.81780-14-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260323223434.81780-1-mohamed@unpredictable.fr> References: <20260323223434.81780-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=QO1lhwLL c=1 sm=1 tr=0 ts=69c1c01e cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=WK8LibQvd4XDxIxmQ_8A:9 X-Proofpoint-ORIG-GUID: wNLytSTucOV3Xj4S8pAkvdffB-7AAeos X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzIzMDE2NyBTYWx0ZWRfX+fMlqLiUTIB1 JPxrXUnu90gQl0zdoqaHnzAwb+6E5Q4WAGPmg/6Pqu4VHHk0oeZMGLmx7ZaMKCJuz2QOQaXk+XY zMe2jr+XFmOKQaXl4lSMJ9jv6CsRIgVgnYg/jfI6fSqSgJHqhitmCuEkbA6hki59/x4er7RhjjE pSeH5w/6FZmgXXL3MCM2XiIZM6y1YykziBffkOYzm43vxc2wb7FD8chP/Oedrrt964wHeG5dWZZ pjUqpIRW9CCGkNTwU3Pc+pAUlv2Ua4j/Y7sAm7IB4bE2ceOnLgB7js89olaeyk+4+sAoDCUvGdN +rf7uUpvxRzLtEA5jhULZmCUkgPU1/nU5hIpG+EjmCS4X1EBz162BOR7uEfWt0= X-Proofpoint-GUID: wNLytSTucOV3Xj4S8pAkvdffB-7AAeos 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-03-23_06,2026-03-23_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 malwarescore=0 clxscore=1030 lowpriorityscore=0 mlxlogscore=760 phishscore=0 mlxscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2603230167 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=lists.gnu.org; Received-SPF: pass client-ip=57.103.84.180; 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: 1774305429498154100 Content-Type: text/plain; charset="utf-8" Now that there's an on-demand interface for fetching CRs and segments, only query GPRs and query everything else on-demand for vmexits. Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 77 +++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index d87afceb08..ff842bf359 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -156,6 +156,26 @@ static const WHV_REGISTER_NAME whpx_register_names[] = =3D { */ }; =20 +static const WHV_REGISTER_NAME whpx_register_names_for_vmexit[] =3D { + /* X64 General purpose registers */ + WHvX64RegisterRax, + WHvX64RegisterRcx, + WHvX64RegisterRdx, + WHvX64RegisterRbx, + WHvX64RegisterRsp, + WHvX64RegisterRbp, + WHvX64RegisterRsi, + WHvX64RegisterRdi, + WHvX64RegisterR8, + WHvX64RegisterR9, + WHvX64RegisterR10, + WHvX64RegisterR11, + WHvX64RegisterR12, + WHvX64RegisterR13, + WHvX64RegisterR14, + WHvX64RegisterR15, +}; + struct whpx_register_set { WHV_REGISTER_VALUE values[RTL_NUMBER_OF(whpx_register_names)]; }; @@ -593,6 +613,47 @@ static void whpx_get_xcrs(CPUState *cpu) cpu_env(cpu)->xcr0 =3D xcr0.Reg64; } =20 +static void whpx_get_registers_for_vmexit(CPUState *cpu, WHPXStateLevel le= vel) +{ + struct whpx_state *whpx =3D &whpx_global; + AccelCPUState *vcpu =3D cpu->accel; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + struct whpx_register_set vcxt; + HRESULT hr; + int idx; + int idx_next; + + assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu)); + + hr =3D whp_dispatch.WHvGetVirtualProcessorRegisters( + whpx->partition, cpu->cpu_index, + whpx_register_names_for_vmexit, + RTL_NUMBER_OF(whpx_register_names_for_vmexit), + &vcxt.values[0]); + if (FAILED(hr)) { + error_report("WHPX: Failed to get virtual processor context, hr=3D= %08lx", + hr); + } + + idx =3D 0; + + /* Indexes for first 16 registers match between HV and QEMU definition= s */ + idx_next =3D 16; + for (idx =3D 0; idx < CPU_NB_REGS; idx +=3D 1) { + env->regs[idx] =3D vcxt.values[idx].Reg64; + } + idx =3D idx_next; + + env->eip =3D vcpu->exit_ctx.VpContext.Rip; + env->eflags =3D vcpu->exit_ctx.VpContext.Rflags; + rflags_to_lflags(env); + + assert(idx =3D=3D RTL_NUMBER_OF(whpx_register_names_for_vmexit)); + + x86_update_hflags(env); +} + void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; @@ -608,7 +669,11 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel = level) =20 assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu)); =20 - if (level > WHPX_LEVEL_FAST_RUNTIME_STATE && !env->tsc_valid) { + if (level =3D=3D WHPX_LEVEL_FAST_RUNTIME_STATE) { + return whpx_get_registers_for_vmexit(cpu, level); + } + + if (!env->tsc_valid) { whpx_get_tsc(cpu); env->tsc_valid =3D !runstate_is_running(); } @@ -623,7 +688,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) hr); } =20 - if (level > WHPX_LEVEL_FAST_RUNTIME_STATE && whpx_irqchip_in_kernel())= { + 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 @@ -680,7 +745,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) env->cr[4] =3D vcxt.values[idx++].Reg64; assert(whpx_register_names[idx] =3D=3D WHvX64RegisterCr8); tpr =3D vcxt.values[idx++].Reg64; - if (level > WHPX_LEVEL_FAST_RUNTIME_STATE && tpr !=3D vcpu->tpr) { + if (tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; cpu_set_apic_tpr(x86_cpu->apic_state, whpx_cr8_to_apic_tpr(tpr)); } @@ -691,9 +756,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) * Extended control registers needs to be handled separately depending * on whether xsave is supported/enabled or not. */ - if (level > WHPX_LEVEL_FAST_RUNTIME_STATE) { - whpx_get_xcrs(cpu); - } + whpx_get_xcrs(cpu); =20 /* 16 XMM registers */ assert(whpx_register_names[idx] =3D=3D WHvX64RegisterXmm0); @@ -768,7 +831,7 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel l= evel) =20 assert(idx =3D=3D RTL_NUMBER_OF(whpx_register_names)); =20 - if (level > WHPX_LEVEL_FAST_RUNTIME_STATE && whpx_irqchip_in_kernel())= { + if (whpx_irqchip_in_kernel()) { whpx_apic_get(x86_cpu->apic_state); } =20 --=20 2.50.1 (Apple Git-155)