Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2038358imm; Wed, 16 May 2018 07:01:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqC2/w1gI66MnSgiqqrUE1RYYppobDIBhuI/l/QkK3jk6Su9fDnaeEmeTWAV0KlSPfOAC9z X-Received: by 2002:a65:4309:: with SMTP id j9-v6mr821542pgq.375.1526479278658; Wed, 16 May 2018 07:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526479278; cv=none; d=google.com; s=arc-20160816; b=MRLGJoTz9JOjFMZDooVuqM83h1EvTAyTL7D+u6JxoE0i8MMdliDwYchL5CH5Xhm8VV AkgLcn1QcdJ+y01cfljU74pwI7m4tfCZEXDMWQyFS+QlinUMZL3KShEosAfopdXL4S1A U+iepIFHv0+qxlqg7ZxihZUiyKpX4dvy1eyABHhu547e0sViWoiR4gFRMyiXLddfqHyD zZ6z0DNHPAt6d/9UPZd4kzH7q9lFRhiiANsiYddOjR/pXzZBfNGw1Vx+USdCZyTplcQt 1ImLDzaNib0jw6aSvIcWJXbCudd0xhZnfB7KO9Jfl0ESHD75gVSvR7OXeqG8yFaRnpNA JqNA== 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:dkim-signature :arc-authentication-results; bh=FiYX2lcYDVTqtfdu1N/89sL0Z+4SpCB6pXtGzHySQhQ=; b=svGyKCpWoXTjrZvZcaVYBq5CHS8E1NH9h7xVrX7O7VIxapMWrAYNCLsJ1xButopHbC VpyBTsQiGnbyVMBgB4I5bO47frGsygjSS7DZXUlrSsvnqmbJkNpK75BXp6n+Yv9WTjxE oZd3FAVhhQjlZ3LRourd4Hy4HFFP6LlGlMt0NHy+WPZO3r9vvWg+4TAkyDPjOcuPJudv i3iYtSaK/upIRXCjwXFTZQ9wuib1O90FQG+JNNuzHGsQCkRvx+LDbelNxw9HyVPYSjv3 mRdj0oFJZUzSycl7tXaygnh7eQXRf2YjFt2xStASxdXgIsqa9h5lI7V5KDERXVZUMRhN BwqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=Nm+9cLEj; dkim=fail header.i=@chromium.org header.s=google header.b=k02WFgm1; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3-v6si2068612pga.487.2018.05.16.07.01.01; Wed, 16 May 2018 07:01:18 -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=fail header.i=@google.com header.s=20161025 header.b=Nm+9cLEj; dkim=fail header.i=@chromium.org header.s=google header.b=k02WFgm1; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752613AbeEPN7G (ORCPT + 99 others); Wed, 16 May 2018 09:59:06 -0400 Received: from mail-ua0-f194.google.com ([209.85.217.194]:34500 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752505AbeEPN7E (ORCPT ); Wed, 16 May 2018 09:59:04 -0400 Received: by mail-ua0-f194.google.com with SMTP id f22-v6so597624uam.1 for ; Wed, 16 May 2018 06:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=FiYX2lcYDVTqtfdu1N/89sL0Z+4SpCB6pXtGzHySQhQ=; b=Nm+9cLEjD4T9QfcK5Ovl30KSSx+ZnbD/qj0hkasBHC+rzC5F8k06O/LSPZQbhUqfO7 V0pynzX+ip1B4p5SfVrsjRiMwY/wTM6157R3DYZfMiMnJTvTqONQd4gYNf/qCwfkEylW aN8tmlX0fs70XJJRoehYlS4rE74ZNw0olSpTJoxhG9K9kusBU7Vzpfx4i6nHo2qt9l1w w36vvMVOuFUOgMQ8a0/wRcJKaDzsu4cLfB8YWImWogTAhvazlNBZrt2L42D6i0vGjA1B BXL+1Erp7adXsmAxRUmcfltQ7WBeRIzoupnFcUtN5uzUdcFpDr3OzqN0Wjvfqahq6P11 hK/w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=FiYX2lcYDVTqtfdu1N/89sL0Z+4SpCB6pXtGzHySQhQ=; b=k02WFgm1SKdqvoTBY1Qf8PKp9U9651GgtaKMmVF+P4WaFTuuLA5n1ljOcsukBBTi+c SyD847PjVhTq2geM1B8OWZh9XtC/AxrXQdAFbkrdcRwUJqDWsNQoF5fBxNkGCS2o+CWU +3Ndbpts23OyV9Q4zuqaSx4Gvwp+3EA9hqUek= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=FiYX2lcYDVTqtfdu1N/89sL0Z+4SpCB6pXtGzHySQhQ=; b=BGGGsNju37GLOIgT4EnRF0NdGVWqf+NoUvsQ9P4nQweHmepd2o4wQ3nJciYPjnLoEM 5v0dJ4PMl8pZsaF05QF3iCoU4TUROpyN6pOdBVqeElCbloZIAdeV6T0/+0jlkV4TAWDN kWmbTj8b0KBRdH1SA+Tb20rhksVeKSZkeUwalryPiiIuwmK6W1N9ZFnD6jGgEbT6A8va GHamElAb7BT+Ry7G+mXxcniD2JBVI8/bvAnYnOyYFZNe8FUpowkA+knKq58qrOqYM94d pR+3kero7dtlFPpkACRC0gBgoGKApKiY7AsMeT8py9zEAMLY+YDJ6Nu+fknvOo0VPByF bm5Q== X-Gm-Message-State: ALKqPwe+sKC6ROoExH9khGn+LPuWKumdqVSKkfzEzoO9ydiUxKsSqMHH Tk4akzZriy0vETgS+2sHn+tQZpcsST43Fn8R937zvg== X-Received: by 2002:ab0:4ce2:: with SMTP id e34-v6mr952397uag.0.1526479143159; Wed, 16 May 2018 06:59:03 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1f:bd1:0:0:0:0:0 with HTTP; Wed, 16 May 2018 06:59:02 -0700 (PDT) In-Reply-To: <20180515141124.84254-6-namit@vmware.com> References: <20180515141124.84254-1-namit@vmware.com> <20180515141124.84254-6-namit@vmware.com> From: Kees Cook Date: Wed, 16 May 2018 06:59:02 -0700 X-Google-Sender-Auth: iabVJPc_2xAqCX4lXEpYcGTnKu8 Message-ID: Subject: Re: [RFC 5/8] x86: refcount: prevent gcc distortions To: Nadav Amit Cc: LKML , Nadav Amit , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , X86 ML , Jan Beulich , Josh Poimboeuf 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, May 15, 2018 at 7:11 AM, Nadav Amit wrote: > 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. > > This patch allows to inline functions such as __get_seccomp_filter(). > The effect of the patch is as follows on the kernel size: > > text data bss dec hex filename > 18146418 10064100 2936832 31147350 1db4556 ./vmlinux before > 18148228 10063968 2936832 31149028 1db4be4 ./vmlinux after (+1678) > > Static text symbols: > Before: 39673 > After: 39649 (-24) > > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: "H. Peter Anvin" > Cc: x86@kernel.org > Cc: Kees Cook > Cc: Jan Beulich > Cc: Josh Poimboeuf > > Signed-off-by: Nadav Amit > --- > arch/x86/include/asm/refcount.h | 55 ++++++++++++++++++++------------- > 1 file changed, 33 insertions(+), 22 deletions(-) > > diff --git a/arch/x86/include/asm/refcount.h b/arch/x86/include/asm/refcount.h > index 4cf11d88d3b3..a668c534206d 100644 > --- a/arch/x86/include/asm/refcount.h > +++ b/arch/x86/include/asm/refcount.h > @@ -14,34 +14,43 @@ > * central refcount exception. The fixup address for the exception points > * back to the regular execution flow in .text. > */ > -#define _REFCOUNT_EXCEPTION \ > - ".pushsection .text..refcount\n" \ > - "111:\tlea %[counter], %%" _ASM_CX "\n" \ > - "112:\t" ASM_UD2 "\n" \ > - ASM_UNREACHABLE \ > - ".popsection\n" \ > - "113:\n" \ > + > +asm ("\n" > + ".macro __REFCOUNT_EXCEPTION counter:vararg\n\t" Why are these vararg? Also, I think for the whole series, these #define-a-macro cases need a comment in the code. It's not obvious from looking at the code why they've defined a macro instead of just leaving the asm as it was. Beyond that, as long as there is no behavioral changes, I'm fine with the changes. -Kees -- Kees Cook Pixel Security