From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3DB9C433E0 for ; Fri, 5 Mar 2021 12:06:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98E7A65016 for ; Fri, 5 Mar 2021 12:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229611AbhCEMFk (ORCPT ); Fri, 5 Mar 2021 07:05:40 -0500 Received: from foss.arm.com ([217.140.110.172]:52376 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbhCEMF1 (ORCPT ); Fri, 5 Mar 2021 07:05:27 -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 6F22531B; Fri, 5 Mar 2021 04:05:27 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.47.91]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B046D3F766; Fri, 5 Mar 2021 04:05:24 -0800 (PST) Date: Fri, 5 Mar 2021 12:04:53 +0000 From: Mark Rutland To: Marco Elver Cc: Christophe Leroy , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , LKML , linuxppc-dev@lists.ozlabs.org, kasan-dev , Catalin Marinas , Will Deacon , Linux ARM , broonie@kernel.org, linux-toolchains@vger.kernel.org Subject: Re: [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends Message-ID: <20210305120453.GA74705@C02TD0UTHF1T.local> References: <1802be3e-dc1a-52e0-1754-a40f0ea39658@csgroup.eu> <20210304145730.GC54534@C02TD0UTHF1T.local> <20210304165923.GA60457@C02TD0UTHF1T.local> <20210304180154.GD60457@C02TD0UTHF1T.local> <20210304185148.GE60457@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Thu, Mar 04, 2021 at 08:01:29PM +0100, Marco Elver wrote: > On Thu, 4 Mar 2021 at 19:51, Mark Rutland wrote: > > On Thu, Mar 04, 2021 at 07:22:53PM +0100, Marco Elver wrote: > > > I was having this problem with KCSAN, where the compiler would > > > tail-call-optimize __tsan_X instrumentation. > > > > Those are compiler-generated calls, right? When those are generated the > > compilation unit (and whatever it has included) might not have provided > > a prototype anyway, and the compiler has special knowledge of the > > functions, so it feels like the compiler would need to inhibit TCO here > > for this to be robust. For their intended usage subjecting them to TCO > > doesn't seem to make sense AFAICT. > > > > I suspect that compilers have some way of handling that; otherwise I'd > > expect to have heard stories of mcount/fentry calls getting TCO'd and > > causing problems. So maybe there's an easy fix there? > > I agree, the compiler builtins should be handled by the compiler > directly, perhaps that was a bad example. But we also have "explicit > instrumentation", e.g. everything that's in . True -- I agree for those we want similar, and can see a case for a no-tco-calls-to-me attribute on functions as with noreturn. Maybe for now it's worth adding prevent_tail_call_optimization() to the instrument_*() call wrappers in ? As those are __always_inline, that should keep the function they get inlined in around. Though we probably want to see if we can replace the mb() in prevent_tail_call_optimization() with something that doesn't require a real CPU barrier. [...] > > I reckon for basically any instrumentation we don't want calls to be > > TCO'd, though I'm not immediately sure of cases beyond sanitizers and > > mcount/fentry. > > Thinking about this more, I think it's all debugging tools. E.g. > lockdep, if you lock/unlock at the end of a function, you might tail > call into lockdep. If the compiler applies TCO, and lockdep determines > there's a bug and then shows a trace, you'll have no idea where the > actual bug is. The kernel has lots of debugging facilities that add > instrumentation in this way. So perhaps it's a general debugging-tool > problem (rather than just sanitizers). This makes sense to me. Thanks, Mark.