Received: by 10.213.65.68 with SMTP id h4csp289370imn; Tue, 13 Mar 2018 04:35:10 -0700 (PDT) X-Google-Smtp-Source: AG47ELsZrOtxY7dBR1H0503HHA8HiR1F8YHkunELk+bBQHiSHFd3ooK4/WDFdY/SJEA8EfuWOOkN X-Received: by 10.101.65.134 with SMTP id a6mr207385pgq.331.1520940910156; Tue, 13 Mar 2018 04:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520940910; cv=none; d=google.com; s=arc-20160816; b=ivFC5pYjpWwJIAiwzHrG4z2KRI8SEnAOJkC2sEM6ml/TeWQeezRVbr9Q3q2Nfn2CZT sgqwDl1IkZH4TtHeeHYjkwODXCUO6e6guKvipzuuAH6BAC+fgb0hJ3MKvm/w8nzA/0Tl NJyZjXi2RRA1D23rPB41CfGYANrvHNAiEMRyuUSyZnFiIYbWRd6OLOgoUJR7nw02e+69 a3vQIdnUluCJXQ4IUQCuQDjOArqZXGR/+UzxgYBk+7RIc0Jt5cZo/j7rc4OF7LyslXaY pPq8rO+7/RHbD3XOXq4S1U4l7FGRtgMGtbfDPcDt6t/HLatMPagVttUWT9uTvsPR+vGM ZxMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=HPuHET3Q8y65SKeDi55cQq05lwGeLN7Y5y5TsOD+2iE=; b=oU9sky6rAUlKgwQ6E6kN6Xp0lUdQiD6ilXfDGs2r9gnMDrJE8aO0tNDEuZ/Xm6T6LN uvwDYhdJ2fqIb/5LRmSvxfMJ91WhLA0VXzhYC1dSQcD9VgnP5UpZexiPzqU58aZLDeLV cdkVPjmPcT+pg1c8ih//JrCz9t/CO/g19fKypSmATsDzxOriB/cbCBCKLpd/4d4H3Zrz yRdD3B3Km7m09SAFmBM1XCLZ8vZhuhc0CGDFArxl5xFOSU2po9w9Mk0+t5Ch3DclrEKY jlA3M/ifLi4JeayaSPthaBrMMJbniuXdHmwJYa0c3UdnHsY5m6oGXZ5/pRa+MTzQMw4g 35eA== 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 c11si110486pga.382.2018.03.13.04.34.55; Tue, 13 Mar 2018 04:35:10 -0700 (PDT) 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 S933027AbeCMLdp convert rfc822-to-8bit (ORCPT + 99 others); Tue, 13 Mar 2018 07:33:45 -0400 Received: from smtp-out4.electric.net ([192.162.216.181]:63613 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933011AbeCMLdn (ORCPT ); Tue, 13 Mar 2018 07:33:43 -0400 Received: from 1eviBS-0003f7-U2 by out4a.electric.net with emc1-ok (Exim 4.90_1) (envelope-from ) id 1eviBX-00046D-TI; Tue, 13 Mar 2018 04:33:39 -0700 Received: by emcmailer; Tue, 13 Mar 2018 04:33:39 -0700 Received: from [156.67.243.126] (helo=AcuMS.aculab.com) by out4a.electric.net with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1eviBS-0003f7-U2; Tue, 13 Mar 2018 04:33:34 -0700 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 13 Mar 2018 11:34:31 +0000 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 13 Mar 2018 11:34:31 +0000 From: David Laight To: 'Stephen Kitt' , "hare@suse.com" , "axboe@kernel.dk" , "jejb@linux.vnet.ibm.com" , "martin.petersen@oracle.com" CC: "linux-scsi@vger.kernel.org" , "kernel-hardening@lists.openwall.com" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" Subject: RE: [PATCH] scsi: resolve COMMAND_SIZE at compile time Thread-Topic: [PATCH] scsi: resolve COMMAND_SIZE at compile time Thread-Index: AQHTt/bqFPEiuDS4SUu2kXmgJWeSEqPODPRw Date: Tue, 13 Mar 2018 11:34:31 +0000 Message-ID: References: <20180309232933.14e39858@heffalump.sk2.org> <20180309223355.21222-1-steve@sk2.org> In-Reply-To: <20180309223355.21222-1-steve@sk2.org> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.33] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Outbound-IP: 156.67.243.126 X-Env-From: David.Laight@ACULAB.COM X-Proto: esmtps X-Revdns: X-HELO: AcuMS.aculab.com X-TLS: TLSv1.2:ECDHE-RSA-AES256-SHA384:256 X-Authenticated_ID: X-PolicySMART: 3396946, 3397078 X-Virus-Status: Scanned by VirusSMART (c) X-Virus-Status: Scanned by VirusSMART (s) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephen Kitt > Sent: 09 March 2018 22:34 > > COMMAND_SIZE currently uses an array of values in block/scsi_ioctl.c. > A number of device_handler functions use this to initialise arrays, > and this is flagged by -Wvla. > > This patch replaces COMMAND_SIZE with a variant using a formula which > can be resolved at compile time in cases where the opcode is fixed, > resolving the array size and avoiding the VLA. The downside is that > the code is less maintainable and that some call sites end up having > more complex generated code. > > Since scsi_command_size_tbl is dropped, we can remove the dependency > on BLK_SCSI_REQUEST from drivers/target/Kconfig. > > This was prompted by https://lkml.org/lkml/2018/3/7/621 > > Signed-off-by: Stephen Kitt > --- > block/scsi_ioctl.c | 8 -------- > drivers/target/Kconfig | 1 - > include/scsi/scsi_common.h | 13 +++++++++++-- > 3 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c > index 60b471f8621b..b9e176e537be 100644 > --- a/block/scsi_ioctl.c > +++ b/block/scsi_ioctl.c > @@ -41,14 +41,6 @@ struct blk_cmd_filter { > > static struct blk_cmd_filter blk_default_cmd_filter; > > -/* Command group 3 is reserved and should never be used. */ > -const unsigned char scsi_command_size_tbl[8] = > -{ > - 6, 10, 10, 12, > - 16, 12, 10, 10 > -}; > -EXPORT_SYMBOL(scsi_command_size_tbl); > - > #include > > static int sg_get_version(int __user *p) > diff --git a/drivers/target/Kconfig b/drivers/target/Kconfig > index 4c44d7bed01a..b5f05b60cf06 100644 > --- a/drivers/target/Kconfig > +++ b/drivers/target/Kconfig > @@ -4,7 +4,6 @@ menuconfig TARGET_CORE > depends on SCSI && BLOCK > select CONFIGFS_FS > select CRC_T10DIF > - select BLK_SCSI_REQUEST # only for scsi_command_size_tbl.. > select SGL_ALLOC > default n > help > diff --git a/include/scsi/scsi_common.h b/include/scsi/scsi_common.h > index 731ac09ed231..48d950666376 100644 > --- a/include/scsi/scsi_common.h > +++ b/include/scsi/scsi_common.h > @@ -15,8 +15,17 @@ scsi_varlen_cdb_length(const void *hdr) > return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8; > } > > -extern const unsigned char scsi_command_size_tbl[8]; > -#define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7] > +/* > + * 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))))) Why not: (6 + (15 & (0x446a6440u .... Specifying the constant in hex makes it more obvious. It is a shame about the 16, but an offset is easier than the negate. David