Received: by 10.213.65.68 with SMTP id h4csp1672320imn; Mon, 26 Mar 2018 12:11:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+TUvFD8O8Ra0WTM2B6xxr+lpTUbSdGecUP1txdcDzg1W2iB19ox/jmBZbdTSUdpIZsAy4d X-Received: by 2002:a17:902:7c83:: with SMTP id y3-v6mr4559578pll.271.1522091516114; Mon, 26 Mar 2018 12:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522091516; cv=none; d=google.com; s=arc-20160816; b=xjr5QW1kniT/vlus0dOQhtWeklm+bc5nV9fgK1Y5xmwKxxNjJ3U6sMC+QpNwzi07m8 CrL5qAi2TRgxQpFRiAeVZ8AzqFwgw4lUwN6hGp12RoFCJN0a9K1BgtBLHDeJSDeMBd6O 6XBhbCZ69cjni2h5DDnoNITHveK/Olk30A/+7Lt61wQ7JB34G7+bD/X3Mx0CswvLyjXh Tb8P0WQd3cbDLlWmzEJXvX1Qk1JbNTUwUBA/XOjlJc4r9O3Dw09UU01hzEX/p+hya970 FZ4gEGWSAogxizIWhv4VarxN81jn2JRFh7I0TygN5F/AJpIkkUP5imGEp6TBzyPmHxiz co9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=6urL0vpYoYcdIPJGUzWD4jxHiEI0SBbkCjdFo4IVRaU=; b=h7l5NLqawkUH8opM0yFQ1JB0tegaY8MsRW5XLQ84XwIlNeETrcBbejpCTLO2iULFDR 6PG9pAsTCncR8u4lfZfzLKlXGhQy7WC1fapPjPA5uyt5UlKvutmFGgm6QFAzGAvIiJ37 i4OomcEgejcjFO680Ig4ebPtmw5JJ3htled1MaITgjd1O5my2GM9bFhxNtZfxblgRYWR ebvMYxqgMT4DE0tGRcy9o6rRbdnFhrAxm1wPXl1uxdkMOsWYwvbUql8vnYNB4KpSUk6H Vt13J2LqWC9HEMmGbPb627e9eQpyVtprCezq4dnPbbwiCtiP5jQjR2QB7yweGQ4GjRg2 2URw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k14si2957896pgc.505.2018.03.26.12.11.40; Mon, 26 Mar 2018 12:11:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752048AbeCZTKr (ORCPT + 99 others); Mon, 26 Mar 2018 15:10:47 -0400 Received: from mail.efficios.com ([167.114.142.138]:41502 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751776AbeCZTKr (ORCPT ); Mon, 26 Mar 2018 15:10:47 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 4684C1A649C; Mon, 26 Mar 2018 15:10:46 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id LNiIgGw4app2; Mon, 26 Mar 2018 15:10:45 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 77FA71A6498; Mon, 26 Mar 2018 15:10:45 -0400 (EDT) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tPSdILcRQn7J; Mon, 26 Mar 2018 15:10:45 -0400 (EDT) Received: from thinkos.internal.efficios.com (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) by mail.efficios.com (Postfix) with ESMTPSA id 514221A6493; Mon, 26 Mar 2018 15:10:45 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Alexei Starovoitov , Peter Zijlstra , Ingo Molnar Subject: [RFC PATCH] tracepoint: Provide tracepoint_kernel_find_by_name Date: Mon, 26 Mar 2018 15:10:31 -0400 Message-Id: <20180326191031.14939-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide an API allowing eBPF to lookup core kernel tracepoints by name. Given that a lookup by name explicitly requires tracepoint definitions to be unique for a given name (no duplicate keys), include a WARN_ON_ONCE() check that only a single match is encountered at runtime. This should always be the case, given that a DEFINE_TRACE emits a __tracepoint_##name symbol, which would cause a link-time error if more than one instance is found. Nevertheless, check this at runtime with WARN_ON_ONCE() to stay on the safe side. Signed-off-by: Mathieu Desnoyers CC: Steven Rostedt CC: Alexei Starovoitov CC: Peter Zijlstra CC: Ingo Molnar --- include/linux/tracepoint.h | 1 + kernel/tracepoint.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index c94f466d57ef..1b4ae64b7c6a 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -43,6 +43,7 @@ tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data); extern void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), void *priv); +extern struct tracepoint *tracepoint_kernel_find_by_name(const char *name); #ifdef CONFIG_MODULES struct tp_module { diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 671b13457387..0a59f988055a 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -60,6 +60,11 @@ struct tp_probes { struct tracepoint_func probes[0]; }; +struct tp_find_args { + const char *name; + struct tracepoint *tp; +}; + static inline void *allocate_probes(int count) { struct tp_probes *p = kmalloc(count * sizeof(struct tracepoint_func) @@ -528,6 +533,36 @@ void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), } EXPORT_SYMBOL_GPL(for_each_kernel_tracepoint); +static void find_tp(struct tracepoint *tp, void *priv) +{ + struct tp_find_args *args = priv; + + if (!strcmp(tp->name, args->name)) { + WARN_ON_ONCE(args->tp); + args->tp = tp; + } +} + +/** + * tracepoint_kernel_find_by_name - lookup a core kernel tracepoint by name + * @name: tracepoint name + * + * Returns the tracepoint structure associated with the name received as + * parameter, or NULL if not found. Lookup is only performed throughout + * core kernel tracepoints. + */ +struct tracepoint *tracepoint_kernel_find_by_name(const char *name) +{ + struct tp_find_args args = { + .name = name, + .tp = NULL, + }; + + for_each_tracepoint_range(__start___tracepoints_ptrs, + __stop___tracepoints_ptrs, find_tp, &args); + return args.tp; +} + #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS /* NB: reg/unreg are called while guarded with the tracepoints_mutex */ -- 2.11.0