mirror of
https://github.com/qemu/qemu.git
synced 2024-12-04 09:13:39 +08:00
ea375f9ab8
This grand cleanup drops all reset and vmsave/load related synchronization points in favor of four(!) generic hooks: - cpu_synchronize_all_states in qemu_savevm_state_complete (initial sync from kernel before vmsave) - cpu_synchronize_all_post_init in qemu_loadvm_state (writeback after vmload) - cpu_synchronize_all_post_init in main after machine init - cpu_synchronize_all_post_reset in qemu_system_reset (writeback after system reset) These writeback points + the existing one of VCPU exec after cpu_synchronize_state map on three levels of writeback: - KVM_PUT_RUNTIME_STATE (during runtime, other VCPUs continue to run) - KVM_PUT_RESET_STATE (on synchronous system reset, all VCPUs stopped) - KVM_PUT_FULL_STATE (on init or vmload, all VCPUs stopped as well) This level is passed to the arch-specific VCPU state writing function that will decide which concrete substates need to be written. That way, no writer of load, save or reset functions that interact with in-kernel KVM states will ever have to worry about synchronization again. That also means that a lot of reasons for races, segfaults and deadlocks are eliminated. cpu_synchronize_state remains untouched, just as Anthony suggested. We continue to need it before reading or writing of VCPU states that are also tracked by in-kernel KVM subsystems. Consequently, this patch removes many cpu_synchronize_state calls that are now redundant, just like remaining explicit register syncs. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
180 lines
5.6 KiB
C
180 lines
5.6 KiB
C
#include "hw/hw.h"
|
|
#include "hw/boards.h"
|
|
#include "kvm.h"
|
|
|
|
void cpu_save(QEMUFile *f, void *opaque)
|
|
{
|
|
CPUState *env = (CPUState *)opaque;
|
|
unsigned int i, j;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
qemu_put_betls(f, &env->gpr[i]);
|
|
#if !defined(TARGET_PPC64)
|
|
for (i = 0; i < 32; i++)
|
|
qemu_put_betls(f, &env->gprh[i]);
|
|
#endif
|
|
qemu_put_betls(f, &env->lr);
|
|
qemu_put_betls(f, &env->ctr);
|
|
for (i = 0; i < 8; i++)
|
|
qemu_put_be32s(f, &env->crf[i]);
|
|
qemu_put_betls(f, &env->xer);
|
|
qemu_put_betls(f, &env->reserve_addr);
|
|
qemu_put_betls(f, &env->msr);
|
|
for (i = 0; i < 4; i++)
|
|
qemu_put_betls(f, &env->tgpr[i]);
|
|
for (i = 0; i < 32; i++) {
|
|
union {
|
|
float64 d;
|
|
uint64_t l;
|
|
} u;
|
|
u.d = env->fpr[i];
|
|
qemu_put_be64(f, u.l);
|
|
}
|
|
qemu_put_be32s(f, &env->fpscr);
|
|
qemu_put_sbe32s(f, &env->access_type);
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
#if defined(TARGET_PPC64)
|
|
qemu_put_betls(f, &env->asr);
|
|
qemu_put_sbe32s(f, &env->slb_nr);
|
|
#endif
|
|
qemu_put_betls(f, &env->sdr1);
|
|
for (i = 0; i < 32; i++)
|
|
qemu_put_betls(f, &env->sr[i]);
|
|
for (i = 0; i < 2; i++)
|
|
for (j = 0; j < 8; j++)
|
|
qemu_put_betls(f, &env->DBAT[i][j]);
|
|
for (i = 0; i < 2; i++)
|
|
for (j = 0; j < 8; j++)
|
|
qemu_put_betls(f, &env->IBAT[i][j]);
|
|
qemu_put_sbe32s(f, &env->nb_tlb);
|
|
qemu_put_sbe32s(f, &env->tlb_per_way);
|
|
qemu_put_sbe32s(f, &env->nb_ways);
|
|
qemu_put_sbe32s(f, &env->last_way);
|
|
qemu_put_sbe32s(f, &env->id_tlbs);
|
|
qemu_put_sbe32s(f, &env->nb_pids);
|
|
if (env->tlb) {
|
|
// XXX assumes 6xx
|
|
for (i = 0; i < env->nb_tlb; i++) {
|
|
qemu_put_betls(f, &env->tlb[i].tlb6.pte0);
|
|
qemu_put_betls(f, &env->tlb[i].tlb6.pte1);
|
|
qemu_put_betls(f, &env->tlb[i].tlb6.EPN);
|
|
}
|
|
}
|
|
for (i = 0; i < 4; i++)
|
|
qemu_put_betls(f, &env->pb[i]);
|
|
#endif
|
|
for (i = 0; i < 1024; i++)
|
|
qemu_put_betls(f, &env->spr[i]);
|
|
qemu_put_be32s(f, &env->vscr);
|
|
qemu_put_be64s(f, &env->spe_acc);
|
|
qemu_put_be32s(f, &env->spe_fscr);
|
|
qemu_put_betls(f, &env->msr_mask);
|
|
qemu_put_be32s(f, &env->flags);
|
|
qemu_put_sbe32s(f, &env->error_code);
|
|
qemu_put_be32s(f, &env->pending_interrupts);
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
qemu_put_be32s(f, &env->irq_input_state);
|
|
for (i = 0; i < POWERPC_EXCP_NB; i++)
|
|
qemu_put_betls(f, &env->excp_vectors[i]);
|
|
qemu_put_betls(f, &env->excp_prefix);
|
|
qemu_put_betls(f, &env->hreset_excp_prefix);
|
|
qemu_put_betls(f, &env->ivor_mask);
|
|
qemu_put_betls(f, &env->ivpr_mask);
|
|
qemu_put_betls(f, &env->hreset_vector);
|
|
#endif
|
|
qemu_put_betls(f, &env->nip);
|
|
qemu_put_betls(f, &env->hflags);
|
|
qemu_put_betls(f, &env->hflags_nmsr);
|
|
qemu_put_sbe32s(f, &env->mmu_idx);
|
|
qemu_put_sbe32s(f, &env->power_mode);
|
|
}
|
|
|
|
int cpu_load(QEMUFile *f, void *opaque, int version_id)
|
|
{
|
|
CPUState *env = (CPUState *)opaque;
|
|
unsigned int i, j;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
qemu_get_betls(f, &env->gpr[i]);
|
|
#if !defined(TARGET_PPC64)
|
|
for (i = 0; i < 32; i++)
|
|
qemu_get_betls(f, &env->gprh[i]);
|
|
#endif
|
|
qemu_get_betls(f, &env->lr);
|
|
qemu_get_betls(f, &env->ctr);
|
|
for (i = 0; i < 8; i++)
|
|
qemu_get_be32s(f, &env->crf[i]);
|
|
qemu_get_betls(f, &env->xer);
|
|
qemu_get_betls(f, &env->reserve_addr);
|
|
qemu_get_betls(f, &env->msr);
|
|
for (i = 0; i < 4; i++)
|
|
qemu_get_betls(f, &env->tgpr[i]);
|
|
for (i = 0; i < 32; i++) {
|
|
union {
|
|
float64 d;
|
|
uint64_t l;
|
|
} u;
|
|
u.l = qemu_get_be64(f);
|
|
env->fpr[i] = u.d;
|
|
}
|
|
qemu_get_be32s(f, &env->fpscr);
|
|
qemu_get_sbe32s(f, &env->access_type);
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
#if defined(TARGET_PPC64)
|
|
qemu_get_betls(f, &env->asr);
|
|
qemu_get_sbe32s(f, &env->slb_nr);
|
|
#endif
|
|
qemu_get_betls(f, &env->sdr1);
|
|
for (i = 0; i < 32; i++)
|
|
qemu_get_betls(f, &env->sr[i]);
|
|
for (i = 0; i < 2; i++)
|
|
for (j = 0; j < 8; j++)
|
|
qemu_get_betls(f, &env->DBAT[i][j]);
|
|
for (i = 0; i < 2; i++)
|
|
for (j = 0; j < 8; j++)
|
|
qemu_get_betls(f, &env->IBAT[i][j]);
|
|
qemu_get_sbe32s(f, &env->nb_tlb);
|
|
qemu_get_sbe32s(f, &env->tlb_per_way);
|
|
qemu_get_sbe32s(f, &env->nb_ways);
|
|
qemu_get_sbe32s(f, &env->last_way);
|
|
qemu_get_sbe32s(f, &env->id_tlbs);
|
|
qemu_get_sbe32s(f, &env->nb_pids);
|
|
if (env->tlb) {
|
|
// XXX assumes 6xx
|
|
for (i = 0; i < env->nb_tlb; i++) {
|
|
qemu_get_betls(f, &env->tlb[i].tlb6.pte0);
|
|
qemu_get_betls(f, &env->tlb[i].tlb6.pte1);
|
|
qemu_get_betls(f, &env->tlb[i].tlb6.EPN);
|
|
}
|
|
}
|
|
for (i = 0; i < 4; i++)
|
|
qemu_get_betls(f, &env->pb[i]);
|
|
#endif
|
|
for (i = 0; i < 1024; i++)
|
|
qemu_get_betls(f, &env->spr[i]);
|
|
qemu_get_be32s(f, &env->vscr);
|
|
qemu_get_be64s(f, &env->spe_acc);
|
|
qemu_get_be32s(f, &env->spe_fscr);
|
|
qemu_get_betls(f, &env->msr_mask);
|
|
qemu_get_be32s(f, &env->flags);
|
|
qemu_get_sbe32s(f, &env->error_code);
|
|
qemu_get_be32s(f, &env->pending_interrupts);
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
qemu_get_be32s(f, &env->irq_input_state);
|
|
for (i = 0; i < POWERPC_EXCP_NB; i++)
|
|
qemu_get_betls(f, &env->excp_vectors[i]);
|
|
qemu_get_betls(f, &env->excp_prefix);
|
|
qemu_get_betls(f, &env->hreset_excp_prefix);
|
|
qemu_get_betls(f, &env->ivor_mask);
|
|
qemu_get_betls(f, &env->ivpr_mask);
|
|
qemu_get_betls(f, &env->hreset_vector);
|
|
#endif
|
|
qemu_get_betls(f, &env->nip);
|
|
qemu_get_betls(f, &env->hflags);
|
|
qemu_get_betls(f, &env->hflags_nmsr);
|
|
qemu_get_sbe32s(f, &env->mmu_idx);
|
|
qemu_get_sbe32s(f, &env->power_mode);
|
|
|
|
return 0;
|
|
}
|