From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2943C2B9F7 for ; Mon, 24 May 2021 16:34:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 975CD613D8 for ; Mon, 24 May 2021 16:34:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233193AbhEXQgQ convert rfc822-to-8bit (ORCPT ); Mon, 24 May 2021 12:36:16 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]:22017 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbhEXQgO (ORCPT ); Mon, 24 May 2021 12:36:14 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-130-Su6f02UuPwmFID_yslxeDA-1; Mon, 24 May 2021 17:34:43 +0100 X-MC-Unique: Su6f02UuPwmFID_yslxeDA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 24 May 2021 17:34:39 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.015; Mon, 24 May 2021 17:34:39 +0100 From: David Laight To: 'Mark Rutland' , Christoph Hellwig CC: Joe Richey , "trivial@kernel.org" , Joe Richey , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "x86@kernel.org" , "H. Peter Anvin" , Paolo Bonzini , Lorenzo Pieralisi , Mauro Carvalho Chehab , Zhangfei Gao , Zhou Wang , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-media@vger.kernel.org" , "linux-accelerators@lists.ozlabs.org" Subject: RE: [PATCH 0/6] Don't use BIT() macro in UAPI headers Thread-Topic: [PATCH 0/6] Don't use BIT() macro in UAPI headers Thread-Index: AQHXUJhmyhlvadTh4EyDNcSC3h2x96ry0v3w Date: Mon, 24 May 2021 16:34:39 +0000 Message-ID: <56cdb86fe8984a94b4a7a8073476d849@AcuMS.aculab.com> References: <20210520104343.317119-1-joerichey94@gmail.com> <20210524122901.GH1040@C02TD0UTHF1T.local> In-Reply-To: <20210524122901.GH1040@C02TD0UTHF1T.local> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland > Sent: 24 May 2021 13:29 > > On Mon, May 24, 2021 at 12:46:26PM +0100, Christoph Hellwig wrote: > > On Thu, May 20, 2021 at 03:43:37AM -0700, Joe Richey wrote: > > > This patch series changes all UAPI uses of BIT() to just be open-coded. > > > However, there really should be a check for this in checkpatch.pl > > > Currently, the script actually _encourages_ users to use the BIT macro > > > even if adding things to UAPI. > > > > Yes. In fact it should warn about BIT() in general. It is totally > > pointless obsfucation that doesn't even save any typing at all. > > That's not quite true; the point is that if you use BIT() consistently, > then even when you refer to bits 32 to 63 you won't accidentally > introduce shifts of more than the width of int, and the definition will > work equally well for assembly and C, which isn't true if you use `1UL` > in the definition. > > With that in mind it's shorter and clearer than its functional > equivalent: > > BIT(x) > (UL(1) << (x)) > > So IMO it's preferable to use BIT() generally, or _BITUL() in uapi > headers. And then, suddenly the compiler warns about truncation of the high bits when ~BIT(x) is used to mask a 32bit value on 64bit systems. Once the C standard committee had decided to change from K&R's 'sign preserving' integer promotions to 'value preserving' you always lose somewhere. Personally I prefer hex constants - I can't count bits at all. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89E57C2B9F7 for ; Tue, 25 May 2021 00:28:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 502A561415 for ; Tue, 25 May 2021 00:28:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 502A561415 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=ACULAB.COM Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=P3EdiY6zjlMNIxXcuaKvrDft3iOZO9ChD1Vd6SzlrSo=; b=lOKomG20FQ3hTL fKuchBqa+3UkXZmszPqnHm9lrWDsI+GdUVDxfRDxxpT6nLtmTwU4gMQINRtKo/0P9NdJF1sTUAIrp sbQHQgRlvQxOc5rbURWg1kXWBK/b7RNlXV708jEKhnZkMTLqRRwoqtaV5Fg7yOaOiXWcxdFVG2Gg1 KDI9zOb+lMVAQW8pwxXie//BLb5Ge9eSi8Rmvh8z4QCobPCPY9QypWs6hyl72Yucu7yC8nbzSl871 m3mEWeIXdPRzguCxq/gRpqBnF4qUzvhVnZPzptrXloQK7rkuHNZPtunBwrNAO8Lp/HzcgeY0Dce+y 5UzpoLp9vgbUj1avNXlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llKt5-002Y6z-Sy; Tue, 25 May 2021 00:25:37 +0000 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1llDXU-0017vA-LA for linux-arm-kernel@lists.infradead.org; Mon, 24 May 2021 16:34:51 +0000 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-130-Su6f02UuPwmFID_yslxeDA-1; Mon, 24 May 2021 17:34:43 +0100 X-MC-Unique: Su6f02UuPwmFID_yslxeDA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 24 May 2021 17:34:39 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.015; Mon, 24 May 2021 17:34:39 +0100 From: David Laight To: 'Mark Rutland' , Christoph Hellwig CC: Joe Richey , "trivial@kernel.org" , Joe Richey , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "x86@kernel.org" , "H. Peter Anvin" , Paolo Bonzini , Lorenzo Pieralisi , Mauro Carvalho Chehab , Zhangfei Gao , Zhou Wang , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-media@vger.kernel.org" , "linux-accelerators@lists.ozlabs.org" Subject: RE: [PATCH 0/6] Don't use BIT() macro in UAPI headers Thread-Topic: [PATCH 0/6] Don't use BIT() macro in UAPI headers Thread-Index: AQHXUJhmyhlvadTh4EyDNcSC3h2x96ry0v3w Date: Mon, 24 May 2021 16:34:39 +0000 Message-ID: <56cdb86fe8984a94b4a7a8073476d849@AcuMS.aculab.com> References: <20210520104343.317119-1-joerichey94@gmail.com> <20210524122901.GH1040@C02TD0UTHF1T.local> In-Reply-To: <20210524122901.GH1040@C02TD0UTHF1T.local> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210524_093449_034384_00AF8B83 X-CRM114-Status: GOOD ( 22.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mark Rutland > Sent: 24 May 2021 13:29 > > On Mon, May 24, 2021 at 12:46:26PM +0100, Christoph Hellwig wrote: > > On Thu, May 20, 2021 at 03:43:37AM -0700, Joe Richey wrote: > > > This patch series changes all UAPI uses of BIT() to just be open-coded. > > > However, there really should be a check for this in checkpatch.pl > > > Currently, the script actually _encourages_ users to use the BIT macro > > > even if adding things to UAPI. > > > > Yes. In fact it should warn about BIT() in general. It is totally > > pointless obsfucation that doesn't even save any typing at all. > > That's not quite true; the point is that if you use BIT() consistently, > then even when you refer to bits 32 to 63 you won't accidentally > introduce shifts of more than the width of int, and the definition will > work equally well for assembly and C, which isn't true if you use `1UL` > in the definition. > > With that in mind it's shorter and clearer than its functional > equivalent: > > BIT(x) > (UL(1) << (x)) > > So IMO it's preferable to use BIT() generally, or _BITUL() in uapi > headers. And then, suddenly the compiler warns about truncation of the high bits when ~BIT(x) is used to mask a 32bit value on 64bit systems. Once the C standard committee had decided to change from K&R's 'sign preserving' integer promotions to 'value preserving' you always lose somewhere. Personally I prefer hex constants - I can't count bits at all. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel