Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp881268imm; Fri, 5 Oct 2018 13:30:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV61cI5EQtjzvry8TOaI+7U2XaGrFVCMFMTxVlayOiSl4EZq5gROFlqcRf4Dw0Y4er/1QAuSs X-Received: by 2002:a17:902:4583:: with SMTP id n3-v6mr13344883pld.255.1538771411304; Fri, 05 Oct 2018 13:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538771411; cv=none; d=google.com; s=arc-20160816; b=DSH33oTc8ANyP2lzT382g+XIAEt+ZZQy/OPlDAMkuDocGwG3b8Vt4vMi2mbREuK/qw rXLPzfK85828vqi8t4SQSdfvsxg0IC/5IyQKhCVb9iwLt892pNr/01TViA7ki7cixT6y UNR437kfCoY7bGijzMj7wG9W1C0tg/pUkxrMV8nlFeeYHVW6q0VS7QkwSkTrYEBl9Bbu 0NGZhUuKKFJizZ9Gody3ru2FJeJv6z8POSA8BnKKEOK43HFuSxOscvIvYMSHf2J4W1Qk MqWZ6FbSotC+p2ZG7taDYzC07MXaSuXks23dr8Pulrc3PzjLLWztETEcNU+lYa/Ehs9P TkIg== 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; bh=hrnlUnfxtnnnrLchlaKF45JJ2uv00x0zmGoKsbbs8bY=; b=IR98khRPQ3P15/VJ+7DKRXvZcD1MzviU8xk4n6UCtVfq/Y6roRKs60jLQhDlWXYKd8 zzFZtDzCGh+Y5AOKH7f06xWUO+/80I4QVD+3KLe+AHhIXjOBsAq1KNu/NigNHhwAYkBY XQTa5G0yoHV+Pkp7kB+SQBOMncS7910oDsXfJ8az3pZL4+WHbhJy9QtctOTCysIpZJbd 9VL2hL+PSsHUVjTwQMKk6c27POPw4YpzpkIqfDfp1AxvkV2ebjaF5TJwNzdzhNZrgJTV vciKVbQUhxWUv7ETBwNXIUUYwFTbq3eyiW4nU9U+8yarCLV55sJ/e0Qze9mJPNSfHISu 1HRw== 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 a9-v6si8747578pgf.380.2018.10.05.13.29.56; Fri, 05 Oct 2018 13:30:11 -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 S1729070AbeJFD3Y (ORCPT + 99 others); Fri, 5 Oct 2018 23:29:24 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:51649 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728170AbeJFD3X (ORCPT ); Fri, 5 Oct 2018 23:29:23 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Fri, 5 Oct 2018 13:28:53 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id C81DD40402; Fri, 5 Oct 2018 13:29:02 -0700 (PDT) From: Nadav Amit To: Ingo Molnar CC: , , Nadav Amit , Andy Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Josh Poimboeuf , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Ingo Molnar Subject: [PATCH 1/3] x86/extable: Macrofy inline assembly code to work around GCC inlining bugs Date: Fri, 5 Oct 2018 13:27:16 -0700 Message-ID: <20181005202718.229565-2-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181005202718.229565-1-namit@vmware.com> References: <20181005093108.GA24723@gmail.com> <20181005202718.229565-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 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 - which is also a minor cleanup for the exception table code. Text size goes up a bit: text data bss dec hex filename 18162555 10226288 2957312 31346155 1de4deb ./vmlinux before 18162879 10226256 2957312 31346447 1de4f0f ./vmlinux after (+292) But this allows the inlining of functions such as nested_vmx_exit_reflected(), set_segment_reg(), __copy_xstate_to_user() which is a net benefit. 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: https://lore.kernel.org/lkml/20181003213100.189959-9-namit@vmware.com/T/#u Signed-off-by: Ingo Molnar --- arch/x86/include/asm/asm.h | 53 ++++++++++++++------------------------ arch/x86/kernel/macros.S | 1 + 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h index 6467757bb39f..21b086786404 100644 --- a/arch/x86/include/asm/asm.h +++ b/arch/x86/include/asm/asm.h @@ -120,12 +120,25 @@ /* Exception table entry */ #ifdef __ASSEMBLY__ # define _ASM_EXTABLE_HANDLE(from, to, handler) \ - .pushsection "__ex_table","a" ; \ - .balign 4 ; \ - .long (from) - . ; \ - .long (to) - . ; \ - .long (handler) - . ; \ + ASM_EXTABLE_HANDLE from to handler + +.macro ASM_EXTABLE_HANDLE from:req to:req handler:req + .pushsection "__ex_table","a" + .balign 4 + .long (\from) - . + .long (\to) - . + .long (\handler) - . .popsection +.endm +#else /* __ASSEMBLY__ */ + +# define _ASM_EXTABLE_HANDLE(from, to, handler) \ + "ASM_EXTABLE_HANDLE from=" #from " to=" #to \ + " handler=\"" #handler "\"\n\t" + +/* For C file, we already have NOKPROBE_SYMBOL macro */ + +#endif /* __ASSEMBLY__ */ # define _ASM_EXTABLE(from, to) \ _ASM_EXTABLE_HANDLE(from, to, ex_handler_default) @@ -148,6 +161,7 @@ _ASM_PTR (entry); \ .popsection +#ifdef __ASSEMBLY__ .macro ALIGN_DESTINATION /* check for bad alignment of destination */ movl %edi,%ecx @@ -171,34 +185,7 @@ _ASM_EXTABLE_UA(100b, 103b) _ASM_EXTABLE_UA(101b, 103b) .endm - -#else -# define _EXPAND_EXTABLE_HANDLE(x) #x -# define _ASM_EXTABLE_HANDLE(from, to, handler) \ - " .pushsection \"__ex_table\",\"a\"\n" \ - " .balign 4\n" \ - " .long (" #from ") - .\n" \ - " .long (" #to ") - .\n" \ - " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \ - " .popsection\n" - -# define _ASM_EXTABLE(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_default) - -# define _ASM_EXTABLE_UA(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess) - -# define _ASM_EXTABLE_FAULT(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault) - -# define _ASM_EXTABLE_EX(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext) - -# define _ASM_EXTABLE_REFCOUNT(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount) - -/* For C file, we already have NOKPROBE_SYMBOL macro */ -#endif +#endif /* __ASSEMBLY__ */ #ifndef __ASSEMBLY__ /* diff --git a/arch/x86/kernel/macros.S b/arch/x86/kernel/macros.S index 71d8b716b111..7baa40d5bf16 100644 --- a/arch/x86/kernel/macros.S +++ b/arch/x86/kernel/macros.S @@ -11,3 +11,4 @@ #include #include #include +#include -- 2.17.1