Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp136910pxb; Tue, 17 Aug 2021 21:35:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRSDjTfiekUaqSa8X5635KRaCWebI1yUJxQWUNAGMijHd2/d23ht2lcCQVz61RNBihNYlG X-Received: by 2002:a17:907:831d:: with SMTP id mq29mr7642874ejc.127.1629261357473; Tue, 17 Aug 2021 21:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629261357; cv=none; d=google.com; s=arc-20160816; b=APo9nMDDoa8Ku+jPgnyZvZZAZ/K2ADFD8OSbLsFRPeyOrmLay5FNN2GKzzaXfvqcbh 082OakH+k+VKvP/XxJK+2ZLv1kdMhr2KemZHxiSdmVLTVjW7NDPu2STvnTZGv6S3ed+T NPTeNf7FMeUYB1QUrJ0ZMW+8QvtF4nNoxDG05CMZeEFdjn/SSmTk75x3MJgudorZ0MMM eOV5y1mFmTlkr+1PZWTS1r1KyYFKlZvh1D+52/izxewrwTx1KehJG0hknWIkCMilts55 Vk29R83b9b3C2x8tpjSOpCIV7CBUYLCYCgaODraPGKAs/yD+BSeUynYb+218YVmiIqbN mnyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=M/5AwiU0mmr9iU0HzXxkJdPv0CjNvQGqEDwuAvDs6Ps=; b=Iikt1rxuCE0hgolDvovUuv1URzdoOZUW0Wj2rISuuG5pIC3pMnp7y98yDhW7X4j4DZ agYxx7+izSePNwJbLs6cwBIp/d/aJd5brdA7Zvu+lCyfrRJUI+Mi0wCfVmQOW7qygfJD tlmQrgncUC6CUXNxjSgUWC02MuSXnRpGUJnJTU8nA3UWKuOgcK1iolZ/OJjUXB/YQFTp RJrZpcdm1jDpXdw0sOXaZdFtEW4zCwKkv6DIHCfWETCQXuNGVAELH8sJjGy1mfvyXNpy YRv8qhvFZYwUKEqRt70O+bYyl3nBT75uMxboYIlzXT0mIXo9JxlJpRD+rGcX4BrvVvRp yCSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si4255799ejv.423.2021.08.17.21.35.34; Tue, 17 Aug 2021 21:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234174AbhHREdo (ORCPT + 99 others); Wed, 18 Aug 2021 00:33:44 -0400 Received: from mga03.intel.com ([134.134.136.65]:5812 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbhHREdo (ORCPT ); Wed, 18 Aug 2021 00:33:44 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10079"; a="216284583" X-IronPort-AV: E=Sophos;i="5.84,330,1620716400"; d="scan'208";a="216284583" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2021 21:33:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,330,1620716400"; d="scan'208";a="488288748" Received: from pl-dbox.sh.intel.com (HELO pl-dbox) ([10.239.159.39]) by fmsmga008.fm.intel.com with ESMTP; 17 Aug 2021 21:33:06 -0700 Date: Wed, 18 Aug 2021 12:27:20 +0800 From: Philip Li To: Nathan Chancellor Cc: Kees Cook , "Gustavo A. R. Silva" , Masahiro Yamada , Linus Torvalds , "Gustavo A. R. Silva" , Nick Desaulniers , Linux Kbuild mailing list , Linux Kernel Mailing List , clang-built-linux , linux-hardening@vger.kernel.org Subject: Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+ Message-ID: <20210818042720.GA1645557@pl-dbox> References: <20210817005624.1455428-1-nathan@kernel.org> <80fa539a-b767-76ed-dafa-4d8d1a6b063e@kernel.org> <5c856f36-69a7-e274-f72a-c3aef195adeb@kernel.org> <202108171056.EDCE562@keescook> <3f28b45e-e725-8b75-042a-d34d90c56361@kernel.org> <71d76c41-7f9b-6d60-ba4f-0cd84596b457@embeddedor.com> <202108171602.159EB2C7EA@keescook> <72ae69b4-6069-ade5-a12b-8ee0435f803a@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <72ae69b4-6069-ade5-a12b-8ee0435f803a@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 17, 2021 at 04:23:41PM -0700, Nathan Chancellor wrote: > On 8/17/2021 4:06 PM, Kees Cook wrote: > > On Tue, Aug 17, 2021 at 04:33:25PM -0500, Gustavo A. R. Silva wrote: > > > > > > > > > On 8/17/21 16:17, Masahiro Yamada wrote: > > > > On Wed, Aug 18, 2021 at 3:25 AM Nathan Chancellor wrote: > > > > > > > > > > On 8/17/2021 11:03 AM, Kees Cook wrote: > > > > > > On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote: > > > > > > > If you/Gustavo would prefer, I can upgrade that check to > > > > > > > > > > > > > > ifneq ($(call cc-option, -Wunreachable-code-fallthrough),) > > > > > > > > > > > > > > I was just trying to save a call to the compiler, as that is more expensive > > > > > > > than a shell test call. > > > > > > > > > > > > I prefer the option test -- this means no changes are needed on the > > > > > > kernel build side if it ever finds itself backported to earlier versions > > > > > > (and it handles the current case of "14" not meaning "absolute latest"). > > > > > > > > > > > > More specifically, I think you want this (untested): > > > > > > > > > > That should work but since -Wunreachable-code-fallthrough is off by > > > > > default, I did not really see a reason to include it in KBUILD_CFLAGS. I > > > > > do not have a strong opinion though, your version is smaller than mine > > > > > is so we can just go with that. I'll defer to Gustavo on it since he has > > > > > put in all of the work cleaning up the warnings. > > > > > > > > > > > > > > > > https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8 > > > > > > > > did two things: > > > > > > > > (1) Change the -Wimplicit-fallthrough behavior so that it fits > > > > to our use in the kernel > > > > > > > > (2) Add a new option -Wunreachable-code-fallthrough > > > > that works like the previous -Wimplicit-fallthrough of > > > > Clang <= 13.0.0 > > > > > > > > > > > > They are separate things. > > > > > > > > Checking the presence of -Wunreachable-code-fallthrough > > > > does not make sense since we are only interested in (1) here. > > > > > > > > So, checking the Clang version is sensible and matches > > > > the explanation in the comment block. > > > > I thought one of the problems (which is quickly draining away) that > > needed to be solved here is that some Clang trunk builds (that report > > as version 14) don't yet have support for -Wunreachable-code-fallthrough > > since they aren't new enough. > > Philip, how often is the kernel test robot's clang version rebuilt? Would it > be possible to bump it to latest ToT or at least > 9ed4a94d6451046a51ef393cd62f00710820a7e8 so that we do not get bit by this > warning when we go to enable this flag? Got it, currently we do upgrade in weekly cadence (but it may fall behind sometimes), and the one we use now is clang version 14.0.0 (https://github.com/llvm/llvm-project 2c6448cdc2f68f8c28fd0bd9404182b81306e6e6) We will ugrade to the head of llvm-project master today. Thanks > > I do not know of any other CI aside from ours that is testing with tip of > tree clang and ours should already have a clang that includes my patch since > it comes from apt.llvm.org. > > > > > # Warn about unmarked fall-throughs in switch statement. > > > > # Clang prior to 14.0.0 warned on unreachable fallthroughs with > > > > # -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED(). > > > > # https://bugs.llvm.org/show_bug.cgi?id=51094 > > > > ifeq ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000) > > > > KBUILD_CFLAGS += -Wimplicit-fallthrough > > > > endif > > Very clever and nifty trick! I have verified that it works for clang 13 and > 14 along with a theoretical clang 15. Gustavo, feel free to stick a > > Reviewed-by: Nathan Chancellor > Tested-by: Nathan Chancellor > > if you so desire. > > > > > > > > > The $(sort ...) is alphabetical sort, not numeric sort. > > > > It works for us because the minimum Clang version is 10.0.1 > > > > (that is CONFIG_CLANG_VERSION is always 6-digit) > > > > > > > > It will break when Clang version 100.0.0 is released. > > > > > > > > But, before that, we will raise the minimum supported clang version, > > > > and this conditional will go away. > > > > If a version test is preferred, cool; this is a nice trick. :) > > > > > I like this. :) > > > > > > I'm going to make the 0-day robot test it in my tree, first. > > > > Sounds good to me! > >