Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7490331ybn; Mon, 30 Sep 2019 14:54:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9WhlCR6w+CAy+4R26P7VYcONFUDBBIPeBiE8HC4uACzSnyh4d0VS8bHjgGGfb57coupvb X-Received: by 2002:a17:906:6b98:: with SMTP id l24mr21638767ejr.208.1569880483379; Mon, 30 Sep 2019 14:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569880483; cv=none; d=google.com; s=arc-20160816; b=ZLiAMlcmCowjEAhCSWgpBu8cu4oYVydx+LnhZp6JMDhKgOg6XOdjnzwkeaN9aqEqKx DJYfGGTivXR+6inscEB9dQ7J9rdWbGzX2W9S4evF2FZbF4QTEmvT5kT69Y82AqLexmiN QOwj4OIvJyhHkYcq3lqACGGTlmmxb9aqYbNALqh4iYCzsAsmF0rNsJHx3eidMsAt2kUP DT0Mt8xBZU15/DK4IDONCARQFJd7QQrGg8UjEIued4LIZfFZULZCw4h1PlQ1SwG1Ffgb IE7vfoUXVh8DABCRnyMO7zwHR4Nl0uZfDUHkezYgsZ9n3OwnivxrnjCrOfpA+MfEr39P Nj5w== 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 :in-reply-to:references:mime-version:dkim-signature; bh=nZqLTazAKZGG4KJ4iEi3hzNpvjFqh7JVEXlZWdade0A=; b=LucOkanW9VjHLZaMf5wbtIubQ7qsCjenwPeYZwsHqeqRQvlmdjMC6PuwcMed2bCixT Vdc/T09PRQvzBSJfJjnGgRqgyPVjRRz94dIOqlCb1nBfLEBGrGFkmCw1QFkEr/doCxjq dFHkflJzty/nJOVsNS22VyPxWhqeXq4NHu7eqbqrHxQSB5MRX35IzKQr6RV9wyHRWzxR m4ZCMRhKXe9V+RKQw5XhbOC34tm1F4uiWkfhyleZA6GBXjoY49iUYm7+OPjxmK4BFTNU prS9GTzp5dDEJDVKorAsyI2Tk3zDIKVzhuGRPnVL/Xqgyr7UTA5Z051r+IVRWSmyfYP/ e9WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cB206ZEg; 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 i16si8437111ejo.255.2019.09.30.14.54.17; Mon, 30 Sep 2019 14:54:43 -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=cB206ZEg; 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 S1732364AbfI3VuY (ORCPT + 99 others); Mon, 30 Sep 2019 17:50:24 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44690 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731582AbfI3VuX (ORCPT ); Mon, 30 Sep 2019 17:50:23 -0400 Received: by mail-pg1-f193.google.com with SMTP id i14so8079537pgt.11 for ; Mon, 30 Sep 2019 14:50:23 -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; bh=nZqLTazAKZGG4KJ4iEi3hzNpvjFqh7JVEXlZWdade0A=; b=cB206ZEgRonZzA9R7W2bEe12czYrZkepf8raUEl93I/yZxZo1Jw4kmluZnhffkw2Hz 2oWyvjF4bnDyf0vqh1F8HJVYGhy8Epba0CrVSh/jRVoeUIruGvrCZ/L/NkRcOMbkOGxy eKN0/SNwe6z/DHIETMseeHvpzVHHytSXAC0SZ1VsLCe5z3KScHSwF8KLFlJOsNIm2kpr y4Oy5htt/7JyyD/fxIuLtQGeiwyWMCae4sEidLkAVFrl9h1lHYKOkLJuqyzvRiVnhXds 6wyQzqOa+tdH84XBUzDUjVdNjVujBquh4Mi3uPIR/FNF1bEpGA7yp0j5OAtRvAG6zwfW ZcWA== 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; bh=nZqLTazAKZGG4KJ4iEi3hzNpvjFqh7JVEXlZWdade0A=; b=hTCoskAX1K1TFlBEzAYI6GsfwKOmsboUpgv1OxXvqwFJr5/CVzVDc62P57Zu7CfJ5t 56DWg5NKjpT6KsMCpNiTItwF0+mACs7N5yxTM+voosxZmUSp27UQ8dIvnXYFU9yhiKEU xdkMxqFMKCQWF044+bGpkyy5ZpR8CJ5vYCbGmaQU3HPvZe3Bv2ye1qMfaVo0EMRW5R7x T4pNSIIk3QhV1FGY1S/edCj9whNEJK8dySRYenIw8yQmaW+xVRSlK1UhxjBN3hb23WEp ZcCRRRaw+aTyuE4R9NGnL2k0aJUwh6ZlgEdtp24339HZ57WxlcIZDrzJe3Et88upd99U xG7w== X-Gm-Message-State: APjAAAURtXIjh0R7dIuWYiQ9ZBGeljOtuPqoeGnkMqkoZP9BTzJtnrBb BethtjQVTgVkXWWxxsqRVfo+H/3JZDVXd8weTrgM5g== X-Received: by 2002:a17:90a:154f:: with SMTP id y15mr645274pja.73.1569880222086; Mon, 30 Sep 2019 14:50:22 -0700 (PDT) MIME-Version: 1.0 References: <20190830034304.24259-1-yamada.masahiro@socionext.com> <20190930112636.vx2qxo4hdysvxibl@willie-the-truck> <20190930121803.n34i63scet2ec7ll@willie-the-truck> In-Reply-To: <20190930121803.n34i63scet2ec7ll@willie-the-truck> From: Nick Desaulniers Date: Mon, 30 Sep 2019 14:50:10 -0700 Message-ID: Subject: Re: [PATCH] compiler: enable CONFIG_OPTIMIZE_INLINING forcibly To: Will Deacon , Masahiro Yamada , Linus Torvalds Cc: Nicolas Saenz Julienne , Andrew Morton , Ingo Molnar , Borislav Petkov , Miguel Ojeda , linux-arch , LKML , Catalin Marinas , Russell King , Stefan Wahren , Kees Cook 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 Mon, Sep 30, 2019 at 5:18 AM Will Deacon wrote: > > On Mon, Sep 30, 2019 at 09:05:11PM +0900, Masahiro Yamada wrote: > > On Mon, Sep 30, 2019 at 8:26 PM Will Deacon wrote: > > > On Fri, Sep 27, 2019 at 03:38:44PM -0700, Linus Torvalds wrote: > > > > Soem of that code is pretty subtle. They have fixed register usage > > > > (but the asm macros actually check them). And the inline asms clobber > > > > the link register, but they do seem to clearly _state_ that they > > > > clobber it, so who knows. > > > > > > > > Just based on the EFAULT, I'd _guess_ that it's some interaction with > > > > the domain access control register (so that get/set_domain() thing). > > > > But I'm not even sure that code is enabled for the Rpi2, so who > > > > knows.. > > > > > > FWIW, we've run into issues with CONFIG_OPTIMIZE_INLINING and local > > > variables marked as 'register' where GCC would do crazy things and end > > > up corrupting data, so I suspect the use of fixed registers in the arm > > > uaccess functions is hitting something similar: > > > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91111 > > > > No. Not similar at all. > > They're similar in that enabling CONFIG_OPTIMIZE_INLINING causes register > variables to go wrong. I agree that the ARM code looks dodgy with > that call to uaccess_save_and_enable(), but there are __asmeq macros > in there to try to catch that, so it's still very fishy. > > > I fixed it already. See > > https://lore.kernel.org/patchwork/patch/1132459/ > > You fixed the specific case above for 32-bit ARM, but the arm64 case > is due to a compiler bug. As it happens, we've reworked our atomics > in 5.4 so that particular issue no longer triggers, but the fact remains > that GCC has been shown to screw up explicit register allocation for > perfectly legitimate code when giving the flexibility to move code out > of line. So __attribute__((always_inline)) doesn't guarantee that code will be inlined. For instance in LLVM's inliner, it asks/answers "should I inline" and "can I inline." "Should" has to do with a cost model, and is very heuristic-y. "Can" has more to do with the transforms, and whether they're all implemented and safe. If you if you say __attribute__((always_inline)), the answer to "can I inline this" can still be *no*. The only way to guarantee inlining is via the C preprocessor. The only way to prevent inlining is via __attribute__((no_inline)). inline and __attribute__((always_inline)) are a heuristic laden mess and should not be relied upon. I would also look closely at code that *requires* inlining or the lack there of to be correct. That the kernel no longer compiles at -O0 is not a good thing IMO, and hurts developers that want a short compile/execute/debug cycle. In this case, if there's a known codegen bug in a particular compiler or certain versions of it, I recommend the use of either the C preprocessor or __attribute__((no_inline)) to get the desired behavior localized to the function in question, and for us to proceed with Masahiro's cleanup. The comment above the use of CONFIG_OPTIMIZE_INLINING in include/linux/compiler_types.h says: * Force always-inline if the user requests it so via the .config. Which makes me grimace (__attribute__((always_inline)) doesn't *force* anything as per above), and the idea that forcing things marked inline to also be __attribute__((always_inline)) is an "optimization" (re: the name of the config; CONFIG_OPTIMIZE_INLINING) is also highly suspect. Aggressive inlining leads to image size bloat, instruction cache and register pressure; it is not exclusively an optimization. > > > The problems are fixable by writing correct code. > > Right, in the compiler ;) > > > I think we discussed this already. > > We did? > > > - There is nothing arch-specific in CONFIG_OPTIMIZE_INLINING > > Apart from the bugs... and even then, that's just based on reports. > > > - 'inline' is just a hint. It does not guarantee function inlining. > > This is standard. > > > > - The kernel macrofies 'inline' to add __attribute__((__always_inline__)) > > This terrible hack must end. > > I'm all for getting rid of hacks, but not at the cost of correctness. > > > - __attribute__((__always_inline__)) takes aways compiler's freedom, > > and prevents it from optimizing the code for -O2, -Os, or whatever. > > s/whatever/miscompiling the code/ > > If it helps, here is more information about the arm64 failure which > triggered the GCC bugzilla: > > https://www.spinics.net/lists/arm-kernel/msg730329.html > > Will -- Thanks, ~Nick Desaulniers