Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3371889pxb; Mon, 17 Jan 2022 18:54:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJyODqwbgAa52soA7zjyXHgHzNv89PgIYgDFXjR9u/x4MK72LZiSe7Fy+GP00gCsprtBOXsL X-Received: by 2002:aa7:86c9:0:b0:4c2:61c:1888 with SMTP id h9-20020aa786c9000000b004c2061c1888mr21290207pfo.70.1642474470498; Mon, 17 Jan 2022 18:54:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642474470; cv=none; d=google.com; s=arc-20160816; b=stbzF7JMpCN7cmpL6aC7N80NUB0/jyvdXKR88+Qb6LDOPg5Q3Zrcxx/3X23lqQyDhL JDhmu4YQyi6uX1FLQaUcjo7KKn8CNLcw2fged9MVmWtw6n0z+NwYeaA3dE5J6ZnYcR+3 fQ2n5Ann7Z1aX9PFVs7hgJbak6Hqb8X6PyGzEGsUfl3704xrXHa5M/kDu0lLPTGc2sDY C2JKtbNiDHj3lZjNl8XQAX3u6f70S4AvGuy/4X2YsT5ciEpQMO9k4bLr2n+qRis/XT+U U1JXPyjnmokvu0H0tpwYw7bkA+32gbJqHTz6y4EPiUflVWnx/HA0+8FHSCLG6C93s/iz 1hpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=fZgWPWOX9Mc6FibI4zRymEqtmZX2ottHTayO6iuSsq0=; b=xixruVOft6hiaxxx/6KZ377gHYNZ3Z8jzJ47/yoZHw5Jq1buhkbam7mRC610OFEvuw kjHFbJa/T+BeEG2IM1eVS14nkNGSk7/s6eTJmHd+wzK16VVgNNxog4r0Hgnl5OUcOMJc Kkaje7L3nES2MsP3kA0lMp/0O0tC+TEkMh7pF8S44yA6rQsGYN/64sdBamfWALgLCkNl WHXrBo/FfJZH3LAwSXE6HHCibk4xVevdQJz8StUipmW33F6btBQvCf2dxU1aLWl/GVQ6 K/LelzBqRCbgFYazR0YhmU6ww4CkNivwcjND8I+HizTD4qqoD/EfujXM9fZ3SNuDqP3A 6eWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jrtc27.com header.s=gmail.jrtc27.user header.b=OyzcBB+q; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x78si7621842pgx.21.2022.01.17.18.54.18; Mon, 17 Jan 2022 18:54:30 -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=@jrtc27.com header.s=gmail.jrtc27.user header.b=OyzcBB+q; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239332AbiAQRdq (ORCPT + 99 others); Mon, 17 Jan 2022 12:33:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238089AbiAQRdm (ORCPT ); Mon, 17 Jan 2022 12:33:42 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63B91C06161C for ; Mon, 17 Jan 2022 09:33:42 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id v123so22054266wme.2 for ; Mon, 17 Jan 2022 09:33:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jrtc27.com; s=gmail.jrtc27.user; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=fZgWPWOX9Mc6FibI4zRymEqtmZX2ottHTayO6iuSsq0=; b=OyzcBB+qy5rvsCZSRU/KkaPmbiHFhhrAtEzXEnoLEjKYvIWrJbt/DrsVNf5Z1udWOv PSad0frh2KtmWQkbt1/rDEfOhb3RaB0rMZ1kJZKXZ6/YDx5+9O+5lDpgPaPz82EFm9Cw +mSZuEhsmXaE6uZ1AI3nwGfVI2sPMZ3TDGHlMzEcMEX1bxBMCcvcAJZdU4L2ugw05agX ycMVOidCPnZLVBjLoCbG6RL/IjBrjuvV0YB33RQscWORkd9yZM1rqCOKATLkRMuWLOYj YWpuuJoS7kqqNfpCQNysX9au6OUkpuGzS149cxyNE/taSa8BU8E4D1/0jxqMI75I3ZTt +0Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=fZgWPWOX9Mc6FibI4zRymEqtmZX2ottHTayO6iuSsq0=; b=OisIS8+CAwLRfNqVwgj/H9/z1eH0X3eubGXQJFFaOQ9SATmjr9mCayXCpZnITLyuiF ClBx0CV7UHwJlSuIC2GsLKbQ+yMK6bhHqYN5RUbxA4yzTrKvxWliWgT5rWcRmN6IK4Vl whm98EMZN14HFCQWbVgXpehyoCPp53VhsL0CFbywnb67xYKEOAvDiWS7TZToD7ZxR0d8 NRInIFsVQw1QUXBTxKKDnCVsiQ2TaWaXjmH1UpzpgT0kCViOy0t7LmpUbEPWDFQYASyg YT8HlI2VpvPMgZCHoFGt7/2w69HTVexjyL/3njFzTbt7NsednpxnbEQBrUSZJKHecGvh dGJg== X-Gm-Message-State: AOAM531LcJ1feEtXtQEWv1tsDJwBlrNkHKbNXHmbG14fgRqCQUCVtRS+ r/hDYL9RgpYwENKe7bJYP5rtKg== X-Received: by 2002:a5d:6847:: with SMTP id o7mr20330024wrw.706.1642440821028; Mon, 17 Jan 2022 09:33:41 -0800 (PST) Received: from smtpclient.apple (global-5-142.nat-2.net.cam.ac.uk. [131.111.5.142]) by smtp.gmail.com with ESMTPSA id b6sm8184682wri.108.2022.01.17.09.33.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jan 2022 09:33:40 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: Re: [PATCH] riscv: eliminate unreliable __builtin_frame_address(1) From: Jessica Clarke In-Reply-To: <20220117154433.3124-1-changbin.du@gmail.com> Date: Mon, 17 Jan 2022 17:33:40 +0000 Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv , linux-kernel@vger.kernel.org Content-Transfer-Encoding: 7bit Message-Id: References: <20220117154433.3124-1-changbin.du@gmail.com> To: Changbin Du X-Mailer: Apple Mail (2.3693.40.0.1.81) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17 Jan 2022, at 15:44, Changbin Du wrote: > > I tried different pieces of code which uses __builtin_frame_address(1) > (with both gcc version 7.5.0 and 10.3.0) to verify whether it works as > expected on riscv64. The result is negative. > > What the compiler had generated is as below: > 31 fp = (unsigned long)__builtin_frame_address(1); > 0xffffffff80006024 <+200>: ld s1,0(s0) > > It takes '0(s0)' as the address of frame 1 (caller), but the actual address > should be '-16(s0)'. > > | ... | <-+ > +-----------------+ | > | return address | | > | previous fp | | > | saved registers | | > | local variables | | > $fp --> | ... | | > +-----------------+ | > | return address | | > | previous fp --------+ > | saved registers | > $sp --> | local variables | > +-----------------+ > > This leads the kernel can not dump the full stack trace on riscv. > > [ 7.222126][ T1] Call Trace: > [ 7.222804][ T1] [] dump_backtrace+0x2c/0x3a > > This problem is not exposed on most riscv builds just because the '0(s0)' > occasionally is the address frame 2 (caller's caller), if only ra and fp > are stored in frame 1 (caller). > > | ... | <-+ > +-----------------+ | > | return address | | > $fp --> | previous fp | | > +-----------------+ | > | return address | | > | previous fp --------+ > | saved registers | > $sp --> | local variables | > +-----------------+ > > This could be a *bug* of gcc that should be fixed. But as noted in gcc > manual "Calling this function with a nonzero argument can have > unpredictable effects, including crashing the calling program.", let's > remove the '__builtin_frame_address(1)' in backtrace code. Yes, this is a bug, that is always wrong. LLVM gets this right. https://godbolt.org/z/MrhsoPPM6 Jess