From patchwork Wed Dec 1 15:26:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12650191 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 3EEB3C433EF for ; Wed, 1 Dec 2021 15:26:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8761B6B00A2; Wed, 1 Dec 2021 10:26:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 824356B00A3; Wed, 1 Dec 2021 10:26:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C4EE6B00A4; Wed, 1 Dec 2021 10:26:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id 5A0C26B00A2 for ; Wed, 1 Dec 2021 10:26:24 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 20B5582DB0 for ; Wed, 1 Dec 2021 15:26:14 +0000 (UTC) X-FDA: 78869601468.28.FA5D8C4 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf28.hostedemail.com (Postfix) with ESMTP id 4DB689000505 for ; Wed, 1 Dec 2021 15:26:13 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id g80-20020a1c2053000000b003331a764709so638wmg.2 for ; Wed, 01 Dec 2021 07:26:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=KwI6f4Z+SG6OLZ2CA76lIDj1HnRQns/gAAi6BnRl9xE=; b=L4KrD9fytPCqFfJpm7zKkhS2HO4DerOuUVaA/yqVFNpq2ISBqnspeoM40Yvr0t7k/D 4iB0lDCoqTijStxCKHlbhOx3O3Fb0tJSEgpfnH1GHPJCe22BpkW/34cppuOiFTLUDlrZ Uu+CYeg9YBIKTbm3GXdkp6NOX0szTlGc0WMN48DnnO+9nMyi+2B1TItUDNBJ+/2MXbQV fNEHRtFwwkwbIsIGUvfWP1+nXooOpGx5aOorerAL3HND0JkqkWNwn4I40B2Rmcy9psXH Dix19JTyCsztwltZECYBTFMqarDF4ghypj1oTqoWDDT11ruXegfBl22e6Zos/ackfENo bwGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=KwI6f4Z+SG6OLZ2CA76lIDj1HnRQns/gAAi6BnRl9xE=; b=zTa/1yl2Jj4JfzQ+Jdaxi4d1kih+bKcfHSeoZNh322JCNSzZFm+TNy2j0BirHwGg6+ fTHNKslf+cAuVC4Z93VmWOH8KJOoTxQ3HiT75xAxq7u7Ae4cJHZLD2XLsVBg+ZjJ/YjI BdV2IeErKR5/IkgKEft5NvKqY+iNhdMPNw8DWSADfmWdbK1JCC62rpfgzblra8OLBLlO fuyqkqI9nuZk5nYwEgITsqYgqS3BPtEJt/a8AZD0BRlvHredsZD9xM9mSnQMOzFqs3Op 414+F2mbS/jGhBK4Q+KLQEmcXK6+HBeNm5g/828reEnM7ivW2Aa6N+j8eLTfP/VbD9jd 7GDQ== X-Gm-Message-State: AOAM530PWIYyoRLRsg5CUXeEEXE0vhjZv5KFI7ZWmu2AqayH289bt+Hf fU9/t8OdcYI6ZG66Sz1RBmyRUgdMPw== X-Google-Smtp-Source: ABdhPJzH7BSHdEv19rN0wDFTHkoKh/DPf7zIINrpO+Z1PL0DO5khj8ogwlSq8tOln6a56ZQ+PVk6VSMzSw== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:95ad:1401:cf07:6d1a]) (user=elver job=sendgmr) by 2002:a05:600c:4f0b:: with SMTP id l11mr21247wmq.0.1638372371145; Wed, 01 Dec 2021 07:26:11 -0800 (PST) Date: Wed, 1 Dec 2021 16:26:04 +0100 Message-Id: <20211201152604.3984495-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH] kcov: fix generic Kconfig dependencies if ARCH_WANTS_NO_INSTR From: Marco Elver To: elver@google.com, Andrew Morton Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, Peter Zijlstra , Nick Desaulniers , Nathan Chancellor , Dmitry Vyukov , Andrey Konovalov , Mark Rutland , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4DB689000505 X-Stat-Signature: 7fbsh6e9b939uogauxdwb8qzhibupizu Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=L4KrD9fy; spf=pass (imf28.hostedemail.com: domain of 3E5SnYQUKCOwSZjSfUccUZS.QcaZWbil-aaYjOQY.cfU@flex--elver.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3E5SnYQUKCOwSZjSfUccUZS.QcaZWbil-aaYjOQY.cfU@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1638372373-677465 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: Until recent versions of GCC and Clang, it was not possible to disable KCOV instrumentation via a function attribute. The relevant function attribute was introduced in 540540d06e9d9 ("kcov: add __no_sanitize_coverage to fix noinstr for all architectures"). x86 was the first architecture to want a working noinstr, and at the time no compiler support for the attribute existed yet. Therefore, 0f1441b44e823 ("objtool: Fix noinstr vs KCOV") introduced the ability to NOP __sanitizer_cov_*() calls in .noinstr.text. However, this doesn't work for other architectures like arm64 and s390 that want a working noinstr per ARCH_WANTS_NO_INSTR. At the time of 0f1441b44e823, we didn't yet have ARCH_WANTS_NO_INSTR, but now we can move the Kconfig dependency checks to the generic KCOV option. KCOV will be available if: - architecture does not care about noinstr, OR - we have objtool support (like on x86), OR - GCC is 12.0 or newer, OR - Clang is 13.0 or newer. Signed-off-by: Marco Elver Reviewed-by: Nathan Chancellor Acked-by: Mark Rutland Acked-by: Peter Zijlstra (Intel) --- arch/x86/Kconfig | 2 +- lib/Kconfig.debug | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 95dd1ee01546..c030b2ee93b3 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -78,7 +78,7 @@ config X86 select ARCH_HAS_FILTER_PGPROT select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL - select ARCH_HAS_KCOV if X86_64 && STACK_VALIDATION + select ARCH_HAS_KCOV if X86_64 select ARCH_HAS_MEM_ENCRYPT select ARCH_HAS_MEMBARRIER_SYNC_CORE select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 9ef7ce18b4f5..589c8aaa2d5b 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1977,6 +1977,8 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS + depends on !ARCH_WANTS_NO_INSTR || STACK_VALIDATION || \ + GCC_VERSION >= 120000 || CLANG_VERSION >= 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC help