Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1518803ybg; Thu, 4 Jun 2020 11:42:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGuDMt73c7E6rDpUchq0Zfk65pwqJiOzwZEqtOUOE7G/uJncsn8ZiayEU1eVTGWQ8+v+TM X-Received: by 2002:aa7:c942:: with SMTP id h2mr5704221edt.23.1591296179653; Thu, 04 Jun 2020 11:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591296179; cv=none; d=google.com; s=arc-20160816; b=EeTJW6iXNqDIYRRuqy+lyPTn95HcloYVFBpafwBL1tC0xXNmqqF6FeEg0Hr8NyKOO/ ruMfnNY7BMWzOcpohPyuXlJ9e7aT/TgwZ+2oKv0R9SZkws/JfqzUV8EGH+Ki6akdHkvh ULboOwWYTvW9XkLu8SDIpK/AkZgDeIHGIg33CHIkP/gnCrS5CRU2EqWgZbmaUmCQUTU1 Q3rlPyk/gcE0Ex0VxMsbRdvDFPJ19IySfLWZZnzmu9dL7g5DBU4oR5SCc3kAVMzuOGva 99InX4k/duejTp3u4AnEXVzupfWVMuF1/LLsA+KzHyqUkNBzn3Fe5lry8784Tt15NXMJ T6GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ImRfD2cqJ0tQ89Ygd7DHH9ExVVNMqaoCZMhHXpLzooU=; b=X+nSbzc32mRo51qr3aYSP7LRt+li095SeTuvGKRcPPJ65AlSymxM5UBYMG8PtW1E0y QVLnEiKzRav3g3gJFb/wuVt3EMNbJWsfEa6GNP18Im5gztF9fxQIfRLek8Z8QkdDpqgX hS9u3lkgKYu/0g2evoRQ/7eai4MCKKYrznUh102W7sVm7JTabX6i48Qb7PZCi16+PQC5 qv6Eg3UdvLb7FMJ/i0CVEHAgNvID0qEx/YUolzF5H2I9YmzLfCJn519aDg2RnBCrWepa /RviRDOqKO9zTG3Epn5K8VJV4oIJ5dhPic680Iwnwf98L+gjs1FxLfiiAoDFy/S34pHR lLjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wK7E14tk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r16si2320521eds.6.2020.06.04.11.42.36; Thu, 04 Jun 2020 11:42:59 -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=@google.com header.s=20161025 header.b=wK7E14tk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728780AbgFDODI (ORCPT + 99 others); Thu, 4 Jun 2020 10:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728496AbgFDODH (ORCPT ); Thu, 4 Jun 2020 10:03:07 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95911C08C5C0 for ; Thu, 4 Jun 2020 07:03:06 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id y17so2214151plb.8 for ; Thu, 04 Jun 2020 07:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ImRfD2cqJ0tQ89Ygd7DHH9ExVVNMqaoCZMhHXpLzooU=; b=wK7E14tkPXobd7wDQL7W8LDVbrDwK7tITVXSLRkBIJdEYvo3HtCPYNTUV67NicHiyj 9AWMuN3o/OCp+XDPOyVJ4OD+zKHZhzvB8phTAhL2BJKc+dCHU/C4r9FrBiSo0lAAV3zF /+TX7AQJSWs4CfyqHdFGIQmXqaBGBSbT3Ij+yk2atYIdyrFpLiXaOPYyYGKO3mK2Pr3H 08eNplDAwz4UYU/RZPegMsv/4aKNxGvubjCgs8lENLh7IR346BBMADPg8DSesz7AMTmh pDz1FCdbw8eIu7sHR/LUVKGggNgaJ3/9sRr3n1KYCTdXms2GBXMCQt0Wrna+r97AAGpc Df2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ImRfD2cqJ0tQ89Ygd7DHH9ExVVNMqaoCZMhHXpLzooU=; b=kpQ4Rf3hw6NlP8btAoafcdvlNmgC1fJ6YLzH57o9X/onClSa8eHmbvMruwGu0+etbN 6U3IfClNhYWLyo+rVzFi9KatD+Ow43vbLS1aB5RyILI23UWkzpmHBfAbvW9gQpscT/8z qHXtVg4jN9yNcIDhFhNGz8zGPqlsrj9fmbjx3mAZsN36q3d9yTcq1I7tzMDTBSuzy5jh KxOoSTkgvfbaHcT8ReUGT7KSSR7+58bbBbAywFYvtofgPyhS3C6XqFFXgkVQM3IN2wBc Vtptiu6fIJ5z/bLol7iw3vRR17Ph11kUMwmw8RBYDk2XldhKFJoSjc4zVqhL7BGcK3kx hU1A== X-Gm-Message-State: AOAM532NcT1NEOb4LDO59NHqjhzcXNrdgUlIc//zqRgd1PxVFEduvFYc YeTfmXHGRgPVmruTmloPFLpNTZXi427xBmLSc+GFaw== X-Received: by 2002:a17:90b:1244:: with SMTP id gx4mr6178570pjb.136.1591279385737; Thu, 04 Jun 2020 07:03:05 -0700 (PDT) MIME-Version: 1.0 References: <20200604095057.259452-1-elver@google.com> <20200604110918.GA2750@hirez.programming.kicks-ass.net> In-Reply-To: <20200604110918.GA2750@hirez.programming.kicks-ass.net> From: Andrey Konovalov Date: Thu, 4 Jun 2020 16:02:54 +0200 Message-ID: Subject: Re: [PATCH -tip] kcov: Make runtime functions noinstr-compatible To: Peter Zijlstra , Marco Elver Cc: Borislav Petkov , Thomas Gleixner , Ingo Molnar , clang-built-linux , "Paul E . McKenney" , Dmitry Vyukov , Alexander Potapenko , kasan-dev , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 4, 2020 at 1:09 PM Peter Zijlstra wrote: > > On Thu, Jun 04, 2020 at 11:50:57AM +0200, Marco Elver wrote: > > The KCOV runtime is very minimal, only updating a field in 'current', > > and none of __sanitizer_cov-functions generates reports nor calls any > > other external functions. > > Not quite true; it writes to t->kcov_area, and we need to make > absolutely sure that doesn't take faults or triggers anything else > untowards. > > > Therefore we can make the KCOV runtime noinstr-compatible by: > > > > 1. always-inlining internal functions and marking > > __sanitizer_cov-functions noinstr. The function write_comp_data() is > > now guaranteed to be inlined into __sanitize_cov_trace_*cmp() > > functions, which saves a call in the fast-path and reduces stack > > pressure due to the first argument being a constant. Maybe we could do CFLAGS_REMOVE_kcov.o = $(CC_FLAGS_FTRACE) the same way we do it for KASAN? And drop notrace/noinstr from kcov. Would it resolve the issue? I'm not sure which solution is better though. > > > > 2. For Clang, correctly pass -fno-stack-protector via a separate > > cc-option, as -fno-conserve-stack does not exist on Clang. > > > > The major benefit compared to adding another attribute to 'noinstr' to > > not collect coverage information, is that we retain coverage visibility > > in noinstr functions. We also currently lack such an attribute in both > > GCC and Clang. > > > > > -static void notrace write_comp_data(u64 type, u64 arg1, u64 arg2, u64 ip) > > +static __always_inline void write_comp_data(u64 type, u64 arg1, u64 arg2, u64 ip) > > { > > struct task_struct *t; > > u64 *area; > > @@ -231,59 +231,59 @@ static void notrace write_comp_data(u64 type, u64 arg1, u64 arg2, u64 ip) > > } > > } > > This thing; that appears to be the meat of it, right? > > I can't find where t->kcov_area comes from.. is that always > kcov_mmap()'s vmalloc_user() ? > > That whole kcov_remote stuff confuses me. > > KCOV_ENABLE() has kcov_fault_in_area(), which supposedly takes the > vmalloc faults for the current task, but who does it for the remote? Hm, no one. This might be an issue, thanks for noticing! > Now, luckily Joerg went and ripped out the vmalloc faults, let me check > where those patches are... w00t, they're upstream in this merge window. Could you point me to those patches? Even though it might work fine now, we might get issues if we backport remote kcov to older kernels. > > So no #PF from writing to t->kcov_area then, under the assumption that > the vmalloc_user() is the only allocation site. > > But then there's hardware watchpoints, if someone goes and sets a data > watchpoint in the kcov_area we're screwed. Nothing actively prevents > that from happening. Then again, the same is currently true for much of > current :/ > > Also, I think you need __always_inline on kaslr_offset() > > > And, unrelated to this patch in specific, I suppose I'm going to have to > extend objtool to look for data that is used from noinstr, to make sure > we exclude it from inspection and stuff, like that kaslr offset crud for > example. > > Anyway, yes, it appears you're lucky (for having Joerg remove vmalloc > faults) and this mostly should work as is.