Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3190365ybg; Fri, 25 Oct 2019 00:01:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwz+BXb/JSNJxY60ril9s7/EkvQnN/gP1JN8PyRwrGm3QD6jIKJZ59rvrovVteB3+fZNwWe X-Received: by 2002:a17:906:3e41:: with SMTP id t1mr1934516eji.103.1571986861613; Fri, 25 Oct 2019 00:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571986861; cv=none; d=google.com; s=arc-20160816; b=JbCqLpS6ftCBCuK5/2noBpO2aFePgPH9MQZWvx9LMArYuJ9EpOAJQBizUYSnVvMu3R pbAOS6pL7XU67E+Rt8739b0YJh7WFON9OVF1+FHDTgW+2Sw//4MDAqXEmO1Be04HW54y l+JdZA09aQnbJls94xRRc/RCKmVwIUH7dtc4yNf37uyhkXvFdzOqcGvDfLoKLOwPdxR7 RnQfVApLVWX+aG7D9EWEaaOD8NisYrTxw+aLcuCqBhR1uF5xbfO3lLg3hho9lYPNmvC9 eAdsJ2KSGIVCvbIfwVvbRpDcUVZtwWw0EYcTVKKKYfb+EuYMQyj1RiHS1jkO8tNS6F5W aPIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2wjWXnfmi/lTkSLWwKyZUWPMN4Uje8x22OKVQg74ivk=; b=TIYwT+86wafCiXhcBngfK3p2VJz4E6pvwTGCH/tFadc5DXfWzepE/HlLNOoDWUtDpA rxFkGMSMj13uTT2GnA4qwL6kUjFZ2aA799PVYa0HEuFVbdN9W1WyIc96qCMT7baHeNwP 6Hhrx/CGAc7/FTNi9fOfJ66r+MxDlAN3zcZoq8eAuNo7AagsGVLJCnvVjHlbQ8CjW0z7 0LEN4H6LEug5Lbam5T9HZXJgSY3x9Fop7ZjFvo72TUH0LjXJy06DCAJB4GvB/KCJl754 IMGtdTA1T6dDp6dRyQ4eVbRb70M/tAXBjOShfW88XcQaXh+JPCHDFaqLdCaPRpC9xIMw t6lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=TLFo2ofc; 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 ci9si652227ejb.60.2019.10.25.00.00.37; Fri, 25 Oct 2019 00:01:01 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=TLFo2ofc; 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 S2405826AbfJXKRW (ORCPT + 99 others); Thu, 24 Oct 2019 06:17:22 -0400 Received: from merlin.infradead.org ([205.233.59.134]:56030 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392611AbfJXKRV (ORCPT ); Thu, 24 Oct 2019 06:17:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2wjWXnfmi/lTkSLWwKyZUWPMN4Uje8x22OKVQg74ivk=; b=TLFo2ofco6nF7FVRWwmBtThyz NlF17gVU/LknAkHLbHW32DdtkQS3CiDQFPJhalKVrZZ3T/sTQ72MotFfz7igqWzaxzBdiBTSmpmXl esa6mKLQdVPkdSiBNMlXek95MKVJUqEK8mvTJdtQbh65h6fjZJuOfi/8MyGC6jrM25fIzFLrtEH99 E8Npcsn+aLHIboE2/HJxCAqDJQo7bkazuO0wb7tjKtwBxiN6pxPvhmDdjr5U/AagAL6ZezYT7zvpW HPKDQGW9I+TXQ5CkHG39efsmt/mMr+zasbd3JrSIKRKDlcgUAg1mKVq54jAIXglz7Ex+MWstenTiJ ZcL3JU7ZA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNaA9-0006Uj-Ge; Thu, 24 Oct 2019 10:17:03 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4950F3006E3; Thu, 24 Oct 2019 12:15:11 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 97E612100B874; Thu, 24 Oct 2019 12:16:09 +0200 (CEST) Date: Thu, 24 Oct 2019 12:16:09 +0200 From: Peter Zijlstra To: Steven Rostedt Cc: x86@kernel.org, linux-kernel@vger.kernel.org, mhiramat@kernel.org, bristot@redhat.com, jbaron@akamai.com, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, namit@vmware.com, hpa@zytor.com, luto@kernel.org, ard.biesheuvel@linaro.org, jpoimboe@redhat.com, jeyu@kernel.org Subject: Re: [PATCH v4 15/16] module: Move where we mark modules RO,X Message-ID: <20191024101609.GA4131@hirez.programming.kicks-ass.net> References: <20191018073525.768931536@infradead.org> <20191018074634.801435443@infradead.org> <20191021222110.49044eb5@oasis.local.home> <20191022202401.GO1817@hirez.programming.kicks-ass.net> <20191023145245.53c75d70@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191023145245.53c75d70@gandalf.local.home> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 23, 2019 at 02:52:45PM -0400, Steven Rostedt wrote: > After applying this series and this patch I triggered this: Bah, I hate C. (also for some reason I had KPROBE_EVENTS disabled, when I enabled it it failed on boot due to selftests) this one seems to boot and survive your selftests thing (that takes for bloody ever to run). --- Subject: ftrace: Rework event_create_dir() Rework event_create_dir() to use an array of static data instead of function pointers where possible. The problem is that it would call the function pointer on module load before parse_args(), possibly even before jump_labels were initialized. Luckily the generated functions don't use jump_labels but it still seems fragile. It also gets in the way of changing when we make the module map executable. The generated function are basically calling trace_define_field() with a bunch of static arguments. So instead of a function, capture these arguments in a static array, avoiding the function call. Now there are a number of cases where the fields are dynamic (syscall arguments, kprobes and uprobes), in which case a static array does not work, for these we preserve the function call. Luckily all these cases are not related to modules and so we can retain the function call for them. Signed-off-by: Peter Zijlstra (Intel) --- fs/xfs/xfs_trace.h | 4 +- include/linux/trace_events.h | 18 ++++++- include/trace/events/filemap.h | 2 +- include/trace/trace_events.h | 64 ++++++++----------------- kernel/trace/trace.h | 31 ++++++------ kernel/trace/trace_entries.h | 66 +++++++------------------ kernel/trace/trace_events.c | 20 +++++++- kernel/trace/trace_export.c | 106 +++++++++++++++-------------------------- kernel/trace/trace_kprobe.c | 16 ++++++- kernel/trace/trace_syscalls.c | 50 ++++++++----------- kernel/trace/trace_uprobe.c | 9 +++- 11 files changed, 172 insertions(+), 214 deletions(-) diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index eaae275ed430..53c5485cf2a1 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -218,8 +218,8 @@ DECLARE_EVENT_CLASS(xfs_bmap_class, TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_ino_t, ino) - __field(void *, leaf); - __field(int, pos); + __field(void *, leaf) + __field(int, pos) __field(xfs_fileoff_t, startoff) __field(xfs_fsblock_t, startblock) __field(xfs_filblks_t, blockcount) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 30a8cdcfd4a4..a379255c14a9 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -187,6 +187,22 @@ enum trace_reg { struct trace_event_call; +#define TRACE_FUNCTION_TYPE ((const char *)~0UL) + +struct trace_event_fields { + const char *type; + union { + struct { + const char *name; + const int size; + const int align; + const int is_signed; + const int filter_type; + }; + int (*define_fields)(struct trace_event_call *); + }; +}; + struct trace_event_class { const char *system; void *probe; @@ -195,7 +211,7 @@ struct trace_event_class { #endif int (*reg)(struct trace_event_call *event, enum trace_reg type, void *data); - int (*define_fields)(struct trace_event_call *); + struct trace_event_fields *fields_array; struct list_head *(*get_fields)(struct trace_event_call *); struct list_head fields; int (*raw_init)(struct trace_event_call *); diff --git a/include/trace/events/filemap.h b/include/trace/events/filemap.h index ee05db7ee8d2..796053e162d2 100644 --- a/include/trace/events/filemap.h +++ b/include/trace/events/filemap.h @@ -85,7 +85,7 @@ TRACE_EVENT(file_check_and_advance_wb_err, TP_ARGS(file, old), TP_STRUCT__entry( - __field(struct file *, file); + __field(struct file *, file) __field(unsigned long, i_ino) __field(dev_t, s_dev) __field(errseq_t, old) diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h index 4ecdfe2e3580..ca1d2e745a3f 100644 --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -394,22 +394,16 @@ static struct trace_event_functions trace_event_type_funcs_##call = { \ #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #undef __field_ext -#define __field_ext(type, item, filter_type) \ - ret = trace_define_field(event_call, #type, #item, \ - offsetof(typeof(field), item), \ - sizeof(field.item), \ - is_signed_type(type), filter_type); \ - if (ret) \ - return ret; +#define __field_ext(_type, _item, _filter_type) { \ + .type = #_type, .name = #_item, \ + .size = sizeof(_type), .align = __alignof__(_type), \ + .is_signed = is_signed_type(_type), .filter_type = _filter_type }, #undef __field_struct_ext -#define __field_struct_ext(type, item, filter_type) \ - ret = trace_define_field(event_call, #type, #item, \ - offsetof(typeof(field), item), \ - sizeof(field.item), \ - 0, filter_type); \ - if (ret) \ - return ret; +#define __field_struct_ext(_type, _item, _filter_type) { \ + .type = #_type, .name = #_item, \ + .size = sizeof(_type), .align = __alignof__(_type), \ + 0, .filter_type = _filter_type }, #undef __field #define __field(type, item) __field_ext(type, item, FILTER_OTHER) @@ -418,25 +412,16 @@ static struct trace_event_functions trace_event_type_funcs_##call = { \ #define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER) #undef __array -#define __array(type, item, len) \ - do { \ - char *type_str = #type"["__stringify(len)"]"; \ - BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ - BUILD_BUG_ON(len <= 0); \ - ret = trace_define_field(event_call, type_str, #item, \ - offsetof(typeof(field), item), \ - sizeof(field.item), \ - is_signed_type(type), FILTER_OTHER); \ - if (ret) \ - return ret; \ - } while (0); +#define __array(_type, _item, _len) { \ + .type = #_type"["__stringify(_len)"]", .name = #_item, \ + .size = sizeof(_type[_len]), .align = __alignof__(_type), \ + .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, #undef __dynamic_array -#define __dynamic_array(type, item, len) \ - ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \ - offsetof(typeof(field), __data_loc_##item), \ - sizeof(field.__data_loc_##item), \ - is_signed_type(type), FILTER_OTHER); +#define __dynamic_array(_type, _item, _len) { \ + .type = "__data_loc " #_type "[]", .name = #_item, \ + .size = 4, .align = 4, \ + .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, #undef __string #define __string(item, src) __dynamic_array(char, item, -1) @@ -446,16 +431,9 @@ static struct trace_event_functions trace_event_type_funcs_##call = { \ #undef DECLARE_EVENT_CLASS #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ -static int notrace __init \ -trace_event_define_fields_##call(struct trace_event_call *event_call) \ -{ \ - struct trace_event_raw_##call field; \ - int ret; \ - \ - tstruct; \ - \ - return ret; \ -} +static struct trace_event_fields trace_event_fields_##call[] = { \ + tstruct \ + {} }; #undef DEFINE_EVENT #define DEFINE_EVENT(template, name, proto, args) @@ -613,7 +591,7 @@ static inline notrace int trace_event_get_offsets_##call( \ * * static struct trace_event_class __used event_class_