Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1432524pxb; Thu, 4 Mar 2021 11:06:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxT/4O8x4kq+VPpakgDj+nEo1/8MStg7MLn1HNctiI/IRH//I36LPaPFRKRdJz2GBNmQ4+C X-Received: by 2002:aa7:c441:: with SMTP id n1mr5847366edr.203.1614884782491; Thu, 04 Mar 2021 11:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614884782; cv=none; d=google.com; s=arc-20160816; b=VbvgvQdDTfxLixAr9mVWnEIb6tZV2n5QZYmdWycC3b3aGRksVMMkX2o4yxv0z1ee/8 VXF6x7MwZg8ZoVTk8b4VWhP/yNvJXIqBIRZ+Bl3MyE1/99sLk9SZvMU4KQ8Wv8VZ16gg T7SrQ0GqeN7qQ/JJrDHk8ktKR8BpPQ+vC2XFrTuepCtRgrIDJ+Kqd4t0bNictcTxu6LX WqFSZjfAOLCx3gB7Y9KcnFB9T49U2UpXVXJioKSmrMY+MyynCAVEzHu+y2E3z37NCYng Yd/2GpD2pKQ9L0zEAtNAW6ZFRo7sOjh5VU4KR87pfv7uwxXUW0BeLEuQ7xak5VP3iqu+ Q0yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Rx9w1y6lR0AXBTE6W2W51QrNrTbTRZVSR3aeHfGZBUY=; b=uH7lMgL/D+IvUBHfteSymZsUCaWccJ1IZjsUgKQ7vGRCpi4o5DBPk+OfWa4k364owJ AIN7to269sXN6PEzdB171M1Geyt4kqR1+CI9+g3vVswXgRt/t8QA++54agQBDKq7eruV V938ov8pJiJw9jnUvOA5axv1TxuJPI/Ic1QWwfhJLLYjRt+mBwzy+01OGlDlOyiJgbCR uFj71QgGJX2WLza5QRiLFQJFl/FvuZLjofuwUkwdlC8HDr5aiDA2f34pHD4EAoK9MK+6 TlJu4tVLXWSyOAasiHfnQH9gL6VedZBzd39kUc58cYV8Q6jfgovAw3nXjLZCZ8nn9qM3 Cx+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b67si198118edf.490.2021.03.04.11.05.59; Thu, 04 Mar 2021 11:06:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232771AbhCDSCw (ORCPT + 99 others); Thu, 4 Mar 2021 13:02:52 -0500 Received: from foss.arm.com ([217.140.110.172]:42354 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232520AbhCDSCo (ORCPT ); Thu, 4 Mar 2021 13:02:44 -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 3662731B; Thu, 4 Mar 2021 10:01:59 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.53.210]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 38B273F7D7; Thu, 4 Mar 2021 10:01:57 -0800 (PST) Date: Thu, 4 Mar 2021 18:01:54 +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: <20210304180154.GD60457@C02TD0UTHF1T.local> References: <1802be3e-dc1a-52e0-1754-a40f0ea39658@csgroup.eu> <20210304145730.GC54534@C02TD0UTHF1T.local> <20210304165923.GA60457@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-kernel@vger.kernel.org On Thu, Mar 04, 2021 at 06:25:33PM +0100, Marco Elver wrote: > On Thu, Mar 04, 2021 at 04:59PM +0000, Mark Rutland wrote: > > On Thu, Mar 04, 2021 at 04:30:34PM +0100, Marco Elver wrote: > > > On Thu, 4 Mar 2021 at 15:57, Mark Rutland wrote: > > > > [adding Mark Brown] > > > > > > > > The bigger problem here is that skipping is dodgy to begin with, and > > > > this is still liable to break in some cases. One big concern is that > > > > (especially with LTO) we cannot guarantee the compiler will not inline > > > > or outline functions, causing the skipp value to be too large or too > > > > small. That's liable to happen to callers, and in theory (though > > > > unlikely in practice), portions of arch_stack_walk() or > > > > stack_trace_save() could get outlined too. > > > > > > > > Unless we can get some strong guarantees from compiler folk such that we > > > > can guarantee a specific function acts boundary for unwinding (and > > > > doesn't itself get split, etc), the only reliable way I can think to > > > > solve this requires an assembly trampoline. Whatever we do is liable to > > > > need some invasive rework. > > > > > > Will LTO and friends respect 'noinline'? > > > > I hope so (and suspect we'd have more problems otherwise), but I don't > > know whether they actually so. > > > > I suspect even with 'noinline' the compiler is permitted to outline > > portions of a function if it wanted to (and IIUC it could still make > > specialized copies in the absence of 'noclone'). > > > > > One thing I also noticed is that tail calls would also cause the stack > > > trace to appear somewhat incomplete (for some of my tests I've > > > disabled tail call optimizations). > > > > I assume you mean for a chain A->B->C where B tail-calls C, you get a > > trace A->C? ... or is A going missing too? > > Correct, it's just the A->C outcome. I'd assumed that those cases were benign, e.g. for livepatching what matters is what can be returned to, so B disappearing from the trace isn't a problem there. Is the concern debugability, or is there a functional issue you have in mind? > > > Is there a way to also mark a function non-tail-callable? > > > > I think this can be bodged using __attribute__((optimize("$OPTIONS"))) > > on a caller to inhibit TCO (though IIRC GCC doesn't reliably support > > function-local optimization options), but I don't expect there's any way > > to mark a callee as not being tail-callable. > > I don't think this is reliable. It'd be > __attribute__((optimize("-fno-optimize-sibling-calls"))), but doesn't > work if applied to the function we do not want to tail-call-optimize, > but would have to be applied to the function that does the tail-calling. Yup; that's what I meant then I said you could do that on the caller but not the callee. I don't follow why you'd want to put this on the callee, though, so I think I'm missing something. Considering a set of functions in different compilation units: A->B->C->D->E->F->G->H->I->J->K ... if K were marked in this way, and J was compiled with visibility of this, J would stick around, but J's callers might not, and so the a trace might see: A->J->K ... do you just care about the final caller, i.e. you just need certainty that J will be in the trace? If so, we can somewhat bodge that by having K have an __always_inline wrapper which has a barrier() or similar after the real call to K, so the call couldn't be TCO'd. Otherwise I'd expect we'd probably need to disable TCO generally. > So it's a bit backwards, even if it worked. > > > Accoding to the GCC documentation, GCC won't TCO noreturn functions, but > > obviously that's not something we can use generally. > > > > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes > > Perhaps we can ask the toolchain folks to help add such an attribute. Or > maybe the feature already exists somewhere, but hidden. > > +Cc linux-toolchains@vger.kernel.org > > > > But I'm also not sure if with all that we'd be guaranteed the code we > > > want, even though in practice it might. > > > > True! I'd just like to be on the least dodgy ground we can be. > > It's been dodgy for a while, and I'd welcome any low-cost fixes to make > it less dodgy in the short-term at least. :-) :) Thanks, Mark.