From nobody Sun Apr 12 04:21:27 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1771836214; cv=none; d=zohomail.com; s=zohoarc; b=aDcDOu7rtDXju93qJ0VkX33wAzKh14/4vgZ/wOEoYMkF6UGr/aYb7eablXgXPIvmXysukusP8i5BP+SQ0O3LrKFP3dNsMT15P46o9Xg3djf3w7laDTa/8Ri6EfZiM3M8sByXTBKR/ujt4CS/dWcygzwv0lMUJBNG9+rqQPFIjKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771836214; h=Content-Type: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=tErMiEuDLXt0dMED3y+T60xeOyEgc7UicdCqP1DD7/0=; b=bZJoIXWaN0gF5sIntQAIscMu/+yOMYVkll2oTJTSgch6kae246OgWDrT5wh+D6vFUkDDjFyQUhoctZ4GZKgUM//loT24LPW3wou1ZNc77dqBeH8Mv8s/3PTbQBi2F67+ox3ZO3UHhpXdfHWo+S+EC07ZSVqFRA4eRGQKoZotLSo= 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 1771836214555906.7233085351105; Mon, 23 Feb 2026 00:43:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuRSY-0000ns-Gk; Mon, 23 Feb 2026 03:38:30 -0500 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 1vuRSS-0000UP-Q8 for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:38:24 -0500 Received: from p-east2-cluster3-host3-snip4-5.eps.apple.com ([57.103.77.156] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vuRSP-0002Gi-BK for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:38:23 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-60-percent-12 (Postfix) with ESMTPS id CDA31180020E; Mon, 23 Feb 2026 08:38:15 +0000 (UTC) Received: from localhost.localdomain (unknown [17.42.251.67]) by p00-icloudmta-asmtp-us-east-1a-60-percent-12 (Postfix) with ESMTPSA id B88041800179; Mon, 23 Feb 2026 08:38:12 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1771835900; x=1774427900; bh=tErMiEuDLXt0dMED3y+T60xeOyEgc7UicdCqP1DD7/0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:x-icloud-hme; b=edjSSTnRMQ7/LG5/BoJr0aULbymu5OW913C06fZsEWmnC2N/k0PvELnTgjN2eHyJTVc7Ovb33+De5L6juiHGbtNwNmSJrCieBpFWuNbF5Nx3qHSFTrUA90R0FPDJQ9g5CDPpeT+8pz9U7EzR5tGulfhUsUo8/scwinXCd2wU7qClyT+ET5kkY47kbmgfKNchrq3NkvYjezOF0zVLdDhUxYc03UZSioeOtIzT7iFNPwdYVZPGBEzqA2PTczmIccVNaOw5Wk6X+wAjhVrhPlxgLBpoyGtn61MOQnia99ZvVy9Y4lFj31T1mnr8/IhWW7HUvAIPETeC8OZAsfefucvwoQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Cameron Esfahani , Magnus Kulke , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Phil Dennis-Jordan , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Wei Liu , Roman Bolshakov , Magnus Kulke , Peter Maydell , Bernhard Beschow , qemu-arm@nongnu.org, Mohamed Mediouni , Pedro Barbuda , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu Subject: [PATCH v5 15/27] whpx: common, i386, arm: rework state levels Date: Mon, 23 Feb 2026 09:37:21 +0100 Message-ID: <20260223083734.48533-16-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260223083734.48533-1-mohamed@unpredictable.fr> References: <20260223083734.48533-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: CKG1-Z0D2FapmAPSjki1-TKiZv_j0cFe X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIzMDA3NiBTYWx0ZWRfXynRb3+vZnTMJ h4Qwq3rCxAvKHOcizEuVzuyIR6pc+cFaqd17At5mWn+SKwMueG1NlORUU+0bIV9q/axUj30i6L4 Cc4SCL+fFHtELWyzDR8m8jqVUaMkVMd35m7VHyTQ5ngRzVCYrOuuFIeBWrZvpyGck1A70gVMmcP U6AMqMws1R10nOyuAA39Tt99POxhe0LrE7CPbSIyXauwTv5bamebDatXr3Q8yZs47HQN5Kf+G4B fREpqFBB/wZkXi5hDPU9rW/FLgOLpiRfckidb540Hn9cXHJEDpQSE9OXhQLjpDnyHkuvHjRh5QF 8aNve28SG6TObeT6H7mSfpgIY2nUPiEMrTsj3qbAX5WmsRZGifc1tXZCU78xKc= X-Authority-Info-Out: v=2.4 cv=AN8t5o3d c=1 sm=1 tr=0 ts=699c11fa cx=c_apl:c_apl_out:c_pps a=YrL12D//S6tul8v/L+6tKg==:117 a=YrL12D//S6tul8v/L+6tKg==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=KKAkSRfTAAAA:8 a=N0RsYbKkH9eAvmUnK9wA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-GUID: CKG1-Z0D2FapmAPSjki1-TKiZv_j0cFe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-23_01,2026-02-20_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 clxscore=1030 malwarescore=0 adultscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602230076 X-JNJ: AAAAAAABrSrlbG57qK7QLuw8XCPEToBrZUf6E/0LH8Y4JUAP00hZ7+xwQWLjhaoiYU2pdeX+QI3Q/WoSmUhwmx3Bk/mKV4mp9Ylqlahm+prZBnU6rp6mJSVuwlJJCX3r3qmi2khFbBD547DbCx1EboQ1kWs9odXExY/wsW5E3WLJNOkxtHYjAQF3aaEJJYQrAHomZm8RxoH5XgAPn5dSdICbLGhwB6Tb14jKFIwffMoaMSp7y+6UC24itYL3gPogS4muDH7/ow883xyMguhdsTqvskRdEugpcKtlE+mYzqyyOxnTHIykuiJD4CB6haOqtsBRsFotMpQ2f1bBLerVyT/QuYI5uBXksCuqd14B5xZxDfdVCB7qEoxMS9+BngC2N17D8W8KKbUT7GX17dOHLYMfapaA4L/OZQoQ5tLkF1SUF9RXQwq7FxmutlJ+OOnmacn/YT2lRP6sZzi6Vbrkw+lljGX+7axuzIfngXSLTs5duB1MB+0fvhaV1ZeKB8pn/1A2Zg25CfubB+iXrb4x9txbyLcLSLElFmzK0j9xaoBxR2ygDPPE1Q8i4+SxD6VTe5s9U3RokHZCCYQQGj7R2JiB+KTjXgtljLosmWGmOwkBA72eVCn+WgniW4h4HQxj+kViFBNQybbVz50hWRQ7/OGimKGTnHTPrKKBYx37RJO6jeBTkgTLAd+vHh9brtXCsPkPf5R6vW/OunvEJQSqQBwbhJlDcE/qbM7Ig6+48cYUEWIyLH7l0Rjf8VDyqAH91d1C1wYIMbb8HrKH+TlT/kLqa4gSoJDdFH6uLGI= 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.77.156; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 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_CERTIFIED_BLOCKED=0.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1771836214896158500 Change state levels from a set of ifdefs to an enum. Make register state loads use state levels too. Signed-off-by: Mohamed Mediouni Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- accel/whpx/whpx-common.c | 8 ++++---- include/system/whpx-accel-ops.h | 16 ++++++++++------ include/system/whpx-all.h | 6 ++++-- target/arm/whpx/whpx-all.c | 8 ++++---- target/i386/whpx/whpx-all.c | 16 ++++++++-------- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c index 88eef55799..4863fc8663 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -46,7 +46,7 @@ struct WHPDispatch whp_dispatch; void whpx_flush_cpu_state(CPUState *cpu) { if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty =3D false; } } @@ -180,7 +180,7 @@ int whpx_last_vcpu_stopping(CPUState *cpu) static void do_whpx_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data a= rg) { if (!cpu->vcpu_dirty) { - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); cpu->vcpu_dirty =3D true; } } @@ -188,14 +188,14 @@ static void do_whpx_cpu_synchronize_state(CPUState *c= pu, run_on_cpu_data arg) static void do_whpx_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg) { - whpx_set_registers(cpu, WHPX_SET_RESET_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RESET_STATE); cpu->vcpu_dirty =3D false; } =20 static void do_whpx_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg) { - whpx_set_registers(cpu, WHPX_SET_FULL_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_FULL_STATE); cpu->vcpu_dirty =3D false; } =20 diff --git a/include/system/whpx-accel-ops.h b/include/system/whpx-accel-op= s.h index ed9d4c49f4..4b2a732654 100644 --- a/include/system/whpx-accel-ops.h +++ b/include/system/whpx-accel-ops.h @@ -22,11 +22,15 @@ void whpx_cpu_synchronize_post_reset(CPUState *cpu); void whpx_cpu_synchronize_post_init(CPUState *cpu); void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu); =20 -/* state subset only touched by the VCPU itself during runtime */ -#define WHPX_SET_RUNTIME_STATE 1 -/* state subset modified during VCPU reset */ -#define WHPX_SET_RESET_STATE 2 -/* full state set, modified during initialization or on vmload */ -#define WHPX_SET_FULL_STATE 3 +typedef enum WHPXStateLevel { + /* subset of runtime state for faster returns from vmexit */ + WHPX_LEVEL_FAST_RUNTIME_STATE, + /* state subset only touched by the VCPU itself during runtime */ + WHPX_LEVEL_RUNTIME_STATE, + /* state subset modified during VCPU reset */ + WHPX_LEVEL_RESET_STATE, + /* full state set, modified during initialization or on vmload */ + WHPX_LEVEL_FULL_STATE +} WHPXStateLevel; =20 #endif /* TARGET_I386_WHPX_ACCEL_OPS_H */ diff --git a/include/system/whpx-all.h b/include/system/whpx-all.h index b831c463b0..2cbea71b14 100644 --- a/include/system/whpx-all.h +++ b/include/system/whpx-all.h @@ -2,10 +2,12 @@ #ifndef SYSTEM_WHPX_ALL_H #define SYSTEM_WHPX_ALL_H =20 +#include "system/whpx-accel-ops.h" + /* Called by whpx-common */ int whpx_vcpu_run(CPUState *cpu); -void whpx_get_registers(CPUState *cpu); -void whpx_set_registers(CPUState *cpu, int level); +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level); +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level); int whpx_accel_init(AccelState *as, MachineState *ms); void whpx_cpu_instance_init(CPUState *cs); HRESULT whpx_set_exception_exit_bitmap(UINT64 exceptions); diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c index 9a9a19c196..a4d54b027f 100644 --- a/target/arm/whpx/whpx-all.c +++ b/target/arm/whpx/whpx-all.c @@ -418,7 +418,7 @@ int whpx_vcpu_run(CPUState *cpu) do { bool advance_pc =3D false; if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty =3D false; } =20 @@ -483,7 +483,7 @@ int whpx_vcpu_run(CPUState *cpu) default: error_report("WHPX: Unexpected VP exit code 0x%08x", vcpu->exit_ctx.ExitReason); - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); bql_lock(); qemu_system_guest_panicked(cpu_get_crash_info(cpu)); bql_unlock(); @@ -517,7 +517,7 @@ static void clean_whv_register_value(WHV_REGISTER_VALUE= *val) memset(val, 0, sizeof(WHV_REGISTER_VALUE)); } =20 -void whpx_get_registers(CPUState *cpu) +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { ARMCPU *arm_cpu =3D ARM_CPU(cpu); CPUARMState *env =3D &arm_cpu->env; @@ -564,7 +564,7 @@ void whpx_get_registers(CPUState *cpu) aarch64_restore_sp(env, arm_current_el(env)); } =20 -void whpx_set_registers(CPUState *cpu, int level) +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { ARMCPU *arm_cpu =3D ARM_CPU(cpu); CPUARMState *env =3D &arm_cpu->env; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index baa3169c55..c09d9affef 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -367,7 +367,7 @@ static uint64_t whpx_cr8_to_apic_tpr(uint64_t cr8) return cr8 << 4; } =20 -void whpx_set_registers(CPUState *cpu, int level) +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; AccelCPUState *vcpu =3D cpu->accel; @@ -386,7 +386,7 @@ void whpx_set_registers(CPUState *cpu, int level) * Following MSRs have side effects on the guest or are too heavy for * runtime. Limit them to full state update. */ - if (level >=3D WHPX_SET_RESET_STATE) { + if (level >=3D WHPX_LEVEL_RESET_STATE) { whpx_set_tsc(cpu); } =20 @@ -583,7 +583,7 @@ static void whpx_get_xcrs(CPUState *cpu) cpu_env(cpu)->xcr0 =3D xcr0.Reg64; } =20 -void whpx_get_registers(CPUState *cpu) +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; AccelCPUState *vcpu =3D cpu->accel; @@ -770,10 +770,10 @@ static int emulate_instruction(CPUState *cpu, const u= int8_t *insn_bytes, size_t struct x86_decode decode =3D { 0 }; x86_insn_stream stream =3D { .bytes =3D insn_bytes, .len =3D insn_len = }; =20 - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE); decode_instruction_stream(env, &decode, &stream); exec_instruction(env, &decode); - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE); =20 return 0; } @@ -1589,7 +1589,7 @@ int whpx_vcpu_run(CPUState *cpu) =20 do { if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty =3D false; } =20 @@ -1796,7 +1796,7 @@ int whpx_vcpu_run(CPUState *cpu) break; } case WHvRunVpExitReasonException: - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); =20 if ((vcpu->exit_ctx.VpException.ExceptionType =3D=3D WHvX64ExceptionTypeDebugTrapOrFault) && @@ -1828,7 +1828,7 @@ int whpx_vcpu_run(CPUState *cpu) default: error_report("WHPX: Unexpected VP exit code %d", vcpu->exit_ctx.ExitReason); - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); bql_lock(); qemu_system_guest_panicked(cpu_get_crash_info(cpu)); bql_unlock(); --=20 2.50.1 (Apple Git-155)