Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6815811rdb; Fri, 15 Dec 2023 09:02:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHN1RNmkK40ADm5P/eSKCWFkqfzGTRcRpmis6C2DgeTHwMD2ONeVkcuF99hdCSd1s2OYniZ X-Received: by 2002:a05:651c:4c6:b0:2cc:41b9:697c with SMTP id e6-20020a05651c04c600b002cc41b9697cmr1728316lji.2.1702659750852; Fri, 15 Dec 2023 09:02:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702659750; cv=none; d=google.com; s=arc-20160816; b=EM4b1dr0I7FMYbFKnPankHdmTco3we4ndFjt/OVhn6P638eqdZo81l+eWc+RhnChq/ aJ2YT/KdhDrpDspjI5d2MsZO9aeAyOQvXWzeYzPsUa7UmHtSb4c6Mrj4OqyXCrgWC+DY lx+oEQaWx/R7BuY7yDYvJ5mevdA9R2aRERXc1ouh7lVebu2V/80h/74bgIqpsdQWmnUE DmCRm5lUNrOBuT2plJ9Ie/2UfDb/P0ccu+oIJzVyYC/NRVugu1lh4JC2kKLgqrU9khIS 8JUHrLYGhGX6xLbzQwkufyAv0Mve6Ib6EGQNnjoEzNb/XQyWCqRnN7XelVHBI/o1mJQJ SrtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=B2YPCL9awtaXdHC9oWXUXcPCAxjjCJr0Vn0rYyQXOJo=; fh=Dl46zzDK09aj7uyyUgM38hrQilYXJmTH0pLyHumYf6A=; b=xR5xmDmgdS/0/fzQcwt2u6wGyd2P1bRN5HQu10Xe8wgev04C1a6PAbygwZ4m31GYU4 tQgrE/t3amwCl4M7L0DWLUhQIBtIT/+wJG9JM3dwifbZs4RSsyinDzrTX+PNrsVlvtAY IZcNchL/agoA1PJ703K6qUYe4H+3q7Xydvnau1SDqPIY+8nbLbxxiCEGNclnIEJk7ANj VpfQvWzw/tXSa6oPfsQ0uz46fincKLihJBKyoPWg3X6N4l49771HFLacHraTgwuIRBpZ pcg5ASjfHC7sLuL7mj64BA/0q78dim9mSG7Zt7wa7VWfJf3RSSv1Q+tnr7oyDABQlNuT C22Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=PQkTfPy1; spf=pass (google.com: domain of linux-kernel+bounces-1347-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1347-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v23-20020a509557000000b00551cb4c0df1si3254587eda.458.2023.12.15.09.02.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:02:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1347-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=PQkTfPy1; spf=pass (google.com: domain of linux-kernel+bounces-1347-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1347-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6D1991F249DB for ; Fri, 15 Dec 2023 17:02:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1B953EA9B; Fri, 15 Dec 2023 17:02:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="PQkTfPy1" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E9C93FB28; Fri, 15 Dec 2023 17:02:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BFGwALZ020777; Fri, 15 Dec 2023 17:02:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=B2YPCL9awtaXdHC9oWXUXcPCAxjjCJr0Vn0rYyQXOJo=; b=PQkTfPy19H+mSenEhnpAiTSvzh99ikxC/N8xceArJNxfudZcsbS0iOFt+hC3Kj8ja6T8 UPTff1wKw+WBjX3WrJhILb3ZQ14r22XUASmkpKxeUEQsYdVMco2e6feitgRiI+kTQIZZ B8djZ5swFOcvuTSZFpj3MMJQDkE1ClPmW/fmCAhkm7pO/x/xjyys/Zh0zHmMH+HLc+CX /SCEsUAPPyX3MBoZYp0tUJOxo7e2lpW+SyN+vnlQ1oow7pFzKfzV7As2MYeNy76kpKjG 7jJFh/woJavBz8s9wXz23TkFkX4pRSiLGsIIbFnsnyoDE7l6JbVMDcLZuX44bwbZlFAY gw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v0tft8qpg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 17:02:13 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BFGjUjK006288; Fri, 15 Dec 2023 17:02:12 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v0tft8qnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 17:02:12 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3BFFXtGX013937; Fri, 15 Dec 2023 17:02:11 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uw592rwft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 17:02:11 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3BFH28GG27853434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Dec 2023 17:02:08 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8CD1B20043; Fri, 15 Dec 2023 17:02:08 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5FF8A20040; Fri, 15 Dec 2023 17:02:08 +0000 (GMT) Received: from p-imbrenda (unknown [9.152.224.66]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2023 17:02:08 +0000 (GMT) Date: Fri, 15 Dec 2023 18:02:06 +0100 From: Claudio Imbrenda To: Nina Schoetterl-Glausch Cc: Paolo Bonzini , Shuah Khan , Janosch Frank , Christian Borntraeger , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: s390: selftest: memop: Fix undefined behavior Message-ID: <20231215180206.740df738@p-imbrenda> In-Reply-To: <20231215161125.943551-1-nsg@linux.ibm.com> References: <20231215161125.943551-1-nsg@linux.ibm.com> Organization: IBM X-Mailer: Claws Mail 4.2.0 (GTK 3.24.38; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: p_xIXzpWKEXFMQuEJFyjrgTdOUj5Kojn X-Proofpoint-GUID: sAFCq5iOnK_QJcqwHmouXldvP6Q9_rtw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-15_10,2023-12-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1011 impostorscore=0 phishscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312150118 On Fri, 15 Dec 2023 17:11:25 +0100 Nina Schoetterl-Glausch wrote: > If an integer's type has x bits, shifting the integer left by x or more > is undefined behavior. > This can happen in the rotate function when attempting to do a rotation > of the whole value by 0. is 0 the only problematic value? because in that case... > > Fixes: 0dd714bfd200 ("KVM: s390: selftest: memop: Add cmpxchg tests") > Signed-off-by: Nina Schoetterl-Glausch > --- > tools/testing/selftests/kvm/s390x/memop.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/kvm/s390x/memop.c b/tools/testing/selftests/kvm/s390x/memop.c > index bb3ca9a5d731..2eba9575828e 100644 > --- a/tools/testing/selftests/kvm/s390x/memop.c > +++ b/tools/testing/selftests/kvm/s390x/memop.c > @@ -485,11 +485,13 @@ static bool popcount_eq(__uint128_t a, __uint128_t b) > > static __uint128_t rotate(int size, __uint128_t val, int amount) > { > - unsigned int bits = size * 8; > + unsigned int left, right, bits = size * 8; > ...why not just: if (!amount) return val; ? > - amount = (amount + bits) % bits; > + right = (amount + bits) % bits; > + /* % 128 prevents left shift UB if size == 16 && right == 0 */ > + left = (bits - right) % 128; > val = cut_to_size(size, val); > - return (val << (bits - amount)) | (val >> amount); > + return (val << left) | (val >> right); > } > > const unsigned int max_block = 16; > > base-commit: 305230142ae0637213bf6e04f6d9f10bbcb74af8