accel/kvm: Factor kvm_cpu_synchronize_put() out
The same code is duplicated 3 times: factor a common method. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Link: https://lore.kernel.org/r/20251008040715.81513-4-philmd@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
665a8035b7
commit
0de36ecb2b
1 changed files with 19 additions and 28 deletions
|
|
@ -2937,22 +2937,32 @@ void kvm_cpu_synchronize_state(CPUState *cpu)
|
|||
}
|
||||
}
|
||||
|
||||
static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg)
|
||||
static bool kvm_cpu_synchronize_put(CPUState *cpu, KvmPutState state,
|
||||
const char *desc)
|
||||
{
|
||||
Error *err = NULL;
|
||||
int ret = kvm_arch_put_registers(cpu, KVM_PUT_RESET_STATE, &err);
|
||||
int ret = kvm_arch_put_registers(cpu, state, &err);
|
||||
if (ret) {
|
||||
if (err) {
|
||||
error_reportf_err(err, "Restoring resisters after reset: ");
|
||||
error_reportf_err(err, "Restoring resisters %s: ", desc);
|
||||
} else {
|
||||
error_report("Failed to put registers after reset: %s",
|
||||
error_report("Failed to put registers %s: %s", desc,
|
||||
strerror(-ret));
|
||||
}
|
||||
cpu_dump_state(cpu, stderr, CPU_DUMP_CODE);
|
||||
vm_stop(RUN_STATE_INTERNAL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
cpu->vcpu_dirty = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
if (!kvm_cpu_synchronize_put(cpu, KVM_PUT_RESET_STATE, "after reset")) {
|
||||
cpu_dump_state(cpu, stderr, CPU_DUMP_CODE);
|
||||
vm_stop(RUN_STATE_INTERNAL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void kvm_cpu_synchronize_post_reset(CPUState *cpu)
|
||||
|
|
@ -2966,19 +2976,9 @@ void kvm_cpu_synchronize_post_reset(CPUState *cpu)
|
|||
|
||||
static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
Error *err = NULL;
|
||||
int ret = kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE, &err);
|
||||
if (ret) {
|
||||
if (err) {
|
||||
error_reportf_err(err, "Putting registers after init: ");
|
||||
} else {
|
||||
error_report("Failed to put registers after init: %s",
|
||||
strerror(-ret));
|
||||
}
|
||||
if (!kvm_cpu_synchronize_put(cpu, KVM_PUT_FULL_STATE, "after init")) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cpu->vcpu_dirty = false;
|
||||
}
|
||||
|
||||
void kvm_cpu_synchronize_post_init(CPUState *cpu)
|
||||
|
|
@ -3168,20 +3168,11 @@ int kvm_cpu_exec(CPUState *cpu)
|
|||
MemTxAttrs attrs;
|
||||
|
||||
if (cpu->vcpu_dirty) {
|
||||
Error *err = NULL;
|
||||
ret = kvm_arch_put_registers(cpu, KVM_PUT_RUNTIME_STATE, &err);
|
||||
if (ret) {
|
||||
if (err) {
|
||||
error_reportf_err(err, "Putting registers after init: ");
|
||||
} else {
|
||||
error_report("Failed to put registers after init: %s",
|
||||
strerror(-ret));
|
||||
}
|
||||
if (!kvm_cpu_synchronize_put(cpu, KVM_PUT_RUNTIME_STATE,
|
||||
"at runtime")) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
cpu->vcpu_dirty = false;
|
||||
}
|
||||
|
||||
kvm_arch_pre_run(cpu, run);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue