Message ID | 20230414082943.1341757-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp223549vqo; Fri, 14 Apr 2023 01:37:09 -0700 (PDT) X-Google-Smtp-Source: AKy350bnMheYuVOoeP9t+Ej986z5MLdxH5/l+tB6lGbB32GKXaVQxkjNTHp+hprdquWyaPg2eams X-Received: by 2002:a17:902:ce8c:b0:1a6:7b92:15ec with SMTP id f12-20020a170902ce8c00b001a67b9215ecmr2030263plg.41.1681461428995; Fri, 14 Apr 2023 01:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681461428; cv=none; d=google.com; s=arc-20160816; b=hFleXXnkQgY0n+51QvNu+0NoC8WfO06Fppm/7Y8BN2TjPY2HOsnYwdgH/MaIArdd4D +W6Egty0m9U2PnqldD4zcYMMlY8L8mrRAvTY4/tpQL+JxcJ9bTX+1MnYmoSrdWPcPbmb ppnWVNkELcSgvMV5F4vsAhRR+TRJx2l3zJA5RXYrTLuYUUbD1zZepcfZcVSb7r0yUjmR /GnANDRKKBxf/nbwxf2iF8H0Vy3ReqQmQFyIt+oR/kE1N+sUHmUUc4HnQtAT6kjo5oMX YeNDSTYWqRYv0bV3uOJIoT/MxMJLDQGQ79N1n5ov8ys/+FJzL/mSSSCP3ms3I31ZCQUU /FIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=F0nAr7knvbuggdLaOyKz0wqlPkbknidAEagf8h7aml4=; b=aXwIZ81Ac1cY8cZ9j1Nromvu/93xv/1fWoZxouUIfQUS3aJ5dv66VOAsNNFSx70+As w0wHhyit6aq7cAeXpb0cH1BAZk3gHFApbyxLXOvHn7JHrUiiHWx99FzqGstfOZbYoqWe T9iPWMMSiKFc5GQDwOB+xntImt9OKxMGPchtsoTcEQKM8N4JtPCEYJZD4RH+9rzyv7xk bCv3QxCou/fgsEYtDQvjr8N+0YJ8ZhLlqOstp3fWxAj6G0BpEK9W3TOyEYXBPbLWxj2b FBexH5DcEMF1cc94aqwAx2VAm90z+MJrV2iFyr1yxuLaA6hZhRvcqNmpbQixDs/LJsVg hGeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MAc0Wdvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a1709028a8b00b001a63af5f8d8si3888624plo.4.2023.04.14.01.36.51; Fri, 14 Apr 2023 01:37:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MAc0Wdvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbjDNIac (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Fri, 14 Apr 2023 04:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbjDNIaG (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 14 Apr 2023 04:30:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88B6A6E9F; Fri, 14 Apr 2023 01:29:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 16EE9644E4; Fri, 14 Apr 2023 08:29:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48916C433EF; Fri, 14 Apr 2023 08:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681460997; bh=ZTCTGs1pRDDeWJeFuWw6MUiRlW5oe3Xoqp/dtRXoY0o=; h=From:To:Cc:Subject:Date:From; b=MAc0WdvtaHTQOVtkR71fygSK181HZrRel+3IJliSMjR6cKg5dK5tzRhJDo1C1DnAE hRdOVKQ2Ip5CbFSmSU84TD3LjP7ZdbPWd1iGEkvtwgrXmdrDrxZL24zdDQq+t+5R+e aBVFLXTpI+fCGZ3onY6KnK+j5ZusS2MaxSB+PvBvc3oEf6H0ezQa+ujnG4ohFqS2/X K3N4MPlM3l668EE6yYNPGiaLVybR+oBVjQjHPIMuXLoVCdfMrdS7JE3jrGlZiCg4Bn INujmut/VQNgRi7hYKV5qlcf99alLjF5ILdUr25hqG42/inaD3nS1f2NgXnfW4/B0X uMTHV4E9s7kmQ== From: Arnd Bergmann <arnd@kernel.org> To: Andrey Ryabinin <ryabinin.a.a@gmail.com>, Masahiro Yamada <masahiroy@kernel.org>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Marco Elver <elver@google.com> Cc: Arnd Bergmann <arnd@arndb.de>, Nicolas Schier <nicolas@fjasle.eu>, Alexander Potapenko <glider@google.com>, Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, Tom Rix <trix@redhat.com>, Andrew Morton <akpm@linux-foundation.org>, Michael Ellerman <mpe@ellerman.id.au>, "Peter Zijlstra (Intel)" <peterz@infradead.org>, linux-kbuild@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] kasan: remove hwasan-kernel-mem-intrinsic-prefix=1 for clang-14 Date: Fri, 14 Apr 2023 10:29:27 +0200 Message-Id: <20230414082943.1341757-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763140099273615200?= X-GMAIL-MSGID: =?utf-8?q?1763140099273615200?= |
Series |
kasan: remove hwasan-kernel-mem-intrinsic-prefix=1 for clang-14
|
|
Commit Message
Arnd Bergmann
April 14, 2023, 8:29 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de> Unknown -mllvm options don't cause an error to be returned by clang, so the cc-option helper adds the unknown hwasan-kernel-mem-intrinsic-prefix=1 flag to CFLAGS with compilers that are new enough for hwasan but too old for this option. This causes a rather unreadable build failure: fixdep: error opening file: scripts/mod/.empty.o.d: No such file or directory make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:252: scripts/mod/empty.o] Error 2 fixdep: error opening file: scripts/mod/.devicetable-offsets.s.d: No such file or directory make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:114: scripts/mod/devicetable-offsets.s] Error 2 Add a version check to only allow this option with clang-15, gcc-13 or later versions. Fixes: 51287dcb00cc ("kasan: emit different calls for instrumentable memintrinsics") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- There is probably a better way to do this than to add version checks, but I could not figure it out. --- scripts/Makefile.kasan | 5 +++++ 1 file changed, 5 insertions(+)
Comments
On Fri, Apr 14, 2023 at 10:29:27AM +0200, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > Unknown -mllvm options don't cause an error to be returned by clang, so > the cc-option helper adds the unknown hwasan-kernel-mem-intrinsic-prefix=1 > flag to CFLAGS with compilers that are new enough for hwasan but too Hmmm, how did a change like commit 0e1aa5b62160 ("kcsan: Restrict supported compilers") work if cc-option does not work with unknown '-mllvm' flags (or did it)? That definitely seems like a problem, as I see a few different places where '-mllvm' options are used with cc-option. I guess I will leave that up to the sanitizer folks to comment on that further, one small comment below. > old for this option. This causes a rather unreadable build failure: > > fixdep: error opening file: scripts/mod/.empty.o.d: No such file or directory > make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:252: scripts/mod/empty.o] Error 2 > fixdep: error opening file: scripts/mod/.devicetable-offsets.s.d: No such file or directory > make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:114: scripts/mod/devicetable-offsets.s] Error 2 > > Add a version check to only allow this option with clang-15, gcc-13 > or later versions. > > Fixes: 51287dcb00cc ("kasan: emit different calls for instrumentable memintrinsics") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > There is probably a better way to do this than to add version checks, > but I could not figure it out. > --- > scripts/Makefile.kasan | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan > index c186110ffa20..2cea0592e343 100644 > --- a/scripts/Makefile.kasan > +++ b/scripts/Makefile.kasan > @@ -69,7 +69,12 @@ CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ > $(instrumentation_flags) > > # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). > +ifeq ($(call clang-min-version, 150000),y) > CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > +endif > +ifeq ($(call gcc-min-version, 130000),y) > +CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > +endif I do not think you need to duplicate this block, I think ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) endif would work, as only one of those conditions can be true at a time. Cheers, Nathan
On Fri, Apr 14, 2023, at 18:26, Nathan Chancellor wrote: > On Fri, Apr 14, 2023 at 10:29:27AM +0200, Arnd Bergmann wrote: >> From: Arnd Bergmann <arnd@arndb.de> >> >> Unknown -mllvm options don't cause an error to be returned by clang, so >> the cc-option helper adds the unknown hwasan-kernel-mem-intrinsic-prefix=1 >> flag to CFLAGS with compilers that are new enough for hwasan but too > > Hmmm, how did a change like commit 0e1aa5b62160 ("kcsan: Restrict > supported compilers") work if cc-option does not work with unknown > '-mllvm' flags (or did it)? That definitely seems like a problem, as I > see a few different places where '-mllvm' options are used with > cc-option. I guess I will leave that up to the sanitizer folks to > comment on that further, one small comment below. That one adds both "-fsanitize=thread" and "-mllvm -tsan-distinguish-volatile=1". If the first one is missing in the compiler, neither will be set. If only the second one fails, I assume you'd get the same result I see with hwasan-kernel-mem-intrinsic-prefix=1. >> # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). >> +ifeq ($(call clang-min-version, 150000),y) >> CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) >> +endif >> +ifeq ($(call gcc-min-version, 130000),y) >> +CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) >> +endif > > I do not think you need to duplicate this block, I think > > ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) > CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > endif > > would work, as only one of those conditions can be true at a time. Are you sure that clang-min-version evaluates to an empty string rather than "n" or something else? I haven't found a documentation that says anything about it other than it returning "y" if the condition is true. Arnd
On Fri, Apr 14, 2023 at 08:53:49PM +0200, Arnd Bergmann wrote: > On Fri, Apr 14, 2023, at 18:26, Nathan Chancellor wrote: > > On Fri, Apr 14, 2023 at 10:29:27AM +0200, Arnd Bergmann wrote: > >> From: Arnd Bergmann <arnd@arndb.de> > >> > >> Unknown -mllvm options don't cause an error to be returned by clang, so > >> the cc-option helper adds the unknown hwasan-kernel-mem-intrinsic-prefix=1 > >> flag to CFLAGS with compilers that are new enough for hwasan but too > > > > Hmmm, how did a change like commit 0e1aa5b62160 ("kcsan: Restrict > > supported compilers") work if cc-option does not work with unknown > > '-mllvm' flags (or did it)? That definitely seems like a problem, as I > > see a few different places where '-mllvm' options are used with > > cc-option. I guess I will leave that up to the sanitizer folks to > > comment on that further, one small comment below. > > That one adds both "-fsanitize=thread" and "-mllvm > -tsan-distinguish-volatile=1". If the first one is missing in the > compiler, neither will be set. If only the second one fails, I assume > you'd get the same result I see with hwasan-kernel-mem-intrinsic-prefix=1. I did not look close enough but it turns out that this check is always true for the versions of clang that the kernel currently supports, so it could not fail even if '-mllvm' flag checking worked. $ git grep tsan-distinguish-volatile llvmorg-11.0.0 llvmorg-11.0.0:llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp: "tsan-distinguish-volatile", cl::init(false), llvmorg-11.0.0:llvm/test/Instrumentation/ThreadSanitizer/volatile.ll:; RUN: opt < %s -tsan -tsan-distinguish-volatile -S | FileCheck %s At the time of the Linux change though, we did not have a minimum supported version, so that check was necessary. I wonder if LLVM regressed with regards to '-mllvm' flag checking at some point... > >> # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). > >> +ifeq ($(call clang-min-version, 150000),y) > >> CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > >> +endif > >> +ifeq ($(call gcc-min-version, 130000),y) > >> +CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > >> +endif > > > > I do not think you need to duplicate this block, I think > > > > ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) > > CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > > endif > > > > would work, as only one of those conditions can be true at a time. > > Are you sure that clang-min-version evaluates to an empty string > rather than "n" or something else? I haven't found a documentation > that says anything about it other than it returning "y" if the condition > is true. Yes, see the test-ge and test-gt macros in scripts/Kbuild.include, they will only ever print the empty string or 'y'. Cheers, Nathan
On Fri, 14 Apr 2023 at 18:26, Nathan Chancellor <nathan@kernel.org> wrote: > > On Fri, Apr 14, 2023 at 10:29:27AM +0200, Arnd Bergmann wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > > > Unknown -mllvm options don't cause an error to be returned by clang, so > > the cc-option helper adds the unknown hwasan-kernel-mem-intrinsic-prefix=1 > > flag to CFLAGS with compilers that are new enough for hwasan but too > > Hmmm, how did a change like commit 0e1aa5b62160 ("kcsan: Restrict > supported compilers") work if cc-option does not work with unknown > '-mllvm' flags (or did it)? That definitely seems like a problem, as I > see a few different places where '-mllvm' options are used with > cc-option. I guess I will leave that up to the sanitizer folks to > comment on that further, one small comment below. Urgh, this one turns out to be rather ridiculous. It's only a problem with hwasan... If you try it for yourself, e.g. with something "normal" like: > clang -Werror -mllvm -asan-does-not-exist -c -x c /dev/null -o /dev/null It errors as expected. But with: > clang -Werror -mllvm -hwasan-does-not-exist -c -x c /dev/null -o /dev/null It ends up printing _help_ text, because anything "-h..." (if it doesn't recognize it as a long-form argument), will make it produce the help text. > > old for this option. This causes a rather unreadable build failure: > > > > fixdep: error opening file: scripts/mod/.empty.o.d: No such file or directory > > make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:252: scripts/mod/empty.o] Error 2 > > fixdep: error opening file: scripts/mod/.devicetable-offsets.s.d: No such file or directory > > make[4]: *** [/home/arnd/arm-soc/scripts/Makefile.build:114: scripts/mod/devicetable-offsets.s] Error 2 > > > > Add a version check to only allow this option with clang-15, gcc-13 > > or later versions. > > > > Fixes: 51287dcb00cc ("kasan: emit different calls for instrumentable memintrinsics") > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > > --- > > There is probably a better way to do this than to add version checks, > > but I could not figure it out. > > --- > > scripts/Makefile.kasan | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan > > index c186110ffa20..2cea0592e343 100644 > > --- a/scripts/Makefile.kasan > > +++ b/scripts/Makefile.kasan > > @@ -69,7 +69,12 @@ CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ > > $(instrumentation_flags) > > > > # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). > > +ifeq ($(call clang-min-version, 150000),y) > > CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > > +endif > > +ifeq ($(call gcc-min-version, 130000),y) > > +CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > > +endif > > I do not think you need to duplicate this block, I think > > ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) > CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) > endif We just need the clang version check. If the compiler is gcc, it'll do the "right thing" (i.e. not print help text). So at a minimum, we need if "clang version >= 15 or gcc". Checking if gcc is 13 or later doesn't hurt though, so I don't mind either way. So on a whole this patch is the right thing to do because fixing old clang versions to not interpret unrecognized options that start with "-h.." as help isn't something we can realistically do. Thanks, -- Marco
On Tue, Apr 18, 2023, at 14:06, Marco Elver wrote: > On Fri, 14 Apr 2023 at 18:26, Nathan Chancellor <nathan@kernel.org> wrote: >> On Fri, Apr 14, 2023 at 10:29:27AM +0200, Arnd Bergmann wrote: > It errors as expected. But with: > >> clang -Werror -mllvm -hwasan-does-not-exist -c -x c /dev/null -o /dev/null > > It ends up printing _help_ text, because anything "-h..." (if it > doesn't recognize it as a long-form argument), will make it produce > the help text. Ah, that explains a lot. I think I actually tried a few other options, but probably only edited part of the option name, and not the beginning, so I always saw the help text. >> > # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). >> > +ifeq ($(call clang-min-version, 150000),y) >> > CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) >> > +endif >> > +ifeq ($(call gcc-min-version, 130000),y) >> > +CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) >> > +endif >> >> I do not think you need to duplicate this block, I think >> >> ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) >> CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) >> endif > > We just need the clang version check. If the compiler is gcc, it'll do > the "right thing" (i.e. not print help text). So at a minimum, we need > if "clang version >= 15 or gcc". Checking if gcc is 13 or later > doesn't hurt though, so I don't mind either way. I've sent a v2 now, with an updated help text and the simplified version check. It might be possible to change the cc-option check in a way that parses the output, this variant should do that, if we care: echo "char *str = \"check that assembler works\";" | clang -Werror -mllvm -hwasan-does-not-exist -S -x c - -o - | grep -q "check that assembler works" Arnd
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index c186110ffa20..2cea0592e343 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -69,7 +69,12 @@ CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ $(instrumentation_flags) # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). +ifeq ($(call clang-min-version, 150000),y) CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) +endif +ifeq ($(call gcc-min-version, 130000),y) +CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) +endif endif # CONFIG_KASAN_SW_TAGS