From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933011AbcFOPGX (ORCPT ); Wed, 15 Jun 2016 11:06:23 -0400 Received: from foss.arm.com ([217.140.101.70]:38163 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932699AbcFOPGW (ORCPT ); Wed, 15 Jun 2016 11:06:22 -0400 Date: Wed, 15 Jun 2016 16:05:58 +0100 From: Mark Rutland To: Dmitry Vyukov Cc: Alexander Potapenko , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , marc.zyngier@arm.com, Catalin Marinas , Will Deacon , LKML , Quentin Casasnovas , Kostya Serebryany , syzkaller , Christoffer Dall , Andrew Morton Subject: Re: [PATCH v2] arm64: allow building with kcov coverage on ARM64 Message-ID: <20160615150558.GB7971@leverpostej> References: <1465923441-107596-1-git-send-email-glider@google.com> <20160614175543.GA2468@leverpostej> <20160615092509.GA3984@leverpostej> <20160615114438.GC3984@leverpostej> <20160615142550.GA7971@leverpostej> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 15, 2016 at 04:36:18PM +0200, Dmitry Vyukov wrote: > > However, it looks like I missed a warning from the kernel build system, > > and my toolchain doesn't actually support -fsanitize-coverage=trace-pc, > > so I'm not going to be able to test that further. > > > > It would be great if we could deliberately not register the debugfs file > > when there was no compiler support for the feature, for those like me > > who miss the build time warning. We do something like that for the LSE > > atomics on arm64. > > Hi Mark, > > It's a common problem and it would be great to detect this. > But I think it's better to return ENOTSUP from open rather than not > registering the file at all. This way higher level tools will be able > to more easily diagnose the issue and properly report to user. A > missing file looks like not mounted debugfs (which another common > issue). I have no strong feeling either way, so long as we don't silently carry on in a case that makes no sense. > I am not sure how to do it. > Compiler does not provide any define for this option. And I am not > familiar enough with kernel makefiles. Would it be possible to add a > define to CLAGS in the makefile along with printing the warning? If you follow the arm64 LSE example, you can do something like the below. Note that this relies on CFLAGS_KCOV being cleared when not supported by the toolchain. I used ENOTSUPP rather than ENOTSUP as there's no standard definition for the later in the Linux headers. Mark. ---->8---- diff --git a/Makefile b/Makefile index 0f70de6..e6ef260 100644 --- a/Makefile +++ b/Makefile @@ -369,7 +369,7 @@ LDFLAGS_MODULE = CFLAGS_KERNEL = AFLAGS_KERNEL = CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im -Wno-maybe-uninitialized -CFLAGS_KCOV = -fsanitize-coverage=trace-pc +CFLAGS_KCOV = -fsanitize-coverage=trace-pc -DCONFIG_KCOV_CC # Use USERINCLUDE when you must reference the UAPI directories only. diff --git a/kernel/kcov.c b/kernel/kcov.c index a02f2dd..df2cafd 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -3,6 +3,7 @@ #define DISABLE_BRANCH_PROFILING #include #include +#include #include #include #include @@ -160,6 +161,13 @@ static int kcov_open(struct inode *inode, struct file *filep) { struct kcov *kcov; + /* + * CONFIG_KCOV was selected, but the compiler does not support the + * options KCOV requires. + */ + if (!IS_ENABLED(CONFIG_KCOV_CC)) + return -ENOTSUPP; + kcov = kzalloc(sizeof(*kcov), GFP_KERNEL); if (!kcov) return -ENOMEM;