Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1138896imm; Tue, 15 May 2018 14:29:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZon3U/QCJ2OLPhv9qvVYGaxQwCFx/cDozu2HWblJ192f8wMlOtAStw/x83gVr687+CLCtl3 X-Received: by 2002:a63:5f95:: with SMTP id t143-v6mr13348071pgb.165.1526419769391; Tue, 15 May 2018 14:29:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526419769; cv=none; d=google.com; s=arc-20160816; b=BWz7IB9Be+TMgeTftxabupRZElvSpxugLvGDDGbwCMwDIbBvSAcX4kSDB6Ck4n4Jef Z69nAOMRfRFEYfdHOo4ZMgJRxjYrHGXp4P8GIv6GEwuHFZWSA3rAK5QGxWtC8aVojqBd 58cEEAR0KYdvWjA5o+xXEY2dLUp6S7Kq8rSVwAmnWlo13qxITNir2kJk1beElfboqCAV Xq1ffzrshB/nE/AKKW9fkTsKdAqwg0yo34JwzzBEEHPYPRZzcVkFFsHwXaLsQ5Xy/7A1 MidxChKPNhxx5xkR75gzt9te/uZbpDAdtSdyYH6XsxSnxJQT+yKGyFM650gyce7Zs4bq 9Uww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=HnyDhN6nd+Sx3h73n1rocepKvXNpoprBlIgOmkxqXwU=; b=hjA+eH5eWRbyl2AZpUBvxFi2ux/Foq90fd8MG8J0zwRIA+UhbYqiYT+aQSnej13+LS xKeM01fK0rgszrs72JWWxVleYFMaiobaVG5RzLb7+0UG7ob/6sV93jbp+5z0EqC3fLFu MiJysJhAJ84HCgcPT6/Fm0nZpcDccgVdy+Dnbz1Yt8igFue/x3fyevPnIPMXV1Hk/mUM svtXEO6bj2we2hrq8sQ/WEX9Iiye63/GpULSTd0CXuZuOwGbAp8PqNw7cvzUFx7iVV3R ufmYV0HTzJi8w9OLLHHfo3FpU258ZsJOLo1O3bRQfrEMBq4Z34u/9tTsI/3RvQOw0nWJ P9qw== ARC-Authentication-Results: i=1; mx.google.com; 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 o9-v6si751124pgp.508.2018.05.15.14.29.15; Tue, 15 May 2018 14:29:29 -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; 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 S1752628AbeEOV1y (ORCPT + 99 others); Tue, 15 May 2018 17:27:54 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:48538 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752758AbeEOV0P (ORCPT ); Tue, 15 May 2018 17:26:15 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Tue, 15 May 2018 14:25:47 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 2AD7BB07B0; Tue, 15 May 2018 14:26:11 -0700 (PDT) From: Nadav Amit To: CC: , Nadav Amit , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , Peter Zijlstra , Josh Poimboeuf Subject: [RFC 2/8] x86: bug: prevent gcc distortions Date: Tue, 15 May 2018 07:11:18 -0700 Message-ID: <20180515141124.84254-12-namit@vmware.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515141124.84254-1-namit@vmware.com> References: <20180515141124.84254-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org GCC considers the number of statements in inlined assembly blocks, according to new-lines and semicolons, as an indication to the cost of the block in time and space. This data is distorted by the kernel code, which puts information in alternative sections. As a result, the compiler may perform incorrect inlining and branch optimizations. The solution is to set an assembly macro and call it from the inlinedv assembly block. As a result GCC considers the inline assembly block as a single instruction. This patch increases the kernel size: text data bss dec hex filename 18126824 10067268 2936832 31130924 1db052c ./vmlinux before 18127205 10068388 2936832 31132425 1db0b09 ./vmlinux after (+1501) But enables more aggressive inlining (and probably branch decisions). The number of static text symbols in vmlinux is lower. Before: 40015 After: 39860 (-155) Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Peter Zijlstra Cc: Josh Poimboeuf Signed-off-by: Nadav Amit --- arch/x86/include/asm/bug.h | 48 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index 6804d6642767..a2d981beb6cb 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -30,33 +30,43 @@ #ifdef CONFIG_DEBUG_BUGVERBOSE -#define _BUG_FLAGS(ins, flags) \ +asm("\n" + ".macro __BUG_FLAGS ins:req file:req line:req flags:req size:req\n" + "1:\t \\ins\n\t" + ".pushsection __bug_table,\"aw\"\n" + "2:\t "__BUG_REL(1b) "\t# bug_entry::bug_addr\n\t" + __BUG_REL(\\file) "\t# bug_entry::file\n\t" + ".word \\line" "\t# bug_entry::line\n\t" + ".word \\flags" "\t# bug_entry::flags\n\t" + ".org 2b+\\size\n\t" + ".popsection\n" + ".endm"); + +#define _BUG_FLAGS(ins, flags) \ do { \ - asm volatile("1:\t" ins "\n" \ - ".pushsection __bug_table,\"aw\"\n" \ - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ - "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ - "\t.word %c1" "\t# bug_entry::line\n" \ - "\t.word %c2" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c3\n" \ - ".popsection" \ - : : "i" (__FILE__), "i" (__LINE__), \ - "i" (flags), \ + asm volatile("__BUG_FLAGS \"" ins "\" %c0 %c1 %c2 %c3" \ + : : "i" (__FILE__), "i" (__LINE__), \ + "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0) #else /* !CONFIG_DEBUG_BUGVERBOSE */ +asm("\n" + ".macro __BUG_FLAGS ins:req flags:req size:req\n" + "1:\t \\ins\n\t" + ".pushsection __bug_table,\"aw\"\n" + "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n\t" + ".word \\flags" "\t# bug_entry::flags\n\t" + ".org 2b+\\size\n\t" + ".popsection\n" + ".endm"); + #define _BUG_FLAGS(ins, flags) \ do { \ - asm volatile("1:\t" ins "\n" \ - ".pushsection __bug_table,\"aw\"\n" \ - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ - "\t.word %c0" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c1\n" \ - ".popsection" \ - : : "i" (flags), \ - "i" (sizeof(struct bug_entry))); \ + asm volatile("__BUG_FLAGS \"" ins "\" %c0 %c1" \ + : : "i" (flags), \ + "i" (sizeof(struct bug_entry))); \ } while (0) #endif /* CONFIG_DEBUG_BUGVERBOSE */ -- 2.17.0