Change state levels from a set of ifdefs to an enum. Make register state loads use state levels too.
Signed-off-by: Mohamed Mediouni <[email protected]> --- 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 245e64a12f..06038dd7f1 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -46,7 +46,7 @@ struct WHPDispatch whp_dispatch; void 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 = 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 arg) { if (!cpu->vcpu_dirty) { - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); cpu->vcpu_dirty = true; } } @@ -188,14 +188,14 @@ static void do_whpx_cpu_synchronize_state(CPUState *cpu, 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 = false; } 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 = false; } diff --git a/include/system/whpx-accel-ops.h b/include/system/whpx-accel-ops.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); -/* 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; #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 +#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 c8d71a252e..a1be82b878 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 = false; if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty = false; } @@ -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)); } -void whpx_get_registers(CPUState *cpu) +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { ARMCPU *arm_cpu = ARM_CPU(cpu); CPUARMState *env = &arm_cpu->env; @@ -564,7 +564,7 @@ void whpx_get_registers(CPUState *cpu) aarch64_restore_sp(env, arm_current_el(env)); } -void whpx_set_registers(CPUState *cpu, int level) +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { ARMCPU *arm_cpu = ARM_CPU(cpu); CPUARMState *env = &arm_cpu->env; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 0e8fb0e72e..7bbe63e794 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; } -void whpx_set_registers(CPUState *cpu, int level) +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx = &whpx_global; AccelCPUState *vcpu = 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 >= WHPX_SET_RESET_STATE) { + if (level >= WHPX_LEVEL_RESET_STATE) { whpx_set_tsc(cpu); } @@ -582,7 +582,7 @@ static void whpx_get_xcrs(CPUState *cpu) cpu_env(cpu)->xcr0 = xcr0.Reg64; } -void whpx_get_registers(CPUState *cpu) +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx = &whpx_global; AccelCPUState *vcpu = cpu->accel; @@ -768,10 +768,10 @@ static int emulate_instruction(CPUState *cpu, const uint8_t *insn_bytes, size_t struct x86_decode decode = { 0 }; x86_insn_stream stream = { .bytes = insn_bytes, .len = insn_len }; - 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); return 0; } @@ -1587,7 +1587,7 @@ int whpx_vcpu_run(CPUState *cpu) do { if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty = false; } @@ -1794,7 +1794,7 @@ int whpx_vcpu_run(CPUState *cpu) break; } case WHvRunVpExitReasonException: - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); if ((vcpu->exit_ctx.VpException.ExceptionType == WHvX64ExceptionTypeDebugTrapOrFault) && @@ -1826,7 +1826,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(); -- 2.50.1 (Apple Git-155)
