Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5884675imb; Fri, 8 Mar 2019 04:42:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzzCX8NyMovN4ylOKu5IoME+APDTyTouTfoWUoWs541welpOXwXSlRSboy+feIHc26r4mQ1 X-Received: by 2002:a17:902:421:: with SMTP id 30mr18234045ple.142.1552048961138; Fri, 08 Mar 2019 04:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552048961; cv=none; d=google.com; s=arc-20160816; b=BLnOIJ8hgUx8TIVLnEOoUWvWG+nwjE8rRDojCXF8beMcQmyriVWkHrkHxdihE/8+Ad kzUGDh/w2foFLDWKZ9X4I+uaqUbpl9EiIjnNvP0Iu3SbgTrwhal9qSyTvhbDYp76VASN nV4ydBjm6k1MJw2xasm320cksl9muugdwgpa0Gwt5OIBjFvAGc2WkfKbpCFZJLZiFBCg FT59CIk3rePWj/HRwFowVc04fLr5l3u1/OxQNlnYu4ae339AOMLnkzxq1IYgT+KIbO6y 8QtD3HIFyk3Ct8wRnRXH3Df47j4bw2GCspwtwE3mTZMNKMo8MvJWydQrypLNS4pIctfX 4eHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=adR+E/OsmXqnABOXHM75x+oGV2p1CkxaPVcL89SSKxk=; b=SFYY4R8yubaZxEPltUI1Un/wxDiZGh3YB8z+mf59ITbkU7ei4KBNu/MUQg4e9IRjpl 5p8to8w5hoS+r1HfFEfNO5fKlbCdkvf3rOqhmDKXKHFtxEhT9uP0a0bOrNkJ8y6crpXy 4W9cXHzScTAs40XelSYAihQpC3TvPzmVbAMtrzwXcbaFIKTqvgP/utw8cYf5pOEcuIm2 pUjRyZ5M3Z51/dZRYOczEVVarWIOP4dDCxukLBWnrI0gL89oIqysQ5rNSCDgkHCatCY3 U7l8FO5hD3KG1GGYnaiNqVCoLTdzQQw8ZBjZFcPjUDkk4zItUmWsPW3k5R2O9cdzL5eU Z3lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=mlVO6F81; 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 186si7127753pfe.262.2019.03.08.04.42.25; Fri, 08 Mar 2019 04:42:41 -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=@ziepe.ca header.s=google header.b=mlVO6F81; 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 S1726424AbfCHMmC (ORCPT + 99 others); Fri, 8 Mar 2019 07:42:02 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:40116 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726340AbfCHMmC (ORCPT ); Fri, 8 Mar 2019 07:42:02 -0500 Received: by mail-qk1-f194.google.com with SMTP id h28so11033948qkk.7 for ; Fri, 08 Mar 2019 04:42:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=adR+E/OsmXqnABOXHM75x+oGV2p1CkxaPVcL89SSKxk=; b=mlVO6F81w/F/09bjDwhaDMn1EfbWifaSFgeXOqWYz2ouX0yLy/AzOdARDXZF+Tu5sB St06omjkkaGQzT9GNgARgJFqgH6Cm8aDigUHJ5WARK4U6M4qEPqB2qpASegSZtzfFEmc R8LSTlsdehB5Lp+SzadAiUCbkIYHOfEHiTnt/1gt1AH8a3NJVxhcsEjd88fx3PQADjUg JO7xnjhDm/DgIntu7fvZZtWL62zhx3aNQY34E8ZswqhZCN976vV74sh1AhRDGp8OLGBm GoqlxCLp0bLwRzsfqUz14f8t5qWH/opxD2BFKrYVvzko6+7gzu6jXTgEYfVNvQDb/l8u m7/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=adR+E/OsmXqnABOXHM75x+oGV2p1CkxaPVcL89SSKxk=; b=MMxoVaXmJRJR0z1fygZFpw/AvqJXwNUoFWN5xw8Mn1p2jAQavCKopFouHySUY4LhcZ qKY5JhiuoCRAIT8VfKesWHADOrAeRoIT7qTUtQeIgT0XjDYvL3Bjqm4Sp9n7AI0Ks8qJ DDfTWjDiMERsyKr/mh8kcCv+OMgsdw/QkVyDR5BZywtjwndHMkEXaTCetElnYjMeC2sK pR8gYiyGN/at3wgdJKJQ/51pgGEbXz2/6A+q/fLpmeWu5wgd90heaav/Bxp9wtYUIYNn Xok9STBZmeaifC9dsZhTSvpL43FHhWBL59d+xTfH7zk1ny32n3kzQzmrLjLzfAFxZW+M uN4g== X-Gm-Message-State: APjAAAWFVGREieYq84uUeFj3wOJELRqfFyYfir1rm4rt6xiXw7EfadiL 2p6u7ntepy+g4oBkk3NjWVoCRg== X-Received: by 2002:ae9:c008:: with SMTP id u8mr621240qkk.286.1552048920742; Fri, 08 Mar 2019 04:42:00 -0800 (PST) Received: from ziepe.ca ([24.137.65.181]) by smtp.gmail.com with ESMTPSA id l16sm3893714qke.20.2019.03.08.04.41.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Mar 2019 04:41:59 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1h2Ep4-0006Kj-6d; Fri, 08 Mar 2019 08:41:58 -0400 Date: Fri, 8 Mar 2019 08:41:58 -0400 From: Jason Gunthorpe To: Rasmus Villemoes Cc: Bart Van Assche , Kees Cook , "linux-kernel@vger.kernel.org" , "linux-rdma@vger.kernel.org" , Leon Romanovsky Subject: Re: [PATCH] Avoid that check_shl_overflow() triggers a compiler warning when building with W=1 Message-ID: <20190308124158.GD9321@ziepe.ca> References: <20190307010153.81157-1-bvanassche@acm.org> <20190307012417.GU1758@mellanox.com> <8a5bd9ae-ebfe-687c-2868-d0f2a610d1e0@acm.org> <2c122567-d14b-7867-9230-67f570c13d15@rasmusvillemoes.dk> <1552003703.45180.17.camel@acm.org> <2d60debb-2b64-1b1f-7e16-d20720c93e28@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2d60debb-2b64-1b1f-7e16-d20720c93e28@rasmusvillemoes.dk> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 08, 2019 at 08:58:21AM +0100, Rasmus Villemoes wrote: > On 08/03/2019 01.08, Bart Van Assche wrote: > > On Thu, 2019-03-07 at 08:18 +0100, Rasmus Villemoes wrote: > >> On 07/03/2019 03.14, Bart Van Assche wrote: > >>> On 3/6/19 5:24 PM, Jason Gunthorpe wrote: > >>>>> > >>>>> diff --git a/include/linux/overflow.h b/include/linux/overflow.h > >>>>> index 40b48e2133cb..8afe0c0ada6f 100644 > >>>>> +++ b/include/linux/overflow.h > >>>>> @@ -202,6 +202,24 @@ > >>>>> #endif /* COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW */ > >>>>> +/* > >>>>> + * Evaluate a >= 0 without triggering a compiler warning if the type > >>>>> of a > >>>>> + * is an unsigned type. > >>>>> + */ > >>>>> +#define is_positive(a) ({ \ > >> > >> is_non_negative, please! positive means > 0. And perhaps it's better to > >> move these utility macros closer to the top of the file, together with > >> the other type/range helpers. > > > > Hi Rasmus, > > > > Thank you for the feedback. But according to what I found online opinions > > about whether or not zero is a positive number seem to vary. From > > https://en.wikipedia.org/wiki/Sign_(mathematics): > > Yes, I'm a mathematician, I'm aware of that. You can also find people > who use "less than" in the "<=" sense, and then say "strictly less than" > when they mean "<". > > > Terminology for signs > > > > When 0 is said to be neither positive nor negative, the following phrases > > may be used to refer to the sign of a number: > > * A number is positive if it is greater than zero. > > * A number is negative if it is less than zero. > > * A number is non-negative if it is greater than or equal to zero. > > * A number is non-positive if it is less than or equal to zero. > > > > When 0 is said to be both positive and negative, modified phrases are used > > to refer to the sign of a number: > > * A number is strictly positive if it is greater than zero. > > * A number is strictly negative if it is less than zero. > > * A number is positive if it is greater than or equal to zero. > > * A number is negative if it is less than or equal to zero. > > Right, but in no way does it ever make sense to mix these conventions. > So the options for describing ">= 0, < 0" are "non_negative, negative" > or "positive, strictly_negative". > > In the context of the C language, the first convention is used. While > not explicitly stated, it can be inferred from usage of the terms. > First, the word nonnegative is used (e.g. in defining argc). Second, "If > the value of the right operand [in a shift expression] is negative [...] > the behaviour is undefined.", so certainly negative cannot include 0. > Third, E* constants are required to be positive, and "[errno] is never > set to zero by any library function". Etc. etc. Lets use is_unsigned() or is_unsigned_value() then for the name of the test, that is pretty unambiguous and alot nicer to read than is_not_negative() FWIW, in computer science I generally see the terms used as: negatve: < 0 positive: >= 0 natural: > 0 This language naturally follows the twos complement construction where it is very logical to say a number with the sign bit set is 'negative' and a number with it clear is 'positive', which means 0 is positive. Which is probably enraging to mathematicians.. But has a certain logic. .. and most CS places don't actually care about the difference between > 0 and >= 0 , while < 0 is usually highly interesting. Jason