提交 980ebe87 编写于 作者: A Aaron Lindsay 提交者: Peter Maydell

target/arm: Swap PMU values before/after migrations

Because of the PMU's design, many register accesses have side effects
which are inter-related, meaning that the normal method of saving CP
registers can result in inconsistent state. These side-effects are
largely handled in pmu_op_start/finish functions which can be called
before and after the state is saved/restored. By doing this and adding
raw read/write functions for the affected registers, we avoid
migration-related inconsistencies.
Signed-off-by: NAaron Lindsay <aclindsa@gmail.com>
Signed-off-by: NAaron Lindsay <aaron@os.amperecomputing.com>
Reviewed-by: NPeter Maydell <peter.maydell@linaro.org>
Message-id: 20181211151945.29137-4-aaron@os.amperecomputing.com
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
上级 5d05b9d4
...@@ -1459,11 +1459,13 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { ...@@ -1459,11 +1459,13 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
.opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 0, .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 0,
.access = PL0_RW, .accessfn = pmreg_access_ccntr, .access = PL0_RW, .accessfn = pmreg_access_ccntr,
.type = ARM_CP_IO, .type = ARM_CP_IO,
.readfn = pmccntr_read, .writefn = pmccntr_write, }, .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt),
.readfn = pmccntr_read, .writefn = pmccntr_write,
.raw_readfn = raw_read, .raw_writefn = raw_write, },
#endif #endif
{ .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64, { .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7, .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7,
.writefn = pmccfiltr_write, .writefn = pmccfiltr_write, .raw_writefn = raw_write,
.access = PL0_RW, .accessfn = pmreg_access, .access = PL0_RW, .accessfn = pmreg_access,
.type = ARM_CP_IO, .type = ARM_CP_IO,
.fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0), .fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0),
......
...@@ -620,6 +620,10 @@ static int cpu_pre_save(void *opaque) ...@@ -620,6 +620,10 @@ static int cpu_pre_save(void *opaque)
{ {
ARMCPU *cpu = opaque; ARMCPU *cpu = opaque;
if (!kvm_enabled()) {
pmu_op_start(&cpu->env);
}
if (kvm_enabled()) { if (kvm_enabled()) {
if (!write_kvmstate_to_list(cpu)) { if (!write_kvmstate_to_list(cpu)) {
/* This should never fail */ /* This should never fail */
...@@ -641,6 +645,17 @@ static int cpu_pre_save(void *opaque) ...@@ -641,6 +645,17 @@ static int cpu_pre_save(void *opaque)
return 0; return 0;
} }
static int cpu_post_save(void *opaque)
{
ARMCPU *cpu = opaque;
if (!kvm_enabled()) {
pmu_op_finish(&cpu->env);
}
return 0;
}
static int cpu_pre_load(void *opaque) static int cpu_pre_load(void *opaque)
{ {
ARMCPU *cpu = opaque; ARMCPU *cpu = opaque;
...@@ -653,6 +668,10 @@ static int cpu_pre_load(void *opaque) ...@@ -653,6 +668,10 @@ static int cpu_pre_load(void *opaque)
*/ */
env->irq_line_state = UINT32_MAX; env->irq_line_state = UINT32_MAX;
if (!kvm_enabled()) {
pmu_op_start(&cpu->env);
}
return 0; return 0;
} }
...@@ -721,6 +740,10 @@ static int cpu_post_load(void *opaque, int version_id) ...@@ -721,6 +740,10 @@ static int cpu_post_load(void *opaque, int version_id)
hw_breakpoint_update_all(cpu); hw_breakpoint_update_all(cpu);
hw_watchpoint_update_all(cpu); hw_watchpoint_update_all(cpu);
if (!kvm_enabled()) {
pmu_op_finish(&cpu->env);
}
return 0; return 0;
} }
...@@ -729,6 +752,7 @@ const VMStateDescription vmstate_arm_cpu = { ...@@ -729,6 +752,7 @@ const VMStateDescription vmstate_arm_cpu = {
.version_id = 22, .version_id = 22,
.minimum_version_id = 22, .minimum_version_id = 22,
.pre_save = cpu_pre_save, .pre_save = cpu_pre_save,
.post_save = cpu_post_save,
.pre_load = cpu_pre_load, .pre_load = cpu_pre_load,
.post_load = cpu_post_load, .post_load = cpu_post_load,
.fields = (VMStateField[]) { .fields = (VMStateField[]) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册