Received: by 10.192.245.15 with SMTP id i15csp924665imn; Sat, 10 Mar 2018 12:50:41 -0800 (PST) X-Google-Smtp-Source: AG47ELv2559T/b8JpfKpVT5h2YnOnCyA86EE0zwM7OkTc8W3cC6b4S65OOMB24MHZ3MOtVYco+Rt X-Received: by 2002:a17:902:27:: with SMTP id 36-v6mr3089333pla.128.1520715041079; Sat, 10 Mar 2018 12:50:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520715041; cv=none; d=google.com; s=arc-20160816; b=ptTU9Mh1Wsm6kGPuMXa+qL6wgno0/bknyRNhwt38bUdygbZOufbiYPHHIVwHZncD5g BdxXe/0AHqkqKNls6vMpjN9mw5AwjJmVDSo59Y42c0dkK6rbKW7OMBakrlotD4TRpo5I p88C0gDnz8YponRzKFZjaq6KJK219Lh/V4tliAjCRWupKcJ2eGatYD3tHgMZt/DiTKhA ep/3/xaH4zlGWQD25Tg9rjpv2krHJojOurmjs3WIWeG828V0Bos94MRQ3H6jSgIlJ+Im xXuIIO+p/G/2AE8BIAMn+WciE/Ts6k30Z0cWCnrUhI9juRv6QBNAwBCwjUIn7isy6lwx Ah5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:mime-version:references :in-reply-to:date:cc:to:from:subject:arc-authentication-results; bh=670YpE19lQdi+HzJhkgye9x1Q5/mRBwFavXmHlNlNIk=; b=caomJB+FOknDvUMX2fLa9HOnzipnNizDCYfjEQfYJNpa/TQlRB4EVS012VpX9wiK+U zMGSgM5YhilT3pwsug8dXAkz9wmK/0SRNEXEsHzHw4RlYzuU4Q7f080nWRrmmpplcxnL d+MX7zZrpCLKmve+7s+NglWvCgyzIEAOOY6TkrLRAREaVC1pjHjC/jTentQ4eXc1ew0t SJeyYqMXbOfYmzhu+kliROJapKwXbh5qxeMnE7GAvpQ6j/8oDEbUzl4TyySa8xnDsWrE ZKyWd2I1n9tXNH6tK1AAd7MOgs/FxXeT4RX5fIGh5J4qmsR57CYWzoeO79pXOZMiYgXt eNJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2-v6si3299399plo.567.2018.03.10.12.50.26; Sat, 10 Mar 2018 12:50:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751200AbeCJUtf (ORCPT + 99 others); Sat, 10 Mar 2018 15:49:35 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:59304 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751043AbeCJUte (ORCPT ); Sat, 10 Mar 2018 15:49:34 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2AKmeJc124550 for ; Sat, 10 Mar 2018 15:49:33 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gmdsnx07h-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Sat, 10 Mar 2018 15:49:33 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 10 Mar 2018 13:49:32 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 10 Mar 2018 13:49:28 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2AKnSLw9896356; Sat, 10 Mar 2018 13:49:28 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B703C603C; Sat, 10 Mar 2018 13:49:28 -0700 (MST) Received: from jarvis.ext.hansenpartnership.com (unknown [9.85.159.172]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTPS id 3AD57C6037; Sat, 10 Mar 2018 13:49:26 -0700 (MST) Subject: Re: [PATCH] scsi: resolve COMMAND_SIZE at compile time From: James Bottomley To: Stephen Kitt , Bart Van Assche Cc: "hare@suse.com" , "martin.petersen@oracle.com" , "axboe@kernel.dk" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "kernel-hardening@lists.openwall.com" Date: Sat, 10 Mar 2018 12:49:17 -0800 In-Reply-To: <20180310142930.0692200b@heffalump.sk2.org> References: <20180309232933.14e39858@heffalump.sk2.org> <20180309223355.21222-1-steve@sk2.org> <1520635631.2907.16.camel@wdc.com> <20180310142930.0692200b@heffalump.sk2.org> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-OM5HNyDTbZlw5Ws0bDJ4" X-Mailer: Evolution 3.20.5 Mime-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18031020-0016-0000-0000-0000085F90DA X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008648; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000254; SDB=6.01001157; UDB=6.00509306; IPR=6.00780488; MB=3.00019960; MTD=3.00000008; XFM=3.00000015; UTC=2018-03-10 20:49:31 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031020-0017-0000-0000-00003DCA3343 Message-Id: <1520714957.4495.5.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-10_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803100254 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-OM5HNyDTbZlw5Ws0bDJ4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, 2018-03-10 at 14:29 +0100, Stephen Kitt wrote: > Hi Bart, >=20 > On Fri, 9 Mar 2018 22:47:12 +0000, Bart Van Assche c.com> > wrote: > >=20 > > On Fri, 2018-03-09 at 23:33 +0100, Stephen Kitt wrote: > > >=20 > > > +/* > > > + * SCSI command sizes are as follows, in bytes, for fixed size > > > commands, > > > per > > > + * group: 6, 10, 10, 12, 16, 12, 10, 10. The top three bits of > > > an opcode > > > + * determine its group. > > > + * The size table is encoded into a 32-bit value by subtracting > > > each > > > value > > > + * from 16, resulting in a value of 1715488362 > > > + * (6 << 28 + 6 << 24 + 4 << 20 + 0 << 16 + 4 << 12 + 6 << 8 + 6 > > > << 4 + > > > 10). > > > + * Command group 3 is reserved and should never be used. > > > + */ > > > +#define COMMAND_SIZE(opcode) \ > > > + (16 - (15 & (1715488362 >> (4 * (((opcode) >> 5) & > > > 7)))))=C2=A0=C2=A0 > >=20 > > To me this seems hard to read and hard to verify. Could this have > > been > > written as a combination of ternary expressions, e.g. using a gcc > > statement > > expression to ensure that opcode is evaluated once? >=20 > That=E2=80=99s what I=E2=80=99d tried initially, e.g. >=20 > #define COMMAND_SIZE(opcode) ({ \ > int index =3D ((opcode) >> 5) & 7; \ > index =3D=3D 0 ? 6 : (index =3D=3D 4 ? 16 : index =3D=3D 3 || index =3D= =3D 5 ? 12 : > 10); \ > }) >=20 > But gcc still reckons that results in a VLA, defeating the initial > purpose of > the exercise. >=20 > Does it help if I make the magic value construction clearer? >=20 > #define SCSI_COMMAND_SIZE_TBL ( \ > =C2=A0=C2=A0=C2=A0(16 -=C2=A0=C2=A06) \ > + ((16 - 10) <<=C2=A0=C2=A04) \ > + ((16 - 10) <<=C2=A0=C2=A08) \ > + ((16 - 12) << 12) \ > + ((16 - 16) << 16) \ > + ((16 - 12) << 20) \ > + ((16 - 10) << 24) \ > + ((16 - 10) << 28)) >=20 > #define COMMAND_SIZE(opcode) =09 > \ > =C2=A0 (16 - (15 & (SCSI_COMMAND_SIZE_TBL >> (4 * (((opcode) >> 5) & > 7))))) Couldn't we do the less clever thing of making the array a static const and moving it to a header? =C2=A0That way the compiler should be able to work it out at compile time. James --=-OM5HNyDTbZlw5Ws0bDJ4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iHUEABMIAB0WIQTnYEDbdso9F2cI+arnQslM7pishQUCWqREzQAKCRDnQslM7pis hQCdAP9X+JY9S6TJJVa9NN/j9DR6ai4u+PI2CzZEfB4w3WKAagD/TC1cwqmOjCnr 2FGwySKUezmBHURe948ekZU+nbgRvQM= =yP4n -----END PGP SIGNATURE----- --=-OM5HNyDTbZlw5Ws0bDJ4--