From patchwork Tue Aug 13 22:40:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13762638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E20A6C52D7C for ; Tue, 13 Aug 2024 22:40:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7432D6B0082; Tue, 13 Aug 2024 18:40:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CB6B6B0083; Tue, 13 Aug 2024 18:40:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56C196B0085; Tue, 13 Aug 2024 18:40:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3672C6B0082 for ; Tue, 13 Aug 2024 18:40:41 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A247080AE0 for ; Tue, 13 Aug 2024 22:40:40 +0000 (UTC) X-FDA: 82448693040.22.0096355 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf26.hostedemail.com (Postfix) with ESMTP id DE8C6140012 for ; Tue, 13 Aug 2024 22:40:38 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ZG6A2Cxz; spf=pass (imf26.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723588803; a=rsa-sha256; cv=none; b=wOOipke+PV7ew+nHNbZFIUcjCBKFedSYjebSDSFKY2lWISM3ZxBYxO5RVMeVA/F1ftfhFC CZYvPQfwcH8M6hrPwFq3I59D+juocXReUO5OIwLSnJBJC5tYB3n8IXRGKsju/tmaqFSxUD M4/E4ofJ0X8VdQkk+D+Ek84m02b2dZM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ZG6A2Cxz; spf=pass (imf26.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723588803; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=ROfZ7+FlItYIEY2a1H0ZOdv21L9gnBvePHx9MzL+ryA=; b=4j5tax++RFytKAr7LHaJJwQVn1GeR3N9z3WrrnEZrkr3/mdjD9MdHiPJpkgq3hqoAqymhe 8LIggMn5dJc9yzb8BqoRd8W19PfeQ3Z7hal6qZnhtwKtV+F+6Lu1mZKjO0W4DBeAyOHjE2 1g0o7rZAkjFu74aV+z0YtXjOCqUpvcE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723588836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ROfZ7+FlItYIEY2a1H0ZOdv21L9gnBvePHx9MzL+ryA=; b=ZG6A2CxzyNqBWcnrUSisSO1zgP1W5vYO1OHHeRg0tYTRmKK70oBvGAA2oHJlw7k2P3b4uT nS9fgk0Yw2Ik8XAxY1DdctABZ5PCP7qxbhL75C8qMbp/H+srNwAtCDpDf84eRHZtOP5S4f T7nPHar1FHd6KTBRSe72lMMbe7wul+Y= From: andrey.konovalov@linux.dev To: Marco Elver , Matthew Maurer Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, Miguel Ojeda , linux-kernel@vger.kernel.org Subject: [PATCH] kasan: simplify and clarify Makefile Date: Wed, 14 Aug 2024 00:40:27 +0200 Message-Id: <20240813224027.84503-1-andrey.konovalov@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: fngqza7x7d1hz44tij56zqs7qzgmzdwj X-Rspamd-Queue-Id: DE8C6140012 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723588838-341442 X-HE-Meta: U2FsdGVkX18mSsNv3PF0sRLciw/QdqbF7tdAqjFQKsmDMXqZyOC+Ymj2DExU2OYS15mQSwEFU0QXH4cOacDEni/dzi1EMeqkBSzIAna/5zhz8jBD/F5l/vQRpUPdpwptan6tOEgEBXIp8gc7hE2gLMcJxJ8cBjnWMs1lIOVuvEMtRDmMvmaZGaolrEiY5fGITS/2MFeFwD4MyohZyzOosdZPYzl53trSwjmEpL8bBhTm7mkTXTpMb9Wk4UOIrnuAsmW0Psog5Fc+IIEFUVJId7Tk8nmVW9hcEHo6i6WNv/NgWPSzUC6R8Gik0bnLev7qn/4MvBTOX3BaxUeQKuFcC2G41REPFIfabrmew5RkaYgMspXE3MHAvQXG6PLB+krEhseV0ASHjSGQv5DV+4BerdNJdBy8POdszn2Tn34XN2e9fj6vjj+IpJ+FQ06WXuL3m9oQx+dNqkN58SFR2dhrxU5jDeR3rACrmVMu9xMLl/i2wpTdOAIpecArOi79TFW4D3+8XB/3YdvdJNuhTpci8uNDFBFleItPh9wKNEyCvWrW+7cO8hAHwU2WZEmBA0mREB/W3derGDWGS0t/O5cZOkoDKVtn5/zuygoa/KmiDrn1kEmTN20OdlogLkqmVLE6QUnCCfttzbN8uT8UdcjQbdRPhpWWCpPCJDi233uRUaDVTgu8cL44c2Q4RVnGtwDjQZ4IbxPW/T+FgcuffE/elawefJwvaEf/JGJRecaPtq2B8S9XgNtbwHYyGWuPTwqw/vAeVppfn+S3ZkpuORVplQE45mAmWOMAARcrDA3h3L9O1dOiwG00BX+qnEZ1iSYiDk1s67lHy0cPflMNJzjsE1Wd4CAVbOAPEIDYDAO8srrR72lMDEeqix9ndmR+OoChtk2jWann9iXmEeivk7Hf5TOPelnh49NCnkN+kEtX20Xi/9/nnd0djGchUsxzGbPXd56azeBlH+5vZyJh7Pz bfHt1SEw YM7JdQsx5Wtzc3a1uOom78Mh0NTIYzkt9fON6NP8SfJPOpaVF94a1UXGWIaJAHK7rJxgfFbmqxHUeKDPBP+EasrtXrdB8ww4huBewYBPuSqNMmcThAH8SD5NuZaDeuHHCoGWfud4ziSb9gDdMDtZvXQ2mvL4U6yuRh5pNGitdlpaBU8xabuuUu8Hws6B683OijI0V/RuflTQuhqs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov When KASAN support was being added to the Linux kernel, GCC did not yet support all of the KASAN-related compiler options. Thus, the KASAN Makefile had to probe the compiler for supported options. Nowadays, the Linux kernel GCC version requirement is 5.1+, and thus we don't need the probing of the -fasan-shadow-offset parameter: it exists in all 5.1+ GCCs. Simplify the KASAN Makefile to drop CFLAGS_KASAN_MINIMAL. Also add a few more comments and unify the indentation. Signed-off-by: Andrey Konovalov --- scripts/Makefile.kasan | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 390658a2d5b74..04b108f311d24 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -22,30 +22,29 @@ endif ifdef CONFIG_KASAN_GENERIC ifdef CONFIG_KASAN_INLINE + # When the number of memory accesses in a function is less than this + # call threshold number, the compiler will use inline instrumentation. + # 10000 is chosen offhand as a sufficiently large number to make all + # kernel functions to be instrumented inline. call_threshold := 10000 else call_threshold := 0 endif -CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address - -# -fasan-shadow-offset fails without -fsanitize -CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ - -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \ - $(call cc-option, -fsanitize=kernel-address \ - -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) - -ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) - CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) -else - # Now add all the compiler specific options that are valid standalone - CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ - $(call cc-param,asan-globals=1) \ - $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ - $(call cc-param,asan-instrument-allocas=1) -endif - -CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable)) +# First, enable -fsanitize=kernel-address together with providing the shadow +# mapping offset, as for GCC, -fasan-shadow-offset fails without -fsanitize +# (GCC accepts the shadow mapping offset via -fasan-shadow-offset instead of +# a normal --param). Instead of ifdef-checking the compiler, rely on cc-option. +CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \ + -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \ + $(call cc-option, -fsanitize=kernel-address \ + -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) + +# Now, add other parameters enabled in a similar way with GCC and Clang. +CFLAGS_KASAN += $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ + $(call cc-param,asan-stack=$(stack_enable)) \ + $(call cc-param,asan-instrument-allocas=1) \ + $(call cc-param,asan-globals=1) # Instrument memcpy/memset/memmove calls by using instrumented __asan_mem*() # instead. With compilers that don't support this option, compiler-inserted @@ -57,9 +56,9 @@ endif # CONFIG_KASAN_GENERIC ifdef CONFIG_KASAN_SW_TAGS ifdef CONFIG_KASAN_INLINE - instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)) + instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)) else - instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1) + instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1) endif CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ @@ -70,7 +69,7 @@ CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) -CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) + CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) endif endif # CONFIG_KASAN_SW_TAGS