Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1628941pxb; Thu, 4 Mar 2021 16:55:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyblP+ZhvtJkrOpCwDcipkI0JiAIh57OIkogT3jnqcXYLY6BFOWbNTgeNEwXjQx6uYsGfwG X-Received: by 2002:a05:6e02:1b88:: with SMTP id h8mr5791423ili.39.1614905720558; Thu, 04 Mar 2021 16:55:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614905720; cv=none; d=google.com; s=arc-20160816; b=kWei1NWYZyPJYVe90s0s59vsOZEsIYkv8CV3P/e+++PMYc/lwn5xrtfidGVLyrMu7l z18+rkpGNmeCCbn3/wd4vQSa97UNmSt+/QJuGIhw1KM9jhLGSU5XrD9NqfsH7JrAFJ+L ZRmrMdMBXPPxQBumAUhMJFaL4wWtE5v6YW2D/ixs0Ca3pYX0z18b3KzlWzrKQL1lSAMQ irD/jAobJ8N76XmANGmNfhSe7J4qZTuX6w+fHdzQUmFSHa/en2jVOS4PwymgT6SFX+9/ qoCGyov8M1WD/+TxcHWkGAigWqVp8GN0nNUCp+Y8abKaYY8Wg0m7RD1287qHz3dRLJGZ lV9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FYzGpTewhxHxL7CpcepbC9L9ykWvrUtL+K0xz4SbvmU=; b=eVu+D9bqx6LuC6Qi97mGCEJ8tziN0GgMUuS0F1GYzyodkyJzLSTwcPogurslt/s659 RvG2PzlprlE8oO51be9+OLF+wR4CykeHQ4boYq8tgz8GDNw6T/RMLPmKOhglv/aBA440 5hluENXX6n3kxk0H0kShmENqdShF0E/YH2MpzdULw4AOF9IBlqGJ1UpqMqSXF6F5NuVi DXxCHlUhS2Hq/Sicp3JTgKYcxuNr8ZLb5bLtrC7PeVJfUD/Njhdpd7zsRSG8rE5UYpsn XReFTfZo2Qf79+2ddNu6z0POJS9DhRkaUQ+Hr8IdFx7hQOvRRasiaV0c4sCsPP5UEbRj HaSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=U51rv4zp; 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 y12si719843ilv.132.2021.03.04.16.55.07; Thu, 04 Mar 2021 16:55:20 -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=U51rv4zp; 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 S232377AbhCDRz4 (ORCPT + 99 others); Thu, 4 Mar 2021 12:55:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232450AbhCDRzh (ORCPT ); Thu, 4 Mar 2021 12:55:37 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D964CC061574 for ; Thu, 4 Mar 2021 09:54:56 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id 18so36116704lff.6 for ; Thu, 04 Mar 2021 09:54:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FYzGpTewhxHxL7CpcepbC9L9ykWvrUtL+K0xz4SbvmU=; b=U51rv4zpBK86lIfGRkTUAlvQqBCWAyLeojeIdsRGl2dxMbLRu1PBgHvwQy2RAlDHGS qS95kFnaphLP7itFtdaZV7DD1nsen8f+JhImMQpAhLZG8qUpDZULwh9eDoCKAArsemLI 9UnBzTRoUe0UVj57BSVi22s7dx6bM1/vbMcIR/FUonD1VZlUC16b1aFbgm8U+XpXciOY 7n1p/D7SALszYOuW+BmXU3FKIHhJJLXOSAflaMzSFM8wNGBfP6mXixU6n1IktuHAHFH/ eSSyz8RFBx7y5FWRMYtxK+X00wKN/qDTaSkmYqBWEA1gg8vbtwLkOJxNmU4SWeaKq9p8 7Ldg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FYzGpTewhxHxL7CpcepbC9L9ykWvrUtL+K0xz4SbvmU=; b=W+nJ50LTJ+s/k/DIhSAtt0tQ/aCDDByK9QrbpB3tVLln/rOapIE52l+yUgckslkdNK TUXuqMYyMFHvFDyFi/YwDS9lud1Cs8YQuu0Y4mBnmySJbJRvczVSBXseX0Sj7uip9HBs A8vYHHVhL8wVShHNkO1J6tv5/p4RCqOo8pRrokMtWYOKwiHSpJ38B54pfjb/NKQ8hu+d IhH7pIeD9uHXCGMV7lM59Vjq4oTnsc5PDYo5FNIFXWDrNZAkH6+YksElaep8yud+sQUx xPB7lJMNlzdprEvaARRNui7VRJquckPQ8IgTLX/NYik4ckExhSEpNEFygatMQQ4lnjYf cyzQ== X-Gm-Message-State: AOAM530zjirCtj5X2Xw/RnsK10OzIr7y/Cp+WK6Vx/KhgN8tWbd1DjrX s7znLyxN+pu1PR9mnAVPxK00mUrCAiRM+mIt+EJOmA== X-Received: by 2002:ac2:532c:: with SMTP id f12mr3178752lfh.73.1614880495105; Thu, 04 Mar 2021 09:54:55 -0800 (PST) MIME-Version: 1.0 References: <1802be3e-dc1a-52e0-1754-a40f0ea39658@csgroup.eu> <20210304145730.GC54534@C02TD0UTHF1T.local> <20210304165923.GA60457@C02TD0UTHF1T.local> In-Reply-To: From: Nick Desaulniers Date: Thu, 4 Mar 2021 09:54:44 -0800 Message-ID: Subject: Re: [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends To: Marco Elver Cc: Mark Rutland , Christophe Leroy , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , LKML , linuxppc-dev , kasan-dev , Catalin Marinas , Will Deacon , Linux ARM , Mark Brown , linux-toolchains@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 4, 2021 at 9:42 AM 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. > > > > 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 include/linux/compiler.h:246: prevent_tail_call_optimization commit a9a3ed1eff36 ("x86: Fix early boot crash on gcc-10, third try") > > 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 -- Thanks, ~Nick Desaulniers