From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A26FD12F37B; Tue, 2 Jul 2024 23:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719963545; cv=none; b=sAl1iEs7qhqIqtxQkIp5lzIVluQozApJo+3ahH7cgXt97hqowEuX0ITpvbLRmu44J2AUrDH0JmK4/GUk2DBOerEyFYQtJCa8QrL8hYuh5DXJ47Ch9GQnMRG27HtJyW2r9184ph/1zBcPROtPSrg7JiSKrMH/v9cA5rGEYPzKaU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719963545; c=relaxed/simple; bh=UjxnxLhiGA9d+TthrYHIqBGx+X7+t17Yzvu+fEUiXZI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XPZJc+0HyuNxavOfA+yQL7Dmam3Cj2iwmQdpcVYcBhPr8Oipkiui+Sxrxfaq4RvEdxIOtdzV7p16hKA1qJ80p0XGY2deRQn+Sm3n7wq6rDoJcl8piEuYCM8z5wOfmScELjUWrfk32HaaEkt8Wwdy8n+cxQHZChSbLCZGLYUo3HE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cHx74wJG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cHx74wJG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B950EC116B1; Tue, 2 Jul 2024 23:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719963545; bh=UjxnxLhiGA9d+TthrYHIqBGx+X7+t17Yzvu+fEUiXZI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cHx74wJGAG7QAn2Ezj2m4UcuEenAq+rfg1ploYBfnJWQ6i7XcgEEktEd6g2e5gltr +49O5TMnpiAIJBRNterCsrInXLiI22dfCYFd7RSCtj3VGhl16mICOjCs0ST60zIQR7 mlZONVtfOXuLACTF+OaHmTAGFVOCD7iVDgfXZE8PpfOSyHdIg8UcSKm+123AVDIOKT W2Sq3aRySY4qq+9L4OIhId4dhhiXr85ajQiLfotTjXB7/rQ/899RmXWtvPNnOHgbHx ZCk66pab69RChBZhqtd/kRHXWyJtMRS5UXpfwqZ++Jp+MNgvbPL4rdqxdtBf08jSrV TvYwwq1ke9MJA== Date: Tue, 2 Jul 2024 16:39:02 -0700 From: Josh Poimboeuf To: Andrii Nakryiko Cc: linux-trace-kernel@vger.kernel.org, peterz@infradead.org, rostedt@goodmis.org, mhiramat@kernel.org, x86@kernel.org, mingo@redhat.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, rihams@fb.com, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v2] perf,x86: avoid missing caller address in stack traces captured in uprobe Message-ID: <20240702233902.p42gfhhnxo2veemf@treble> References: <20240702171858.187562-1-andrii@kernel.org> <20240702233554.slj6kh7dn2mc2w4n@treble> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240702233554.slj6kh7dn2mc2w4n@treble> On Tue, Jul 02, 2024 at 04:35:56PM -0700, Josh Poimboeuf wrote: > On Tue, Jul 02, 2024 at 10:18:58AM -0700, Andrii Nakryiko wrote: > > When tracing user functions with uprobe functionality, it's common to > > install the probe (e.g., a BPF program) at the first instruction of the > > function. This is often going to be `push %rbp` instruction in function > > preamble, which means that within that function frame pointer hasn't > > been established yet. This leads to consistently missing an actual > > caller of the traced function, because perf_callchain_user() only > > records current IP (capturing traced function) and then following frame > > pointer chain (which would be caller's frame, containing the address of > > caller's caller). > > > > So when we have target_1 -> target_2 -> target_3 call chain and we are > > tracing an entry to target_3, captured stack trace will report > > target_1 -> target_3 call chain, which is wrong and confusing. > > > > This patch proposes a x86-64-specific heuristic to detect `push %rbp` > > (`push %ebp` on 32-bit architecture) instruction being traced. Given > > entire kernel implementation of user space stack trace capturing works > > under assumption that user space code was compiled with frame pointer > > register (%rbp/%ebp) preservation, it seems pretty reasonable to use > > this instruction as a strong indicator that this is the entry to the > > function. In that case, return address is still pointed to by %rsp/%esp, > > so we fetch it and add to stack trace before proceeding to unwind the > > rest using frame pointer-based logic. > > > > Signed-off-by: Andrii Nakryiko > > Should it also check for ENDBR64? > > When compiled with -fcf-protection=branch, the first instruction of the > function will almost always be ENDBR64. I'm not sure about other > distros, but at least Fedora compiles its binaries like that. BTW, there are some cases (including leaf functions and some stack alignment sequences) where a "push %rbp" can happen inside a function. Then it would presumably add a bogus trace entry. Are such false positives ok? -- Josh