Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3224221ybc; Mon, 25 Nov 2019 10:56:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyTrRO2oOPi8l3yYiSYP3962NedamoNkfQ3+KSEPhLQhCX5a6AHX8+KWCf4V/7NakBAoQN3 X-Received: by 2002:a17:906:6dcf:: with SMTP id j15mr39168956ejt.104.1574708200780; Mon, 25 Nov 2019 10:56:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574708200; cv=none; d=google.com; s=arc-20160816; b=NXYxIJL75vJIadmFP/1bsOhOsL7Xy7VZwgpgfepa8CacYYN4LWlBvJe31QsjBA1qxa 2q/fVUMCWI5GJ0Qg3g+lqB6MmAIRhSj3lJ4sY0wCWUVLiIx26icLVM6bGsuYGStfPuX8 sRW66Kwao2CauA5etcP5zh/mPYnqmkqIEURcBe7Nn99wQ1vZqchdFIJSc2K0xPylZkoW ibGJhJzAE3w5e6fDGtUe9Cwv0PeqPLBwGJ53fEEnJCU3qOTbfcCdhLga7oESv68qVT/E iocfpum6AW2LCk/DzzAZoOdwcXre0WHfx9olP5/SErEmfzbHEsYK63TO0S5DWaTZe5SY Zdpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=tHbfH0zHQ/iHrVop/lQ6dHIbGmrgJn72JpMiRgVYAfY=; b=SU2b9oPqYLOWy3ax6jm3hlLBSXOFE4JRMf2FPFQlqMTtuXfJXLshjYccVg4WieJ/Hr YVTqVde69CiYmeN2CqCzhFU/dM4Q5VUL8rbDZ3bdEAm8gFMoBr20LsnWRli4Mv9PNZ3T bka+d9SjLlNGa8ChMIcIVI6zeNEm7MRse0+rYIAVJ/tgv5bPtOTtoTlFCU7Egw97n4EZ 9uF/m7VQEXXjsb08AWxv+J/dRTwiPJApXOF7N/+ylyk+iQzIK5JVD8/+iY+/Y0v7MHum H6X2Tsm4J/2jpU/mIvXVBHJxR8AcH4rJHB5Scuj8xgrx14VYPZ/IaUxbsyhL4pSe/yi2 GiGA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17si6363122edc.6.2019.11.25.10.56.16; Mon, 25 Nov 2019 10:56:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727099AbfKYSjm (ORCPT + 99 others); Mon, 25 Nov 2019 13:39:42 -0500 Received: from foss.arm.com ([217.140.110.172]:53788 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727029AbfKYSjm (ORCPT ); Mon, 25 Nov 2019 13:39:42 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CFDBE31B; Mon, 25 Nov 2019 10:39:41 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 652BA3F68E; Mon, 25 Nov 2019 10:39:40 -0800 (PST) Date: Mon, 25 Nov 2019 18:39:38 +0000 From: Mark Rutland To: Marco Elver Cc: Will Deacon , Peter Zijlstra , Boqun Feng , Arnd Bergmann , Dmitry Vyukov , LKML , linux-arch , kasan-dev , "Paul E. McKenney" , Randy Dunlap Subject: Re: [PATCH 1/2] asm-generic/atomic: Prefer __always_inline for wrappers Message-ID: <20191125183936.GG32635@lakrids.cambridge.arm.com> References: <20191122154221.247680-1-elver@google.com> <20191125173756.GF32635@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 25, 2019 at 07:22:33PM +0100, Marco Elver wrote: > 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. Given the wrappers are trivial, and for !KASAN && !KCSAN, this would make them equivalent to the things they wrap, that sounds fine to me. > > > 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) Great! Fancy putting that in the commit message? > > > 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. I would expect that they would suffer the same problem if used in a UACCESS region, so if that's what we're trying to fix here, I think that we need to do likewise there. The majority are trivial wrappers (shuffling arguments or adding trivial barriers), so those seem fine. The rest call things that we're inlining here. Would you be able to give that a go? > > > 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. Great; thanks! Mark.