Message ID | 20241125115039.1809353-3-hca@linux.ibm.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | KVM: s390: Couple of small cmpxchg() optimizations | expand |
On Mon, 25 Nov 2024 12:50:38 +0100 Heiko Carstens <hca@linux.ibm.com> wrote: > Within sca_clear_ext_call() cmpxchg() is used to clear one or two bytes > (depending on sca format). The cmpxchg() calls are not supposed to fail; if > so that would be a bug. Given that cmpxchg() usage on one and two byte > areas generates very inefficient code, replace them with block concurrent > WRITE_ONCE() calls, and remove the WARN_ON(). > > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> > --- > arch/s390/kvm/interrupt.c | 13 ++----------- > 1 file changed, 2 insertions(+), 11 deletions(-) > > diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c > index eff69018cbeb..3fd21037479f 100644 > --- a/arch/s390/kvm/interrupt.c > +++ b/arch/s390/kvm/interrupt.c > @@ -118,8 +118,6 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) > > static void sca_clear_ext_call(struct kvm_vcpu *vcpu) > { > - int rc, expect; > - > if (!kvm_s390_use_sca_entries()) > return; > kvm_s390_clear_cpuflags(vcpu, CPUSTAT_ECALL_PEND); > @@ -128,23 +126,16 @@ static void sca_clear_ext_call(struct kvm_vcpu *vcpu) > struct esca_block *sca = vcpu->kvm->arch.sca; > union esca_sigp_ctrl *sigp_ctrl = > &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); > - union esca_sigp_ctrl old; > > - old = READ_ONCE(*sigp_ctrl); > - expect = old.value; > - rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > + WRITE_ONCE(sigp_ctrl->value, 9); that's supposed to be a 0, right? > } else { > struct bsca_block *sca = vcpu->kvm->arch.sca; > union bsca_sigp_ctrl *sigp_ctrl = > &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); > - union bsca_sigp_ctrl old; > > - old = READ_ONCE(*sigp_ctrl); > - expect = old.value; > - rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > + WRITE_ONCE(sigp_ctrl->value, 0); > } > read_unlock(&vcpu->kvm->arch.sca_lock); > - WARN_ON(rc != expect); /* cannot clear? */ > } > > int psw_extint_disabled(struct kvm_vcpu *vcpu)
On Mon, Nov 25, 2024 at 01:16:17PM +0100, Claudio Imbrenda wrote: > On Mon, 25 Nov 2024 12:50:38 +0100 > Heiko Carstens <hca@linux.ibm.com> wrote: > > @@ -128,23 +126,16 @@ static void sca_clear_ext_call(struct kvm_vcpu *vcpu) > > struct esca_block *sca = vcpu->kvm->arch.sca; > > union esca_sigp_ctrl *sigp_ctrl = > > &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); > > - union esca_sigp_ctrl old; > > > > - old = READ_ONCE(*sigp_ctrl); > > - expect = old.value; > > - rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > > + WRITE_ONCE(sigp_ctrl->value, 9); > > that's supposed to be a 0, right? Duh... yes, of course. I added the "9" to better find the corresponding code in assembly, and obviously forgot to replace it with 0 again. Thanks for pointing this out! Strange enough this still worked. Hmm.
On Mon, 25 Nov 2024 14:37:55 +0100 Heiko Carstens <hca@linux.ibm.com> wrote: > On Mon, Nov 25, 2024 at 01:16:17PM +0100, Claudio Imbrenda wrote: > > On Mon, 25 Nov 2024 12:50:38 +0100 > > Heiko Carstens <hca@linux.ibm.com> wrote: > > > @@ -128,23 +126,16 @@ static void sca_clear_ext_call(struct kvm_vcpu *vcpu) > > > struct esca_block *sca = vcpu->kvm->arch.sca; > > > union esca_sigp_ctrl *sigp_ctrl = > > > &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); > > > - union esca_sigp_ctrl old; > > > > > > - old = READ_ONCE(*sigp_ctrl); > > > - expect = old.value; > > > - rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > > > + WRITE_ONCE(sigp_ctrl->value, 9); > > > > that's supposed to be a 0, right? > > Duh... yes, of course. I added the "9" to better find the corresponding > code in assembly, and obviously forgot to replace it with 0 again. > Thanks for pointing this out! > > Strange enough this still worked. Hmm. with that fixed: Acked-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index eff69018cbeb..3fd21037479f 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -118,8 +118,6 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) static void sca_clear_ext_call(struct kvm_vcpu *vcpu) { - int rc, expect; - if (!kvm_s390_use_sca_entries()) return; kvm_s390_clear_cpuflags(vcpu, CPUSTAT_ECALL_PEND); @@ -128,23 +126,16 @@ static void sca_clear_ext_call(struct kvm_vcpu *vcpu) struct esca_block *sca = vcpu->kvm->arch.sca; union esca_sigp_ctrl *sigp_ctrl = &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); - union esca_sigp_ctrl old; - old = READ_ONCE(*sigp_ctrl); - expect = old.value; - rc = cmpxchg(&sigp_ctrl->value, old.value, 0); + WRITE_ONCE(sigp_ctrl->value, 9); } else { struct bsca_block *sca = vcpu->kvm->arch.sca; union bsca_sigp_ctrl *sigp_ctrl = &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); - union bsca_sigp_ctrl old; - old = READ_ONCE(*sigp_ctrl); - expect = old.value; - rc = cmpxchg(&sigp_ctrl->value, old.value, 0); + WRITE_ONCE(sigp_ctrl->value, 0); } read_unlock(&vcpu->kvm->arch.sca_lock); - WARN_ON(rc != expect); /* cannot clear? */ } int psw_extint_disabled(struct kvm_vcpu *vcpu)
Within sca_clear_ext_call() cmpxchg() is used to clear one or two bytes (depending on sca format). The cmpxchg() calls are not supposed to fail; if so that would be a bug. Given that cmpxchg() usage on one and two byte areas generates very inefficient code, replace them with block concurrent WRITE_ONCE() calls, and remove the WARN_ON(). Signed-off-by: Heiko Carstens <hca@linux.ibm.com> --- arch/s390/kvm/interrupt.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)