whpx: common, i386, arm: rework state levels
Change state levels from a set of ifdefs to an enum. Make register state loads use state levels too. Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/r/20260223233950.96076-16-mohamed@unpredictable.fr Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Mohamed Mediouni committed
Feb 24, 2026 at 00:39 UTC
49f31a967140e65babe2f78fe6e6859342446619
5 files changed
+30
-24
accel/whpx/whpx-common.c
+4
-4
@@ -46,7 +46,7 @@ struct WHPDispatch whp_dispatch;
46
void whpx_flush_cpu_state(CPUState *cpu)
47
{
48
if (cpu->vcpu_dirty) {
49
- whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);
49
+ whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE);
50
cpu->vcpu_dirty = false;
51
}
52
}
@@ -180,7 +180,7 @@ int whpx_last_vcpu_stopping(CPUState *cpu)
180
static void do_whpx_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
181
{
182
if (!cpu->vcpu_dirty) {
183
- whpx_get_registers(cpu);
183
+ whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE);
184
cpu->vcpu_dirty = true;
185
}
186
}
@@ -188,14 +188,14 @@ static void do_whpx_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
188
static void do_whpx_cpu_synchronize_post_reset(CPUState *cpu,
189
run_on_cpu_data arg)
190
{
191
- whpx_set_registers(cpu, WHPX_SET_RESET_STATE);
191
+ whpx_set_registers(cpu, WHPX_LEVEL_RESET_STATE);
192
cpu->vcpu_dirty = false;
193
}
194
195
static void do_whpx_cpu_synchronize_post_init(CPUState *cpu,
196
run_on_cpu_data arg)
197
{
198
- whpx_set_registers(cpu, WHPX_SET_FULL_STATE);
198
+ whpx_set_registers(cpu, WHPX_LEVEL_FULL_STATE);
199
cpu->vcpu_dirty = false;
200
}
201
include/system/whpx-accel-ops.h
+10
-6
@@ -22,11 +22,15 @@ void whpx_cpu_synchronize_post_reset(CPUState *cpu);
22
void whpx_cpu_synchronize_post_init(CPUState *cpu);
23
void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu);
24
25
-/* state subset only touched by the VCPU itself during runtime */
26
-#define WHPX_SET_RUNTIME_STATE 1
27
-/* state subset modified during VCPU reset */
28
-#define WHPX_SET_RESET_STATE 2
29
-/* full state set, modified during initialization or on vmload */
30
-#define WHPX_SET_FULL_STATE 3
25
+typedef enum WHPXStateLevel {
26
+ /* subset of runtime state for faster returns from vmexit */
27
+ WHPX_LEVEL_FAST_RUNTIME_STATE,
28
+ /* state subset only touched by the VCPU itself during runtime */
29
+ WHPX_LEVEL_RUNTIME_STATE,
30
+ /* state subset modified during VCPU reset */
31
+ WHPX_LEVEL_RESET_STATE,
32
+ /* full state set, modified during initialization or on vmload */
33
+ WHPX_LEVEL_FULL_STATE
34
+} WHPXStateLevel;
35
36
#endif /* TARGET_I386_WHPX_ACCEL_OPS_H */
include/system/whpx-all.h
+4
-2
@@ -2,10 +2,12 @@
2
#ifndef SYSTEM_WHPX_ALL_H
3
#define SYSTEM_WHPX_ALL_H
4
5
+#include "system/whpx-accel-ops.h"
6
+
7
/* Called by whpx-common */
8
int whpx_vcpu_run(CPUState *cpu);
7
-void whpx_get_registers(CPUState *cpu);
8
-void whpx_set_registers(CPUState *cpu, int level);
9
+void whpx_get_registers(CPUState *cpu, WHPXStateLevel level);
10
+void whpx_set_registers(CPUState *cpu, WHPXStateLevel level);
11
int whpx_accel_init(AccelState *as, MachineState *ms);
12
void whpx_cpu_instance_init(CPUState *cs);
13
HRESULT whpx_set_exception_exit_bitmap(UINT64 exceptions);
target/arm/whpx/whpx-all.c
+4
-4
@@ -417,7 +417,7 @@ int whpx_vcpu_run(CPUState *cpu)
417
do {
418
bool advance_pc = false;
419
if (cpu->vcpu_dirty) {
420
- whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);
420
+ whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE);
421
cpu->vcpu_dirty = false;
422
}
423
@@ -482,7 +482,7 @@ int whpx_vcpu_run(CPUState *cpu)
482
default:
483
error_report("WHPX: Unexpected VP exit code 0x%08x",
484
vcpu->exit_ctx.ExitReason);
485
- whpx_get_registers(cpu);
485
+ whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE);
486
bql_lock();
487
qemu_system_guest_panicked(cpu_get_crash_info(cpu));
488
bql_unlock();
@@ -516,7 +516,7 @@ static void clean_whv_register_value(WHV_REGISTER_VALUE *val)
516
memset(val, 0, sizeof(WHV_REGISTER_VALUE));
517
}
518
519
-void whpx_get_registers(CPUState *cpu)
519
+void whpx_get_registers(CPUState *cpu, WHPXStateLevel level)
520
{
521
ARMCPU *arm_cpu = ARM_CPU(cpu);
522
CPUARMState *env = &arm_cpu->env;
@@ -563,7 +563,7 @@ void whpx_get_registers(CPUState *cpu)
563
aarch64_restore_sp(env, arm_current_el(env));
564
}
565
566
-void whpx_set_registers(CPUState *cpu, int level)
566
+void whpx_set_registers(CPUState *cpu, WHPXStateLevel level)
567
{
568
ARMCPU *arm_cpu = ARM_CPU(cpu);
569
CPUARMState *env = &arm_cpu->env;
target/i386/whpx/whpx-all.c
+8
-8
@@ -367,7 +367,7 @@ static uint64_t whpx_cr8_to_apic_tpr(uint64_t cr8)
367
return cr8 << 4;
368
}
369
370
-void whpx_set_registers(CPUState *cpu, int level)
370
+void whpx_set_registers(CPUState *cpu, WHPXStateLevel level)
371
{
372
struct whpx_state *whpx = &whpx_global;
373
AccelCPUState *vcpu = cpu->accel;
@@ -386,7 +386,7 @@ void whpx_set_registers(CPUState *cpu, int level)
386
* Following MSRs have side effects on the guest or are too heavy for
387
* runtime. Limit them to full state update.
388
*/
389
- if (level >= WHPX_SET_RESET_STATE) {
389
+ if (level >= WHPX_LEVEL_RESET_STATE) {
390
whpx_set_tsc(cpu);
391
}
392
@@ -583,7 +583,7 @@ static void whpx_get_xcrs(CPUState *cpu)
583
cpu_env(cpu)->xcr0 = xcr0.Reg64;
584
}
585
586
-void whpx_get_registers(CPUState *cpu)
586
+void whpx_get_registers(CPUState *cpu, WHPXStateLevel level)
587
{
588
struct whpx_state *whpx = &whpx_global;
589
AccelCPUState *vcpu = cpu->accel;
@@ -770,10 +770,10 @@ static int emulate_instruction(CPUState *cpu, const uint8_t *insn_bytes, size_t
770
struct x86_decode decode = { 0 };
771
x86_insn_stream stream = { .bytes = insn_bytes, .len = insn_len };
772
773
- whpx_get_registers(cpu);
773
+ whpx_get_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE);
774
decode_instruction_stream(env, &decode, &stream);
775
exec_instruction(env, &decode);
776
- whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);
776
+ whpx_set_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE);
777
778
return 0;
779
}
@@ -1589,7 +1589,7 @@ int whpx_vcpu_run(CPUState *cpu)
1589
1590
do {
1591
if (cpu->vcpu_dirty) {
1592
- whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);
1592
+ whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE);
1593
cpu->vcpu_dirty = false;
1594
}
1595
@@ -1796,7 +1796,7 @@ int whpx_vcpu_run(CPUState *cpu)
1796
break;
1797
}
1798
case WHvRunVpExitReasonException:
1799
- whpx_get_registers(cpu);
1799
+ whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE);
1800
1801
if ((vcpu->exit_ctx.VpException.ExceptionType ==
1802
WHvX64ExceptionTypeDebugTrapOrFault) &&
@@ -1828,7 +1828,7 @@ int whpx_vcpu_run(CPUState *cpu)
1828
default:
1829
error_report("WHPX: Unexpected VP exit code %d",
1830
vcpu->exit_ctx.ExitReason);
1831
- whpx_get_registers(cpu);
1831
+ whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE);
1832
bql_lock();
1833
qemu_system_guest_panicked(cpu_get_crash_info(cpu));
1834
bql_unlock();