Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3928738imm; Mon, 4 Jun 2018 11:37:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJUguONnnXu9lcw0F/jWEPjCXDiWiDjmT+JFqJY3gN0UM9oJ11UaDlP7e8KE5PsqDwRlNQ5 X-Received: by 2002:a17:902:8b82:: with SMTP id ay2-v6mr22630694plb.295.1528137470071; Mon, 04 Jun 2018 11:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528137470; cv=none; d=google.com; s=arc-20160816; b=PcyC6F19HJyAQ8Z4dLOGoN3GZ4z8f5o4Yuib2B/hYgFDM9FKc5ooKFckIgB5fBdbUp 4uDTE2PfZS3SXBwiQfYc+YoYwnOsSEVNSy9aIJfn11H/5WYf5bHPHc6NEJjkNkgVpgPT kmbMLvnNAGlw3HazaJAof/RXq/CKeq4oktK2V8esD1B3lD6UPW5KVs6neZUJdrha54ae x2WkbG44g41o7etTrvicUumpvk5cRJxY5HBpGc7ge53e5shhNeFVTg/eWnLeE4oG9etY gK+xX5/xYXOpepH6b9YofITcQPmRVFvv4WgKxin0kXr8nSaCpfBDWNDUvHcfTk1yMMpD Y94g== 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=NNljA3w95Rpq5rNavvG7L0T/h70iDiixRc1v3p5AEwg=; b=BrLpgNK92tq5U6jykPjBXOlTPrga7TMxYRDywrVi0x779KIp6ZHkY5QKRnM4Wq/ScO 86qLzJ2MysUZaPaf2FqZCQfIs6APwob68SbSZk3fD0pIfAILzhgazZBjPNc9e5nw4l1z OChuzaovz4pCz1qw6Acq+/JPM6aCwzR6TT5WG1QBRdcnsQmFdt662/deOJZ6UOi5Sw5+ alkFlto04e5zPGyaLu7QHkMUarV3om8Ls7uUvVL2JL/2YoQL/eWi5pXwOfUWjzr6EwTx aZ8ayuO8GBuDTczs4lb+jiWhsWLauRB/yYMe0ithToQAltP+BRqGmpo2QqkLl3Dh//8G jlSg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10-v6si44674863pfo.121.2018.06.04.11.37.34; Mon, 04 Jun 2018 11:37:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751336AbeFDSgc (ORCPT + 99 others); Mon, 4 Jun 2018 14:36:32 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:2727 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751058AbeFDSg3 (ORCPT ); Mon, 4 Jun 2018 14:36:29 -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; Mon, 4 Jun 2018 11:36:14 -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 2A184B0BFA; Mon, 4 Jun 2018 11:36:27 -0700 (PDT) From: Nadav Amit To: , CC: Nadav Amit , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Peter Zijlstra , Josh Poimboeuf Subject: [PATCH v2 5/9] x86: bug: prevent gcc distortions Date: Mon, 4 Jun 2018 04:21:27 -0700 Message-ID: <20180604112131.59100-6-namit@vmware.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180604112131.59100-1-namit@vmware.com> References: <20180604112131.59100-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 18146889 10225380 2957312 31329581 1de0d2d ./vmlinux before 18147336 10226688 2957312 31331336 1de1408 ./vmlinux after (+1755) But enables more aggressive inlining (and probably branch decisions). The number of static text symbols in vmlinux is lower. Static text symbols: Before: 40218 After: 40053 (-165) 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 | 98 ++++++++++++++++++++++---------------- arch/x86/kernel/macros.S | 1 + 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index 6804d6642767..5090035e6d16 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -4,6 +4,8 @@ #include +#ifndef __ASSEMBLY__ + /* * Despite that some emulators terminate on UD2, we use it for WARN(). * @@ -20,53 +22,15 @@ #define LEN_UD2 2 -#ifdef CONFIG_GENERIC_BUG - -#ifdef CONFIG_X86_32 -# define __BUG_REL(val) ".long " __stringify(val) -#else -# define __BUG_REL(val) ".long " __stringify(val) " - 2b" -#endif - -#ifdef CONFIG_DEBUG_BUGVERBOSE - -#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), \ - "i" (sizeof(struct bug_entry))); \ -} while (0) - -#else /* !CONFIG_DEBUG_BUGVERBOSE */ - #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), \ + asm volatile("ASM_BUG ins=\"" ins "\" file=%c0 line=%c1 " \ + "flags=%c2 size=%c3" \ + : : "i" (__FILE__), "i" (__LINE__), \ + "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0) -#endif /* CONFIG_DEBUG_BUGVERBOSE */ - -#else - -#define _BUG_FLAGS(ins, flags) asm volatile(ins) - -#endif /* CONFIG_GENERIC_BUG */ - #define HAVE_ARCH_BUG #define BUG() \ do { \ @@ -82,4 +46,54 @@ do { \ #include +#else /* __ASSEMBLY__ */ + +#ifdef CONFIG_GENERIC_BUG + +#ifdef CONFIG_X86_32 +.macro __BUG_REL val:req + .long \val +.endm +#else +.macro __BUG_REL val:req + .long \val - 2b +.endm +#endif + +#ifdef CONFIG_DEBUG_BUGVERBOSE + +.macro ASM_BUG ins:req file:req line:req flags:req size:req +1: \ins + .pushsection __bug_table,"aw" +2: __BUG_REL val=1b # bug_entry::bug_addr + __BUG_REL val=\file # bug_entry::file + .word \line # bug_entry::line + .word \flags # bug_entry::flags + .org 2b+\size + .popsection +.endm + +#else /* !CONFIG_DEBUG_BUGVERBOSE */ + +.macro ASM_BUG ins:req file:req line:req flags:req size:req +1: \ins + .pushsection __bug_table,"aw" +2: __BUG_REL val=1b # bug_entry::bug_addr + .word \flags # bug_entry::flags + .org 2b+\size + .popsection +.endm + +#endif /* CONFIG_DEBUG_BUGVERBOSE */ + +#else /* CONFIG_GENERIC_BUG */ + +.macro ASM_BUG ins:req file:req line:req flags:req size:req + \ins +.endm + +#endif /* CONFIG_GENERIC_BUG */ + +#endif /* __ASSEMBLY__ */ + #endif /* _ASM_X86_BUG_H */ diff --git a/arch/x86/kernel/macros.S b/arch/x86/kernel/macros.S index 852487a9fc56..66ccb8e823b1 100644 --- a/arch/x86/kernel/macros.S +++ b/arch/x86/kernel/macros.S @@ -9,3 +9,4 @@ #include #include #include +#include -- 2.17.0