Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3338367ybk; Tue, 19 May 2020 02:04:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHjuhCBmy9r7ncr2Chh+SaZE7mwhvQ6pYEGmPpe72fxgCzZj8gXrHHT3r9USQ4MMWBGpjT X-Received: by 2002:a17:906:9605:: with SMTP id s5mr17555183ejx.135.1589879076917; Tue, 19 May 2020 02:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589879076; cv=none; d=google.com; s=arc-20160816; b=gmKsncyzHH7nIG05etyt3MOikOYL99uEZGn/v1FDW4itvsvG0lYEFOhbiLcIq38+Y0 rSGAPvSEWFrMlev/aHO0fYyM9EvIVEXXqQ8an/Z945FK+i65xlBD4jqlMVoryEPRcZaz mWgyVJ4Z/7cfey3ryEb8fuFHMnqSQpGMoVZkBdxINt41OFeXN5VvuPZROo9t7Ix91KJc zMAJSqinCmB2rmkKp4UzROvmKgVNXz5vayq9vXZ1nB3Z5ciDaL0WsOJPf2X53X45sPJr Q0cYyvhcZIEJ9SD20g32T1cfoE2MNH9OKKZXs8QrXA8A3csWZMUMpQB6YPaIvZlyMvJ6 srCA== 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=QVvLau/9rnCPsCtt46lwjQQtMKtK/oxJF//68Ttv+kc=; b=RapVq8rj9HPmzxmh92N7DfdvTlb/aPkMtT+Fxlk25GhqYzXJofcjwcMPBFDW207Se6 F1oMLORetPB5cjCB6PHE+ZubDtvXx/IQtdAlb7RGbW/zJxtA8ncDKTAeXPM4VbCcuPo8 VjQy1S7Mtspsf+sLLa3NnVBozLM0ep4MLgn4ktbTHVl0JdiUGIGbl+sZ7DVeg0lk5MG7 +JPyEmrrNNkPPbo7TiHOlhWcR/ZrPi8gl7ZiNLBHn3Tqfl9n/FKo0g5ovb+sI/JPVV+p 0ptyoLXUiU/h41cgFB0EDlRd+RJlkB8rln+rJNIC3wnJH11C1dZemIxLHBnrYBtWfldR +WvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=GvILhhcI; 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 si17si7784586ejb.288.2020.05.19.02.04.12; Tue, 19 May 2020 02:04:36 -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=bombadil.20170209 header.b=GvILhhcI; 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 S1726938AbgESJCt (ORCPT + 99 others); Tue, 19 May 2020 05:02:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbgESJCs (ORCPT ); Tue, 19 May 2020 05:02:48 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1ECBC061A0C for ; Tue, 19 May 2020 02:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=QVvLau/9rnCPsCtt46lwjQQtMKtK/oxJF//68Ttv+kc=; b=GvILhhcIZtJOf8m0a2HgOo2CTD 4y13cf35CqBx7M4Wk5ISf0byOEUzHU3ihh3Tr1yPD1F4Lye9HtppxWVr2F0Uf7PbXq6MFEcqhaVyP THqXaMJa6ODe6RTRH98GNbagiBN8yFYSz9Px2NAHzIL9Yw69vvj6VCXfOAZAqJ+keN7IL3kZQKXsL qLg9Mae1MOV+b2JJ/OfKg3ILTLF7SuvCBo83wZgqPNy9jX7RXws7m6UwkE/uZDX6TjE3pPIdfXF63 HqPfMou0yV6xotCYd1i30tKPQ4rjuVNuPhuOBChcGud/LAH2lNZsLYEPXu4p+inUH23CmX6WOp55E tN6pmksw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jay8r-0002i1-Fo; Tue, 19 May 2020 09:02:29 +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 6EEC130067C; Tue, 19 May 2020 11:02:26 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 37A9D2105F3AF; Tue, 19 May 2020 11:02:26 +0200 (CEST) Date: Tue, 19 May 2020 11:02:26 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: LKML , x86@kernel.org, "Paul E. McKenney" , Andy Lutomirski , Alexandre Chartre , Frederic Weisbecker , Paolo Bonzini , Sean Christopherson , Masami Hiramatsu , Petr Mladek , Steven Rostedt , Joel Fernandes , Boris Ostrovsky , Juergen Gross , Brian Gerst , Mathieu Desnoyers , Josh Poimboeuf , Will Deacon , Tom Lendacky , Wei Liu , Michael Kelley , Jason Chen CJ , Zhao Yakui Subject: Re: [patch V6 00/37] x86/entry: Rework leftovers and merge plan Message-ID: <20200519090226.GD279861@hirez.programming.kicks-ass.net> References: <20200518160750.GA279861@hirez.programming.kicks-ass.net> <87367xvvmy.fsf@nanos.tec.linutronix.de> <20200519083826.GC279861@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200519083826.GC279861@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 19, 2020 at 10:38:26AM +0200, Peter Zijlstra wrote: > $ make CC=gcc-9 O=defconfig-build/ vmlinux -j40 -s > vmlinux.o: warning: objtool: exc_debug()+0x158: call to trace_hwlat_timestamp() leaves .noinstr.text section > vmlinux.o: warning: objtool: exc_nmi()+0x190: call to trace_hwlat_timestamp() leaves .noinstr.text section > vmlinux.o: warning: objtool: do_machine_check()+0x46: call to mce_rdmsrl() leaves .noinstr.text section > $ > > (it really isn't defconfig, but your config-fail + DEBUG_ENTRY) > With comment on, as requested. --- diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index f128e5c2ed42..fb34ff641e0a 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -79,8 +79,8 @@ do { \ do { \ instrumentation_begin(); \ _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \ - instrumentation_end(); \ annotate_reachable(); \ + instrumentation_end(); \ } while (0) #include diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 7db5902f8f6e..4b8fabed46ae 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -120,25 +120,61 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, /* Annotate a C jump table to allow objtool to follow the code flow */ #define __annotate_jump_table __section(.rodata..c_jump_table) +#ifdef CONFIG_DEBUG_ENTRY /* Begin/end of an instrumentation safe region */ -#define instrumentation_begin() ({ \ +#define instrumentation_begin() ({ \ asm volatile("%c0:\n\t" \ ".pushsection .discard.instr_begin\n\t" \ ".long %c0b - .\n\t" \ ".popsection\n\t" : : "i" (__COUNTER__)); \ }) -#define instrumentation_end() ({ \ - asm volatile("%c0:\n\t" \ +/* + * Because instrumentation_{begin,end}() can nest, objtool validation considers + * _begin() a +1 and _end() a -1 and computes a sum over the instructions. + * When the value is greater than 0, we consider instrumentation allowed. + * + * There is a problem with code like: + * + * noinstr void foo() + * { + * instrumentation_begin(); + * ... + * if (cond) { + * instrumentation_begin(); + * ... + * instrumentation_end(); + * } + * bar(); + * instrumentation_end(); + * } + * + * If instrumentation_end() would be an empty label, like all the other + * annotations, the inner _end(), which is at the end of a conditional block, + * would land on the instruction after the block. + * + * If we then consider the sum of the !cond path, we'll see that the call to + * bar() is with a 0-value, even though, we meant it to happen with a positive + * value. + * + * To avoid this, have _end() be a NOP instruction, this ensures it will be + * part of the condition block and does not escape. + */ +#define instrumentation_end() ({ \ + asm volatile("%c0: nop\n\t" \ ".pushsection .discard.instr_end\n\t" \ ".long %c0b - .\n\t" \ ".popsection\n\t" : : "i" (__COUNTER__)); \ }) +#endif /* CONFIG_DEBUG_ENTRY */ #else #define annotate_reachable() #define annotate_unreachable() #define __annotate_jump_table +#endif + +#ifndef instrumentation_begin #define instrumentation_begin() do { } while(0) #define instrumentation_end() do { } while(0) #endif