From: David Hildenbrand <d...@linux.vnet.ibm.com> Let's unify the code to sync registers by moving the checks into a helper function can_sync_regs().
Signed-off-by: David Hildenbrand <d...@linux.vnet.ibm.com> Signed-off-by: Jens Freimann <jf...@linux.vnet.ibm.com> Reviewed-by: Cornelia Huck <cornelia.h...@de.ibm.com> Signed-off-by: Cornelia Huck <cornelia.h...@de.ibm.com> --- target-s390x/kvm.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index f3f8f2c..1483082 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -202,6 +202,11 @@ void kvm_s390_reset_vcpu(S390CPU *cpu) } } +static int can_sync_regs(CPUState *cs, int regs) +{ + return cap_sync_regs && (cs->kvm_run->kvm_valid_regs & regs) == regs; +} + int kvm_arch_put_registers(CPUState *cs, int level) { S390CPU *cpu = S390_CPU(cs); @@ -216,7 +221,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) cs->kvm_run->psw_addr = env->psw.addr; cs->kvm_run->psw_mask = env->psw.mask; - if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) { + if (can_sync_regs(cs, KVM_SYNC_GPRS)) { for (i = 0; i < 16; i++) { cs->kvm_run->s.regs.gprs[i] = env->regs[i]; cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_GPRS; @@ -273,9 +278,8 @@ int kvm_arch_put_registers(CPUState *cs, int level) } } - if (cap_sync_regs && - cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS && - cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) { + /* access registers and control registers*/ + if (can_sync_regs(cs, KVM_SYNC_ACRS | KVM_SYNC_CRS)) { for (i = 0; i < 16; i++) { cs->kvm_run->s.regs.acrs[i] = env->aregs[i]; cs->kvm_run->s.regs.crs[i] = env->cregs[i]; @@ -294,7 +298,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) } /* Finally the prefix */ - if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) { + if (can_sync_regs(cs, KVM_SYNC_PREFIX)) { cs->kvm_run->s.regs.prefix = env->psa; cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_PREFIX; } else { @@ -317,7 +321,7 @@ int kvm_arch_get_registers(CPUState *cs) env->psw.mask = cs->kvm_run->psw_mask; /* the GPRS */ - if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) { + if (can_sync_regs(cs, KVM_SYNC_GPRS)) { for (i = 0; i < 16; i++) { env->regs[i] = cs->kvm_run->s.regs.gprs[i]; } @@ -332,9 +336,7 @@ int kvm_arch_get_registers(CPUState *cs) } /* The ACRS and CRS */ - if (cap_sync_regs && - cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS && - cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) { + if (can_sync_regs(cs, KVM_SYNC_ACRS | KVM_SYNC_CRS)) { for (i = 0; i < 16; i++) { env->aregs[i] = cs->kvm_run->s.regs.acrs[i]; env->cregs[i] = cs->kvm_run->s.regs.crs[i]; @@ -361,7 +363,7 @@ int kvm_arch_get_registers(CPUState *cs) env->fpc = fpu.fpc; /* The prefix */ - if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) { + if (can_sync_regs(cs, KVM_SYNC_PREFIX)) { env->psa = cs->kvm_run->s.regs.prefix; } -- 1.7.9.5