Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2194620rdd; Fri, 12 Jan 2024 02:11:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaMJSulEjFO6Ei2j4p3744IMxMe0Tj4RKG5q8QvYS5EI4bWz5ryZd3zQUPCn0un9ggmhWH X-Received: by 2002:ac2:546c:0:b0:50e:2737:f603 with SMTP id e12-20020ac2546c000000b0050e2737f603mr471419lfn.48.1705054313961; Fri, 12 Jan 2024 02:11:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705054313; cv=none; d=google.com; s=arc-20160816; b=JXKYkIc9FGEV9/dGNFneIQuEjKrhV73aAtwJyCnKhzlVzweIO0DFalZusqgVI6C4aw 5hUwm2vac05ZbuhSWoSHf79HE/b3DwMa9WinK0az3hIYrN05DnTV4CjBePWkq5ZLyvB3 FiLMb9CfuesolK6N9Q2sHbI0MDiAyYodeNvKhUe3qvWwOxt8YZOZOg4wuEql+b1OH9/h U8zZj5xYsPnX2NhFkuPoQkinisB3dGgy3mUkGGP8wAGKIRO3yHurIxdkH4OJDBn1nMuY MUuxe2mHqjgOgFmQXhnRc9pSqHkcDI1Roii5ic9HKfV92i4yvd3TCOQEpEGMmfAc7TsG rpRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=S3U6MEEbPsVEqlsbkJ9JEzF8j0Efbt31JB40r8LLec0=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=CZC072xkOFD8IrKumWd/QXJ114kD4x9IK4j4XH0IB0xIP0Lw0W9lFvXu03xN1/7eZO Qi+kd1tsZkip4PXlEYr2Kj5KDbEa/oiu3fQIK/We8y/wwlDLzU1DGgq3LVdei2KJuPtm O1R4/kG9YPt29MsvKhIwLb3evGe8RzRKeLkRSGO6bGnPmxJSCzu69sQtJyFYyBGDSnvq hjdkE99cmvWNQU/8dgs8ERi8bH4Wi6tpsO0PbPraCiodo9GPxy0PQeRf264nMWww/4uy A+tXA9zNo5w/+ncPZDwxgo4eerhUEsI1kHxXBoUeAYsUbnscvGJcOR/zkK2DYsOwWQlj /wPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=fcHkdHfm; spf=pass (google.com: domain of linux-kernel+bounces-24546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24546-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y5-20020a170906470500b00a2a189b1053si1282000ejq.365.2024.01.12.02.11.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:11:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=fcHkdHfm; spf=pass (google.com: domain of linux-kernel+bounces-24546-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24546-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id ADC4F1F20DD4 for ; Fri, 12 Jan 2024 10:11:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1B195DF11; Fri, 12 Jan 2024 10:11:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fcHkdHfm" 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 EF3925C8FE; Fri, 12 Jan 2024 10:11:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA1DEC433C7; Fri, 12 Jan 2024 10:11:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705054268; bh=l4T04Izc/70L9UMANWu0UT3Aiu5pk/yJS8gqVOArAYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fcHkdHfmth7YLv7ppjDQ8oPvDRFGePuG+EG2ufQTYsnw/sEIo9nIpEhgbRQEVcBA4 scNaXjwe4jFdHzCrWgPyB+UmzcWjN7NWOpgV/hnfgoge+LT1JU/bCRuMh7Z06jCKGJ JCnHGHHmwFdY1Ge5RRCqGOdWz6cqins3KTqoy88xqhsN1IOLsHXUnBcFO4Avkg92ok 78XfikJx4D3zhb88xgnIHNSHJjK6u7KlolOYQj+oAfIkiTcApZbrXc7Tv4cZcX0XDW 5yjfXzap2pbztRtE/en/40WXo1j6reokEplaycDPvQPUufdj5SAR57XOFyuIIEcUZM LQBWS45JlamBw== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: 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 , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [PATCH v6 01/36] ftrace: Fix DIRECT_CALLS to use SAVE_REGS by default Date: Fri, 12 Jan 2024 19:11:02 +0900 Message-Id: <170505426238.459169.6078729647487152980.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170505424954.459169.10630626365737237288.stgit@devnote2> References: <170505424954.459169.10630626365737237288.stgit@devnote2> User-Agent: StGit/0.19 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="utf-8" Content-Transfer-Encoding: 8bit From: Masami Hiramatsu (Google) The commit 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS") changed DIRECT_CALLS to use SAVE_ARGS when there are multiple ftrace_ops at the same function, but since the x86 only support to jump to direct_call from ftrace_regs_caller, when we set the function tracer on the same target function on x86, ftrace-direct does not work as below (this actually works on arm64.) At first, insmod ftrace-direct.ko to put a direct_call on 'wake_up_process()'. # insmod kernel/samples/ftrace/ftrace-direct.ko # less trace . -0 [006] ..s1. 564.686958: my_direct_func: waking up rcu_preempt-17 -0 [007] ..s1. 564.687836: my_direct_func: waking up kcompactd0-63 -0 [006] ..s1. 564.690926: my_direct_func: waking up rcu_preempt-17 -0 [006] ..s1. 564.696872: my_direct_func: waking up rcu_preempt-17 -0 [007] ..s1. 565.191982: my_direct_func: waking up kcompactd0-63 Setup a function filter to the 'wake_up_process' too, and enable it. # cd /sys/kernel/tracing/ # echo wake_up_process > set_ftrace_filter # echo function > current_tracer # less trace . -0 [006] ..s3. 686.180972: wake_up_process <-call_timer_fn -0 [006] ..s3. 686.186919: wake_up_process <-call_timer_fn -0 [002] ..s3. 686.264049: wake_up_process <-call_timer_fn -0 [002] d.h6. 686.515216: wake_up_process <-kick_pool -0 [002] d.h6. 686.691386: wake_up_process <-kick_pool Then, only function tracer is shown on x86. But if you enable 'kprobe on ftrace' event (which uses SAVE_REGS flag) on the same function, it is shown again. # echo 'p wake_up_process' >> dynamic_events # echo 1 > events/kprobes/p_wake_up_process_0/enable # echo > trace # less trace . -0 [006] ..s2. 2710.345919: p_wake_up_process_0: (wake_up_process+0x4/0x20) -0 [006] ..s3. 2710.345923: wake_up_process <-call_timer_fn -0 [006] ..s1. 2710.345928: my_direct_func: waking up rcu_preempt-17 -0 [006] ..s2. 2710.349931: p_wake_up_process_0: (wake_up_process+0x4/0x20) -0 [006] ..s3. 2710.349934: wake_up_process <-call_timer_fn -0 [006] ..s1. 2710.349937: my_direct_func: waking up rcu_preempt-17 To fix this issue, use SAVE_REGS flag for multiple ftrace_ops flag of direct_call by default. Link: https://lore.kernel.org/all/170484558617.178953.1590516949390270842.stgit@devnote2/ Fixes: 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Mark Rutland Tested-by: Mark Rutland [arm64] Acked-by: Jiri Olsa --- kernel/trace/ftrace.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index b01ae7d36021..c060d5b47910 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5325,7 +5325,17 @@ static LIST_HEAD(ftrace_direct_funcs); static int register_ftrace_function_nolock(struct ftrace_ops *ops); +/* + * If there are multiple ftrace_ops, use SAVE_REGS by default, so that direct + * call will be jumped from ftrace_regs_caller. Only if the architecture does + * not support ftrace_regs_caller but direct_call, use SAVE_ARGS so that it + * jumps from ftrace_caller for multiple ftrace_ops. + */ +#ifndef HAVE_DYNAMIC_FTRACE_WITH_REGS #define MULTI_FLAGS (FTRACE_OPS_FL_DIRECT | FTRACE_OPS_FL_SAVE_ARGS) +#else +#define MULTI_FLAGS (FTRACE_OPS_FL_DIRECT | FTRACE_OPS_FL_SAVE_REGS) +#endif static int check_direct_multi(struct ftrace_ops *ops) {