spapr: reset @kvm_vcpu_dirty before starting CPU
PATCH 1/1 spapr: reset @kvm_vcpu_dirty before starting CPU
Normally QEMU kvm_arch_get_registers() reads registers and sets a dirty flag which prevents further registers reading from KVM till kvm_arch_put_registers() executes and resets the flag.
However if we run QEMU with "-S" ("suspended"), then execute "info cpus" from the QEMU monitor, we end up with not reading registers in rtas_start_cpu() as qmp_query_cpus() calls kvm_cpu_synchronize_state() which leaves @kvm_vcpu_dirty=true what prevents kvm_cpu_synchronize_state() from synchronizing registers and we loose the values.
This resets @kvm_vcpu_dirty flag as we do not have content which we really want to keep at this point as the CPU is halted.
---
We could also reset @kvm_vcpu_dirty in qmp_query_cpus() but that would be racy.
--- hw/ppc/spapr_rtas.c | 2 ++ 1 file changed, 2 insertions(+)
hw/ppc/spapr_rtas.c +2 -0
@@ -185,6 +185,8 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,/* This will make sure qemu state is up to date with kvm, and * mark it dirty so our changes get flushed back before the * new cpu enters */ + + cs->kvm_vcpu_dirty = false;kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME );
Signature · 1 line
1.8.4.rc4
Quoted 10 lines · Alexey Kardashevskiy
Normally QEMU
kvm_arch_get_registers()reads registers and sets a dirty flag which prevents further registers reading from KVM tillkvm_arch_put_registers()executes and resets the flag.However if we run QEMU with "-S" ("suspended"), then execute "info cpus" from the QEMU monitor, we end up with not reading registers in
rtas_start_cpu()asqmp_query_cpus()callskvm_cpu_synchronize_state()which leaves @kvm_vcpu_dirty=true what preventskvm_cpu_synchronize_state()from synchronizing registers and we loose the values.
Quoted 5 lines
This resets @kvm_vcpu_dirty flag as we do not have content which we really want to keep at this point as the CPU is halted.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
Alex, ping. Is it complicated or controversial patch? ;)
Quoted 21 lines
We could also reset @kvm_vcpu_dirty in
qmp_query_cpus()but that would be racy.--- hw/ppc/spapr_rtas.c | 2 ++ 1 file changed, 2 insertions(+)hw/ppc/spapr_rtas.c +2
-0@@ -185,6 +185,8 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,/* This will make sure qemu state is up to date with kvm, and * mark it dirty so our changes get flushed back before the * new cpu enters */ + + cs->kvm_vcpu_dirty = false;kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME );
Signature · 1 line
Alexey
Quoted 9 lines · Alexey Kardashevskiy
Normally QEMU
kvm_arch_get_registers()reads registers and sets a dirty flag which prevents further registers reading from KVM tillkvm_arch_put_registers()executes and resets the flag.However if we run QEMU with "-S" ("suspended"), then execute "info cpus" from the QEMU monitor, we end up with not reading registers in
rtas_start_cpu()asqmp_query_cpus()callskvm_cpu_synchronize_state()which leaves @kvm_vcpu_dirty=true what preventskvm_cpu_synchronize_state()from synchronizing registers and we loose the values.
But that's fine because the values are already synchronized and couldn't have changed because the guest cpu wasn't running, no?
Alex
Quoted 29 lines
This resets @kvm_vcpu_dirty flag as we do not have content which we really want to keep at this point as the CPU is halted.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
We could also reset @kvm_vcpu_dirty in
qmp_query_cpus()but that would be racy.
---hw/ppc/spapr_rtas.c| 2 ++1 file changed, 2 insertions(+)hw/ppc/spapr_rtas.c +2
-0@@ -185,6 +185,8 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,/* This will make sure qemu state is up to date with kvm, and * mark it dirty so our changes get flushed back before the * new cpu enters */ + + cs->kvm_vcpu_dirty = false;kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME );Signature · 1 line
1.8.4.rc4
Quoted 14 lines · Alexander Graf
Quoted 9 lines · Alexey Kardashevskiy
Normally QEMU
kvm_arch_get_registers()reads registers and sets a dirty flag which prevents further registers reading from KVM tillkvm_arch_put_registers()executes and resets the flag.However if we run QEMU with "-S" ("suspended"), then execute "info cpus" from the QEMU monitor, we end up with not reading registers in
rtas_start_cpu()asqmp_query_cpus()callskvm_cpu_synchronize_state()which leaves @kvm_vcpu_dirty=true what preventskvm_cpu_synchronize_state()from synchronizing registers and we loose the values.
Quoted 2 lines
But that's fine because the values are already synchronized and couldn't have changed because the guest cpu wasn't running, no?
Discovered today that "[PATCH] spapr: fix H_SET_MODE to sync LPCR with KVM" seems to be v2 of this as that patch solves the issue this patch was intended to solve so I'll drop this one.
Quoted 34 lines
Alex
Quoted 29 lines
This resets @kvm_vcpu_dirty flag as we do not have content which we really want to keep at this point as the CPU is halted.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
We could also reset @kvm_vcpu_dirty in
qmp_query_cpus()but that would be racy.
---hw/ppc/spapr_rtas.c| 2 ++1 file changed, 2 insertions(+)hw/ppc/spapr_rtas.c +2
-0@@ -185,6 +185,8 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,/* This will make sure qemu state is up to date with kvm, and * mark it dirty so our changes get flushed back before the * new cpu enters */ + + cs->kvm_vcpu_dirty = false;kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME );Signature · 1 line
1.8.4.rc4
Signature · 1 line
Alexey
Am 15.01.2014 05:57, schrieb Alexey Kardashevskiy:
Quoted 27 lines
Normally QEMU
kvm_arch_get_registers()reads registers and sets a dirty flag which prevents further registers reading from KVM tillkvm_arch_put_registers()executes and resets the flag.However if we run QEMU with "-S" ("suspended"), then execute "info cpus" from the QEMU monitor, we end up with not reading registers in
rtas_start_cpu()asqmp_query_cpus()callskvm_cpu_synchronize_state()which leaves @kvm_vcpu_dirty=true what preventskvm_cpu_synchronize_state()from synchronizing registers and we loose the values.This resets @kvm_vcpu_dirty flag as we do not have content which we really want to keep at this point as the CPU is halted.
Signed-off-by Alexey Kardashevskiy <[email protected]>---
We could also reset @kvm_vcpu_dirty in
qmp_query_cpus()but that would be racy.--- hw/ppc/spapr_rtas.c | 2 ++ 1 file changed, 2 insertions(+)hw/ppc/spapr_rtas.c +0
-0
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr, · line 190
Quoted 6 lines
hw/ppc/spapr_rtas.c +2
-0@@ -185,6 +185,8 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,/* This will make sure qemu state is up to date with kvm, and * mark it dirty so our changes get flushed back before the * new cpu enters */ + + cs->kvm_vcpu_dirty = false;kvm_cpu_synchronize_state (cs);
While I am not familiar with whether or not the dirty flag should be changed, I've noticed in the past that sPAPR is the only user of kvm_cpu_synchronize_state() outside of KVM code IIUC. Would be nice if you could replace that with cpu_synchronize_state() in its own patch when you find some time.
Regards,
Andreas
Quoted 3 lines
hw/ppc/spapr_rtas.c +0
-0env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME );
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg