Received: by 10.223.185.116 with SMTP id b49csp6981129wrg; Wed, 28 Feb 2018 20:23:24 -0800 (PST) X-Google-Smtp-Source: AG47ELskvuZ1f7ZbNiF58iSLWryKi5RHP9T7SgYKhG/ppR6GpJCnml4Z/4u7cF3WNrQzm5gnUr3l X-Received: by 10.98.196.199 with SMTP id h68mr588134pfk.42.1519878204502; Wed, 28 Feb 2018 20:23:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519878204; cv=none; d=google.com; s=arc-20160816; b=gI1wxFTUZn98yobAIldN3wGqJjL5vPBZoPrWwS7xE7q27FCU/Sxi2Go2p1Ve+/eVJv p3BuZlbUznoLmAh6t5pVPqe00U3gT8ea8V0EMDjPIA4Uk1BimS25S71kop28JQA++xuf K5taJek2eBkN9Ai64qCJXBCbTpvfhPUp32gbwBE0WMslc75zCrfbABW7mKIFovznIeHu uS14H/Z/ikVOca90r7E2veo+Ps+Mn+Wzawf0mMGVpOQhIx7h05rGiev+/vXPpVQSqPb3 6ng0GvObeFvhQoWjM/q/PvV/sI9X4yH3fWHuXnI63qITdZ4nE6FAC3JvITl1kD7QMdt/ 7Jpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix :arc-authentication-results; bh=semErl1PfuE+SeZMJVMySQa0tx4TSmCHXPL9rEgd3a8=; b=UNiwzcWRGu4CNTAiNjRfxZ1fJ82gl4F8HE64M8tIuX5iThC4kW5YpvvYAP3WfY1+8j /fhxX0ko/R3ONVXKYt6zP/0sqxat0WYAiZrNl5bNQjw47GnuP4P2iT01RDNT31UaJwV4 XV3KTPh72ObeyMm7nqjdPnTfie/XIXGSNtmK1pEY+gGNGV/6wTATz7vSL5GRObu01Q3X TEOH7noUDAUtmWqx/aaZhMVfgUxWxRzvEWT9DWf8bXg9XUwB5/Gf1VZ/L0IE3pqVuukh /n6RNfrUugNmkVoP0AD9vwc1NgwksyhsyNuLeB9mfHdLUAa4LuZP57u+iTw58Gs/H5qG Z56g== 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 b10si1948647pgn.140.2018.02.28.20.23.09; Wed, 28 Feb 2018 20:23:24 -0800 (PST) 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 S965971AbeCAEVo (ORCPT + 99 others); Wed, 28 Feb 2018 23:21:44 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:48966 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965826AbeCAET7 (ORCPT ); Wed, 28 Feb 2018 23:19:59 -0500 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w214I89b027983 for ; Wed, 28 Feb 2018 20:19:59 -0800 Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2ge81vrcbp-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Feb 2018 20:19:58 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB07.TheFacebook.com (192.168.16.17) with Microsoft SMTP Server id 14.3.361.1; Wed, 28 Feb 2018 20:19:57 -0800 Received: by devbig500.prn1.facebook.com (Postfix, from userid 572438) id 578F52181285; Wed, 28 Feb 2018 20:19:57 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Alexei Starovoitov Smtp-Origin-Hostname: devbig500.prn1.facebook.com To: CC: , , , , , , , , Smtp-Origin-Cluster: prn1c29 Subject: [PATCH bpf-next 2/5] tracepoint: compute num_args at build time Date: Wed, 28 Feb 2018 20:19:54 -0800 Message-ID: <20180301041957.399230-3-ast@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180301041957.399230-1-ast@kernel.org> References: <20180301041957.399230-1-ast@kernel.org> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-01_02:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org add fancy macro to compute number of arguments passed into tracepoint at compile time and store it as part of 'struct tracepoint'. The number is necessary to check safety of bpf program access that is coming in subsequent patch. for_each_tracepoint_range() api has no users inside the kernel. Make it more useful with ability to stop for_each() loop depending via callback return value. In such form it's used in subsequent patch. Signed-off-by: Alexei Starovoitov --- include/linux/tracepoint-defs.h | 1 + include/linux/tracepoint.h | 32 +++++++++++++++++++++++--------- include/trace/define_trace.h | 14 +++++++------- kernel/tracepoint.c | 27 ++++++++++++++++----------- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/include/linux/tracepoint-defs.h b/include/linux/tracepoint-defs.h index 64ed7064f1fa..39a283c61c51 100644 --- a/include/linux/tracepoint-defs.h +++ b/include/linux/tracepoint-defs.h @@ -33,6 +33,7 @@ struct tracepoint { int (*regfunc)(void); void (*unregfunc)(void); struct tracepoint_func __rcu *funcs; + u32 num_args; }; #endif diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index c94f466d57ef..b1676e53bb23 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -40,9 +40,19 @@ tracepoint_probe_register_prio(struct tracepoint *tp, void *probe, void *data, int prio); extern int 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); + +#ifdef CONFIG_TRACEPOINTS +void * +for_each_kernel_tracepoint(void *(*fct)(struct tracepoint *tp, void *priv), + void *priv); +#else +static inline void * +for_each_kernel_tracepoint(void *(*fct)(struct tracepoint *tp, void *priv), + void *priv) +{ + return NULL; +} +#endif #ifdef CONFIG_MODULES struct tp_module { @@ -225,23 +235,27 @@ extern void syscall_unregfunc(void); return static_key_false(&__tracepoint_##name.key); \ } +#define ___FN_COUNT(fn,n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n,...) fn##n +#define __FN_COUNT(fn,...) ___FN_COUNT(fn,##__VA_ARGS__,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0) +#define __COUNT(...) __FN_COUNT(/**/,##__VA_ARGS__) + /* * We have no guarantee that gcc and the linker won't up-align the tracepoint * structures, so we create an array of pointers that will be used for iteration * on the tracepoints. */ -#define DEFINE_TRACE_FN(name, reg, unreg) \ +#define DEFINE_TRACE_FN(name, reg, unreg, num_args) \ static const char __tpstrtab_##name[] \ __attribute__((section("__tracepoints_strings"))) = #name; \ struct tracepoint __tracepoint_##name \ __attribute__((section("__tracepoints"))) = \ - { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\ + { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL, num_args };\ static struct tracepoint * const __tracepoint_ptr_##name __used \ __attribute__((section("__tracepoints_ptrs"))) = \ &__tracepoint_##name; -#define DEFINE_TRACE(name) \ - DEFINE_TRACE_FN(name, NULL, NULL); +#define DEFINE_TRACE(name, num_args) \ + DEFINE_TRACE_FN(name, NULL, NULL, num_args); #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \ EXPORT_SYMBOL_GPL(__tracepoint_##name) @@ -275,8 +289,8 @@ extern void syscall_unregfunc(void); return false; \ } -#define DEFINE_TRACE_FN(name, reg, unreg) -#define DEFINE_TRACE(name) +#define DEFINE_TRACE_FN(name, reg, unreg, num_args) +#define DEFINE_TRACE(name, num_args) #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) #define EXPORT_TRACEPOINT_SYMBOL(name) diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h index d9e3d4aa3f6e..c040eda95d41 100644 --- a/include/trace/define_trace.h +++ b/include/trace/define_trace.h @@ -25,7 +25,7 @@ #undef TRACE_EVENT #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ - DEFINE_TRACE(name) + DEFINE_TRACE(name, __COUNT(args)) #undef TRACE_EVENT_CONDITION #define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \ @@ -39,24 +39,24 @@ #undef TRACE_EVENT_FN #define TRACE_EVENT_FN(name, proto, args, tstruct, \ assign, print, reg, unreg) \ - DEFINE_TRACE_FN(name, reg, unreg) + DEFINE_TRACE_FN(name, reg, unreg, __COUNT(args)) #undef TRACE_EVENT_FN_COND #define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \ assign, print, reg, unreg) \ - DEFINE_TRACE_FN(name, reg, unreg) + DEFINE_TRACE_FN(name, reg, unreg, __COUNT(args)) #undef DEFINE_EVENT #define DEFINE_EVENT(template, name, proto, args) \ - DEFINE_TRACE(name) + DEFINE_TRACE(name, __COUNT(args)) #undef DEFINE_EVENT_FN #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \ - DEFINE_TRACE_FN(name, reg, unreg) + DEFINE_TRACE_FN(name, reg, unreg, __COUNT(args)) #undef DEFINE_EVENT_PRINT #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ - DEFINE_TRACE(name) + DEFINE_TRACE(name, __COUNT(args)) #undef DEFINE_EVENT_CONDITION #define DEFINE_EVENT_CONDITION(template, name, proto, args, cond) \ @@ -64,7 +64,7 @@ #undef DECLARE_TRACE #define DECLARE_TRACE(name, proto, args) \ - DEFINE_TRACE(name) + DEFINE_TRACE(name, __COUNT(args)) #undef TRACE_INCLUDE #undef __TRACE_INCLUDE diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 671b13457387..3f2dc5738c2b 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -502,17 +502,22 @@ static __init int init_tracepoints(void) __initcall(init_tracepoints); #endif /* CONFIG_MODULES */ -static void for_each_tracepoint_range(struct tracepoint * const *begin, - struct tracepoint * const *end, - void (*fct)(struct tracepoint *tp, void *priv), - void *priv) +static void *for_each_tracepoint_range(struct tracepoint * const *begin, + struct tracepoint * const *end, + void *(*fct)(struct tracepoint *tp, void *priv), + void *priv) { struct tracepoint * const *iter; + void *ret; if (!begin) - return; - for (iter = begin; iter < end; iter++) - fct(*iter, priv); + return NULL; + for (iter = begin; iter < end; iter++) { + ret = fct(*iter, priv); + if (ret) + return ret; + } + return NULL; } /** @@ -520,11 +525,11 @@ static void for_each_tracepoint_range(struct tracepoint * const *begin, * @fct: callback * @priv: private data */ -void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), - void *priv) +void *for_each_kernel_tracepoint(void *(*fct)(struct tracepoint *tp, void *priv), + void *priv) { - for_each_tracepoint_range(__start___tracepoints_ptrs, - __stop___tracepoints_ptrs, fct, priv); + return for_each_tracepoint_range(__start___tracepoints_ptrs, + __stop___tracepoints_ptrs, fct, priv); } EXPORT_SYMBOL_GPL(for_each_kernel_tracepoint); -- 2.9.5