From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUCZG-0007bV-23 for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:57:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUCZE-0008LI-5N for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:57:46 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:52731) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUCZD-0008Ko-RO for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:57:44 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Apr 2013 09:54:49 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 413A1219005E for ; Mon, 22 Apr 2013 09:59:58 +0100 (BST) Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r3M8vQw651576904 for ; Mon, 22 Apr 2013 08:57:26 GMT Received: from d06av12.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r3M8vZm1028277 for ; Mon, 22 Apr 2013 02:57:36 -0600 Message-ID: <5174FB7E.1090308@de.ibm.com> Date: Mon, 22 Apr 2013 10:57:34 +0200 From: Christian Borntraeger MIME-Version: 1.0 References: <1363024736-2650-1-git-send-email-jjherne@us.ibm.com> <1363024736-2650-2-git-send-email-jjherne@us.ibm.com> In-Reply-To: <1363024736-2650-2-git-send-email-jjherne@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2 v3] [S390-KVM] Regsync: Allow selective runtime register synchronization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: agraf@suse.de Cc: aliguori@us.ibm.com, jan.kiszka@siemens.com, mtosatti@redhat.com, "Jason J. Herne" , qemu-devel@nongnu.org, R65777@freescale.com On 11/03/13 18:58, Jason J. Herne wrote: > We want to avoid expensive register synchronization IOCTL's on the hot path so > a new kvm_s390_get_registers_partial() is introduced as a compliment to > kvm_arch_get_registers(). The new function is called on the hot path, and > kvm_arch_get_registers() is called when we need the complete runtime register > state. > > kvm_arch_put_registers() is updated to only sync the partial runtime set when > we've only dirtied the partial runtime set. This is to avoid sending bad data > back to KVM if we've only partially synced the runtime register set. > > Signed-off-by: Jason J. Herne > Reviewed-by: Christian Borntraeger Alex, we have this code in our private tree (the one thats used by the testers) for a while now and it seems to work fine. This should be ok to apply. Since this also fixes the problem that s390 has not a complete view of the kvm registers in places were we want it (dump etc) we might even consider this a bugfix. Your take if this is still good for 1.5. Christian > --- > target-s390x/cpu.h | 17 +++++++++++++ > target-s390x/kvm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 84 insertions(+) > > diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h > index 9cb739d..69ecb05 100644 > --- a/target-s390x/cpu.h > +++ b/target-s390x/cpu.h > @@ -78,6 +78,11 @@ typedef struct MchkQueue { > uint16_t type; > } MchkQueue; > > +/* Defined values for CPUS390XState.runtime_reg_dirty_mask */ > +#define KVM_S390_RUNTIME_DIRTY_NONE 0 > +#define KVM_S390_RUNTIME_DIRTY_PARTIAL 1 > +#define KVM_S390_RUNTIME_DIRTY_FULL 2 > + > typedef struct CPUS390XState { > uint64_t regs[16]; /* GP registers */ > CPU_DoubleU fregs[16]; /* FP registers */ > @@ -121,6 +126,13 @@ typedef struct CPUS390XState { > uint64_t cputm; > uint32_t todpr; > > + /* on S390 the runtime register set has two dirty states: > + * a partial dirty state in which only the registers that > + * are needed all the time are fetched. And a fully dirty > + * state in which all runtime registers are fetched. > + */ > + uint32_t runtime_reg_dirty_mask; > + > CPU_COMMON > > /* reset does memset(0) up to here */ > @@ -1068,6 +1080,7 @@ void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, > uint32_t io_int_word); > void kvm_s390_crw_mchk(S390CPU *cpu); > void kvm_s390_enable_css_support(S390CPU *cpu); > +int kvm_s390_get_registers_partial(CPUState *cpu); > #else > static inline void kvm_s390_io_interrupt(S390CPU *cpu, > uint16_t subchannel_id, > @@ -1082,6 +1095,10 @@ static inline void kvm_s390_crw_mchk(S390CPU *cpu) > static inline void kvm_s390_enable_css_support(S390CPU *cpu) > { > } > +static inline int kvm_s390_get_registers_partial(CPUState *cpu) > +{ > + return -ENOSYS; > +} > #endif > > static inline void s390_io_interrupt(S390CPU *cpu, > diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c > index 8f111ae..934757e 100644 > --- a/target-s390x/kvm.c > +++ b/target-s390x/kvm.c > @@ -123,6 +123,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) > { > S390CPU *cpu = S390_CPU(cs); > CPUS390XState *env = &cpu->env; > + struct kvm_one_reg reg; > struct kvm_sregs sregs; > struct kvm_regs regs; > int ret; > @@ -147,6 +148,30 @@ int kvm_arch_put_registers(CPUState *cs, int level) > } > } > > + if (env->runtime_reg_dirty_mask == KVM_S390_RUNTIME_DIRTY_FULL) { > + reg.id = KVM_REG_S390_CPU_TIMER; > + reg.addr = (__u64)&(env->cputm); > + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); > + if (ret < 0) { > + return ret; > + } > + > + reg.id = KVM_REG_S390_CLOCK_COMP; > + reg.addr = (__u64)&(env->ckc); > + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); > + if (ret < 0) { > + return ret; > + } > + > + reg.id = KVM_REG_S390_TODPR; > + reg.addr = (__u64)&(env->todpr); > + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); > + if (ret < 0) { > + return ret; > + } > + } > + env->runtime_reg_dirty_mask = KVM_S390_RUNTIME_DIRTY_NONE; > + > /* Do we need to save more than that? */ > if (level == KVM_PUT_RUNTIME_STATE) { > return 0; > @@ -186,11 +211,52 @@ int kvm_arch_get_registers(CPUState *cs) > { > S390CPU *cpu = S390_CPU(cs); > CPUS390XState *env = &cpu->env; > + struct kvm_one_reg reg; > + int r; > + > + r = kvm_s390_get_registers_partial(cs); > + if (r < 0) { > + return r; > + } > + > + reg.id = KVM_REG_S390_CPU_TIMER; > + reg.addr = (__u64)&(env->cputm); > + r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); > + if (r < 0) { > + return r; > + } > + > + reg.id = KVM_REG_S390_CLOCK_COMP; > + reg.addr = (__u64)&(env->ckc); > + r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); > + if (r < 0) { > + return r; > + } > + > + reg.id = KVM_REG_S390_TODPR; > + reg.addr = (__u64)&(env->todpr); > + r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); > + if (r < 0) { > + return r; > + } > + > + env->runtime_reg_dirty_mask = KVM_S390_RUNTIME_DIRTY_FULL; > + return 0; > +} > + > +int kvm_s390_get_registers_partial(CPUState *cs) > +{ > + S390CPU *cpu = S390_CPU(cs); > + CPUS390XState *env = &cpu->env; > struct kvm_sregs sregs; > struct kvm_regs regs; > int ret; > int i; > > + if (env->runtime_reg_dirty_mask) { > + return 0; > + } > + > /* get the PSW */ > env->psw.addr = cs->kvm_run->psw_addr; > env->psw.mask = cs->kvm_run->psw_mask; > @@ -236,6 +302,7 @@ int kvm_arch_get_registers(CPUState *cs) > /* no prefix without sync regs */ > } > > + env->runtime_reg_dirty_mask = KVM_S390_RUNTIME_DIRTY_PARTIAL; > return 0; > } >