Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5630416ybh; Wed, 7 Aug 2019 08:57:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqx08LECP+Qzh76V6W4dRm9v3eXcJHo6HQ1XI8p1h8xt2C7Yu7RD/Be923hE2bP5pyZ2DnyA X-Received: by 2002:a62:5883:: with SMTP id m125mr9962171pfb.248.1565193451258; Wed, 07 Aug 2019 08:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565193451; cv=none; d=google.com; s=arc-20160816; b=Pm0xHTxRxYFbrtxrvj0mgSUCsvXZxspeH2dSXiqu0cbdFednAFLamVG+egDweegY5V MuaKdTZB35jmU1osQMjpmpt9iDZiSwbn387am9rFoYd3aphYhhwPngMVeZ8CHcGCcXh2 lfkk9SRM9InNxsnWLy+Yp9H+3DHx0ZIHUZFudI3u0K410BkKpQuKATN6wZJYNGJKYpWW f8dEMHeLXgHcnKVbWZ0qfAI9mrP0D6/uvrcuZ7YGdV2wAYXewTMfZm+GupjUbdqJXZAj mHOCzGQSpg48wuTpyfG0ToazXkx2Umi8G5oUif4u4bkdMh/DVRjF5mFNaH5V60uSM9i4 AnxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=OAO7XGlQdmEIgpn78eW2L2ZXYXkQrL3lABQNvOER8oU=; b=uZqzXJVDJwE30V/VV18/Zd6J7rmBvsbH+Ib9Nqkn3ritNW6NW74QEfwxVPnJGQpL8r uJUqeT2djiHOA2uMSCicyeMfqOjeOA18djZNPbPugk8MTdmQ+InmDXHUWG37Q2PercUG av2K52Dvi/QGiMH9m22Vg4mRT5XA+bLqaF7o0zZcKN7zgYJRQAaSedCbuXj1Bl0kscV1 ZsQCjRUrGaZBWkHoX5CvSEOBSj/2M97vJf7/U/27zLGwqvibe2N932WIzPg29AMRiFQ9 ISOkFaFs0gPzRXQGUGpK90lKM2x/0ukEy77DYCmpFepwX7P1pvLTE7KQPd83DgchuVkP iNsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="VLvFt6S/"; 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 v97si222942pjb.23.2019.08.07.08.57.15; Wed, 07 Aug 2019 08:57:31 -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=@nifty.com header.s=dec2015msa header.b="VLvFt6S/"; 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 S1730088AbfHGO4S (ORCPT + 99 others); Wed, 7 Aug 2019 10:56:18 -0400 Received: from conssluserg-02.nifty.com ([210.131.2.81]:43980 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729550AbfHGO4R (ORCPT ); Wed, 7 Aug 2019 10:56:17 -0400 Received: from mail-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53]) (authenticated) by conssluserg-02.nifty.com with ESMTP id x77EuBhY021136 for ; Wed, 7 Aug 2019 23:56:11 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com x77EuBhY021136 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1565189771; bh=OAO7XGlQdmEIgpn78eW2L2ZXYXkQrL3lABQNvOER8oU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VLvFt6S/I43TB+5ltV5z9dro2bM6nhwXidEu0BPBdGKajiKSTcZwbD0RGnPPhqnft /mMTw1BfoqPeN8S6lE5X7wTJyEbdPbGKEwhkBW/1t9RhwmAyXYXc+f54mTnNhNckpb wOQmT/2unaSifpeamaZS00so7/hpEivheLJNheRyhLdl3CgqA6pwaJ8jR/Sh0uAqkU ypLaIQExZaFsLFVsj7Mfnil4erpWMEO/xB/lbQoq+cPAtE9Sm4Zqr1dZ3CH68ljCZj r+JTSvXUkD8vHwGDhdBo7tcgQ8//l8NXDLGixIKVJi6+Iaa8GVm1kx85Y1ou+X1aw+ hTSlYn6li1fbQ== X-Nifty-SrcIP: [209.85.217.53] Received: by mail-vs1-f53.google.com with SMTP id v129so60844449vsb.11 for ; Wed, 07 Aug 2019 07:56:11 -0700 (PDT) X-Gm-Message-State: APjAAAU2eIzDvu1YazDvLDgKiVKyfkJS+6E0BjNulTm314jbmOkszx8b /iQBgAJgPcM8CoermwOjNLSbmmvWYcyHMvc7Ogk= X-Received: by 2002:a67:8e0a:: with SMTP id q10mr6182973vsd.215.1565189770430; Wed, 07 Aug 2019 07:56:10 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20190807142728.GA16360@roeck-us.net> From: Masahiro Yamada Date: Wed, 7 Aug 2019 23:55:34 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/2] linux/bits.h: Add compile time sanity check of GENMASK inputs To: Guenter Roeck Cc: Rikard Falkeborn , Andrew Morton , Joe Perches , Johannes Berg , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Best Regards Masahiro Yamada