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=-2.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_MUTT autolearn=ham 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 944E9C43142 for ; Tue, 26 Jun 2018 04:16:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 45D53264CD for ; Tue, 26 Jun 2018 04:16:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="lJbJ3y/p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45D53264CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751141AbeFZEQj (ORCPT ); Tue, 26 Jun 2018 00:16:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:47674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750829AbeFZEQh (ORCPT ); Tue, 26 Jun 2018 00:16:37 -0400 Received: from localhost (unknown [5.29.173.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7DAF4264CD; Tue, 26 Jun 2018 04:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529986597; bh=M4Z9R0h2eMvdwjZ0scm+jSroOY47fpGsCVLr0MXiFg4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lJbJ3y/pQ3Atu4o8rGpd/wnYYRhIbCmQqSVPA2pAiZBuSvoXFFuFJOf5JijUC93aj lwpWzrELgJ1gRnV44TuvUrP4hg4TeJu5b+HWYrRHBJ3cww+rfYWlrGmQIL73z3khas 551MeUh1So3MYDNgJEKGdRsCypzWADVAjz6QPN6w= Date: Tue, 26 Jun 2018 07:16:34 +0300 From: Leon Romanovsky To: Jason Gunthorpe Cc: Rasmus Villemoes , Doug Ledford , Kees Cook , RDMA mailing list , Hadar Hen Zion , Matan Barak , Michael J Ruhl , Noa Osherovich , Raed Salem , Yishai Hadas , Saeed Mahameed , linux-netdev , linux-kernel@vger.kernel.org Subject: Re: [PATCH rdma-next 08/12] overflow.h: Add arithmetic shift helper Message-ID: <20180626041634.GL17747@mtr-leonro.mtl.com> References: <20180624082353.16138-1-leon@kernel.org> <20180624082353.16138-9-leon@kernel.org> <20180625171157.GE5356@mellanox.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sMkrXc3gAYLRVOjR" Content-Disposition: inline In-Reply-To: <20180625171157.GE5356@mellanox.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --sMkrXc3gAYLRVOjR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jun 25, 2018 at 11:11:57AM -0600, Jason Gunthorpe wrote: > On Mon, Jun 25, 2018 at 11:26:05AM +0200, Rasmus Villemoes wrote: > > > check_shift_overflow(a, s, d) { > > unsigned _nbits = 8*sizeof(a); > > typeof(a) _a = (a); > > typeof(s) _s = (s); > > typeof(d) _d = (d); > > > > *_d = ((u64)(_a) << (_s & (_nbits-1))); > > _s >= _nbits || (_s > 0 && (_a >> (_nbits - _s - > > is_signed_type(a))) != 0); > > } > > Those types are not quite right.. What about this? > > check_shift_overflow(a, s, d) ({ > unsigned int _nbits = 8*sizeof(d) - is_signed_type(d); > typeof(d) _a = a; // Shift is always performed on type 'd' > typeof(s) _s = s; > typeof(d) _d = d; > > *_d = (_a << (_s & (_nbits-1))); > > (((*_d) >> (_s & (_nbits-1)) != _a); > }) > > And can we use mathamatcial invertability to prove no overlow and > bound _a ? As above. Rasmus and Jason, Thanks for the feedback. The reason why I introduced function, because wanted to reuse check_mul_overflow macro, but for any reasons which I don't remember now, I had hard time to fix compilation errors. Anyway, I'll resubmit. Thanks > > Jason > -- > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html --sMkrXc3gAYLRVOjR Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBAgAGBQJbMb4iAAoJEORje4g2clinBKwQAJWn7Dr7LawQOUuHxpIQ3tUx hNKFM5PC4ekX3MCYddsN+E/DMif8dbZl5q/RIS0AT3u1kICpwv4twliHgJIOKMbk w0dJ6k+qW9RgOGXvyglHRbX2481p9qh/tV5Wx+/jAzSY4+x0R5JfSl+YjDkSQN9m nPfiMJzgyAs4uQ5/wGbI19REH8sxTY/wm7s8Dvde2WFFz94ksNwj35i3bpYEve5m pSO6Z/7xTBRSa07dvC+gkHZU5W+CeyIYeGnW42F+486DGoNM8rCKeSQNXjc52CYy qyT9G/OpCf/3H9WDVkEDcQ/06b/uM9s/iAUjb34XmLxIfmfWFtHdN6INuOWANQpL Jiv/RUm1tV0pxE4vG3uUuFhm3Bmd010frtsfkRypqaR/N4EWfh+vBM9bFUbmrBoX kfZw0Gdhfl7/yYrc4oYj5I54CZIo14vAzuZL9PtBn1V6ns7YyCGSPcZXVjcMgh0F sWeZ7lLbcD0qrP6BZTOzhKyR28T9V6kSEkMUciBhS8bt0yDp27O0Q3+oXiljNSR5 OWnKOY4pizgr6OMEexh+26aGPM6hBQP1mxCaUKgXTmkB1+JylAbClB6BuD2eXymg 87EAC3j7GK/1RGhOoBKYsYslrJNRMA61dWx3vGtGEm2cAYGw9l0WKnzRZj7KAbTD RIrR9YPhTQK5zHtf8U8R =Kso0 -----END PGP SIGNATURE----- --sMkrXc3gAYLRVOjR--