Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp971546rdd; Wed, 10 Jan 2024 05:10:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOW6RrqtYWCRfBLnGtKarFJN7KlxL7Ok8mgfmqO/AB96zI28u9Ybgv1nl1p8UT/RpqQosY X-Received: by 2002:a05:620a:136b:b0:783:2f11:4c53 with SMTP id d11-20020a05620a136b00b007832f114c53mr1104541qkl.77.1704892224741; Wed, 10 Jan 2024 05:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704892224; cv=none; d=google.com; s=arc-20160816; b=JTDd3aC0d8O7LG6OAY+9gzlwQtA3CRLPOdgQeCq18AlO4CFjP4mQAOdJIFIO7GX4zF VW+0YWdQVNfLHFk4nKqLAROncki30G/FLXNAFEKSqQJUf58XKzZ8qGYzcmyqqp3qyzn5 1Yh1V0O3FNQsc0g+Ws0q0oKMZmcUTCz9DStWbjNuKLjesNubDo9uvIs4GKUasryU4Z1S 9U3hpgxsl/QdNL3u67hZ4Xbu2dCuCmTOjTJ96hEKwf4ggN//NTxOA5gFua998z5/hQWD 7IrLNFpEpYgxpiVGD5UF8rsOQN/7wSwPZtmRiGHHH/UZxFdAoOqF3bUXGcYVWL5/Tj8H ubtw== 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:date:from:dkim-signature; bh=Dcp3BdvYnFjEQy7q3wABGIgUqH9mmv2OBJ3xCim2kMY=; fh=fkkhTSkuWkdoESQ4nA7PP7fMFq3i6M3d10VLE6BoLX8=; b=APyTM4oIlv06tON0sfQkhv8HzG3S3ZfgZMhJ6dpuf3x3DjIk1aM0bqC9G9o01REO/c HjDX285qe09zMK3elupVy727vqSlsJ8tQWEOU77oDyzmGPDBi9Si/D72qQM6e9gbP6qc fidlbogDy7QNNDJn83ZCCqzy1iQEN9ulk9Mcn8N5WRGHSjA54aJq1uKdc5Vk4yQuYDJq QACaTYcnianJkReZFOtFJ1f0W0SPhlEUchdBZtpfx5K+2kUVr3yBgOS7qzdQh5UmMt6C fr2h0fAGfuxCBOmtQd85VeqortTtO2AE2joAGwX1sxaoZkityvGmf0apsW5sOGL+LaNS 15XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="PP3DVEC/"; spf=pass (google.com: domain of linux-kernel+bounces-22214-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22214-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id az43-20020a05620a172b00b007833af128d4si294564qkb.262.2024.01.10.05.10.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 05:10:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22214-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="PP3DVEC/"; spf=pass (google.com: domain of linux-kernel+bounces-22214-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22214-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6EE2E1C21B01 for ; Wed, 10 Jan 2024 13:10:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CA5D487A0; Wed, 10 Jan 2024 13:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PP3DVEC/" Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E40BF482FC; Wed, 10 Jan 2024 13:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-50e7f58c5fbso5283982e87.1; Wed, 10 Jan 2024 05:10:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704892213; x=1705497013; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=Dcp3BdvYnFjEQy7q3wABGIgUqH9mmv2OBJ3xCim2kMY=; b=PP3DVEC/TCmIqGDc3WbZW+M7kWv7ZjvaG/wD4ErVV3iLTD+oIS25qLCx2vnmuSVaUi d8t/YQAdgQDi1toDdpfzywxbiKKFg6478mq2egPuqAAxKERJIEzwRZhgyVTbSbJuEqJP yCCDzIH3gFBu/p/ooSUO3O+utB9f6jCyfNi+V53mWcy9CVtZzBTsHb5ysNw/P1UJcsMA GXF40qDaciu5RzZCArIfNSz/s4v1YmUgw2LfJqt56Wwz/UUo5SPSGSCxDfsb6u1Mca1s LFWR9CKE6sVJgGlBpVIXz2wdnA2g18WnUNzNDYYVeRcn3tFrfCCExdzBliPsu5gdNS9M anSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704892213; x=1705497013; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Dcp3BdvYnFjEQy7q3wABGIgUqH9mmv2OBJ3xCim2kMY=; b=joEgOZjTKTJFMwA/AexTUWWeRo3eCp6WX3kOupbMrtaZJp+wcV00/otycMI+/72tYO iqXLbOE/8vcvHO4Qfhn8kpSzdiEfJImnLjhDXji3mkBp0qAL4XgbTYUdZotZltaQP46D O1+wHFi/ezlWV3isREYS989J4fyRtnMUNZi0tOvRE1UBrNsJAAh+OybDmEOwYwNoVVWU pjqsTBVtKhGosvEzkhILmsE3/ZeQUcZoyYfbbnUMcTQazWR5mYMbnYw+xx8qzSSXsypW 6vPR6HWDDJTr1fsJDeyNZYmz4xtxkd6mZDoXT3erSRh2hF9PlRyyKxP9gWPCVl5pl/Lj fwag== X-Gm-Message-State: AOJu0Yxi29Wbz5c2SuO96IabKRYY/xXRiYfGxUSutBCyTtb1d51FFbEC YNhPgl32/gBRdvJHlWgkzlo= X-Received: by 2002:a19:ca0b:0:b0:50e:bb4d:e502 with SMTP id a11-20020a19ca0b000000b0050ebb4de502mr452352lfg.122.1704892212552; Wed, 10 Jan 2024 05:10:12 -0800 (PST) Received: from krava (2001-1ae9-1c2-4c00-726e-c10f-8833-ff22.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:726e:c10f:8833:ff22]) by smtp.gmail.com with ESMTPSA id u21-20020a170906069500b00a2a67731f31sm2075239ejb.109.2024.01.10.05.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 05:10:12 -0800 (PST) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Wed, 10 Jan 2024 14:10:10 +0100 To: "Masami Hiramatsu (Google)" Cc: Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Florent Revest , Mark Rutland Subject: Re: [PATCH] ftrace: Fix DIRECT_CALLS to use SAVE_REGS by default Message-ID: References: <170484558617.178953.1590516949390270842.stgit@devnote2> 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: <170484558617.178953.1590516949390270842.stgit@devnote2> On Wed, Jan 10, 2024 at 09:13:06AM +0900, Masami Hiramatsu (Google) wrote: > 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. nice catch Acked-by: Jiri Olsa jirka > > Fixes: 60c8971899f3 ("ftrace: Make DIRECT_CALLS work WITH_ARGS and !WITH_REGS") > Cc: stable@vger.kernel.org > Signed-off-by: Masami Hiramatsu (Google) > --- > 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) > { >