From nobody Sun Apr 12 04:21:39 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=1771783535; cv=none; d=zohomail.com; s=zohoarc; b=In0v5Lvgt/U1Og3H3lSJVRvlkPbOBzvfGX9pjF/G8j5SdMITenPy05BERLQAcOxBaJml33oKxzWFxvj8zaZVSKZkjMXdZEXh4v6HtXfiwn6FIh3+qJSnzi0nIAAMw39lP5SLEKGH0aTeDQYSs1ZrN0O6nUSzP8if4sKwGR8IZGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771783535; 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=S/dHE8eF2fHwf6vYtZnHF6VOZ8DfoSaTTU4n/v9usbN4D5oJ67CWmSkOGoiWJqh5GiaU4ifcRF7nFmKC8acG4zN6mZjh91I27s5kXhSyWovY9dnwJPqOPEL/wjqmnK/9M1q+DgqqIWntQexfrX2nOHIlcuHuT8/RUcSxcroONDQ= 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 1771783535083472.61781435260866; Sun, 22 Feb 2026 10:05:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuDnd-0000LY-Fo; Sun, 22 Feb 2026 13:03:21 -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 1vuDnc-0000Hh-9s for qemu-devel@nongnu.org; Sun, 22 Feb 2026 13:03:20 -0500 Received: from qs-2007c-snip4-4.eps.apple.com ([57.103.84.155] 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 1vuDna-0000Wo-Gq for qemu-devel@nongnu.org; Sun, 22 Feb 2026 13:03:20 -0500 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-12 (Postfix) with ESMTPS id E801218004FB; Sun, 22 Feb 2026 18:03:15 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-12 (Postfix) with ESMTPSA id 85B411800123; Sun, 22 Feb 2026 18:03:13 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1771783397; x=1774375397; bh=tErMiEuDLXt0dMED3y+T60xeOyEgc7UicdCqP1DD7/0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:x-icloud-hme; b=Op3K2jEKPjFho1dQ7anuF1levuYMOqETfmGLNF7w3jyWim31ACmWsgK3sy4pACnHkEsWBWe0t8yarxtNP3dGqjP0XiUY45dE/33vdfHGJutV+nfjYYvQyrNNwSlEyNAktqVlOinc97L2bA1styoQnTQ9IIZiw6Nqdf6c1qyx1P8jrxhBarowGoUXxpsnsmld6iL/3I/fYJYbj9NUVIcgkHxS2evjehOgO+6iGILF4Fes1EbXnBVshYhoRyUaXpsYG2fU+Db1J2vkZTv7zM2fdLgyaz6aTIANldDgewcKKgHNKYlvA6tBg0NNHHDkPesyRVOUMx5MyibTCE2I+62E5A== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Mohamed Mediouni , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , Cameron Esfahani , qemu-arm@nongnu.org, Magnus Kulke , Paolo Bonzini , Bernhard Beschow , Pedro Barbuda , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Zhao Liu , Roman Bolshakov , Phil Dennis-Jordan , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Wei Liu Subject: [PATCH v4 15/16] whpx: common, i386, arm: rework state levels Date: Sun, 22 Feb 2026 19:02:39 +0100 Message-ID: <20260222180241.14621-16-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260222180241.14621-1-mohamed@unpredictable.fr> References: <20260222180241.14621-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: I9P_eX_a5BMnri4qMHkJga_E33NOfwG4 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIyMDE3NCBTYWx0ZWRfX1ISfOjkXk6jf vw861KeaAiTq+kKRsbGBznhYj8Me9YHR8rmzlW1OQnqfnaAQt/+CGbPQZGsHvbj9liaj6fq4lWB 28wVpmKT7RckQAFbVtuekR2RQxYjqkto6izutJDtN6amBRSKVOEy0QfKng7mW4oqQow5KTSU1A0 7YcOpv0+HoKeI6oBJ9H5AP7tCq4PoZRBGKAUJP0uGaixSR118qb5NE5zm3Z4wEvRdh6HNpETxm7 TrxoJFJlLjkc+0TTZUZAUlXVt+tr7P6O60l9v2G4tNJwfo24fWbu/DNr3BuhugxBknvZh5j9Xqj TsxXKBlqO5qwio5LC7sh1xT+2/A0imhBI4ci+etz+9IT+cxwJcPUpPQmCMSE9Y= X-Authority-Info-Out: v=2.4 cv=AN8t5o3d c=1 sm=1 tr=0 ts=699b44e5 cx=c_apl:c_apl_out:c_pps a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==: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: I9P_eX_a5BMnri4qMHkJga_E33NOfwG4 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-22_04,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-2602220174 X-JNJ: AAAAAAABUztvXO0nq/M6+hP+bVmwCiMAQ0v+LuH4lOkWqvpvTgjoTE+CYnD6V2OT9JWRtIyfyW+UmPocROTmhJpG8CBw/wmhV/cAQCwQB+DovIKu5MBjqG1LkZnXzdZsV26VT0+vdXWKBSwOOiwcYiLkexrd44dTPihTCoOHQV4O5j2W3+SySS74Vi5gX0Y8C8PSO3Dv05QMZZSlkTzkkwSi5jj4lSFiH6VMEFGnFCYHfM0XZ4dahif17lThLZOG51UR18AamGRKQ0PhjplgSndo/Vfj+w/dEZXuWZpw8yumEaX+mtjC4BCWhZUwU/GaaVf7D06hR/m/UJKfOJxwTnfEJueKYtpMDJqG7d9kvAKJN9RsQJzwAjFYtZcght/yw+U57EA4kBlsGrt0x4XqvXlDwcDNbsbi6A/XnBBEBfAENxwzUsvFbcgVULusj9JEnfiraMyO3OXrvZ/t4yxA0Lm7JWTfdPEmJRsGpev7pJJwnGmwdc/qTZXv8i9SOnVma6oGzj8BCiAFMvXE2SMz5JKToINDwGDeRpvVHwtQeJ7ZaNEk2yakjbIsEpysyzVW4xxLgwtkMQuJhJL90wH99gSul4kOYhhDKmWi4qSISrqTBbiQY9e1JZURPx+gqLUc5x0S8CyTZJpuucApfPdi7hnL+6QZjK86Q37saR3ve13G+1nIdqD59vQqtGzKDrBlmIxmz0OkCkUTXSiWI/OnJs+8BAOm6lh8xs6lIjsCd3Czes011PPOYRe2RgQMnYL0XcmNWtuAA9n3uv8AxG/8qIiXBWBVkqC9FbQv 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.155; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.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: 1771783536421158500 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)