Received: by 10.223.185.111 with SMTP id b44csp1420677wrg; Sat, 10 Mar 2018 05:39:19 -0800 (PST) X-Google-Smtp-Source: AG47ELtWgl1Raw9d69sRNE3lsFSWfOeDVtDGor6E/l844lhl/K8o1EdHOdXpQEeExQTwIxHfXqpv X-Received: by 10.101.82.139 with SMTP id y11mr1736628pgp.68.1520689159219; Sat, 10 Mar 2018 05:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520689159; cv=none; d=google.com; s=arc-20160816; b=s66yLl9KmB38+6wuqp0NkfNp1UGYBxo584bdyNyi21X8jj0RnuZmQxTvZYjQgWnM2B Je8p+hPtlcyzXxVz0o2LBlBYpsK5FDlWbm/gR7q77LVXk0kmyPxZtgHQeE7+RDBJyvbi bbHCsMy4O3ARRA799AYfXaNES/Vs2R0HG9xRQs91uXPllVa3Nah4/0U8Lu2yQvpPsf9t FqI8G7piBtxNwHqDH8VRQpaJSXZilFEG2bLH8wuWGAIQJMmuLa94Wgo9EFA4d+hkHJbF b0CF5U+gZ8yAY9H8DWjykkvEbHon6Wp2EJdtM7Br/AbeKYJi/TrSClrTD0vsSTzkuQ68 DhQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:arc-authentication-results; bh=3l8aRwLM/8+pZGpVJPB7X6fa7AJG169WO6sUTPz+dCk=; b=SG/ej9e8BbscjmEDVYqJkENZM0vsHuZMDfelmw4x49Z2+3nTP6nCZULJ2kySGeG3gr M8ZXy35cZ4OEoIUafT1IfC9MJwPoMub/iqLHDuXoWQOXeXhCXfMKx2qWgWjh/B0O+6Fw zZv4cHNS2PEosZmhDrdmEY6oYZx9Hon3Xm26ULuqPCvaSgb7DJvJzBg/Ulq/LiPLkjjR N3NrZKzZgAM26w3ftLDWqWp986tCMw/kP1y7/XtCSiTcHnHVXGXMQUyCZdIPcwIl1aK1 Iodo9ZOsg/OojiGxFBCVA5A/xNQXmD8B4QOHdWgeJhY27UgQ+8p6Je2nUlJIcULaI3fd Rplg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 23si2752214pfy.85.2018.03.10.05.39.02; Sat, 10 Mar 2018 05:39:19 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933014AbeCJNiG (ORCPT + 99 others); Sat, 10 Mar 2018 08:38:06 -0500 Received: from 9.mo69.mail-out.ovh.net ([46.105.56.78]:58255 "EHLO 9.mo69.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932926AbeCJNiF (ORCPT ); Sat, 10 Mar 2018 08:38:05 -0500 X-Greylist: delayed 1007 seconds by postgrey-1.27 at vger.kernel.org; Sat, 10 Mar 2018 08:38:05 EST Received: from player729.ha.ovh.net (unknown [10.109.122.98]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id 76F135B8BB for ; Sat, 10 Mar 2018 14:29:52 +0100 (CET) Received: from heffalump.sk2.org (gw.sk2.org [88.186.243.14]) (Authenticated sender: steve@sk2.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id B0A685E009A; Sat, 10 Mar 2018 14:29:41 +0100 (CET) Date: Sat, 10 Mar 2018 14:29:30 +0100 From: Stephen Kitt To: Bart Van Assche Cc: "jejb@linux.vnet.ibm.com" , "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" Subject: Re: [PATCH] scsi: resolve COMMAND_SIZE at compile time Message-ID: <20180310142930.0692200b@heffalump.sk2.org> In-Reply-To: <1520635631.2907.16.camel@wdc.com> References: <20180309232933.14e39858@heffalump.sk2.org> <20180309223355.21222-1-steve@sk2.org> <1520635631.2907.16.camel@wdc.com> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/3N3tICVyMiJ8mX7TlQQ=.7+"; protocol="application/pgp-signature" X-Ovh-Tracer-Id: 15983275080714636766 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrkeelgdegkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Sig_/3N3tICVyMiJ8mX7TlQQ=.7+ Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Bart, On Fri, 9 Mar 2018 22:47:12 +0000, Bart Van Assche wrote: > On Fri, 2018-03-09 at 23:33 +0100, Stephen Kitt wrote: > > +/* > > + * SCSI command sizes are as follows, in bytes, for fixed size command= s, > > per > > + * group: 6, 10, 10, 12, 16, 12, 10, 10. The top three bits of an opco= de > > + * 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))))) =20 >=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 stateme= nt > expression to ensure that opcode is evaluated once? That=E2=80=99s what I=E2=80=99d tried initially, e.g. #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); \ }) But gcc still reckons that results in a VLA, defeating the initial purpose = of the exercise. Does it help if I make the magic value construction clearer? #define SCSI_COMMAND_SIZE_TBL ( \ (16 - 6) \ + ((16 - 10) << 4) \ + ((16 - 10) << 8) \ + ((16 - 12) << 12) \ + ((16 - 16) << 16) \ + ((16 - 12) << 20) \ + ((16 - 10) << 24) \ + ((16 - 10) << 28)) #define COMMAND_SIZE(opcode) \ (16 - (15 & (SCSI_COMMAND_SIZE_TBL >> (4 * (((opcode) >> 5) & 7))))) Regards, Stephen --Sig_/3N3tICVyMiJ8mX7TlQQ=.7+ Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEnPVX/hPLkMoq7x0ggNMC9Yhtg5wFAlqj3boACgkQgNMC9Yht g5xKfA/+N51ED2mvt0PbJzGC415SSH48pWK+9c0efNme5li4Tqs8Hm2Y4EcBTWcq h9EuQPL0Cd0p/Zd8pXzihlqlX1i0FevsKf/IpD7icJbaVrQxYZTQhIhDV3dUocqC dW+BqTB4hL/iS6pTm+LEd0+e7i0D8T7noLEI5Z7y6WB9R1NLmfa5RnVBeD40pHRW Khqz1Az8TieXASGur1GvaAtCBE5CQt5pUahOw5KAHodl57tsGHzW/6Hz5J+f2GOI duKM1KEZ0vP5Yz/NGhHDoL278smJmhwCMr4T/VC7xlaTyRQCexME55hWQiTti3C9 v1LfWK5/Is04bUslqjQOL0CkuhXz9+Ql6SW9dcR8OPUbQRz0IyEvVKNLxc7YFqsM m4TBJpfW9BrYc/w9u5VgXto6EY6t1bFr+CjdV3svfQWi+fhvKgZl5F/ed4MkBY8y 6P2cbsmh3Y8bWCJuM9tJD3E+e5WKclI2OpzzzmaA31ky5tDt250CCGcn7TpJHd5M L6Rgt9Evdw2MpEKuDSzJFn9zYy3aI99Zs/S58Sg9AxKAcbw+qcLAfF9yJpxz1chb xLE8YowvlvKMRK6DMjnO3skhvc5RNVFjes8+qfPoVY8oPuha/ygcMn9GPX3aNr0v EWHercIjwlhZz9NrApIN1Lm9+ok/SDLVTsy4bah6XAuz97QQEH4= =RlLD -----END PGP SIGNATURE----- --Sig_/3N3tICVyMiJ8mX7TlQQ=.7+--