Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1628116pxb; Thu, 4 Mar 2021 16:53:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1hEk3XkiaJqc4SEbIlEVqNWGGXuRn1XvHRTLhVfigj0XaLQjhWQ1xmMnqyPFOb1ozyfLp X-Received: by 2002:a5d:9506:: with SMTP id d6mr5846074iom.37.1614905630049; Thu, 04 Mar 2021 16:53:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614905630; cv=none; d=google.com; s=arc-20160816; b=jxJlw5M963E0RieVY9esF64FTeOOfQyiav+cGKE1zBdCvSgzPn88o86MwFC4aDFPG1 XkEcaUx2P0XHwnHEn6mokPsMgdy7xCmcXfCXVrfIsVVUVu2rGf/LW9soDL4uNtyrO0bs Oct5WFVNp1Jptm/m64ixZJvCv7PF1D+KlS3DhwyOLes5wzJEoMsW1RS9D6nGF9n1cvjJ OvTdMuO/hpPwN6z7A/KwNWTwM3ORYGPUS7h0cdpt6P8MD0iToBGEJP3d0YV3C9UDVHpu 2DdKYsYwjmRiNIMXm5FmVUIrm0dcQaTce0g+TMduQxvokIBtFjoefvEYeAmscZnT3vha vu4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=rF5Y4qiLYG77iew1mU5Rkg3muHLgwxb+EueWczzk7UQ=; b=D45arh5KFpHxS0HSqnwyp3cDz6L/MoitNCj6zahM97btaIaRvIyZyXOHM0R4p7ZSJC 9+o0oVrMM+wvsOpEHcdqwO6WFt+xJAxjzusUd6b65e2N49Ad4rrp/rZS7jUFkMFFet/t O04lkiPxmzlgd/RVORmTPMe4N4fog19xbTEDm1vPWSjNUk4HimV4raars2RGXTWb+3kY zJIv6YNrPzQz/Gd73iwS93pnSyBhPf2qyB77C9jjmzUMqO667tU79fwBHCLEG6c2AcXK tKdl4O0ZKBrp619aFCNCIfSI9SZVk69W2sjseKw+tO/k0z66jS4af1AWxGt3BA+0gkCh eMYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mZ9ESMDy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k4si672860ilo.113.2021.03.04.16.53.36; Thu, 04 Mar 2021 16:53:50 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=mZ9ESMDy; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237279AbhCDR0o (ORCPT + 99 others); Thu, 4 Mar 2021 12:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237236AbhCDR0V (ORCPT ); Thu, 4 Mar 2021 12:26:21 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFB03C061574 for ; Thu, 4 Mar 2021 09:25:40 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id u125so10432401wmg.4 for ; Thu, 04 Mar 2021 09:25:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=rF5Y4qiLYG77iew1mU5Rkg3muHLgwxb+EueWczzk7UQ=; b=mZ9ESMDypfYC8jF7LeueBhm2UiIAIN/v6i6QXG6sJvo6vTlym2d/pOVora2yQsMHYx 2eApf3R5G7JrLv4USsVgoEl2yFrP083oeblz/IsBWcPVqzFDaHC2Ix+SoE4MTxgCCw0G gUM+DMdlIqdBM1t5801TPfJMrwTEUXqAgp/A42//Mymhi5Tnuz4Fr5HpWN52HVtRMALP EV5ywj6fcy7GSYJAOqNO2rUKimjOewgB/U9ahmQz7ewEOBkxzO0mYeFiq1MJn9MSElaF wUF9qR+lAvKtsJ6G8C5AiRbNU5A9M5XHYwVuuJ75yXsKiKvPmU2uAhPbn1fGHsYAe4wi sVqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=rF5Y4qiLYG77iew1mU5Rkg3muHLgwxb+EueWczzk7UQ=; b=EgB2vc1u7QgO9ap+1VRDhRfKNK0n/RFX3AapJ3gNYpzaDvfTk/28MS5ATtVxOFHQt1 TfNZTvHInoU+1UQ0cfKvG3O2YtrbbAlqIF/3SirQNp6rnF8rDEFtTkE4Y3wlAFAXDcu/ E5E6cfovdSj+5JB4LR22Qcb44DNnCFYE+Wmfx6v85G2+esaWaCiTkCZ9PaVDKm3HGqcS +QQscOxJaH7+dlAI3wSnMDNU6cgKDAnXyemgMdvDLP9Fd32UFE45BW79KmyKyixd8SQC O0Ly5SgrgPxuidiJSNKg6MgHjqhqX1pFwt6mw3LwviKKnDDLXY3602tJ0uKi0YzI0eIx ileA== X-Gm-Message-State: AOAM531R6HTQAf8vhNbyKJyyef3R5avAIzOpmNF15c7x6aAUBjqiHKne sLNCLqKHd3DR96VI+AY0+l/6cg== X-Received: by 2002:a1c:c244:: with SMTP id s65mr5000395wmf.96.1614878739431; Thu, 04 Mar 2021 09:25:39 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:adef:40fb:49ed:5ab6]) by smtp.gmail.com with ESMTPSA id f17sm36439007wru.31.2021.03.04.09.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 09:25:38 -0800 (PST) Date: Thu, 4 Mar 2021 18:25:33 +0100 From: Marco Elver To: Mark Rutland 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: 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: <20210304165923.GA60457@C02TD0UTHF1T.local> User-Agent: Mutt/2.0.5 (2021-01-21) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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. 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, -- Marco