Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2076280ybg; Fri, 5 Jun 2020 05:08:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAbnQhdBLgqOAATFpqeI0vFBgDGVPDSpeRu0s1JcpSU7LAYzI2rlfMXm2Pd4XSKJxXPVrp X-Received: by 2002:a50:d556:: with SMTP id f22mr9279114edj.307.1591358934272; Fri, 05 Jun 2020 05:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591358934; cv=none; d=google.com; s=arc-20160816; b=WjM+HKcZ+i2L76EfPEMArwuAJM/cbtWxFJkFkniE0fml1kPn/zIK01cLQbdEpXT9ZV b+B/uHx9oMcqj3M9KmUVj54jFZw77gFQR1WD1wqZphMjU8vHrGl5LHfYkwiHro4F+Jif 16KoAN2Z9IrxG8HdeN+sVIoRjVTA1ok71VGbdKrG0HZrQPSQC+aQNBYo8r34fZkb4Iwp 4bddnlSOnGEaCY+wYrArF/ynWdgPmUAPB9BBBqaVmFPZhQMqT+FGTozH1SJu79upOzeM UgR9PgMk5KoAo9C2eM74p2K0JHH5bD8/zlXE6/SaExcfjqB+eUo6xFUs2wvAWrMvKiQE ubDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=KZz+sQK4LPHja6YFeoddpUkcV49dBXnT6yLG+sR4tCM=; b=UtpAL5FPf8DxlSSJVgy5TbG0SD2p60zeuXyhrRXpFLaDV1DUapKq1UkeJ6FY/E9YuL JvjbDat7EZG07EAIdCtVrhegSN8e4JzNOH3PVmBlPY878jfqXDZilpIDG5sbdQNiMAQb 2z9YtQ3vR3WN6ria1EOd3G1xxkAK/wg5ZC+6xTLFBxfki42D+Y5L4U2Kbh6DEVOYPV7d ok515/hp2OmkdbKVLVEUzuo3w7CnsvDB9H4EU9FYEbM99wKzGYYlqWxo4ekD0gxLQUyN B0oUZebu3UA/rULXaHwXxcnGxlehJtKx8gSkxgpJ0erdNp0DNXoJu/khuaxnGJzN3h+Q I18w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=KaWM5eMS; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id um1si3498293ejb.200.2020.06.05.05.08.31; Fri, 05 Jun 2020 05:08:54 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=KaWM5eMS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726416AbgFEMEa (ORCPT + 99 others); Fri, 5 Jun 2020 08:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbgFEME3 (ORCPT ); Fri, 5 Jun 2020 08:04:29 -0400 Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76321C08C5C2 for ; Fri, 5 Jun 2020 05:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=KZz+sQK4LPHja6YFeoddpUkcV49dBXnT6yLG+sR4tCM=; b=KaWM5eMSeJwRLEvot2bT3wItgd gS/wJcxl/Bkdrifs/I1kz2tBTM2gLkVzNlplI+Hxu5GRh97PBGQmCpD2jbYjy0Fsbhy/dt4W7KP5w tVnzblJ7WLd9owreJ+VxlVOM+qzkMsog+YOzlmdZvNIJGH+b3A72EFN02Ujz1JgyNzlrIhoga2l5X /A/kI68HcG502pTreIPbTvhSJAskTqM3XdJngUJMOcsO2EcNC2n7fHgnAUw6wcui3i3h0ExhQtP/0 JJfMWdvJY3QALy7P8L+Icl+wL6WEVPogGVSRwtrNZyGpcXvfQwfi5fHb0OYLbM+AzyB/fib3sq95K ez54gZzg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jhB4l-00084B-Iy; Fri, 05 Jun 2020 12:03:56 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BFF74301A7A; Fri, 5 Jun 2020 14:03:52 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8847A21A75216; Fri, 5 Jun 2020 14:03:52 +0200 (CEST) Date: Fri, 5 Jun 2020 14:03:52 +0200 From: Peter Zijlstra To: Dmitry Vyukov Cc: Marco Elver , Mark Rutland , Borislav Petkov , Thomas Gleixner , Ingo Molnar , clang-built-linux , "Paul E. McKenney" , Alexander Potapenko , Andrey Konovalov , kasan-dev , LKML , the arch/x86 maintainers , Andrew Morton Subject: Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible Message-ID: <20200605120352.GJ3976@hirez.programming.kicks-ass.net> References: <20200605082839.226418-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 05, 2020 at 12:57:15PM +0200, Dmitry Vyukov wrote: > On Fri, Jun 5, 2020 at 10:28 AM Marco Elver wrote: > > > > While we lack a compiler attribute to add to noinstr that would disable > > KCOV, make the KCOV runtime functions return if the caller is in a > > noinstr section, and mark them noinstr. > > > > Declare write_comp_data() as __always_inline to ensure it is inlined, > > which also reduces stack usage and removes one extra call from the > > fast-path. > > > > In future, our compilers may provide an attribute to implement > > __no_sanitize_coverage, which can then be added to noinstr, and the > > checks added in this patch can be guarded by an #ifdef checking if the > > compiler has such an attribute or not. > > Adding noinstr attribute to instrumentation callbacks looks fine to me. > > But I don't understand the within_noinstr_section part. > As the cover letter mentions, kcov callbacks don't do much and we > already have it inserted and called. What is the benefit of bailing > out a bit earlier rather than letting it run to completion? > Is the only reason for potential faults on access to the vmalloc-ed > region? Vmalloc faults (on x86, the only arch that had them IIRC) are gone, per this merge window. The reason I mentioned them is because it is important that they are gone, and that this hard relies on them being gone, and the patch didn't call that out. There is one additional issue though; you can set hardware breakpoint on vmalloc space, and that would trigger #DB and then we'd be dead when we were already in #DB (IST recursion FTW). And that is not something you can trivially fix, because you can set the breakpoint before the allocation (or perhaps on a previous allocation). That said; we already have this problem with task_struct (and task_stack). IIRC Andy wants to fix the task_stack issue by making all of noinstr run on the entry stack, but we're not there yet. There are no good proposals for random allocations like task_struct or in your case kcov_area. > Andrey, Mark, do you know if it's possible to pre-fault these areas? Under the assumption that vmalloc faults are still a thing: You cannot pre-fault the remote area thing, kernel threads use the mm of the previous user task, and there is no guarantee that mm will have had the vmalloc fault.