Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2831659ybl; Mon, 19 Aug 2019 08:07:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxquq17T31Qgm8kARPZgw4/huVfiVceI/2p7UbhlOFE/AH9eZKpOIQtyCbFLiNHTbQuU2mi X-Received: by 2002:a63:c009:: with SMTP id h9mr20245968pgg.166.1566227251504; Mon, 19 Aug 2019 08:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566227251; cv=none; d=google.com; s=arc-20160816; b=qGSCx9PRULUy/4g9gu6dRxyrWThYCQBFK2FgvL3+Nj4mfb4WJG/FK18aHI65Sakm5V c1UoyuBdnxjjujEUPSBhRio754R+bfOyEqrMs4TDWcyFtsso8ChhvqAl3oK6Lm0q1qNE TFhynUCG040+uX8dRfK+RGLqhkPs4LDKHQkNdj81aM7y2T1cAu7gxgCyymznZOvEnxst /nb9wMzFJSU+SHStg/WYIfvCqQSFU3sr4GJRoSUTR4k4+6seJN3hy1SMpk1GMawkMrb9 MjqNbRrf2v7Jbk0x7ywIcFXZoqN2Hwhfp5GOveM4vqiTtau/9kYe78fi0kj69vVx5VDl 0BaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Pvy/uoRwlQzhWtYHMcSAvYxmZskqAfrju91PELbG3jg=; b=Uzff3zonTakXMJrHvqyyVbydTWcLxhwi2U8Fagwg+1tDbOSUotOkJXZa6cPThCbmpJ bFr8GaYZtmGoM+4B5yd9gVf+eT8tHlM0NqAu1CU+fCloKTVP2KKxflZ0WPrYoejnuScR 2GM2TO9BmrasWCAX9PtxQHivc+qpodZkexjDNIqYQuUhqpo/0qpN91eHBttXfYPOfWHj FpQ447PRIurgEOFmKC8c+AOu9crXbPz7grWS+23jFYhPzL/Rl2lH+kCNKqgYHyvP0h4I atOakk1VlLu72qoUWIuzogp4nnAW9PJuXWOmcAvm2EOM+WGiqPe3fM97WrukEl32hO5D 0xxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Vo54OfXd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m15si10631682pff.267.2019.08.19.08.07.16; Mon, 19 Aug 2019 08:07:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Vo54OfXd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727353AbfHSPGF (ORCPT + 99 others); Mon, 19 Aug 2019 11:06:05 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:4475 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726168AbfHSPGF (ORCPT ); Mon, 19 Aug 2019 11:06:05 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 46By115JXKz9v0lZ; Mon, 19 Aug 2019 17:05:57 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=Vo54OfXd; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id YETEQXL8UOQ4; Mon, 19 Aug 2019 17:05:57 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 46By113ycpz9v0lV; Mon, 19 Aug 2019 17:05:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1566227157; bh=Pvy/uoRwlQzhWtYHMcSAvYxmZskqAfrju91PELbG3jg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Vo54OfXdn5bt4A2X0NgPS36957r7xxFqdm+9+B/RCCVRDEmMGxy2+ENKEV639kUsc WsnZID5Z6b1qlVQvNgEm62YtbGLfjOXbAEMnqTBKGIR+/JOBqkdWJVAjFUOzp7Hwli sXVUmYV3Xta9PkMtsRDzG4XtyWybzIWupfBIntt0= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2F8048B7BC; Mon, 19 Aug 2019 17:06:03 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id aOMEMrlxlL8H; Mon, 19 Aug 2019 17:06:03 +0200 (CEST) Received: from [172.25.230.101] (po15451.idsi0.si.c-s.fr [172.25.230.101]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F29A58B7B9; Mon, 19 Aug 2019 17:06:02 +0200 (CEST) Subject: Re: [PATCH 3/3] powerpc: use __builtin_trap() in BUG/WARN macros. To: Segher Boessenkool Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <20510ce03cc9463f1c9e743c1d93b939de501b53.1566219503.git.christophe.leroy@c-s.fr> <20190819132313.GH31406@gate.crashing.org> <20190819143700.GK31406@gate.crashing.org> From: Christophe Leroy Message-ID: <44a19633-f2a9-79f9-da7c-16ba64a66600@c-s.fr> Date: Mon, 19 Aug 2019 17:05:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190819143700.GK31406@gate.crashing.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 19/08/2019 à 16:37, Segher Boessenkool a écrit : > On Mon, Aug 19, 2019 at 04:08:43PM +0200, Christophe Leroy wrote: >> Le 19/08/2019 à 15:23, Segher Boessenkool a écrit : >>> On Mon, Aug 19, 2019 at 01:06:31PM +0000, Christophe Leroy wrote: >>>> Note that we keep using an assembly text using "twi 31, 0, 0" for >>>> inconditional traps because GCC drops all code after >>>> __builtin_trap() when the condition is always true at build time. >>> >>> As I said, it can also do this for conditional traps, if it can prove >>> the condition is always true. >> >> But we have another branch for 'always true' and 'always false' using >> __builtin_constant_p(), which don't use __builtin_trap(). Is there >> anything wrong with that ?: > > The compiler might not realise it is constant when it evaluates the > __builtin_constant_p, but only realises it later. As the documentation > for the builtin says: > A return of 0 does not indicate that the > value is _not_ a constant, but merely that GCC cannot prove it is a > constant with the specified value of the '-O' option. So you mean GCC would not be able to prove that __builtin_constant_p(cond) is always true but it would be able to prove that if (cond) is always true ? And isn't there a away to tell GCC that '__builtin_trap()' is recoverable in our case ? > > (and there should be many more and more serious warnings here). > >> #define BUG_ON(x) do { \ >> if (__builtin_constant_p(x)) { \ >> if (x) \ >> BUG(); \ >> } else { \ >> if (x) \ >> __builtin_trap(); \ >> BUG_ENTRY("", 0); \ >> } \ >> } while (0) > > I think it may work if you do > > #define BUG_ON(x) do { \ > if (__builtin_constant_p(x)) { \ > if (x) \ > BUG(); \ > } else { \ > BUG_ENTRY("", 0); \ > if (x) \ > __builtin_trap(); \ > } \ > } while (0) It doesn't work: void test_bug1(unsigned long long a) { BUG_ON(a); } 00000090 : 90: 7c 63 23 78 or r3,r3,r4 94: 0f 03 00 00 twnei r3,0 98: 4e 80 00 20 blr RELOCATION RECORDS FOR [__bug_table]: OFFSET TYPE VALUE 00000084 R_PPC_ADDR32 .text+0x00000090 As you see, the relocation in __bug_table points to the 'or' and not to the 'twnei'. > > or even just > > #define BUG_ON(x) do { \ > BUG_ENTRY("", 0); \ > if (x) \ > __builtin_trap(); \ > } \ > } while (0) > > if BUG_ENTRY can work for the trap insn *after* it. > >>> Can you put the bug table asm *before* the __builtin_trap maybe? That >>> should make it all work fine... If you somehow can tell what machine >>> instruction is that trap, anyway. >> >> And how can I tell that ? > > I don't know how BUG_ENTRY works exactly. It's basic, maybe too basic: it adds an inline asm with a label, and adds a .long in the __bug_table section with the address of that label. When putting it after the __builtin_trap(), I changed it to using the address before the one of the label which is always the twxx instruction as far as I can see. #define BUG_ENTRY(insn, flags, ...) \ __asm__ __volatile__( \ "1: " insn "\n" \ ".section __bug_table,\"aw\"\n" \ "2:\t" PPC_LONG "1b, %0\n" \ "\t.short %1, %2\n" \ ".org 2b+%3\n" \ ".previous\n" \ : : "i" (__FILE__), "i" (__LINE__), \ "i" (flags), \ "i" (sizeof(struct bug_entry)), \ ##__VA_ARGS__) Christophe