Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1655065rdb; Mon, 8 Jan 2024 06:22:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLrp4nyi0wEXPZ+m4DwbSyKJPtCkd0/134gDgQIo5OKxHM+rt+o2dLeQiFc6NDXzKfTaf4 X-Received: by 2002:a17:902:e845:b0:1d4:8f4b:f4e3 with SMTP id t5-20020a170902e84500b001d48f4bf4e3mr5338869plg.43.1704723778446; Mon, 08 Jan 2024 06:22:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704723778; cv=none; d=google.com; s=arc-20160816; b=kDqlVpTUNgplJdAdlSdzhnxzTLn0XbFsr7m+sgyTigXarRsfuyNezgv6i9/O2aw0DI FHM8nNJzbON/LeAgfStyZT+izGO0+6dvQLkpBSnKrpEhbcx4VCFAvw10cmy99x5Tu0Pp SpO6qwm68tQ4JY9ODAWcNjxpo3k5rMWPR2HvjK+OOep3ejYvTmeDhsqzArTOacSGmALM ZTPhQycCC+X8G8lnBjdJRAekWQM9hs8jMNxuNRwu7LH4ktAmbElj7+IRjwEG4joVXp9Q UxOt4n9OdbdkTCsvVYmd7rPqQjS9z7guN3FUXFgJj0QWxBR0nm1kKUilNiQKmasW44Zq unmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=1l8zMftL4rstIt7BphpbKArg1j/vOf5hF1enKukgLPU=; fh=563vw1N0KzdI/CLOIL7m0Z0nGoOOeplg3/HMitEV324=; b=hRrRjIgfOjkTu9nenz7gKDzgA+vlRbOBtug+9SPbmOC7pmfyJyhpgbJeUbfI8PNUjH b3O59r0TVdTAOR9xkWvxpJdNKs23L+cGXl3d8Yf9mQvlzVWqfvsYfqWgEnH0Vs9FCQdI mL8oXAhJm/K3IGjE7KIgF0VlOVBQCSGO1pEMe1voIZSA6d8BU73k4BL/MAGVOxk+KcNi yAWb5muoqF9NSXEZaJv3kHBrnOCggX8XAiFHttv6ZS3kzMsbT5EutnVIXskEJLV3CWjW FQ9+D4WCYO1xv882I6LSm6t2iMvJNHp8bSQfYSe7DVxUrMKuyeEbgyZaEH9pKRnzz7tp MqYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19697-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f7-20020a17090274c700b001d3df35d8e4si5977935plt.127.2024.01.08.06.22.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 06:22:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19697-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5A5C4B2285B for ; Mon, 8 Jan 2024 14:22:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDA884778C; Mon, 8 Jan 2024 14:21:14 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F00EF47776; Mon, 8 Jan 2024 14:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 383B3C15; Mon, 8 Jan 2024 06:21:57 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.89.149]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B1A833F64C; Mon, 8 Jan 2024 06:21:08 -0800 (PST) Date: Mon, 8 Jan 2024 14:21:03 +0000 From: Mark Rutland To: Masami Hiramatsu Cc: Alexei Starovoitov , Steven Rostedt , Florent Revest , linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH v5 11/34] function_graph: Have the instances use their own ftrace_ops for filtering Message-ID: References: <170290509018.220107.1347127510564358608.stgit@devnote2> <170290522555.220107.1435543481968270637.stgit@devnote2> <20240108101436.07509def635fbecf80a59ae6@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jan 08, 2024 at 12:25:55PM +0000, Mark Rutland wrote: > We also have HAVE_FUNCTION_GRAPH_RET_ADDR_PTR, but since the return address is > not on the stack at the point function-entry is intercepted we use the FP as > the retp value -- in the absence of tail calls this will be different between a > caller and callee. Ah; I just spotted that this patch changed that in ftrace_graph_func(), which is the source of the bug. As of this patch, we use the address of fregs->lr as the retp value, but the unwinder still uses the FP value, and so when unwind_recover_return_address() calls ftrace_graph_ret_addr(), the retp value won't match the expected entry on the fgraph ret_stack, resulting in failing to find the expected entry. Since the ftrace_regs only exist transiently during function entry/exit, it's possible for a stackframe to reuse that same address on the stack, which would result in finding a different entry by mistake. The diff below restores the existing behaviour and fixes the issue for me. Could you please fold that into this patch? On a separate note, looking at how this patch changed arm64's ftrace_graph_func(), do we need similar changes to arm64's prepare_ftrace_return() for the old-style mcount based ftrace? Mark. ---->8---- diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index 205937e04ece..329092ce06ba 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -495,7 +495,7 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, if (bit < 0) return; - if (!function_graph_enter_ops(*parent, ip, fregs->fp, parent, gops)) + if (!function_graph_enter_ops(*parent, ip, fregs->fp, (void *)fregs->fp, gops)) *parent = (unsigned long)&return_to_handler; ftrace_test_recursion_unlock(bit);