From patchwork Sun Nov 5 16:09:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 161672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2197402vqu; Sun, 5 Nov 2023 08:10:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEg/qn9QbW0Y8sER3ngABm6Tw82xBa5MCwtBv4A/OqwNwwSwbXQ+DsmPpUODV3Oo6CuBj+B X-Received: by 2002:a17:902:e545:b0:1cc:468d:526c with SMTP id n5-20020a170902e54500b001cc468d526cmr19268745plf.9.1699200614103; Sun, 05 Nov 2023 08:10:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699200614; cv=none; d=google.com; s=arc-20160816; b=xLvc7+0o4aDU6bGMvKYnwQVF3sviTLzb4NqWrB7h4tqggRXbmULuF/KJ1P31piS7QW Xm8JSIIv34mrCFBnIbL5IQVe0kb+dyZS8cATJrq35zKQ3ADgA3aN/pfDInmXxQM/U4sk IsW1kVWsgaAjBeu2KpHB7GkIhl/pDCqt8Qs9Q44TVp8tJ9PpWwmv7Hji73RlzQJFRyWv yW17eeK8S6FRb1hF5k/bD17cp2ADY4KpIv09hNpZYHsEtItUmxr6wDW+9kP+dCP/RydW wOtfZPJwn25IxUze26130TDSQCT5o4mBD7Ffr/I3rebeZ1RUi6x+TdGyoeHvn6Mak+c9 oBnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OlxSyKjVM4y+aeDGRKyX0s+d+YhFPOWU1aAkU7qmgR0=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=GqDPXS8Ffg+6P32+NuB3rt5usq8tYurC3y/q7V9xygdrsQeaHxPpRyT1YxSf88YMjm ESu8u7RjSUAVyjjxRJ27tjAehwUsyqu1mDCBJtzeDkoBpx1j28dpe3D3276epvrfGCyz DtCUHCMRyOJyBJuR9XhQ33cmtaxvvrI2w7u/mIswJoDG5BB02SFPfyHWRHLsaluncu8M mBwmvx6GpGjVtOBnKbhhVBLGLeXZSWKJvN1UiX/xsacD1HM27Mqbr7e/Y/d0NsIMcpEd 46SzPXEbAkBub1XJw4lRsO3lNZbYRr64HXhvq7TRCSomFTF1vZAVyb3RtV+UvcqaqvEA V7pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s0rllwGV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s15-20020a170902ea0f00b001b811261289si6531366plg.482.2023.11.05.08.10.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:10:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s0rllwGV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 50FE580B1D39; Sun, 5 Nov 2023 08:10:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229514AbjKEQKA (ORCPT + 34 others); Sun, 5 Nov 2023 11:10:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjKEQJ4 (ORCPT ); Sun, 5 Nov 2023 11:09:56 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EB1AD70 for ; Sun, 5 Nov 2023 08:09:52 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84121C433C7; Sun, 5 Nov 2023 16:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699200592; bh=iHMWoK48jd37dO5Jbonc2zMACTI9ZQjwy+qJj2dU7cc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s0rllwGVgvS8kfem8mLBzFyyTqulUUEwwI5/CqZmswfnc7vPmaD0QsF0As/6xJiCY bla2XGcOMjXwyG50JjwihbCb9Rz3jWVbEB50399XcaNdtXw5TS00v0/Ei95/nUZMUK xuJbTeXzbcg4M4lpyOVqqWlxjCoLgKZt/RjPIK90/uBmuoRwS1zYjDQUYFwDjEKvzf VLCintK0CcfrcwfSUL9ktgqBN/rJDhglXYSTp7tXHRuC7lSYNOrg8xWqMszyE5g/Bs 6NSDvA6vCY2fFsM0f0W6NHDpvMJm0I1BJsvZ+TaueXxGYnd0Hh/ZVVkz2MaO/rqgyZ myOEFSROdm6uQ== 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: [RFC PATCH 16/32] function_graph: Add selftest for passing local variables Date: Mon, 6 Nov 2023 01:09:45 +0900 Message-Id: <169920058540.482486.7562979275156655655.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169920038849.482486.15796387219966662967.stgit@devnote2> References: <169920038849.482486.15796387219966662967.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:10:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781740982926217080 X-GMAIL-MSGID: 1781740982926217080 From: Steven Rostedt (VMware) Add boot up selftest that passes variables from a function entry to a function exit, and make sure that they do get passed around. Signed-off-by: Steven Rostedt (VMware) --- kernel/trace/trace_selftest.c | 161 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index e05f7335525c..14966d8509ed 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c @@ -756,6 +756,165 @@ trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr) #ifdef CONFIG_FUNCTION_GRAPH_TRACER +#ifdef CONFIG_DYNAMIC_FTRACE + +#define BYTE_NUMBER 123 +#define SHORT_NUMBER 12345 +#define WORD_NUMBER 1234567890 +#define LONG_NUMBER 1234567890123456789LL + +static int fgraph_store_size __initdata; +static const char *fgraph_store_type_name __initdata; +static char *fgraph_error_str __initdata; +static char fgraph_error_str_buf[128] __initdata; + +static __init int store_entry(struct ftrace_graph_ent *trace, + struct fgraph_ops *gops) +{ + const char *type = fgraph_store_type_name; + int size = fgraph_store_size; + void *p; + + p = fgraph_reserve_data(size); + if (!p) { + snprintf(fgraph_error_str_buf, sizeof(fgraph_error_str_buf), + "Failed to reserve %s\n", type); + fgraph_error_str = fgraph_error_str_buf; + return 0; + } + + switch (fgraph_store_size) { + case 1: + *(char *)p = BYTE_NUMBER; + break; + case 2: + *(short *)p = SHORT_NUMBER; + break; + case 4: + *(int *)p = WORD_NUMBER; + break; + case 8: + *(long long *)p = LONG_NUMBER; + break; + } + + return 1; +} + +static __init void store_return(struct ftrace_graph_ret *trace, + struct fgraph_ops *gops) +{ + const char *type = fgraph_store_type_name; + long long expect = 0; + long long found = -1; + char *p; + + p = fgraph_retrieve_data(); + if (!p) { + snprintf(fgraph_error_str_buf, sizeof(fgraph_error_str_buf), + "Failed to retrieve %s\n", type); + fgraph_error_str = fgraph_error_str_buf; + return; + } + + switch (fgraph_store_size) { + case 1: + expect = BYTE_NUMBER; + found = *(char *)p; + break; + case 2: + expect = SHORT_NUMBER; + found = *(short *)p; + break; + case 4: + expect = WORD_NUMBER; + found = *(int *)p; + break; + case 8: + expect = LONG_NUMBER; + found = *(long long *)p; + break; + } + + if (found != expect) { + snprintf(fgraph_error_str_buf, sizeof(fgraph_error_str_buf), + "%s returned not %lld but %lld\n", type, expect, found); + fgraph_error_str = fgraph_error_str_buf; + return; + } + fgraph_error_str = NULL; +} + +static struct fgraph_ops store_bytes __initdata = { + .entryfunc = store_entry, + .retfunc = store_return, +}; + +static int __init test_graph_storage_type(const char *name, int size) +{ + char *func_name; + int len; + int ret; + + fgraph_store_type_name = name; + fgraph_store_size = size; + + snprintf(fgraph_error_str_buf, sizeof(fgraph_error_str_buf), + "Failed to execute storage %s\n", name); + fgraph_error_str = fgraph_error_str_buf; + + printk(KERN_CONT "PASSED\n"); + pr_info("Testing fgraph storage of %d byte%s: ", size, size > 1 ? "s" : ""); + + func_name = "*" __stringify(DYN_FTRACE_TEST_NAME); + len = strlen(func_name); + + ret = ftrace_set_filter(&store_bytes.ops, func_name, len, 1); + if (ret && ret != -ENODEV) { + pr_cont("*Could not set filter* "); + return -1; + } + + ret = register_ftrace_graph(&store_bytes); + if (ret) { + printk(KERN_WARNING "Failed to init store_bytes fgraph tracing\n"); + return -1; + } + + DYN_FTRACE_TEST_NAME(); + + unregister_ftrace_graph(&store_bytes); + + if (fgraph_error_str) { + printk(KERN_CONT "*** %s ***", fgraph_error_str); + return -1; + } + + return 0; +} +/* Test the storage passed across function_graph entry and return */ +static __init int test_graph_storage(void) +{ + int ret; + + ret = test_graph_storage_type("byte", 1); + if (ret) + return ret; + ret = test_graph_storage_type("short", 2); + if (ret) + return ret; + ret = test_graph_storage_type("word", 4); + if (ret) + return ret; + ret = test_graph_storage_type("long long", 8); + if (ret) + return ret; + return 0; +} +#else +static inline int test_graph_storage(void) { return 0; } +#endif /* CONFIG_DYNAMIC_FTRACE */ + /* Maximum number of functions to trace before diagnosing a hang */ #define GRAPH_MAX_FUNC_TEST 100000000 @@ -913,6 +1072,8 @@ trace_selftest_startup_function_graph(struct tracer *trace, ftrace_set_global_filter(NULL, 0, 1); #endif + ret = test_graph_storage(); + /* Don't test dynamic tracing, the function tracer already did */ out: /* Stop it if we failed */