Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp135865imm; Fri, 21 Sep 2018 11:36:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaqPJo+Oma8QGpVTeHxCRgCzMWuYSr0Zgfji+A13iyjAwTLC1alXgod8PxYrJbgv481Nvm+ X-Received: by 2002:a63:2587:: with SMTP id l129-v6mr7381223pgl.29.1537555012741; Fri, 21 Sep 2018 11:36:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537555012; cv=none; d=google.com; s=arc-20160816; b=vxwLz7O0JADINPKYOqiOKt13AETqoDQiFaED0JIg0dQR7BOJiD24DAj8524ypztK3E OjXiPEnxSEOC4bN/rn5yjR7xi0Eh0KmhiGe7xAeTfKUzEVJBp0xSNpI2p9GbfF9U9R4A F+PSGuo32MzFz/AXWNiRz1dn2YgOuK3JB34uf29BH8kh3dhOucDbYsKcpIhHNR+Aa4vC DfERgYXKqkP0yghCzThir6XHXgdl/+xsvc4+UG/dLA6xO+Ph59dmO7UVafUZu8yJWgFp 1s0HPEHTHz6VzCAozAHynu4nOAUKd7Y9PSOzk5xPdDU/6EqhRgN2nyKbkz015gQf0Oag JT5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=sExD8i4jvCOL4Zp3pZc8aNg2i3wRkgAenXJfeRMHAeU=; b=PkLBcCTuLPOq+moeYZsjtqCtUMc6n95k65SGePJv0fapxgY73l8G99mng/p3FuluN2 Uno+Hhw7hhK7FS5PmICNwn5cw3ST/1adK4oscCoQEiR2s35vFDFN9nJ15cOKBouPr/yt rbyp+9+A5oKwxJGnyR/eDQazOnbRcYkfKJaqN++lpkk+AgJnbsUGjSxHPZP14pCXh/Vl vYT6MZnmZyHo2AcmWaDS0adRdMEAB1nqr/FJwNiqRzuliBOKZOrGBYLFffY/TkGSpJmp 075sXY9kXM/FBuuJtIcEi751XWuLh8jybgJiNw4R4/WGWJlZDKGyx/l7QBcmN88S3e15 Hlkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AAfeTLz0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si26077454plc.168.2018.09.21.11.36.36; Fri, 21 Sep 2018 11:36:52 -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; dkim=pass header.i=@chromium.org header.s=google header.b=AAfeTLz0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391258AbeIVAZH (ORCPT + 99 others); Fri, 21 Sep 2018 20:25:07 -0400 Received: from mail-yb1-f193.google.com ([209.85.219.193]:47082 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391089AbeIVAZH (ORCPT ); Fri, 21 Sep 2018 20:25:07 -0400 Received: by mail-yb1-f193.google.com with SMTP id y20-v6so5809207ybi.13 for ; Fri, 21 Sep 2018 11:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=sExD8i4jvCOL4Zp3pZc8aNg2i3wRkgAenXJfeRMHAeU=; b=AAfeTLz0anYwKN6H2xdtOLNgrcV1q07Bv5nYNs564RK8hzB3Z3lppjfmamIOxnJQH9 MkhrlIFgCbwlevlKQjT/QQLXvbKqLz1D3W+gsPjS/RZ/iZ6wwtd8t7ZvgDyztiZ5C/O/ hJ+AzsehDFo2uxv4db6IuIkW3YO+ydmkfMGkg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=sExD8i4jvCOL4Zp3pZc8aNg2i3wRkgAenXJfeRMHAeU=; b=Gi24vNw1fEr5KlOD23D5LQanUQVzkSKlPiC8zcq8kIVP+LpZ10u9YVu7KNZVvgvyf9 jjTkKUTCZX6zM9KE8I7uOSV1BwB3cXQxhEeCmelNu160igklZbxQeZSRlT1pO5TBThvg 17jTU8jgnFNTStJLDV+CT2IGWC9NAIeGKekR7ThttBbI0jDnRHavGsv8QCUbFYR8l15y wR4BiA4ZvY/mfJTDLgM8M6t3W+0kLXGVfOnr1vDEQD6FQxZpCpRJwBAj+9vZirADy7L0 2YY1ofhcZCOmfranBeu0UDR0GAEuoLjxVjwd/6DfvoyUEXvGUNfqRHfvKUokRVby3ao6 s8mQ== X-Gm-Message-State: APzg51A/E1u2wfYu9DQs43jkZI3QQTKAWnMkdi/suRaHfYST7ML7RPrC P4uX0cNX/BNWHDyJA6ZQVS7+WGaMjeY= X-Received: by 2002:a25:5485:: with SMTP id i127-v6mr4303285ybb.23.1537554899533; Fri, 21 Sep 2018 11:34:59 -0700 (PDT) Received: from mail-yw1-f41.google.com (mail-yw1-f41.google.com. [209.85.161.41]) by smtp.gmail.com with ESMTPSA id p126-v6sm7321440ywf.22.2018.09.21.11.34.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 11:34:59 -0700 (PDT) Received: by mail-yw1-f41.google.com with SMTP id x83-v6so5573872ywd.4 for ; Fri, 21 Sep 2018 11:34:59 -0700 (PDT) X-Received: by 2002:a0d:fe87:: with SMTP id o129-v6mr4468409ywf.237.1537554398910; Fri, 21 Sep 2018 11:26:38 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:5f04:0:0:0:0:0 with HTTP; Fri, 21 Sep 2018 11:26:38 -0700 (PDT) In-Reply-To: <20180918212847.199085-1-namit@vmware.com> References: <20180918212847.199085-1-namit@vmware.com> From: Kees Cook Date: Fri, 21 Sep 2018 11:26:38 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 00/10] x86: macrofying inline asm for better compilation To: Nadav Amit Cc: Ingo Molnar , LKML , X86 ML , Masahiro Yamada , Sam Ravnborg , Alok Kataria , Christopher Li , Greg Kroah-Hartman , "H. Peter Anvin" , Jan Beulich , Josh Poimboeuf , Juergen Gross , Kate Stewart , Sparse Mailing-list , Peter Zijlstra , Philippe Ombredanne , Thomas Gleixner , virtualization@lists.linux-foundation.org, Linus Torvalds , Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 18, 2018 at 2:28 PM, Nadav Amit wrote: > This patch-set deals with an interesting yet stupid problem: kernel code > that does not get inlined despite its simplicity. There are several > causes for this behavior: "cold" attribute on __init, different function > optimization levels; conditional constant computations based on > __builtin_constant_p(); and finally large inline assembly blocks. > > This patch-set deals with the inline assembly problem. I separated these > patches from the others (that were sent in the RFC) for easier > inclusion. I also separated the removal of unnecessary new-lines which > would be sent separately. > > The problem with inline assembly is that inline assembly is often used > by the kernel for things that are other than code - for example, > assembly directives and data. GCC however is oblivious to the content of > the blocks and assumes their cost in space and time is proportional to > the number of the perceived assembly "instruction", according to the > number of newlines and semicolons. Alternatives, paravirt and other > mechanisms are affected, causing code not to be inlined, and degrading > compilation quality in general. > > The solution that this patch-set carries for this problem is to create > an assembly macro, and then call it from the inline assembly block. As > a result, the compiler sees a single "instruction" and assigns the more > appropriate cost to the code. > > To avoid uglification of the code, as many noted, the macros are first > precompiled into an assembly file, which is later assembled together > with the C files. This also enables to avoid duplicate implementation > that was set before for the asm and C code. This can be seen in the > exception table changes. > > Overall this patch-set slightly increases the kernel size (my build was > done using my Ubuntu 18.04 config + localyesconfig for the record): > > text data bss dec hex filename > 18140829 10224724 2957312 31322865 1ddf2f1 ./vmlinux before > 18163608 10227348 2957312 31348268 1de562c ./vmlinux after (+0.1%) > > The number of static functions in the image is reduced by 379, but > actually inlining is even better, which does not always shows in these > numbers: a function may be inlined causing the calling function not to > be inlined. > > I ran some limited number of benchmarks, and in general the performance > impact is not very notable. You can still see >10 cycles shaved off some > syscalls that manipulate page-tables (e.g., mprotect()), in which > paravirt caused many functions not to be inlined. In addition this > patch-set can prevent issues such as [1], and improves code readability > and maintainability. > > [1] https://patchwork.kernel.org/patch/10450037/ > > v7->v8: * Add acks (Masahiro, Max) > * Rebase on 4.19 (Ingo) I've tested the series for booting and with the refcount lkdtm tests. Looks good, thanks! Tested-by: Kees Cook -Kees -- Kees Cook Pixel Security