Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3853663pxv; Mon, 19 Jul 2021 10:17:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm+JkzH3mPqVLVXeksftEqXIBFWZkq9G8RT0rgA5USolTqfB3eFL6EtUBA/w7LP22wOwvE X-Received: by 2002:a05:6e02:1110:: with SMTP id u16mr18104856ilk.141.1626715075099; Mon, 19 Jul 2021 10:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626715075; cv=none; d=google.com; s=arc-20160816; b=qWrlBMPzA2tJ7LtQH8O9/QhKsE8ed2GGU6CHbAH43ImcbZf5GfJF8pcyFPDxu85zn5 5eduf1xc1OHidb0vGJgJFXK8SfKdjzujV6fV+Oou3j5WCy0bODAECSbPcHZ1JJd8kL00 os5QC1kBcjPki7digq7YpDQJ8MsX/GQsyrKE9vIqibaumZanS0cQFwElR2DBpBE3XNlV B7HJZjUIaQCuhk/3Veieux4eZ/kkRw1AUpRL7q1sq7//PhN08dicvjce74u4SQmTuBpo nFLuRYpHdEi3AAOWyQyKm/CPXek6RDWVRejwNlj+dVIAab0c6rXq4ZzVJMnzWgq7fZqE M2rw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=66gMy5gWuZ96dKx0DN315J2Q4OVwPVeC6ngfJ/S5a2c=; b=sRrO2wHbgICx7mGFTE63hRHN+BBOOB8p1m/pKAVNyqLysPhXQd+367Mu7iRCXkOvzR Yj/e52FMKmTp/HA4knRjxrYvlK6CtGGorTOcAtFCARAeXGqHOEjd1AeWza1F7LlILAZr cWBm/Hcm77W/RnTsIQ+Bi243shwSj68UqevEIEkjUPTc8uMzHdsrKdnioYYjdvuEYZO8 gyZnrEUEsWWbwA2MDFCsbsS6CnC0UEtAMD/DqTQ+IY/sXjR6r21O8rxFYMe2FjlCgctW 8TI4GHJMFSSR0NL+hci+B1c9T0IbyGlkXDmfmLuqtoW3xb3NIGpLgCeOUD669yLELU+Z lB6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CcnOMC1T; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si20598597ilr.103.2021.07.19.10.17.43; Mon, 19 Jul 2021 10:17:55 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CcnOMC1T; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352415AbhGSQc5 (ORCPT + 99 others); Mon, 19 Jul 2021 12:32:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:58334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346339AbhGSPRD (ORCPT ); Mon, 19 Jul 2021 11:17:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 63056611F2; Mon, 19 Jul 2021 15:57:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710247; bh=45GuMCIsNAAFPuiEtXYLR8ryh0fkkKY+94o5SajtHBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CcnOMC1TI72vNvVE5LTglDmcFRTQo7u9pD7JzXt8ZldTdOyJAVjognArjWLsG9pyK FKo0q5AAvO/Any8/HbK9sbCXW49F0K6yXOHFoPiiTb1ptj5YaT+bqt9GGvlBG4qPMf fdLWEBLO3lwfTbfzJBH7bgZHy8n+yuly/Q8mZWOE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marco Elver , "Peter Zijlstra (Intel)" , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Kees Cook , Will Deacon , Ard Biesheuvel , Luc Van Oostenryck , Arvind Sankar , Masahiro Yamada , Sami Tolvanen , Arnd Bergmann , Dmitry Vyukov , Mark Rutland , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 110/243] kcov: add __no_sanitize_coverage to fix noinstr for all architectures Date: Mon, 19 Jul 2021 16:52:19 +0200 Message-Id: <20210719144944.454966054@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marco Elver [ Upstream commit 540540d06e9d9b3769b46d88def90f7e7c002322 ] Until now no compiler supported an attribute to disable coverage instrumentation as used by KCOV. To work around this limitation on x86, noinstr functions have their coverage instrumentation turned into nops by objtool. However, this solution doesn't scale automatically to other architectures, such as arm64, which are migrating to use the generic entry code. Clang [1] and GCC [2] have added support for the attribute recently. [1] https://github.com/llvm/llvm-project/commit/280333021e9550d80f5c1152a34e33e81df1e178 [2] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=cec4d4a6782c9bd8d071839c50a239c49caca689 The changes will appear in Clang 13 and GCC 12. Add __no_sanitize_coverage for both compilers, and add it to noinstr. Note: In the Clang case, __has_feature(coverage_sanitizer) is only true if the feature is enabled, and therefore we do not require an additional defined(CONFIG_KCOV) (like in the GCC case where __has_attribute(..) is always true) to avoid adding redundant attributes to functions if KCOV is off. That being said, compilers that support the attribute will not generate errors/warnings if the attribute is redundantly used; however, where possible let's avoid it as it reduces preprocessed code size and associated compile-time overheads. [elver@google.com: Implement __has_feature(coverage_sanitizer) in Clang] Link: https://lkml.kernel.org/r/20210527162655.3246381-1-elver@google.com [elver@google.com: add comment explaining __has_feature() in Clang] Link: https://lkml.kernel.org/r/20210527194448.3470080-1-elver@google.com Link: https://lkml.kernel.org/r/20210525175819.699786-1-elver@google.com Signed-off-by: Marco Elver Acked-by: Peter Zijlstra (Intel) Reviewed-by: Miguel Ojeda Reviewed-by: Nathan Chancellor Cc: Nick Desaulniers Cc: Kees Cook Cc: Will Deacon Cc: Ard Biesheuvel Cc: Luc Van Oostenryck Cc: Arvind Sankar Cc: Masahiro Yamada Cc: Sami Tolvanen Cc: Arnd Bergmann Cc: Dmitry Vyukov Cc: Mark Rutland Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/compiler-clang.h | 17 +++++++++++++++++ include/linux/compiler-gcc.h | 6 ++++++ include/linux/compiler_types.h | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 189149de77a9..9ba951e3a6c2 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -23,6 +23,12 @@ /* all clang versions usable with the kernel support KASAN ABI version 5 */ #define KASAN_ABI_VERSION 5 +/* + * Note: Checking __has_feature(*_sanitizer) is only true if the feature is + * enabled. Therefore it is not required to additionally check defined(CONFIG_*) + * to avoid adding redundant attributes in other configurations. + */ + #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) /* Emulate GCC's __SANITIZE_ADDRESS__ flag */ #define __SANITIZE_ADDRESS__ @@ -55,6 +61,17 @@ #define __no_sanitize_undefined #endif +/* + * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together + * with no_sanitize("coverage"). Prior versions of Clang support coverage + * instrumentation, but cannot be queried for support by the preprocessor. + */ +#if __has_feature(coverage_sanitizer) +#define __no_sanitize_coverage __attribute__((no_sanitize("coverage"))) +#else +#define __no_sanitize_coverage +#endif + /* * Not all versions of clang implement the type-generic versions * of the builtin overflow checkers. Fortunately, clang implements diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 555ab0fddbef..4cf524ccab43 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -137,6 +137,12 @@ #define __no_sanitize_undefined #endif +#if defined(CONFIG_KCOV) && __has_attribute(__no_sanitize_coverage__) +#define __no_sanitize_coverage __attribute__((no_sanitize_coverage)) +#else +#define __no_sanitize_coverage +#endif + #if GCC_VERSION >= 50100 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 #endif diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index ac3fa37a84f9..2a1c202baa1f 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -205,7 +205,7 @@ struct ftrace_likely_data { /* Section for code which can't be instrumented at all */ #define noinstr \ noinline notrace __attribute((__section__(".noinstr.text"))) \ - __no_kcsan __no_sanitize_address + __no_kcsan __no_sanitize_address __no_sanitize_coverage #endif /* __KERNEL__ */ -- 2.30.2