Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6154184rwl; Mon, 9 Jan 2023 05:02:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXtluz6OfpAz5tDMh5RCbiubQB/wdUYE/4/FCralgeKUPKl20KnyCfM3UpR871mrmyv1zROl X-Received: by 2002:a05:600c:3ca2:b0:3d9:a5a2:65fa with SMTP id bg34-20020a05600c3ca200b003d9a5a265famr24903377wmb.7.1673269330559; Mon, 09 Jan 2023 05:02:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673269330; cv=none; d=google.com; s=arc-20160816; b=iWpozBzJTDNI5gQEEN6T7mh5BfF0sAjRyYdaEph5oPeO6Nh5Me4PbTExWmu1asRjUl STSjN2EOcsihFiLPe/lt4TP5sRVva3vRO1kplrjefJfJ03y+iRIbKWIUbypYAuW6T5P6 akQFN63+VxfmGR9IBMBfUr6hpwvWowM7jLUuWhsdiSIsMLnmgvFvUgdZJb17yQh7cdzg dbhdZpOVSDYjMn1pSde0tZCL2D6ngMjRujYZVBAzSM4pAksNVubMcgn3WLWc3P5Rs9iG OkolU6pBLVyn91HBX+QW6v6yuLNCQcJTLRyNTk0XGKYz4aNKUW0aT2nBjHfnqsj8VB+N tcFw== 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=OacVvB18McZxLNMXZ4NRfCDUji0la1y9ALJrNWFwFLE=; b=tWuZWII4Rur3UZPNmcR0KDCNESGz56BG/Lei9ZQIVbPDtLyL9zaQ/0Fylh1jeUQaNR vCdhovAl0YIjzAwUECEONthjtZVid9T7Wt/RNrTWlLhHy7VbyavQzKI8w3oJrzkY9t/x pBzrGqg43oJj1WiXJYiPeTE07yhx6Y5q60dWNfuqTtlmwt5enBtisn7xsCKP69hodE1l lw7qWJfudt39YIO8RIjUtd5lE5iZkefVMx4xfijhzVzcCm/k0YHI4VcTbGoduQJgs6Gp /zWbt2a30eItSRCpHDpePuCRRQlY2jo/DmsnGMkCxaxyWeokIqxbndRbdEzxJSYgB4E1 Jb8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=h51lh38M; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a10-20020a170906368a00b007c18f5f64cfsi7143174ejc.996.2023.01.09.05.01.58; Mon, 09 Jan 2023 05:02:10 -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=h51lh38M; 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 S234182AbjAIMwF (ORCPT + 52 others); Mon, 9 Jan 2023 07:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbjAIMvx (ORCPT ); Mon, 9 Jan 2023 07:51:53 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D55B06; Mon, 9 Jan 2023 04:51:51 -0800 (PST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 309BP0E7016670; Mon, 9 Jan 2023 12:51:51 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=OacVvB18McZxLNMXZ4NRfCDUji0la1y9ALJrNWFwFLE=; b=h51lh38MrlTHkSBeIFmNSJfQxPpDxyFPlQwMWOCQ5yJSDP5XbETnwGe29+5J11EphkTU RkZ/QMuFCbJe1fFerXbN7ocRbeLHROZY7eEFP+nfJPhSu4LJPXjqjf9IVVOKXgeNVVYY rmkhud7aSuiI8Ta32ZluwdlZGimZjwv3Eo4WK7ZuJdCeoVViWxQ2WuXkfHf6f4sM0pyc FcYd2u2o9N3yCy18Vxb8jPlBfSZ6wON05TZHIYF/Mbj3Wi+Nk6bNNfyeUd3M8/1bQoIC vKuCBb3k7ITGIMoF6X62fhFA9//dUeqbUNYA0tjna60G8g280eW180/Ef52iPQn03BHL Ww== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3myj6jdbsm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 12:51:50 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 309Bi1tx029590; Mon, 9 Jan 2023 12:51:42 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 3myj6jdbs7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 12:51:42 +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 3098Vw80015062; Mon, 9 Jan 2023 12:51:39 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3my00fjybq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Jan 2023 12:51:39 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 309CpaVX43581774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Jan 2023 12:51:36 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15E6A20040; Mon, 9 Jan 2023 12:51:36 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C86BB20049; Mon, 9 Jan 2023 12:51:35 +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 12:51:35 +0000 (GMT) From: Heiko Carstens To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: David Hildenbrand , kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: s390: interrupt: use READ_ONCE() before cmpxchg() Date: Mon, 9 Jan 2023 13:51:35 +0100 Message-Id: <20230109125135.393784-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: AzKIpn3LWjZZNpfB9gis_V1SVAfvtPpx X-Proofpoint-GUID: -aFgml4fVU3jhLtYfr56yl_d8uZadMCI 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_06,2023-01-09_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=712 phishscore=0 adultscore=0 mlxscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301090090 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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..a3bf1b6a7962 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 = 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 = 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); } -- 2.34.1