Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp768940imm; Thu, 4 Oct 2018 03:04:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV606hQ3AZM/0ex039yQ96M02TKNTJDVj/jd33Ks+VL7marH1L4zXHi7zeD0WPH0ABkGreZa3 X-Received: by 2002:a63:da17:: with SMTP id c23-v6mr5192631pgh.23.1538647491453; Thu, 04 Oct 2018 03:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538647491; cv=none; d=google.com; s=arc-20160816; b=tQ5KtxFpdyWVUSNstkyYteXzmaS/27mSnTkAeUi8QJzEGHONaKzV7EXsl4IHvMPRHX Lh5Svy/gfdPlahWypPo838vC6qi1ZE1ubj3/Bs5qv7wYT6QSJolkBZsEqysiGNW6DsG4 GIfRJ9u2E7kc0Pn5VTxwDmyJr9YynhcBMgcqAcyK3tSKhKRIXhNi3lkqS42RnRADb9V5 SCIN1MF0l5p92KHYtdZVba3zr+ZXNTow2ea4cBsUEj4lzcyz3QK7BkMCLpPOWISkLM04 mlBuRTr26W3g45WPJyhrtG4R5AD3n+NYSGdi9cx+S1MM6zRJKtSiEwlDl1lrsnP9qNJJ 1wEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=3HKnvVgFbI821QfiSW8tbO8JKr19JPVxnnrAHwV+CIs=; b=f8VphpVaBYsEr/TPoAI3otI9YoIu0f4rhAduoN6288pNx5KsHcuSy2Jql45cwYJNyz foaQvGe1aYwrvOquvg1DHKGWXKtSlCMN+rodHRSNSCzOZg/RnnoTOBnKakIdHOrNweio PDkT1piClZjH3256rU50NJB9sZCPvZ5tR3MYqUDA90w+IzvzhMEd942ru9W+1GcSzMUT ZBsSbsXC+TsGjGoiLd5zhYRzxxKK2c3ias6OZ7td+vpawDem47jVcZHBzq/sF/vSNPVC Jl6NEEHYmLPoCCUnmX6YXqBmgbahGezZcxHBY2X6uiEAxxJ7CXwMtadoKPmGjX/YZ6kJ G3dw== 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 d10-v6si4692702pla.436.2018.10.04.03.04.35; Thu, 04 Oct 2018 03:04:51 -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 S1728108AbeJDQ42 (ORCPT + 99 others); Thu, 4 Oct 2018 12:56:28 -0400 Received: from terminus.zytor.com ([198.137.202.136]:50309 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727523AbeJDQ4W (ORCPT ); Thu, 4 Oct 2018 12:56:22 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w94A35Re2701847 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 4 Oct 2018 03:03:05 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w94A350F2701844; Thu, 4 Oct 2018 03:03:05 -0700 Date: Thu, 4 Oct 2018 03:03:05 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Nadav Amit Message-ID: Cc: keescook@chromium.org, luto@amacapital.net, jpoimboe@redhat.com, bp@alien8.de, peterz@infradead.org, linux-kernel@vger.kernel.org, dvlasenk@redhat.com, hpa@zytor.com, brgerst@gmail.com, namit@vmware.com, torvalds@linux-foundation.org, mingo@kernel.org, tglx@linutronix.de Reply-To: linux-kernel@vger.kernel.org, peterz@infradead.org, keescook@chromium.org, bp@alien8.de, luto@amacapital.net, jpoimboe@redhat.com, namit@vmware.com, tglx@linutronix.de, mingo@kernel.org, torvalds@linux-foundation.org, brgerst@gmail.com, dvlasenk@redhat.com, hpa@zytor.com In-Reply-To: <20181003213100.189959-6-namit@vmware.com> References: <20181003213100.189959-6-namit@vmware.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/build] x86/alternatives: Macrofy lock prefixes to work around GCC inlining bugs Git-Commit-ID: 77f48ec28e4ccff94d2e5f4260a83ac27a7f3099 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 77f48ec28e4ccff94d2e5f4260a83ac27a7f3099 Gitweb: https://git.kernel.org/tip/77f48ec28e4ccff94d2e5f4260a83ac27a7f3099 Author: Nadav Amit AuthorDate: Wed, 3 Oct 2018 14:30:55 -0700 Committer: Ingo Molnar CommitDate: Thu, 4 Oct 2018 11:24:59 +0200 x86/alternatives: Macrofy lock prefixes to work around GCC inlining bugs As described in: 77b0bf55bc67: ("kbuild/Makefile: Prepare for using macros in inline assembly code to work around asm() related GCC inlining bugs") GCC's inlining heuristics are broken with common asm() patterns used in kernel code, resulting in the effective disabling of inlining. The workaround is to set an assembly macro and call it from the inline assembly block - i.e. to macrify the affected block. As a result GCC considers the inline assembly block as a single instruction. This patch handles the LOCK prefix, allowing more aggresive inlining: text data bss dec hex filename 18140140 10225284 2957312 31322736 1ddf270 ./vmlinux before 18146889 10225380 2957312 31329581 1de0d2d ./vmlinux after (+6845) This is the reduction in non-inlined functions: Before: 40286 After: 40218 (-68) Tested-by: Kees Cook Signed-off-by: Nadav Amit Acked-by: Peter Zijlstra (Intel) Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20181003213100.189959-6-namit@vmware.com Signed-off-by: Ingo Molnar --- arch/x86/include/asm/alternative-asm.h | 20 ++++++++++++++------ arch/x86/include/asm/alternative.h | 11 ++--------- arch/x86/kernel/macros.S | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h index 31b627b43a8e..8e4ea39e55d0 100644 --- a/arch/x86/include/asm/alternative-asm.h +++ b/arch/x86/include/asm/alternative-asm.h @@ -7,16 +7,24 @@ #include #ifdef CONFIG_SMP - .macro LOCK_PREFIX -672: lock +.macro LOCK_PREFIX_HERE .pushsection .smp_locks,"a" .balign 4 - .long 672b - . + .long 671f - . # offset .popsection - .endm +671: +.endm + +.macro LOCK_PREFIX insn:vararg + LOCK_PREFIX_HERE + lock \insn +.endm #else - .macro LOCK_PREFIX - .endm +.macro LOCK_PREFIX_HERE +.endm + +.macro LOCK_PREFIX insn:vararg +.endm #endif /* diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 4cd6a3b71824..d7faa16622d8 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -31,15 +31,8 @@ */ #ifdef CONFIG_SMP -#define LOCK_PREFIX_HERE \ - ".pushsection .smp_locks,\"a\"\n" \ - ".balign 4\n" \ - ".long 671f - .\n" /* offset */ \ - ".popsection\n" \ - "671:" - -#define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; " - +#define LOCK_PREFIX_HERE "LOCK_PREFIX_HERE\n\t" +#define LOCK_PREFIX "LOCK_PREFIX " #else /* ! CONFIG_SMP */ #define LOCK_PREFIX_HERE "" #define LOCK_PREFIX "" diff --git a/arch/x86/kernel/macros.S b/arch/x86/kernel/macros.S index f1fe1d570365..852487a9fc56 100644 --- a/arch/x86/kernel/macros.S +++ b/arch/x86/kernel/macros.S @@ -8,3 +8,4 @@ #include #include +#include