Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1417506pxb; Thu, 4 Mar 2021 10:42:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqsmcMFY1swlQe+nj0KsTAdWiY+3bpJSnPwCDD9+GzX73Xxgy1Ubj0StP4dVqexFVq91Wp X-Received: by 2002:a17:906:aada:: with SMTP id kt26mr5696309ejb.137.1614883372555; Thu, 04 Mar 2021 10:42:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614883372; cv=none; d=google.com; s=arc-20160816; b=0NLRsaKvBxvX8sZ0hSkQWngPmW4c91W+1KLQa0RVpCRpCcJQ7NheXlD7AbpMgweCv8 aRYzyIp/RT93Q9oDDrXOKM7oT++MF//wc9rP4azeCh6qslqgAjm7A6S5o5yjj8WTL2Xo tIElDorG5PTWHgqD6MoN6Uideq1KxFcyOC+D7J9hkCdsJp01E/O9NRS/QO3HolCoqPns DJanIVOCvPKTJYY9pRI7Zwm+U6azopRPwjig/3rSIo21Z9ys732+z/sKrUoLPH9B9WSV DAm7IHK/AejDZ0MGEg08OMlWLQGQrF7a76tY/NTEvJjWcDpm0ZiNaB7CzMpyEbN9240l 4vAw== 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=TQlCYySSGKD3tn5PA5QBN83twsp7f5KnBmdM8Ag4Njo=; b=Gl9hFV2tlxAO3SB1wGaku7GgSSCimSYTBg+LKCDDC0tornzI2aIsu7+BsyVdadaxDd 6tHgNbImB0rYE+XpL1a+IkwSUmtlYOybRw0h/0BkvI8VG9P3anZU5sFCO7YIStRpaZ/E 8qPgjXGyXr5tzYZ0Sv7c0jaS9Dnyrvhj/heqVQ9ZAx0nkg37kvD+w+j+FfD9NH5fT5Wc 5SvLHFicGHpzk+1/OPUgGEYXU8iIm+RwtouoHRtplpA/TaFFOp/Z2fqhL05Lwo0gWdTC uwel/77ykiFzPWpvk2CBcZbhZCuphlrqB83Xd+RmPbiGrTcnCNqQ+P4pCbSSut8Tn7st z62A== 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 jg13si18428605ejc.669.2021.03.04.10.42.28; Thu, 04 Mar 2021 10:42:52 -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 S238748AbhCDRAg (ORCPT + 99 others); Thu, 4 Mar 2021 12:00:36 -0500 Received: from foss.arm.com ([217.140.110.172]:41624 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238823AbhCDRAQ (ORCPT ); Thu, 4 Mar 2021 12:00:16 -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 E108031B; Thu, 4 Mar 2021 08:59:30 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.53.210]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DA6FF3F7D7; Thu, 4 Mar 2021 08:59:28 -0800 (PST) Date: Thu, 4 Mar 2021 16:59:23 +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 Subject: Re: [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends Message-ID: <20210304165923.GA60457@C02TD0UTHF1T.local> References: <1802be3e-dc1a-52e0-1754-a40f0ea39658@csgroup.eu> <20210304145730.GC54534@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 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? > 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. 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 > 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. Thanks, Mark.