Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5722068imm; Tue, 18 Sep 2018 14:31:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaJKrSQhEQDfoaurZZeO7Ayj0qw6Fs8UwehYs8Hiy1sMyrIuI1zRyD/6xiTCaWtddDMzNbX X-Received: by 2002:a17:902:714f:: with SMTP id u15-v6mr31879410plm.154.1537306300197; Tue, 18 Sep 2018 14:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537306300; cv=none; d=google.com; s=arc-20160816; b=xUTvPPI6QNTUOLbiXutquRd17b4v/VAsqCg7dnk/Tb8T6/9aa5aiSfVtX9EOIw/M2A EvXYi9hOjmQRUk+9uusEyRfONH9H5tkkCB+j+2NkQa39ZEVilFcj+ohi7140Xv+kv9PK hMY6roWksvTS3ixu9tFXY5VfwqGG9KGUU4Pz6vC4m+TgoYN2U8D1Qf2Kdsqq22u4scc4 Bc2MuRnYnew41I6eC9WOMF8qJY56rxMxQcvmnsns3lTHRCviVguVqvJgn6kkpKJfmltE xbtOynOdZJudqtB192JelkFD4O0ZFcMSq/IJOJZ4soCZnoS9k4K1ALDsytQSh4ZDW6l8 RBHQ== 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=s5QRDIq5eIocydOvbcWOYjuS3Q+akVFEfgZnNlRqjkQ=; b=1LVDmJWCPuuSyOFOeRg5CLgDCAhslUffw/Kokl9ZQOaCaNhqNnCkF7XddabAHV5oMN 9+X9KJ3ZK3QITD+qsrJZHf3rRH+UjGk5AFa1OwbBEzh9sroVxlRpt5KOS6xjhEktuzQj usd+UHfRxbGduVgGNKfrtGyj5M9cCPcVxd0Y4/raY4qb92s9b5LhjY0Va9ODajTnFBJh zt6qQvj24ZxZmlYDtZ7guLQ5xIy2l+v+Jkp/HiOzQdZ1fI1K3sXqclg6p3XUhlazEnbO dX8KDr4Aa5TlOz/Lw4tUKWFNsI5X+4/+DuGyYysm8X9qHpA3xbdLeL/l5yrSnvYKiX/q Zk6w== 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 v23-v6si19202906plo.19.2018.09.18.14.31.25; Tue, 18 Sep 2018 14:31:40 -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 S1730633AbeISDFK (ORCPT + 99 others); Tue, 18 Sep 2018 23:05:10 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:1294 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730519AbeISDFJ (ORCPT ); Tue, 18 Sep 2018 23:05:09 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Tue, 18 Sep 2018 14:30:11 -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 B8C1BB0C14; Tue, 18 Sep 2018 17:30:35 -0400 (EDT) From: Nadav Amit To: Ingo Molnar CC: , , Nadav Amit , Alok Kataria , Thomas Gleixner , "H. Peter Anvin" , Subject: [PATCH v8 07/10] x86: prevent inline distortion by paravirt ops Date: Tue, 18 Sep 2018 14:28:44 -0700 Message-ID: <20180918212847.199085-8-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180918212847.199085-1-namit@vmware.com> References: <20180918212847.199085-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.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 inlined assembly block. As a result GCC considers the inline assembly block as a single instruction. The effect of the patch is a more aggressive inlining, which also causes a size increase of kernel. text data bss dec hex filename 18147336 10226688 2957312 31331336 1de1408 ./vmlinux before 18162555 10226288 2957312 31346155 1de4deb ./vmlinux after (+14819) Static text symbols: Before: 40053 After: 39942 (-111) Cc: Alok Kataria Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: virtualization@lists.linux-foundation.org Acked-by: Peter Zijlstra (Intel) Reviewed-by: Juergen Gross Signed-off-by: Nadav Amit --- arch/x86/include/asm/paravirt_types.h | 56 +++++++++++++-------------- arch/x86/kernel/macros.S | 1 + 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index 4b75acc23b30..83ce282eed0a 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -346,23 +346,11 @@ extern struct pv_lock_ops pv_lock_ops; #define paravirt_clobber(clobber) \ [paravirt_clobber] "i" (clobber) -/* - * Generate some code, and mark it as patchable by the - * apply_paravirt() alternate instruction patcher. - */ -#define _paravirt_alt(insn_string, type, clobber) \ - "771:\n\t" insn_string "\n" "772:\n" \ - ".pushsection .parainstructions,\"a\"\n" \ - _ASM_ALIGN "\n" \ - _ASM_PTR " 771b\n" \ - " .byte " type "\n" \ - " .byte 772b-771b\n" \ - " .short " clobber "\n" \ - ".popsection\n" - /* Generate patchable code, with the default asm parameters. */ -#define paravirt_alt(insn_string) \ - _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]") +#define paravirt_call \ + "PARAVIRT_CALL type=\"%c[paravirt_typenum]\"" \ + " clobber=\"%c[paravirt_clobber]\"" \ + " pv_opptr=\"%c[paravirt_opptr]\";" /* Simple instruction patching code. */ #define NATIVE_LABEL(a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t" @@ -390,16 +378,6 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf, int paravirt_disable_iospace(void); -/* - * This generates an indirect call based on the operation type number. - * The type number, computed in PARAVIRT_PATCH, is derived from the - * offset into the paravirt_patch_template structure, and can therefore be - * freely converted back into a structure offset. - */ -#define PARAVIRT_CALL \ - ANNOTATE_RETPOLINE_SAFE \ - "call *%c[paravirt_opptr];" - /* * These macros are intended to wrap calls through one of the paravirt * ops structs, so that they can be later identified and patched at @@ -537,7 +515,7 @@ int paravirt_disable_iospace(void); /* since this condition will never hold */ \ if (sizeof(rettype) > sizeof(unsigned long)) { \ asm volatile(pre \ - paravirt_alt(PARAVIRT_CALL) \ + paravirt_call \ post \ : call_clbr, ASM_CALL_CONSTRAINT \ : paravirt_type(op), \ @@ -547,7 +525,7 @@ int paravirt_disable_iospace(void); __ret = (rettype)((((u64)__edx) << 32) | __eax); \ } else { \ asm volatile(pre \ - paravirt_alt(PARAVIRT_CALL) \ + paravirt_call \ post \ : call_clbr, ASM_CALL_CONSTRAINT \ : paravirt_type(op), \ @@ -574,7 +552,7 @@ int paravirt_disable_iospace(void); PVOP_VCALL_ARGS; \ PVOP_TEST_NULL(op); \ asm volatile(pre \ - paravirt_alt(PARAVIRT_CALL) \ + paravirt_call \ post \ : call_clbr, ASM_CALL_CONSTRAINT \ : paravirt_type(op), \ @@ -694,6 +672,26 @@ struct paravirt_patch_site { extern struct paravirt_patch_site __parainstructions[], __parainstructions_end[]; +#else /* __ASSEMBLY__ */ + +/* + * This generates an indirect call based on the operation type number. + * The type number, computed in PARAVIRT_PATCH, is derived from the + * offset into the paravirt_patch_template structure, and can therefore be + * freely converted back into a structure offset. + */ +.macro PARAVIRT_CALL type:req clobber:req pv_opptr:req +771: ANNOTATE_RETPOLINE_SAFE + call *\pv_opptr +772: .pushsection .parainstructions,"a" + _ASM_ALIGN + _ASM_PTR 771b + .byte \type + .byte 772b-771b + .short \clobber + .popsection +.endm + #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PARAVIRT_TYPES_H */ diff --git a/arch/x86/kernel/macros.S b/arch/x86/kernel/macros.S index 66ccb8e823b1..71d8b716b111 100644 --- a/arch/x86/kernel/macros.S +++ b/arch/x86/kernel/macros.S @@ -10,3 +10,4 @@ #include #include #include +#include -- 2.17.1