From patchwork Tue Feb 7 18:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florent Revest X-Patchwork-Id: 54029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3005073wrn; Tue, 7 Feb 2023 10:23:34 -0800 (PST) X-Google-Smtp-Source: AK7set/qMegYfYAsAVKQ+SD5pxT6PCCVGfeMTx9JSFVQgrZp5qT5mQ4Xwymdi0zmt2gwCWCkvx/n X-Received: by 2002:a50:cc9a:0:b0:4aa:b24f:c09b with SMTP id q26-20020a50cc9a000000b004aab24fc09bmr4994493edi.40.1675794214824; Tue, 07 Feb 2023 10:23:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675794214; cv=none; d=google.com; s=arc-20160816; b=sxRr0BLMdUZBD/I7qFvf9IMQmUNmrI8y4Y/eDqlFpfjFoXN8u2Oruj9gcFLmivucMd u+OwlncTj4ehTkn+fsWqi5nvk6CIJ/u3s9nPRLbzjZ/KJYEebwyA3DX5SODk/wwanmqX ud1zn+Bw4kdD1lWBvGa7FbBK3yx5/gt7u04QTrm1C6OKZshZozUfHgjCz1gpNluGlZgg LhdBn1ijWF2ZmxOqXuW9Gy3HucS/2lir5whyTzVIgRPeGRo+poSr/jwuiDMOflb7qoRo rKOEXB9Wbqk8Q8sHc84JrUamoBpta9SnlKqK9IKAhE1nPTMcoTHNCEsLOoty6bM8hZdW JNiw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ho1LTqGpuqCMKTH+Vb+qJkksCrHGryHHWBQdSRtpN18=; b=xe21D4IMTTDCnJRtTulx29rjyI3dhVWeJOTIlcy+hIvejzXSvnGdnpDoRwmbEAaRnw zRZcXjVX9GpzhENwvaLQM0dhdSLNMLcR7T1uUYYQVTTckms0rHIsR/4496cEuhJ4kpMg /MftlYPhZVnYMHH7onVXK/VZgJ15L7GrE3vN6dInpdWFbGxdmQ1XcDCtEq36x6BrCgMF wHsDQaIHD3TxO5bajOmUPkxmCALPqD/g7RZ6xW2SFmpm937TTg/0e9sVT+esNVoQfWA/ wDAI3IWTlovG990ku1f4bH/hy3PvyRb94eODQTSXphLUKCtpoNcBCf2d4KiTsXE5MnGX lRfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=P4zcKCj6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a0564020e8b00b0049e376ac999si16447767eda.529.2023.02.07.10.23.11; Tue, 07 Feb 2023 10:23:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=P4zcKCj6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232563AbjBGSWu (ORCPT + 99 others); Tue, 7 Feb 2023 13:22:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232500AbjBGSWd (ORCPT ); Tue, 7 Feb 2023 13:22:33 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45459C659 for ; Tue, 7 Feb 2023 10:22:03 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id j25so10919058wrc.4 for ; Tue, 07 Feb 2023 10:22:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ho1LTqGpuqCMKTH+Vb+qJkksCrHGryHHWBQdSRtpN18=; b=P4zcKCj6lVBE8Jvr1ZgHF49O5366Nvo9qiNzHONiZ9a6P75W5pxe80lVN0u29Mza1f +OBDh/WcVO0XIq1SrqsIjPdivB0GLwtKrB/cr9ojhMjU3TpH0qf/c7ORhkAc44QkBs6u WC/xsuhdMCe4prb6u8zCMcSjtYduiA/tnKe4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ho1LTqGpuqCMKTH+Vb+qJkksCrHGryHHWBQdSRtpN18=; b=AOcsV0akXU8wAVUofhR7i3xcYmfkJXi/5kPYK3AqdN3fgEiLUq3TUkWpDso8ZcYQoI W7eeL8vHL8jRhiMqtSvlYHi5O8Zqxcn9QgXmAKpaBBsJNYs+h4d7dxwReqoDVqXP8Gws Uh3OwBqCDJlaOI8IZrrUG9AWmUw6F1XI4AMhngNtMzCDotWdMeXBE3bDU8AGYFf5urX1 Nt1hh9ks8ttmwE4326FGrcEufPDtXtcmLvPEc7kgF4igriEpOr0HEjmS879pp6vgst4S gdDffUkMmAOYR+hDCMug4zfqrPn9ioM257i4SGjmQs0XEkcCkpCCUTVrsdX5wSUj0ajS Qm+w== X-Gm-Message-State: AO0yUKXN0Rt+6qISfcB2TKYyRSca3kgBOX8xpWqMTzyBfv5snReQg/bi CwQQHs53+HrGmoxeD0v6vGdzLQ== X-Received: by 2002:a5d:6a08:0:b0:2c3:dbe0:58e9 with SMTP id m8-20020a5d6a08000000b002c3dbe058e9mr3509035wru.47.1675794121697; Tue, 07 Feb 2023 10:22:01 -0800 (PST) Received: from revest.zrh.corp.google.com ([2a00:79e0:9d:6:5307:c0c0:ff97:80de]) by smtp.gmail.com with ESMTPSA id n6-20020a05600c4f8600b003daf672a616sm15578369wmq.22.2023.02.07.10.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 10:22:01 -0800 (PST) From: Florent Revest To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kpsingh@kernel.org, jolsa@kernel.org, xukuohai@huaweicloud.com, lihuafei1@huawei.com, Florent Revest Subject: [PATCH v2 01/10] ftrace: Replace uses of _ftrace_direct APIs with _ftrace_direct_multi Date: Tue, 7 Feb 2023 19:21:26 +0100 Message-Id: <20230207182135.2671106-2-revest@chromium.org> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog In-Reply-To: <20230207182135.2671106-1-revest@chromium.org> References: <20230207182135.2671106-1-revest@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757197594607133257?= X-GMAIL-MSGID: =?utf-8?q?1757197594607133257?= The _multi API requires that users keep their own ops but can enforce that an op is only associated to one direct call. Signed-off-by: Florent Revest Acked-by: Mark Rutland Tested-by: Mark Rutland --- kernel/trace/trace_selftest.c | 11 +++++++---- samples/ftrace/ftrace-direct-modify.c | 12 ++++++++---- samples/ftrace/ftrace-direct-too.c | 12 +++++++----- samples/ftrace/ftrace-direct.c | 12 +++++++----- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index ff0536cea968..57221f69a33b 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c @@ -806,6 +806,9 @@ trace_selftest_startup_function_graph(struct tracer *trace, int ret; unsigned long count; char *func_name __maybe_unused; +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS + struct ftrace_ops direct = {}; +#endif #ifdef CONFIG_DYNAMIC_FTRACE if (ftrace_filter_param) { @@ -870,8 +873,8 @@ trace_selftest_startup_function_graph(struct tracer *trace, * Register direct function together with graph tracer * and make sure we get graph trace. */ - ret = register_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME, - (unsigned long) trace_direct_tramp); + ftrace_set_filter_ip(&direct, (unsigned long)DYN_FTRACE_TEST_NAME, 0, 0); + ret = register_ftrace_direct_multi(&direct, (unsigned long)trace_direct_tramp); if (ret) goto out; @@ -891,8 +894,8 @@ trace_selftest_startup_function_graph(struct tracer *trace, unregister_ftrace_graph(&fgraph_ops); - ret = unregister_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME, - (unsigned long) trace_direct_tramp); + ret = unregister_ftrace_direct_multi(&direct, + (unsigned long) trace_direct_tramp); if (ret) goto out; diff --git a/samples/ftrace/ftrace-direct-modify.c b/samples/ftrace/ftrace-direct-modify.c index de5a0f67f320..ecd76f75cb80 100644 --- a/samples/ftrace/ftrace-direct-modify.c +++ b/samples/ftrace/ftrace-direct-modify.c @@ -96,6 +96,8 @@ asm ( #endif /* CONFIG_S390 */ +static struct ftrace_ops direct; + static unsigned long my_tramp = (unsigned long)my_tramp1; static unsigned long tramps[2] = { (unsigned long)my_tramp1, @@ -114,7 +116,7 @@ static int simple_thread(void *arg) if (ret) continue; t ^= 1; - ret = modify_ftrace_direct(my_ip, my_tramp, tramps[t]); + ret = modify_ftrace_direct_multi(&direct, tramps[t]); if (!ret) my_tramp = tramps[t]; WARN_ON_ONCE(ret); @@ -129,7 +131,9 @@ static int __init ftrace_direct_init(void) { int ret; - ret = register_ftrace_direct(my_ip, my_tramp); + ftrace_set_filter_ip(&direct, (unsigned long) my_ip, 0, 0); + ret = register_ftrace_direct_multi(&direct, my_tramp); + if (!ret) simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn"); return ret; @@ -138,12 +142,12 @@ static int __init ftrace_direct_init(void) static void __exit ftrace_direct_exit(void) { kthread_stop(simple_tsk); - unregister_ftrace_direct(my_ip, my_tramp); + unregister_ftrace_direct_multi(&direct, my_tramp); } module_init(ftrace_direct_init); module_exit(ftrace_direct_exit); MODULE_AUTHOR("Steven Rostedt"); -MODULE_DESCRIPTION("Example use case of using modify_ftrace_direct()"); +MODULE_DESCRIPTION("Example use case of using modify_ftrace_direct_multi()"); MODULE_LICENSE("GPL"); diff --git a/samples/ftrace/ftrace-direct-too.c b/samples/ftrace/ftrace-direct-too.c index e13fb59a2b47..0e907092e2c0 100644 --- a/samples/ftrace/ftrace-direct-too.c +++ b/samples/ftrace/ftrace-direct-too.c @@ -70,21 +70,23 @@ asm ( #endif /* CONFIG_S390 */ +static struct ftrace_ops direct; + static int __init ftrace_direct_init(void) { - return register_ftrace_direct((unsigned long)handle_mm_fault, - (unsigned long)my_tramp); + ftrace_set_filter_ip(&direct, (unsigned long) handle_mm_fault, 0, 0); + + return register_ftrace_direct_multi(&direct, (unsigned long) my_tramp); } static void __exit ftrace_direct_exit(void) { - unregister_ftrace_direct((unsigned long)handle_mm_fault, - (unsigned long)my_tramp); + unregister_ftrace_direct_multi(&direct, (unsigned long)my_tramp); } module_init(ftrace_direct_init); module_exit(ftrace_direct_exit); MODULE_AUTHOR("Steven Rostedt"); -MODULE_DESCRIPTION("Another example use case of using register_ftrace_direct()"); +MODULE_DESCRIPTION("Another example use case of using register_ftrace_direct_multi()"); MODULE_LICENSE("GPL"); diff --git a/samples/ftrace/ftrace-direct.c b/samples/ftrace/ftrace-direct.c index 1f769d0db20f..e446c38f6b58 100644 --- a/samples/ftrace/ftrace-direct.c +++ b/samples/ftrace/ftrace-direct.c @@ -63,21 +63,23 @@ asm ( #endif /* CONFIG_S390 */ +static struct ftrace_ops direct; + static int __init ftrace_direct_init(void) { - return register_ftrace_direct((unsigned long)wake_up_process, - (unsigned long)my_tramp); + ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0); + + return register_ftrace_direct_multi(&direct, (unsigned long) my_tramp); } static void __exit ftrace_direct_exit(void) { - unregister_ftrace_direct((unsigned long)wake_up_process, - (unsigned long)my_tramp); + unregister_ftrace_direct_multi(&direct, (unsigned long)my_tramp); } module_init(ftrace_direct_init); module_exit(ftrace_direct_exit); MODULE_AUTHOR("Steven Rostedt"); -MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()"); +MODULE_DESCRIPTION("Example use case of using register_ftrace_direct_multi()"); MODULE_LICENSE("GPL");