Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp311623ybn; Tue, 1 Oct 2019 21:33:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNA8o/Z6R5Flh9azXLpuNkXlwxeiCVacUv9g3xlWkhQhwWNTve5BH2MtV7Si5dWlEKldPA X-Received: by 2002:a17:906:3108:: with SMTP id 8mr1346777ejx.11.1569990822081; Tue, 01 Oct 2019 21:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569990822; cv=none; d=google.com; s=arc-20160816; b=HM5bMJKhs9h0+bSjiG/xvWcQBfgEUTpIiFrU0vyudn5pevgMrYYtFZCH5WirpO9PpM BB6Z+dGp3d1YI7E7MbzjQHCq8rAcBGwXlZzO7/Zz/v1EcB7KsuihQpfj1ve1toTSzPoX T26VrlcQs/So7MCTbiiTb+UEYLpq4mr6mqCcuN+4PnxCWtbrnrYBhVLEq1TvmiZUVGMC PhYL7djmpa4rfEJlYmvta2Noq7Epn1Lh99snaNKQ5u+jzY8DO9C6zHdYmJ4FWReo0kRR oyET9ZuLQfsO2YF9/qSpYEMq1R2hFN42hqa0gG9qX5s+aP/AMJ9V9J8liQhbo4lDDLES wasA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=O3nprpczOYxtdd8ScPY3MhrdWBir8yiSGFH+vgNdqwU=; b=RddVSwV2iM5plSN3CUWDOF1X17v8QadglkeSC68BGEc9Fucrda+lRwfWzEaKYmjjBF FvE0Hd69p6F/JQ6h7NLtQiC3GtFbDwXudvitXRqd4cK22SRQc8Jlt98XTGgadFEgQgjP tBE/AJLgK31kMTyFSXbvKOs42lZ2MKsA6EAwb3q2AakMIDsdFD9KxA+oMnznpQ6wObcc M7PYlhLxdL/dFpXBzC/lcryTIwVt58FVxUPpKMIyqC9RBGI7JAM+h/HjIPWSfCEGhIAj lw5swYnYU2JIcCvecvlqTmVnRWyT8EyocEkvvG1BRy43JgsM44YHVFjQ6iSOmOSfkavs 3j6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LxyFxDLx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lw9si9914587ejb.51.2019.10.01.21.33.17; Tue, 01 Oct 2019 21:33:42 -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=@google.com header.s=20161025 header.b=LxyFxDLx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727174AbfJAUV6 (ORCPT + 99 others); Tue, 1 Oct 2019 16:21:58 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41386 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725851AbfJAUV5 (ORCPT ); Tue, 1 Oct 2019 16:21:57 -0400 Received: by mail-pf1-f196.google.com with SMTP id q7so8879098pfh.8 for ; Tue, 01 Oct 2019 13:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=O3nprpczOYxtdd8ScPY3MhrdWBir8yiSGFH+vgNdqwU=; b=LxyFxDLxC6BLWinXmves+Z2YK6aEpy6qut/yqGVCOSexQI9Ci9PHEqqWR7oApv/VA6 dVM13D7WP9ceBYycuYU498kaNVL1DrhlEWIAPTbV3mNg7VhCIvIjlTOMmfeHzaCC4YFG LTQsWsQnmGTBbG3vsQ9oxIOzCGRJldbZPo2R45nMtWz34BXnTMqz6mAsyZvoxRQYE1Hu pO5tJ3U1svzF/RwAccOjxUZOsvYfUdNaiq6sskVew4U7vgGbDzk5VGMHC0OK/5NCnDRN KozbchRrEFc2YDL+WhAuGrJbjYRjpRj+G/Zq9y82ojBzXCLnW3dM11JgD8AAM541VXR7 /eBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=O3nprpczOYxtdd8ScPY3MhrdWBir8yiSGFH+vgNdqwU=; b=P8Kwcd3oEEBmojD0zLMtEcfZVbxpkEamm5WAdfqG5VLUi2eBKDAOHnVTszg59UQgrf Bs184JeOH3SstaroNlHnUf4ook7Cq8a9ou8nz8p6ENASk3x9OH4HXh1+Pxn9SlqGrq30 JVa6dO0N5fuSU9CWuSaUZUXj+JZZL9MLvBxSvvfVsTjs28fXT2oeiMpQZLuOcOSOlgrl qJy140vYmB870wrspXGNQ/JG2o3s+OGhRpg/uIr06ACD15IR3m//ljkkBrW1GT5bMuQF 1nSnCKqgYzlRCh4bWrg4iLI92t5Ou5UeAVQjpClJjJEw0sVKDCmW3SNb1qU3KezeZ6DB 6a4w== X-Gm-Message-State: APjAAAWqlSKUFd6++QF9TybzigV44Y17mOxcC46yxz3ngGJvVLpRYHnf MPsHBj4wlOs6k9RcUgovT5V45W8LW05dESfI12bqfw== X-Received: by 2002:a63:7153:: with SMTP id b19mr31503598pgn.10.1569961316418; Tue, 01 Oct 2019 13:21:56 -0700 (PDT) MIME-Version: 1.0 References: <20190930112636.vx2qxo4hdysvxibl@willie-the-truck> <20190930121803.n34i63scet2ec7ll@willie-the-truck> <20191001092823.z4zhlbwvtwnlotwc@willie-the-truck> <20191001170142.x66orounxuln7zs3@willie-the-truck> <20191001175512.GK25745@shell.armlinux.org.uk> <20191001181438.GL25745@shell.armlinux.org.uk> In-Reply-To: <20191001181438.GL25745@shell.armlinux.org.uk> From: Nick Desaulniers Date: Tue, 1 Oct 2019 13:21:44 -0700 Message-ID: Subject: Re: [PATCH] compiler: enable CONFIG_OPTIMIZE_INLINING forcibly To: Russell King - ARM Linux admin Cc: Will Deacon , Masahiro Yamada , Linus Torvalds , Nicolas Saenz Julienne , Andrew Morton , Ingo Molnar , Borislav Petkov , Miguel Ojeda , linux-arch , LKML , Catalin Marinas , Stefan Wahren , Kees Cook , Arnd Bergmann , clang-built-linux Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 1, 2019 at 11:14 AM Russell King - ARM Linux admin wrote: > > On Tue, Oct 01, 2019 at 11:00:11AM -0700, Nick Desaulniers wrote: > > On Tue, Oct 1, 2019 at 10:55 AM Russell King - ARM Linux admin > > wrote: > > > > > > On Tue, Oct 01, 2019 at 10:44:43AM -0700, Nick Desaulniers wrote: > > > > I apologize; I don't mean to be difficult. I would just like to av= oid > > > > surprises when code written with the assumption that it will be > > > > inlined is not. It sounds like we found one issue in arm32 and one= in > > > > arm64 related to outlining. If we fix those two cases, I think we'= re > > > > close to proceeding with Masahiro's cleanup, which I view as a good > > > > thing for the health of the Linux kernel codebase. > > > > > > Except, using the C preprocessor for this turns the arm32 code into > > > yuck: > > > > > > 1. We'd need to turn get_domain() and set_domain() into multi-line > > > preprocessor macro definitions, using the GCC ({ }) extension > > > so that get_domain() can return a value. > > > > > > 2. uaccess_save_and_enable() and uaccess_restore() also need to > > > become preprocessor macro definitions too. > > > > > > So, we end up with multiple levels of nested preprocessor macros. > > > When something goes wrong, the compiler warning/error message is > > > going to be utterly _horrid_. > > > > That's why I preferred V1 of Masahiro's patch, that fixed the inline > > asm not to make use of caller saved registers before calling a > > function that might not be inlined. > > ... which I objected to based on the fact that this uaccess stuff is > supposed to add protection against the kernel being fooled into > accessing userspace when it shouldn't. The whole intention there is > that [sg]et_domain(), and uaccess_*() are _always_ inlined as close > as possible to the call site of the accessor touching userspace. Then use the C preprocessor to force the inlining. I'm sorry it's not as pretty as static inline functions. > > Moving it before the assignments mean that the compiler is then free > to issue memory loads/stores to load up those registers, which is > exactly what we want to avoid. > > > In any case, I violently disagree with the idea that stuff we have > in header files should be permitted not to be inlined because we > have soo much that is marked inline. So there's a very important subtly here. There's: 1. code that adds `inline` cause "oh maybe it would be nice to inline this, but if it isn't no big deal" 2. code that if not inlined is somehow not correct. 3. avoid ODR violations via `static inline` I'll posit that "we have soo much that is marked inline [is predominantly case 1 or 3, not case 2]." Case 2 is a code smell, and requires extra scrutiny. > Having it moved out of line, > and essentially the same function code appearing in multiple C files > is really not an improvement over the current situation with excessive > use of inlining. Anyone who has looked at the code resulting from > dma_map_single() will know exactly what I'm talking about, which is > way in excess of the few instructions we have for the uaccess_* stuff > here. > > The right approach is to move stuff out of line - and by that, I > mean _actually_ move the damn code, so that different compilation > units can use the same instructions, and thereby gain from the > whole point of an instruction cache. And be marked __attribute__((noinline)), otherwise might be inlined via LTO= . > > The whole "let's make inline not really mean inline" is nothing more > than a band-aid to the overuse (and abuse) of "inline". Let's triple check the ISO C11 draft spec just to be sure: =C2=A7 6.7.4.6: A function declared with an inline function specifier is an inline function. Making a function an inline function suggests that calls to the function be as fast as possible. The extent to which such suggestions are effective is implementation-defined. 139) 139) For example, an implementation might never perform inline substitution, or might only perform inline substitutions to calls in the scope of an inline declaration. =C2=A7 J.3.8 [Undefined Behavior] Hints: The extent to which suggestions made by using the inline function specifier are effective (6.7.4). My translation: "Please don't assume inline means anything." For the unspecified GNU C extension __attribute__((always_inline)), it seems to me like it's meant more for performing inlining (an optimization) at -O0. Whether the compiler warns or not seems like a nice side effect, but provides no strong guarantee otherwise. I'm sorry that so much code may have been written with that assumption, and I'm sorry to be the bearer of bad news, but this isn't a recent change. If code was written under false assumptions, it should be rewritten. Sorry. --=20 Thanks, ~Nick Desaulniers