Skip to contentSkip to conversation

spapr: fix H_SET_MODE to sync LPCR with KVM

PATCH In review Alexey Kardashevskiy 2 participants 2 messages Jan 17, 2014 – Jan 20, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr: fix H_SET_MODE to sync LPCR with KVM

The kvm_cpu_exec() only puts registers to KVM if the @kvm_vcpu_dirty flag has been set.

This adds registers sync which also sets @kvm_vcpu_dirty so we store new LPCR to KVM before continuing with the KVM_RUN ioctl.

---
 hw/ppc/spapr_hcall.c | 2 ++
 1 file changed, 2 insertions(+)
hw/ppc/spapr_hcall.c +2 -0
index f755a53..b61d744 100644
@@ -682,6 +682,7 @@ static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPREnvironment *spapr,
             CPU_FOREACH(cs) {
                 PowerPCCPU *cp = POWERPC_CPU(cs);
                 CPUPPCState *env = &cp->env;
+                kvm_cpu_synchronize_state(cs);
                 env->spr[SPR_LPCR] &= ~LPCR_ILE;
             }
             ret = H_SUCCESS;
@@ -691,6 +692,7 @@ static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPREnvironment *spapr,
             CPU_FOREACH(cs) {
                 PowerPCCPU *cp = POWERPC_CPU(cs);
                 CPUPPCState *env = &cp->env;
+                kvm_cpu_synchronize_state(cs);
                 env->spr[SPR_LPCR] |= LPCR_ILE;
             }
             ret = H_SUCCESS;
Signature · 1 line
1.8.4.rc4
#1 lore raw
Quoted 16 lines · Alexey Kardashevskiy

The kvm_cpu_exec() only puts registers to KVM if the @kvm_vcpu_dirty flag has been set.

This adds registers sync which also sets @kvm_vcpu_dirty so we store new LPCR to KVM before continuing with the KVM_RUN ioctl.

---
hw/ppc/spapr_hcall.c | 2 ++

1 file changed, 2 insertions(+)
hw/ppc/spapr_hcall.c +0 -0
index f755a53..b61d744 100644

hw/ppc/spapr_hcall.c static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 685

Quoted 4 lines
hw/ppc/spapr_hcall.c +1 -0
@@ -682,6 +682,7 @@ static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPREnvironment *spapr,
            CPU_FOREACH(cs) {
                PowerPCCPU *cp = POWERPC_CPU(cs);
                CPUPPCState *env = &cp->env;
+                kvm_cpu_synchronize_state(cs);

This should be cpu_synchronize_state(). But even then I'm not 100% sure we're not racy. What guarantees that the other vcpu doesn't go back into the guest before we fiddle with its LPCR?

We might have to put the LPCR fiddling and synchronization into a single function we call through run_on_cpu().

Alex