From: Mohamed Mediouni <mohamed@unpredictable.fr>
These will be used in the next commit on the x86_64 backend too.
Also move flush_cpu_state as it's used by get_reg/set_reg and the arm64 code.
Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
Reviewed-by: Bernhard Beschow <shentey@gmail.com>
Link: https://lore.kernel.org/r/20260223233950.96076-10-mohamed@unpredictable.fr
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/system/whpx-common.h | 3 +++
accel/whpx/whpx-common.c | 35 ++++++++++++++++++++++++++++++++++
target/arm/whpx/whpx-all.c | 37 +-----------------------------------
3 files changed, 39 insertions(+), 36 deletions(-)
diff --git a/include/system/whpx-common.h b/include/system/whpx-common.h
index b86fe9db6eb..a4e16e13099 100644
--- a/include/system/whpx-common.h
+++ b/include/system/whpx-common.h
@@ -20,6 +20,9 @@ int whpx_first_vcpu_starting(CPUState *cpu);
int whpx_last_vcpu_stopping(CPUState *cpu);
void whpx_memory_init(void);
struct whpx_breakpoint *whpx_lookup_breakpoint_by_addr(uint64_t address);
+void whpx_flush_cpu_state(CPUState *cpu);
+void whpx_get_reg(CPUState *cpu, WHV_REGISTER_NAME reg, WHV_REGISTER_VALUE* val);
+void whpx_set_reg(CPUState *cpu, WHV_REGISTER_NAME reg, WHV_REGISTER_VALUE val);
/* On x64: same as WHvX64ExceptionTypeDebugTrapOrFault */
#define WHPX_INTERCEPT_DEBUG_TRAPS 1
diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c
index c57a0d3f0f9..21e9f1a1781 100644
--- a/accel/whpx/whpx-common.c
+++ b/accel/whpx/whpx-common.c
@@ -46,6 +46,41 @@ static HMODULE hWinHvEmulation;
struct whpx_state whpx_global;
struct WHPDispatch whp_dispatch;
+void whpx_flush_cpu_state(CPUState *cpu)
+{
+ if (cpu->vcpu_dirty) {
+ whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);
+ cpu->vcpu_dirty = false;
+ }
+}
+
+void whpx_get_reg(CPUState *cpu, WHV_REGISTER_NAME reg, WHV_REGISTER_VALUE* val)
+{
+ struct whpx_state *whpx = &whpx_global;
+ HRESULT hr;
+
+ whpx_flush_cpu_state(cpu);
+
+ hr = whp_dispatch.WHvGetVirtualProcessorRegisters(whpx->partition, cpu->cpu_index,
+ ®, 1, val);
+
+ if (FAILED(hr)) {
+ error_report("WHPX: Failed to get register %08x, hr=%08lx", reg, hr);
+ }
+}
+
+void whpx_set_reg(CPUState *cpu, WHV_REGISTER_NAME reg, WHV_REGISTER_VALUE val)
+{
+ struct whpx_state *whpx = &whpx_global;
+ HRESULT hr;
+ hr = whp_dispatch.WHvSetVirtualProcessorRegisters(whpx->partition, cpu->cpu_index,
+ ®, 1, &val);
+
+ if (FAILED(hr)) {
+ error_report("WHPX: Failed to set register %08x, hr=%08lx", reg, hr);
+ }
+}
+
/* Tries to find a breakpoint at the specified address. */
struct whpx_breakpoint *whpx_lookup_breakpoint_by_addr(uint64_t address)
{
diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c
index 0a31c7b9464..0d56e468bdf 100644
--- a/target/arm/whpx/whpx-all.c
+++ b/target/arm/whpx/whpx-all.c
@@ -273,14 +273,6 @@ static struct whpx_sreg_match whpx_sreg_match[] = {
{ WHvArm64RegisterSpEl1, ENCODE_AA64_CP_REG(4, 1, 3, 4, 0) },
};
-static void flush_cpu_state(CPUState *cpu)
-{
- if (cpu->vcpu_dirty) {
- whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);
- cpu->vcpu_dirty = false;
- }
-}
-
HRESULT whpx_set_exception_exit_bitmap(UINT64 exceptions)
{
if (exceptions != 0) {
@@ -313,33 +305,6 @@ void whpx_arch_destroy_vcpu(CPUState *cpu)
/* currently empty on Arm */
}
-static void whpx_get_reg(CPUState *cpu, WHV_REGISTER_NAME reg, WHV_REGISTER_VALUE* val)
-{
- struct whpx_state *whpx = &whpx_global;
- HRESULT hr;
-
- flush_cpu_state(cpu);
-
- hr = whp_dispatch.WHvGetVirtualProcessorRegisters(whpx->partition, cpu->cpu_index,
- ®, 1, val);
-
- if (FAILED(hr)) {
- error_report("WHPX: Failed to get register %08x, hr=%08lx", reg, hr);
- }
-}
-
-static void whpx_set_reg(CPUState *cpu, WHV_REGISTER_NAME reg, WHV_REGISTER_VALUE val)
-{
- struct whpx_state *whpx = &whpx_global;
- HRESULT hr;
- hr = whp_dispatch.WHvSetVirtualProcessorRegisters(whpx->partition, cpu->cpu_index,
- ®, 1, &val);
-
- if (FAILED(hr)) {
- error_report("WHPX: Failed to set register %08x, hr=%08lx", reg, hr);
- }
-}
-
static void whpx_get_global_reg(WHV_REGISTER_NAME reg, WHV_REGISTER_VALUE *val)
{
struct whpx_state *whpx = &whpx_global;
@@ -526,7 +491,7 @@ int whpx_vcpu_run(CPUState *cpu)
if (advance_pc) {
WHV_REGISTER_VALUE pc;
- flush_cpu_state(cpu);
+ whpx_flush_cpu_state(cpu);
pc.Reg64 = vcpu->exit_ctx.MemoryAccess.Header.Pc + 4;
whpx_set_reg(cpu, WHvArm64RegisterPc, pc);
}
--
2.53.0