Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5886310ybh; Wed, 7 Aug 2019 13:09:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzo2nqREt9Nr4xAsRU2BHgVJF/c9E2lF3VEhsYliNUBlcH40cFu5sZRV7klMFG2YFGg6d2G X-Received: by 2002:a17:90a:346c:: with SMTP id o99mr199545pjb.20.1565208583937; Wed, 07 Aug 2019 13:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565208583; cv=none; d=google.com; s=arc-20160816; b=Lj/fs3kjTGaUGR+KLDHj+lU6CmYKqeSPPBx5RAHkQUAdY6BimAQ0ysZNpvXFmQdzmI /FN5cAktAhLl4wIFqd0aY4IflSDmY3Z5cXby9p62Ao/xAj2ectNTovIDvF1hKsGfQydL T9Fxy0RPgAVUyMmBHJ/aPiOsgtREpwBnuZaEKXOOWX47sGKOHuN/AyUCkWQrUbC5nsZE uE5bQwUi8/24GUO6dGyCjN7myd3M7YxmM0XtcaTTFMw/eRgxr6/1b3UXCQN7NPUogGEa 7NiCd6s4s5tIzJdd1sMrMxwTBQZoiT2M/h+tzt5kGcjK5ykCRI7WfXV0b5nnUyg/fk7t lWhg== 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:date:from:dkim-signature; bh=e6mJhABhQHvJEBAYgDnbQQku2ARSnWaho1xEKM71w0o=; b=tXh0DHrx/+IbJHIGOw19++hrLQQYMlc52YtSqk1dqcVKvgM/tFnczC1OlsGFF9oE2S heph7phyZG8XWE7lZCppQO7XIDCkXGDW/j01dpxlgkTudXy/k77vEzZw3HznDKxkZDRO OQv9IkulaBKrnXhMYTijbIiCQYu93Fjvfm6TxL/mHuLD1d2Q36WNw3Nh00mvZBdISdzJ dcin25+qwF82y1Z/HJvCtE91d5v+dbhOijwik8hpCdN4kDMZ7Qsp8UQh4+GFtH01j64t 8Mp/VPcZEDjQtmTdOzWtPtgHg593CuiUjo8GYPNSQ/kBmxSouuUFo8aNxLy2eyfxutIV DR4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C+IVsyKj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k65si48512575pge.422.2019.08.07.13.09.27; Wed, 07 Aug 2019 13:09:43 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C+IVsyKj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389155AbfHGUIA (ORCPT + 99 others); Wed, 7 Aug 2019 16:08:00 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:45975 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388210AbfHGUH7 (ORCPT ); Wed, 7 Aug 2019 16:07:59 -0400 Received: by mail-lj1-f194.google.com with SMTP id m23so86578144lje.12 for ; Wed, 07 Aug 2019 13:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=e6mJhABhQHvJEBAYgDnbQQku2ARSnWaho1xEKM71w0o=; b=C+IVsyKjjmvjcsuCAiBwOsW88PYOcUy9oMPpHx48In+3NA3K60lFa7cyfGgUFDV0gp VLZ+qClMfcDOf/tDowIrybHre/a+WioKIkoZ5uX2lZDxINo874lMvdhI23LtLhOhwL+P Utj98Sl+VLxlLcZGPDPPrVZUeulZ7ktKKzHao1lztKROm7MsDHPiqtZT+m/HUdiBCzcV k4PcKDZ1T1zPHm04LjbqIJDHsGF2zc4n54qn7fXpUUuOacqS+5UYNzw+OiOvyg2U9BJE pEffk8cae4c5UCpwsI2b7yESq+UIyeCmvE9lM4mgjXrGMjs+5+SPNgxynVihkQSKc1mR ZVGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=e6mJhABhQHvJEBAYgDnbQQku2ARSnWaho1xEKM71w0o=; b=rOnBYXw4Kyk0/Lq5ViWHjblIEaVUTLZ/Vs4ligl6g0wSALxjamITSah5m1EVaU+KFS 0NUpHla2c8LEoj57iEkDGIZEjxaIB7XtuxdGMmN0ahD7/KXhmuAfoXoF5yXMDi39Dj/U BN9kKYORcIhuOzixXtuKMKzTjibb/33b/n+4rZ2h/FIESV5cmMblxYYUK1KDuGWwpqiL yXVt/aUFj3+jS8vM2pa+vhEjbmGpGnvZY0Kuk+NWSMK/72aVZFGHIhiy5UdX9fS9c3OP Qobj+49ebl3WSpyvt0QIuVvQEFvtz33sGgFTe4GLULm7JWpfL++l1wtQxAEAvcoZYA+5 udMw== X-Gm-Message-State: APjAAAUdFL+uYeYa2m2jqy23t7W0+E3nRhHqLhpVB3ki+CGOlAGHoSYe z3TsWO/vlgv8MAX0N+omb6s= X-Received: by 2002:a2e:298a:: with SMTP id p10mr5869609ljp.74.1565208477643; Wed, 07 Aug 2019 13:07:57 -0700 (PDT) Received: from rikard (h-158-174-186-115.NA.cust.bahnhof.se. [158.174.186.115]) by smtp.gmail.com with ESMTPSA id i62sm18295577lji.14.2019.08.07.13.07.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 07 Aug 2019 13:07:56 -0700 (PDT) From: Rikard Falkeborn X-Google-Original-From: Rikard Falkeborn Date: Wed, 7 Aug 2019 22:07:53 +0200 To: Guenter Roeck Cc: Masahiro Yamada , Rikard Falkeborn , Andrew Morton , Joe Perches , Johannes Berg , Linux Kernel Mailing List Subject: Re: [PATCH v2 2/2] linux/bits.h: Add compile time sanity check of GENMASK inputs Message-ID: <20190807200753.GA14779@rikard> References: <20190731190309.19909-1-rikard.falkeborn@gmail.com> <20190801230358.4193-1-rikard.falkeborn@gmail.com> <20190801230358.4193-2-rikard.falkeborn@gmail.com> <20190807142728.GA16360@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 07, 2019 at 09:52:33AM -0700, Guenter Roeck wrote: > On 8/7/19 7:55 AM, Masahiro Yamada wrote: > > On Wed, Aug 7, 2019 at 11:27 PM Guenter Roeck wrote: > > > > > > On Fri, Aug 02, 2019 at 01:03:58AM +0200, Rikard Falkeborn wrote: > > > > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > > > > as the first argument and the low bit as the second argument. Mixing > > > > them will return a mask with zero bits set. > > > > > > > > Recent commits show getting this wrong is not uncommon, see e.g. > > > > commit aa4c0c9091b0 ("net: stmmac: Fix misuses of GENMASK macro") and > > > > commit 9bdd7bb3a844 ("clocksource/drivers/npcm: Fix misuse of GENMASK > > > > macro"). > > > > > > > > To prevent such mistakes from appearing again, add compile time sanity > > > > checking to the arguments of GENMASK() and GENMASK_ULL(). If both the > > > > arguments are known at compile time, and the low bit is higher than the > > > > high bit, break the build to detect the mistake immediately. > > > > > > > > Since GENMASK() is used in declarations, BUILD_BUG_ON_ZERO() must be > > > > used instead of BUILD_BUG_ON(), and __is_constexpr() must be used instead > > > > of __builtin_constant_p(). > > > > > > > > If successful, BUILD_BUG_OR_ZERO() returns 0 of type size_t. To avoid > > > > problems with implicit conversions, cast the result of BUILD_BUG_OR_ZERO > > > > to unsigned long. > > > > > > > > Since both BUILD_BUG_ON_ZERO() and __is_constexpr() only uses sizeof() > > > > on the arguments passed to them, neither of them evaluate the expression > > > > unless it is a VLA. Therefore, GENMASK(1, x++) still behaves as > > > > expected. > > > > > > > > Commit 95b980d62d52 ("linux/bits.h: make BIT(), GENMASK(), and friends > > > > available in assembly") made the macros in linux/bits.h available in > > > > assembly. Since neither BUILD_BUG_OR_ZERO() or __is_constexpr() are asm > > > > compatible, disable the checks if the file is included in an asm file. > > > > > > > > > > Who is going to fix the fallout ? For example, arm64:defconfig no longer > > > compiles with this patch applied. > > > > > > It seems to me that the benefit of catching misuses of GENMASK is much > > > less than the fallout from no longer compiling kernels, since those > > > kernels won't get any test coverage at all anymore. > > > > > > We cannot apply this until we fix all errors. > > > > I do not understand why Andrew picked up this so soon. > > > > The same was done with the fallthrough warning in mainline, which still results > in all "sh" builds failing there (and in -next, obviously). I don't understand > the logic either, but maybe it is the new normal. > > Guenter Sorry about that. As Masahiro said, the patch was picked up too soon, I've asked Andrew and Stephen Rothwell to remove the patch in a separate email thread. FWIW, there seems to be a patch for the build failure already (all arm builds seems to have the same build error): https://lore.kernel.org/lkml/20190807192305.6604-1-natechancellor@gmail.com/T/#u Rikard