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: 12694338 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79DE9C433F5 for ; Wed, 1 Dec 2021 15:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=T/tip3W/soZqjh0qTAi5oCo8MadTDQnskhEpemLWzyc=; b=Xjh KPly8LUE0lPfY5KR7Dcq8IQnoeJvH8iS7KG+QBdGrUzuGHZJeZAQhTU4ue99zGl5hfBfaNUM5XNd3 eXTlJy5irmjCO7atjBtAzJOHH7qe1RXdaqwgCQwnprnHbq8Qvk9Kk0F+fdolfYVdOAuzhCR97ayuZ e9xpEnJmk/IWM+IGQ9ykH9NSH52BB3FffhDc3ZTWQTDI/4JAXeApP2WxPZg2UDjzsGWzd9/Z2p4Cx OI82E+z4/hVVzQN5nFY5nBW3fXBJMAZvy94h1UqR+HCrznfj/nvUC39iARZPw1GC8MW3CiGaj55Qu NzfbsZKFSCP4mdWygaCiMJ9V7PEfE5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msRUx-009C5U-N5; Wed, 01 Dec 2021 15:26:19 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1msRUs-009C2s-AE for linux-arm-kernel@lists.infradead.org; Wed, 01 Dec 2021 15:26:16 +0000 Received: by mail-wm1-x349.google.com with SMTP id b142-20020a1c8094000000b0033f27b76819so9569280wmd.4 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=0uVtuGHnEL8N48BHt7EWXVCQ8fwNQSp5fyJ4W9/GcKwyS/ZW4jWWP4E/QUe3aOn//y Nm3Z2O5cna9j7XKxahg8POpJ4zRUw+wE+KeDtDmkfSl9UPHuWZXTdq9sTrewLMwezMtq EJ9EAv4+tCdTbldVFgKetj3Fh05W+A61OPegZkkOXnchbjA1Tmrv2tLhvF5o/b2c1ZMU 3OJQEAOQcnh5mGMT9D9nI3dxXW0lNWajUA0EXm4hlLa0banOYUw9DYBEOYKm5uBAQKgg gevtsPHLthTR8Pmgve9Ny9xZKdmMhvf5FUWtsRN+X/M96RvL7gJ4hccKz8LoxgnnlfHE +UjQ== X-Gm-Message-State: AOAM533iyTcy5uWljNWO1UJC3t9omhWNn3qGQ3tsAHgFTTwR+ZBbm/9d GEYQijchqDH/g1PeNLqO4QmhOS1gPQ== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211201_072614_395773_7C949A95 X-CRM114-Status: GOOD ( 18.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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