Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3223538ybc; Mon, 25 Nov 2019 10:55:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxKBHw5BSWKtuzlkWlYDue6lSiDguxa3IVfQsjXJkkStmr7k0jwVx2iSa8wdjMfTVH11Tso X-Received: by 2002:a17:906:a28d:: with SMTP id i13mr38256233ejz.288.1574708156951; Mon, 25 Nov 2019 10:55:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574708156; cv=none; d=google.com; s=arc-20160816; b=Nsa0xv/VJ83A8YlsuSYUuBXbUyKyeVLGE9ZsVfq3VF6ja+6NrlCF2YA3uizz7PoplM zmgEIyGfmiUboIVp9s0lw680cLN4GIvxV+NleboU7+RgSRhioRAvStOBb5AQ4OFWZavo /U622DVPjBWmAlDGar0GmUfNQB5i0lV64jnuOjcw1Tz67Bkdp8BYfVk1vmGl1e/1Pm8j /tsv/C39FLe5p+pcOw3AlBdhgGFU9CPfeQuK8mI11O/UBq7wO0I6cPYNPVKbMIUAHc9e dP07zbWgf8/VAZz1GM0d4IISy0U3Z+r53Mqn/ymXhxB50c+fHDjSKGmLva8XEbEx66kQ kRZQ== 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=d3f1B+bHfH90fvGHAmWwv4t4e/DGz9pyOLoZyxejttE=; b=0+uC6KqcXUilXPXD1HKc97FyRWYd3OEoOWqfI9j8av39TnkIOcNXSTKVmikzwebp12 b78NccmJWw3SN0sghdx8r2GZok5jPg4rdgdaD3COFIVTUDhVG3J+ybLPgRjXXLy47FNe DUbx7Ydf2koJ/RLuR23xe+aAxg/Cmigqj7f0ZJuTGTTdW4JbQPWxepU5BjAWoB4ZVJJX 9Yg3MaMb/6k67EciUECMKYJk6rbCzXiP3giFn6NRGuHU9noWl0rpJ0Blpw6ERwmbn4He aI8+dvTd4FqV7lo3ckeiFeT5wIgJuOypgg3HpBz/7IfuMdERT5nEMF38pbJVaURCizuJ /dYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W+isNVQp; 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 w6si5071003eju.84.2019.11.25.10.55.31; Mon, 25 Nov 2019 10:55:56 -0800 (PST) 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=W+isNVQp; 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 S1727788AbfKYSWr (ORCPT + 99 others); Mon, 25 Nov 2019 13:22:47 -0500 Received: from mail-oi1-f194.google.com ([209.85.167.194]:36336 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727269AbfKYSWr (ORCPT ); Mon, 25 Nov 2019 13:22:47 -0500 Received: by mail-oi1-f194.google.com with SMTP id j7so14043412oib.3 for ; Mon, 25 Nov 2019 10:22:45 -0800 (PST) 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=d3f1B+bHfH90fvGHAmWwv4t4e/DGz9pyOLoZyxejttE=; b=W+isNVQpb4OtG2cL/xWLFDjZyq6LmTyBTSQIACYBzLsXAg7ZfAQ4uA8hJLEJZkAQvR TgBNQzYzkb5M0ljvRH2epUV6bTsUxVx8BnxHlFDg6MkuvL+4d75Ld9YUaVtR1Js2F/4H zChoIppozN/5gzmEQb9FfCc0HUru9cfOOQT/qwK/677oikzCLla4FzzYCrgkDOE/A23x sbqZlSjy8ce/I240GNHFCyYvHZBNMvLL5pOcV+jk/Hth3goy4yJuLRRIDJbZ+5dW9mzk 8+oq27CBgu6UxNPHN5fwzCCFnn/FrmjVMLlfBTptb0+y9bbkW2NY50L7SDJ1YDZpCTxz cD3Q== 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=d3f1B+bHfH90fvGHAmWwv4t4e/DGz9pyOLoZyxejttE=; b=tO/EdLTcfxAaTUb1tzMtH/UyYLTbR8qq/FG5bsSpPBwgCLV8R7FxiixGOu0KP1uTIU VWVaYbHB37f9CPDVGEtSFIPei527HFfpaZN7QAPZ8Jqoyf6vNiyIYjH56k2vO380uPc5 1ERydvHijT2z10DNxCpBLhz/1H0pOr6N1h27m2TP+T6i7x7Itz3ilEsX1ZhzPJ71zBtP yrpZTGeOiuie08nc0I1td005rolw75tIiVUtMApJe76Ey9H26qaEbcm/mNcaAUTx6RXn u2ULYdJIiXGa2cZvoE9UMDIM0dWtPTabZQbL/PthmB1OXY/ZeSxRie11pGB9xYxygs75 +zaQ== X-Gm-Message-State: APjAAAX2uecLm76VjT1pHjwAVzsN1ZyvLMtZB9/lD4xpsO1cHxFo+NpK qSfTk7bs8p1V/TZ5IHXrANFSD1YBC1GH6iB7sE3m0g== X-Received: by 2002:aca:618a:: with SMTP id v132mr136789oib.155.1574706164774; Mon, 25 Nov 2019 10:22:44 -0800 (PST) MIME-Version: 1.0 References: <20191122154221.247680-1-elver@google.com> <20191125173756.GF32635@lakrids.cambridge.arm.com> In-Reply-To: <20191125173756.GF32635@lakrids.cambridge.arm.com> From: Marco Elver Date: Mon, 25 Nov 2019 19:22:33 +0100 Message-ID: Subject: Re: [PATCH 1/2] asm-generic/atomic: Prefer __always_inline for wrappers To: Mark Rutland Cc: Will Deacon , Peter Zijlstra , Boqun Feng , Arnd Bergmann , Dmitry Vyukov , LKML , linux-arch , kasan-dev , "Paul E. McKenney" , Randy Dunlap 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, 25 Nov 2019 at 18:38, Mark Rutland wrote: > > On Fri, Nov 22, 2019 at 04:42:20PM +0100, Marco Elver wrote: > > Prefer __always_inline for atomic wrappers. When building for size > > (CC_OPTIMIZE_FOR_SIZE), some compilers appear to be less inclined to > > inline even relatively small static inline functions that are assumed to > > be inlinable such as atomic ops. This can cause problems, for example in > > UACCESS regions. > > From looking at the link below, the problem is tat objtool isn't happy > about non-whiteliested calls within UACCESS regions. > > Is that a problem here? are the kasan/kcsan calls whitelisted? We whitelisted all the relevant functions. The problem it that small static inline functions private to the compilation unit do not get inlined when CC_OPTIMIZE_FOR_SIZE=y (they do get inlined when CC_OPTIMIZE_FOR_PERFORMANCE=y). For the runtime this is easy to fix, by just making these small functions __always_inline (also avoiding these function call overheads in the runtime when CC_OPTIMIZE_FOR_SIZE). I stumbled upon the issue for the atomic ops, because the runtime uses atomic_long_try_cmpxchg outside a user_access_save() region (and it should not be moved inside). Essentially I fixed up the runtime, but then objtool still complained about the access to atomic64_try_cmpxchg. Hence this patch. I believe it is the right thing to do, because the final inlining decision should *not* be made by wrappers. I would think this patch is the right thing to do irrespective of KCSAN or not. > > By using __always_inline, we let the real implementation and not the > > wrapper determine the final inlining preference. > > That sounds reasonable to me, assuming that doesn't end up significantly > bloating the kernel text. What impact does this have on code size? It actually seems to make it smaller. x86 tinyconfig: - vmlinux baseline: 1316204 - vmlinux with patches: 1315988 (-216 bytes) > > This came up when addressing UACCESS warnings with CC_OPTIMIZE_FOR_SIZE > > in the KCSAN runtime: > > http://lkml.kernel.org/r/58708908-84a0-0a81-a836-ad97e33dbb62@infradead.org > > > > Reported-by: Randy Dunlap > > Signed-off-by: Marco Elver > > --- > > include/asm-generic/atomic-instrumented.h | 334 +++++++++++----------- > > include/asm-generic/atomic-long.h | 330 ++++++++++----------- > > scripts/atomic/gen-atomic-instrumented.sh | 6 +- > > scripts/atomic/gen-atomic-long.sh | 2 +- > > 4 files changed, 336 insertions(+), 336 deletions(-) > > Do we need to do similar for gen-atomic-fallback.sh and the fallbacks > defined in scripts/atomic/fallbacks/ ? I think they should be, but I think that's debatable. Some of them do a little more than just wrap things. If we want to make this __always_inline, I would do it in a separate patch independent from this series to not stall the fixes here. What do you prefer? > [...] > > > diff --git a/scripts/atomic/gen-atomic-instrumented.sh b/scripts/atomic/gen-atomic-instrumented.sh > > index 8b8b2a6f8d68..68532d4f36ca 100755 > > --- a/scripts/atomic/gen-atomic-instrumented.sh > > +++ b/scripts/atomic/gen-atomic-instrumented.sh > > @@ -84,7 +84,7 @@ gen_proto_order_variant() > > [ ! -z "${guard}" ] && printf "#if ${guard}\n" > > > > cat < > -static inline ${ret} > > +static __always_inline ${ret} > > We should add an include of to the preamble if we're > explicitly using __always_inline. Will add in v2. > > diff --git a/scripts/atomic/gen-atomic-long.sh b/scripts/atomic/gen-atomic-long.sh > > index c240a7231b2e..4036d2dd22e9 100755 > > --- a/scripts/atomic/gen-atomic-long.sh > > +++ b/scripts/atomic/gen-atomic-long.sh > > @@ -46,7 +46,7 @@ gen_proto_order_variant() > > local retstmt="$(gen_ret_stmt "${meta}")" > > > > cat < > -static inline ${ret} > > +static __always_inline ${ret} > > Likewise here Will add in v2. Thanks, -- Marco