Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5675902imb; Thu, 7 Mar 2019 23:05:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyhN6Sv3wZw9/Y7yNEK4OwtIYcRCCg4b70KGqxh8Z8YJI7/WJzjUp5e1y7Cj4tuWSDdgh8u X-Received: by 2002:a63:4718:: with SMTP id u24mr15494381pga.381.1552028706892; Thu, 07 Mar 2019 23:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552028706; cv=none; d=google.com; s=arc-20160816; b=BMFfuIUY8s0vHOQrsZiUNyF5uz/ZaVKZoaKs0/09pavvkUYcGWIQjIwpGGDpEjvcCH DRJ6mqQtBLcall9RFqvtQjIiwM6GkfNzenllXWFC/gXQwTwguVnzC3cl+1sL255fQPPV GsFGBm4DnUw3gbpg/uahQ4blutMlB4Cimrif0nPr9b81CfUkAOPlGzE/YkuEGqxmcWWU cDGnZ2Tbub/LCD49X3v3Cz1n9o7fIckxYv4l3OZmDB5JJYNePHMp+xSPSWNCWMkrZsrb g5QMrU9qV1vz35BoVn2550FNPV+X/q9vrUQsZLzNUc9C903ghblfxmcqkeIfIqaDOr6N BYBQ== 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-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=nqcQfbw0y/A1pM2dU1X0o2AFYiXF5apgzGWbdwuuQZg=; b=rrPzw+L7LZhZZUMHlKLz+TMQNFTEhKByFjNsQhq+flYUWyfchuu5o5Y3L3Pj9oKc2u acxYYJXMpZxbA8GHOlPpgnrojh+R6iOlHerAuNWABVJI6YeVJ+LxktyTE5p9HIajSu+s rryL/S0w8nqoDFimu71eFqzO6ZUXleRbRyhUJ7mi5TlaIFauVU/ZiqdPPyEY0JlZ3SWa 4dfBzScDxA5ECa48VrJRYYfiMWXsUDBR67dtkQvf10UCsnLzY/1oZVB+1ZXN2C7NVBoe yAWxdhdEYHb9QlvZGTMsUE6/6Ff/OFI3OiwdScThDNSlt+8RuOkrvg0YGm0+D839mcqT U8Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@Mellanox.com header.s=selector1 header.b=DVncrk+N; 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=pass (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a4si6164790pfj.68.2019.03.07.23.04.51; Thu, 07 Mar 2019 23:05:06 -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; dkim=pass header.i=@Mellanox.com header.s=selector1 header.b=DVncrk+N; 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=pass (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbfCHHDI (ORCPT + 99 others); Fri, 8 Mar 2019 02:03:08 -0500 Received: from mail-eopbgr150072.outbound.protection.outlook.com ([40.107.15.72]:24464 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725776AbfCHHDH (ORCPT ); Fri, 8 Mar 2019 02:03:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nqcQfbw0y/A1pM2dU1X0o2AFYiXF5apgzGWbdwuuQZg=; b=DVncrk+NVKOaHv4VqPAYakezK2ED9KjvL7LRIpH9I9dNDLF13aAKmZeus/TgVxFdBjgv/rfa7791hhO5e1iR0pLbJD1DhBzeNatw1mULddPJRcRsFpK+AiViovzbfedYTE9KihM3wHh9v6LUb1H0s+B1HBDpYxe6SsD5HT4SlZ4= Received: from DB6PR0501MB2694.eurprd05.prod.outlook.com (10.172.226.9) by DB6PR0501MB2390.eurprd05.prod.outlook.com (10.168.75.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.16; Fri, 8 Mar 2019 07:03:02 +0000 Received: from DB6PR0501MB2694.eurprd05.prod.outlook.com ([fe80::d11b:17ac:dc46:eee2]) by DB6PR0501MB2694.eurprd05.prod.outlook.com ([fe80::d11b:17ac:dc46:eee2%9]) with mapi id 15.20.1686.016; Fri, 8 Mar 2019 07:03:02 +0000 From: Leon Romanovsky To: Rasmus Villemoes CC: Kees Cook , Bart Van Assche , Jason Gunthorpe , "linux-kernel@vger.kernel.org" , "linux-rdma@vger.kernel.org" Subject: Re: [PATCH] Avoid that check_shl_overflow() triggers a compiler warning when building with W=1 Thread-Topic: [PATCH] Avoid that check_shl_overflow() triggers a compiler warning when building with W=1 Thread-Index: AQHU1IFjo1AIqyRPikaxzNyP0OOhK6X/X/kAgAAN6YCAAFa0AIAAfZIAgAAM+QCAABRDgIAAArIAgAAC1wCAADbJgIAAsTMA Date: Fri, 8 Mar 2019 07:03:02 +0000 Message-ID: <20190308070258.GF32625@mtr-leonro.mtl.com> References: <20190307010153.81157-1-bvanassche@acm.org> <20190307012417.GU1758@mellanox.com> <8a5bd9ae-ebfe-687c-2868-d0f2a610d1e0@acm.org> <20190307072428.GJ1789@mtr-leonro.mtl.com> <4d90c392-5b6a-fea0-e6cf-c49ac19fdf30@acm.org> <20190307154020.GN1789@mtr-leonro.mtl.com> <20190307170230.GR1789@mtr-leonro.mtl.com> <926da814-b21d-d01d-d0bb-6304bf545218@rasmusvillemoes.dk> In-Reply-To: <926da814-b21d-d01d-d0bb-6304bf545218@rasmusvillemoes.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-clientproxiedby: LNXP265CA0062.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::26) To DB6PR0501MB2694.eurprd05.prod.outlook.com (2603:10a6:4:82::9) authentication-results: spf=none (sender IP is ) smtp.mailfrom=leonro@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [77.138.135.184] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 66999494-c878-4722-6022-08d6a3941ab4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(49563074)(7193020);SRVR:DB6PR0501MB2390; x-ms-traffictypediagnostic: DB6PR0501MB2390: x-microsoft-exchange-diagnostics: =?us-ascii?Q?1;DB6PR0501MB2390;23:FWrUnjaDSx2XBpEXyg6z9uw/Juxuca6wwPlkqxe?= =?us-ascii?Q?LNF+tn1FDoTfGy/DufUyEmbdA+Ebd4aXT00XpTZfLDBOd1Y95s6p+qEt87RW?= =?us-ascii?Q?KtxjD8LDBhwlkm4DdUxPHEbkncYTmx1Spe6tZHJUhApmibT1GirVeKBUVHjn?= =?us-ascii?Q?9jADgakHsa+PcT+KQXCnUjFjh1P63zC5EHYtD22775fTg/7Kpy4MIgyc+qVT?= =?us-ascii?Q?ycJ/zLe0jLQSXpfAtoD/KVsmNoZUaHlEMkRxUviC3XtmeZElowomyO2VKNrA?= =?us-ascii?Q?IQQe/jzlXMDXhiui6/cb9yxztzO2DdROYpY+lkMX3D+hEMk9dH/v1zG2ozhf?= =?us-ascii?Q?TWhy7nsNfvbLRaXevQIPtpZ8aoN6a+yC281Av7miCei1CaaQfLYnrpRObiww?= =?us-ascii?Q?R69m0LRsrjyOSbuJjV8LFIF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?Q?mFrttKA7CQATLVs7co7CSW+g=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 0970508454 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(39860400002)(366004)(346002)(136003)(376002)(199004)(189003)(386003)(6506007)(105586002)(26005)(52116002)(25786009)(5660300002)(99936001)(102836004)(106356001)(1076003)(76176011)(6916009)(7736002)(33656002)(305945005)(53546011)(4326008)(186003)(97736004)(71190400001)(71200400001)(8936002)(53936002)(93886005)(6306002)(81166006)(81156014)(6512007)(9686003)(966005)(3846002)(6116002)(68736007)(14454004)(6246003)(478600001)(229853002)(256004)(86362001)(66066001)(6436002)(316002)(54906003)(476003)(11346002)(8676002)(486006)(6486002)(99286004)(2906002)(446003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0501MB2390;H:DB6PR0501MB2694.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: OuPTvtXvlQdyfodONjVkvSDpqwf/cmTPnOevy6ulo2hafHVM0QIjeRkUmOMEi8CzbbcF4ClSeRL0nNhDAtzYKjhXEwnd+pxTEOiMu9p6oyZReAs4T3DvlKBbUHOSkh5MSBRFZJxFZbWbzheTHyn83i2oMYT4B2Wps4N26tbAZAAQdvi9kfXa5zXBHpKCQgj74KxzRwksNLHttiYE4rCvKbChtzA0GLgxSzarLd8BkgPTpcLN7GdoSoYQqRK0hxZCeoDzwJmMcjuY33qpDEuyx86WyIoFAG/Cfv0fFHY2/JnKppy3WRHC7k6CA/gSEwUQOs6aNDCDnLXKYHnwX8yPut0F08QB0CRZEcd1c4N0SO7bxACeCWUoXSkb/WwXY8otbcz484MkOl0rIMl68yUKrt7LQIzoFTFAySW6sy2wUOM= Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bi5JUZtvcfApsciF" MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66999494-c878-4722-6022-08d6a3941ab4 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2019 07:03:02.1152 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0501MB2390 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --bi5JUZtvcfApsciF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Mar 07, 2019 at 09:28:45PM +0100, Rasmus Villemoes wrote: > On 07/03/2019 18.12, Kees Cook wrote: > > On Thu, Mar 7, 2019 at 9:02 AM Leon Romanovsky wrote: > >> > >> On Thu, Mar 07, 2019 at 08:52:51AM -0800, Kees Cook wrote: > >>> On Thu, Mar 7, 2019 at 7:40 AM Leon Romanovsky wrote: > >>>> > >>>> On Thu, Mar 07, 2019 at 06:53:54AM -0800, Bart Van Assche wrote: > >>>>> On 3/6/19 11:24 PM, Leon Romanovsky wrote: > >>>>>> My simple patch passes too :). > >>>>> > >>>>> Can you repost your patch? > >>>> > >>>> https://patchwork.kernel.org/patch/10841079/ > >>>> > >>>> As Rasmus wrote, the thing is to avoid a < 0 check. In my patch, > >>>> I converted a <= 0 to !(a > 0 || a == 0) expression. > >>> > >>> I'd be happy either way. Is there a larger benefit to having a safe > >>> "is_non_negative()" helper, or should we go with the minimal change to > >>> the shl macro? > >> > >> I personally prefer simplest possible solution. > > So, I played around with a few variants on godbolt.org, and it seems > that gcc is smart enough to combine (a > 0 || a == 0) into (a >= 0) - in > all the cases I tried Leon's patch resulted in the exact same generated > code as the current version. Conversely, and rather surprising to me, > Bart's patch seemed to cause worse code generation. So now I've changed > my mind and also support Leon's version - however, I would _strongly_ > prefer if it introduced > > #define is_non_negative(a) (a > 0 || a == 0) > #define is_negative(a) (!(is_non_negative(a)) > > with appropriate comments and used that. check_shl_overflow is hard > enough to read already. What about if we call them is_normal(a) and is_negative(a)? Thanks --bi5JUZtvcfApsciF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBAgAGBQJcghOiAAoJEORje4g2clin97QQAL6HF9ZSrST2hp50uEBHhn6R DPczPjlSiClkDkd/khZ5/+50IXlJsZmeVPwnJ9qsfw6y65xD/Wufn498I/5ylgfF m+yG5oJmt13ejF7XocEr3rRjY3gXCfi8wWYgomjaWyn028ty47xup6eAwFU+LEXA aKcGm89Xa5HJcHY4KgkBuWT6AXyQjRrmWeQoCqw8hZZoCl0HC4S/8MQw7MTeptT7 xiRJLBrae9eJxnHpvh7myIIU7gU5CJlj88xONKCJ0HqKYEvQT4VH5gYPGvVUXls8 lkqoKhAhEsIhJy7nXQcPsNblTqmaNo1xkICd9rC16pQ5OCe3IPJt2rILdezPdu4w IPUU0k66+vQod2t7glumpBaMQAZkOFlobadtV7q19H9ZK+cyuRL2F5XIn5gZF6gV NLkGfO972V1bYcd25S1XJWn5p463u4Q1Jk2GqH+sBj2dKApogJXS/FJ1Q0RhPoTo Qt4hn285CoFBPYHxEgLp5KRnvArUFP3H40KIm3daDudif4UiaXOHLc+9ebdhMtIA XVLSEg7K7Kbcf/2fHKGKj8R+6T4C8ErmXxRpw2E0jkfBamdGhRDVoMJJpq+O7c4k Auwz9jqfrlZafZxOky9KGIGfnkIPZl4/Cyre5ZcTlkuNAVHyUiF5Kc+/REf3dr5q fQMbtd2nytU79Op65uO+ =wVhp -----END PGP SIGNATURE----- --bi5JUZtvcfApsciF--