Message ID | 20230109145456.2895385-1-hca@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2208109wrt; Mon, 9 Jan 2023 07:09:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXuZxm/UM1TJc4UFS/Q2iz2yURefaXDsOeiCfNbYxzftdVsfAniudfJgnPPprdIZP63p+xLv X-Received: by 2002:a17:903:31c2:b0:192:7447:adfe with SMTP id v2-20020a17090331c200b001927447adfemr49701636ple.36.1673276960707; Mon, 09 Jan 2023 07:09:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673276960; cv=none; d=google.com; s=arc-20160816; b=sEDYbLbYJ7Yl3wtTnj2LbogNcIEG3hwnGtQrZUC0E2aFMnwiPcHNZllhTs2PlSXr+q z0F/85weyvsV7fS2qMPGzWDIY9l0YWqPRE4mM28KcUosGRYBYhWEeB2VTKrjh3ldFzj6 rMTVErGYkEoTLRM89Y3V1oFFw8pSCMmE46HUfEUgYrxzuuJa7wwBfahEtPLAJ8HaUCiM GO68KWQUOSHjc/vtu9CHsxp6OILy4DH5aPmTjznbvI4XDe3/F5N3YB7M1JNKU9xsQGvs 04b8eQ8LecQKHpZX021TaM3EcGdXipJsQF8RBTUEznZKCPsE5/mq+RW51JWzsah2ASQC RIRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dz3MBxgQWcjymajRU5SZ8XCXO5den3d97KfPX9mneKc=; b=E8JWLQSbmg/XpWYNTak9oSwV6BUjAYhPoFRLlIrq0W1/jvLbboGJBOubdc5L2XtwaO UFRhZ8/8CLkyHQMI8PRiLIcMUPvLhsZx9WFZ6f/kHrzR40zqX9oNZ3QS87ysgzmZUQKi Uf/vWo/RnncciS8ybjww+h6AaEcjBhTGGj5cKlXv1sgetDecwHOC3FlQbnfLnKOzI8xm yOGAn7So4DQGzVayYn+jmeQR6Av5sNWwMzyFjT3tBBDJ4oCusI8bknqD2TfJF3PeJD/T 5bK4y2Q2oyqiazvFMQVfwD8bgvGpdU6ZOlscmr5XezFXaIUvqo7X2wgiesfmNn7NNNxt Nd8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Pd+k30Ng; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n16-20020a170902d2d000b0019274931758si10008361plc.577.2023.01.09.07.09.08; Mon, 09 Jan 2023 07:09:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Pd+k30Ng; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234720AbjAIOzP (ORCPT <rfc822;274620705z@gmail.com> + 99 others); Mon, 9 Jan 2023 09:55:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235133AbjAIOzE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 09:55:04 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE0ECE50; Mon, 9 Jan 2023 06:55:03 -0800 (PST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 309DtYHv025507; Mon, 9 Jan 2023 14:55:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=dz3MBxgQWcjymajRU5SZ8XCXO5den3d97KfPX9mneKc=; b=Pd+k30NgEpANXlDSQJi26MRjzX8UX/wtx9a/ZY8jVMPwfWK/rebx8QGhRIkzDK77KGiW N7FIeQzGXbQVisAYyPAL2sqh4VONOQAWXc2BX+cYZdIPIgPdl8ksURYdP0ntd8CtNffZ 9acjI/BYRL1hPy+ly20PH6uukJh5ZpcVCT6v/EExsIp3V1rD8QXVjz/kMlY/QimofepK xNJkJWClvGEAngyUYKJuXKL68oU7aN57qC/n25frlTd4qBqc0arrKpihRs49p/DGXbig fzCFc9zGe82VGYLmmjrfAtvJtCfaa2BZefGX4ixPAO4VDb/OTWFRGHzF4178+wlxyi1O 1w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3myjhtggvc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 14:55:03 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 309DTKi9005770; Mon, 9 Jan 2023 14:55:03 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3myjhtgguh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 14:55:02 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3098dsvM012475; Mon, 9 Jan 2023 14:55:00 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3my00fk47m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 14:55:00 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 309EsuRX23724752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Jan 2023 14:54:57 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF9342004B; Mon, 9 Jan 2023 14:54:56 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9E3D020043; Mon, 9 Jan 2023 14:54:56 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Jan 2023 14:54:56 +0000 (GMT) From: Heiko Carstens <hca@linux.ibm.com> To: Christian Borntraeger <borntraeger@linux.ibm.com>, Janosch Frank <frankja@linux.ibm.com>, Claudio Imbrenda <imbrenda@linux.ibm.com> Cc: David Hildenbrand <david@redhat.com>, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] KVM: s390: interrupt: use READ_ONCE() before cmpxchg() Date: Mon, 9 Jan 2023 15:54:56 +0100 Message-Id: <20230109145456.2895385-1-hca@linux.ibm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 0dbQWy9H7XsqBjKZb6ZTZYdt6mU72qVt X-Proofpoint-GUID: PIGQ1sQM3rg2WuyihH4gTqfp3N0E5Xt3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-09_08,2023-01-09_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 clxscore=1015 phishscore=0 mlxlogscore=730 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090105 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754549695766189061?= X-GMAIL-MSGID: =?utf-8?q?1754558062399842795?= |
Series |
[v2] KVM: s390: interrupt: use READ_ONCE() before cmpxchg()
|
|
Commit Message
Heiko Carstens
Jan. 9, 2023, 2:54 p.m. UTC
Use READ_ONCE() before cmpxchg() to prevent that the compiler generates
code that fetches the to be compared old value several times from memory.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
v2: make it compile
arch/s390/kvm/interrupt.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
Comments
On Mon, 9 Jan 2023 15:54:56 +0100 Heiko Carstens <hca@linux.ibm.com> wrote: > Use READ_ONCE() before cmpxchg() to prevent that the compiler generates > code that fetches the to be compared old value several times from memory. > > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> > --- > > v2: make it compile > > arch/s390/kvm/interrupt.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c > index 1dae78deddf2..ab26aa53ee37 100644 > --- a/arch/s390/kvm/interrupt.c > +++ b/arch/s390/kvm/interrupt.c > @@ -83,8 +83,9 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) > 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 new_val = {0}, old_val = *sigp_ctrl; > + union esca_sigp_ctrl new_val = {0}, old_val; > > + old_val = READ_ONCE(*sigp_ctrl); > new_val.scn = src_id; > new_val.c = 1; > old_val.c = 0; > @@ -95,8 +96,9 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) > 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 new_val = {0}, old_val = *sigp_ctrl; > + union bsca_sigp_ctrl new_val = {0}, old_val; > > + old_val = READ_ONCE(*sigp_ctrl); > new_val.scn = src_id; > new_val.c = 1; > old_val.c = 0; > @@ -126,16 +128,18 @@ 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 = *sigp_ctrl; > + union esca_sigp_ctrl old; > > + old = READ_ONCE(*sigp_ctrl); > expect = old.value; > rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > } 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 = *sigp_ctrl; > + union bsca_sigp_ctrl old; > > + old = READ_ONCE(*sigp_ctrl); > expect = old.value; > rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > }
Am 09.01.23 um 15:54 schrieb Heiko Carstens: > Use READ_ONCE() before cmpxchg() to prevent that the compiler generates > code that fetches the to be compared old value several times from memory. > > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Looks sane. Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> In case you want to take it via the s390 tree: Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com> > --- > > v2: make it compile > > arch/s390/kvm/interrupt.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c > index 1dae78deddf2..ab26aa53ee37 100644 > --- a/arch/s390/kvm/interrupt.c > +++ b/arch/s390/kvm/interrupt.c > @@ -83,8 +83,9 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) > 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 new_val = {0}, old_val = *sigp_ctrl; > + union esca_sigp_ctrl new_val = {0}, old_val; > > + old_val = READ_ONCE(*sigp_ctrl); > new_val.scn = src_id; > new_val.c = 1; > old_val.c = 0; > @@ -95,8 +96,9 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) > 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 new_val = {0}, old_val = *sigp_ctrl; > + union bsca_sigp_ctrl new_val = {0}, old_val; > > + old_val = READ_ONCE(*sigp_ctrl); > new_val.scn = src_id; > new_val.c = 1; > old_val.c = 0; > @@ -126,16 +128,18 @@ 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 = *sigp_ctrl; > + union esca_sigp_ctrl old; > > + old = READ_ONCE(*sigp_ctrl); > expect = old.value; > rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > } 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 = *sigp_ctrl; > + union bsca_sigp_ctrl old; > > + old = READ_ONCE(*sigp_ctrl); > expect = old.value; > rc = cmpxchg(&sigp_ctrl->value, old.value, 0); > }
On Tue, Jan 10, 2023 at 08:15:50PM +0100, Christian Borntraeger wrote: > Am 09.01.23 um 15:54 schrieb Heiko Carstens: > > Use READ_ONCE() before cmpxchg() to prevent that the compiler generates > > code that fetches the to be compared old value several times from memory. > > > > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> > > Looks sane. > > Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> > > In case you want to take it via the s390 tree: > Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com> Given that there don't seem to be any pending s390 specific patches I take it via the s390 tree. Applied.
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 1dae78deddf2..ab26aa53ee37 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -83,8 +83,9 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) 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 new_val = {0}, old_val = *sigp_ctrl; + union esca_sigp_ctrl new_val = {0}, old_val; + old_val = READ_ONCE(*sigp_ctrl); new_val.scn = src_id; new_val.c = 1; old_val.c = 0; @@ -95,8 +96,9 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) 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 new_val = {0}, old_val = *sigp_ctrl; + union bsca_sigp_ctrl new_val = {0}, old_val; + old_val = READ_ONCE(*sigp_ctrl); new_val.scn = src_id; new_val.c = 1; old_val.c = 0; @@ -126,16 +128,18 @@ 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 = *sigp_ctrl; + union esca_sigp_ctrl old; + old = READ_ONCE(*sigp_ctrl); expect = old.value; rc = cmpxchg(&sigp_ctrl->value, old.value, 0); } 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 = *sigp_ctrl; + union bsca_sigp_ctrl old; + old = READ_ONCE(*sigp_ctrl); expect = old.value; rc = cmpxchg(&sigp_ctrl->value, old.value, 0); }