public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] tracing: kill the no longer needed PITA code
@ 2013-07-31 17:31 Oleg Nesterov
  2013-07-31 17:31 ` [PATCH 1/3] tracing: Kill trace_create_file_ops() and friends Oleg Nesterov
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Oleg Nesterov @ 2013-07-31 17:31 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Frederic Weisbecker, Ingo Molnar, zhangwei(Jovi), linux-kernel

Hello.

Simple cleanups on top of the recent (already applied)
id/filter/format/enable changes.

f_op->owner == mod is no longer needed and can go away.

Oleg.

 kernel/trace/trace_events.c |  207 +++++--------------------------------------
 1 files changed, 22 insertions(+), 185 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] tracing: Kill trace_create_file_ops() and friends
  2013-07-31 17:31 [PATCH 0/3] tracing: kill the no longer needed PITA code Oleg Nesterov
@ 2013-07-31 17:31 ` Oleg Nesterov
  2013-07-31 17:31 ` [PATCH 2/3] tracing: Don't pass file_operations array to event_create_dir() Oleg Nesterov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Oleg Nesterov @ 2013-07-31 17:31 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Frederic Weisbecker, Ingo Molnar, zhangwei(Jovi), linux-kernel

trace_create_file_ops() allocates the copy of id/filter/format/enable
file_operations to set "f_op->owner = mod" for fops_get().

However after the recent changes there is no reason to prevent rmmod
even if one of these files is opened. A file operation can do nothing
but fail after remove_event_file_dir() clears ->i_private for every
file removed by trace_module_remove_events().

Kill "struct ftrace_module_file_ops" and fix the compilation errors.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/trace/trace_events.c |  153 +++----------------------------------------
 1 files changed, 9 insertions(+), 144 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 3450496..5fcd18b 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1679,8 +1679,7 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
 }
 
 struct ftrace_module_file_ops;
-static void __add_event_to_tracers(struct ftrace_event_call *call,
-				   struct ftrace_module_file_ops *file_ops);
+static void __add_event_to_tracers(struct ftrace_event_call *call);
 
 /* Add an additional event_call dynamically */
 int trace_add_event_call(struct ftrace_event_call *call)
@@ -1691,7 +1690,7 @@ int trace_add_event_call(struct ftrace_event_call *call)
 
 	ret = __register_event(call, NULL);
 	if (ret >= 0)
-		__add_event_to_tracers(call, NULL);
+		__add_event_to_tracers(call);
 
 	mutex_unlock(&event_mutex);
 	mutex_unlock(&trace_types_lock);
@@ -1759,100 +1758,21 @@ int trace_remove_event_call(struct ftrace_event_call *call)
 
 #ifdef CONFIG_MODULES
 
-static LIST_HEAD(ftrace_module_file_list);
-
-/*
- * Modules must own their file_operations to keep up with
- * reference counting.
- */
-struct ftrace_module_file_ops {
-	struct list_head		list;
-	struct module			*mod;
-	struct file_operations		id;
-	struct file_operations		enable;
-	struct file_operations		format;
-	struct file_operations		filter;
-};
-
-static struct ftrace_module_file_ops *
-find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod)
-{
-	/*
-	 * As event_calls are added in groups by module,
-	 * when we find one file_ops, we don't need to search for
-	 * each call in that module, as the rest should be the
-	 * same. Only search for a new one if the last one did
-	 * not match.
-	 */
-	if (file_ops && mod == file_ops->mod)
-		return file_ops;
-
-	list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
-		if (file_ops->mod == mod)
-			return file_ops;
-	}
-	return NULL;
-}
-
-static struct ftrace_module_file_ops *
-trace_create_file_ops(struct module *mod)
-{
-	struct ftrace_module_file_ops *file_ops;
-
-	/*
-	 * This is a bit of a PITA. To allow for correct reference
-	 * counting, modules must "own" their file_operations.
-	 * To do this, we allocate the file operations that will be
-	 * used in the event directory.
-	 */
-
-	file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
-	if (!file_ops)
-		return NULL;
-
-	file_ops->mod = mod;
-
-	file_ops->id = ftrace_event_id_fops;
-	file_ops->id.owner = mod;
-
-	file_ops->enable = ftrace_enable_fops;
-	file_ops->enable.owner = mod;
-
-	file_ops->filter = ftrace_event_filter_fops;
-	file_ops->filter.owner = mod;
-
-	file_ops->format = ftrace_event_format_fops;
-	file_ops->format.owner = mod;
-
-	list_add(&file_ops->list, &ftrace_module_file_list);
-
-	return file_ops;
-}
-
 static void trace_module_add_events(struct module *mod)
 {
-	struct ftrace_module_file_ops *file_ops = NULL;
 	struct ftrace_event_call **call, **start, **end;
 
 	start = mod->trace_events;
 	end = mod->trace_events + mod->num_trace_events;
 
-	if (start == end)
-		return;
-
-	file_ops = trace_create_file_ops(mod);
-	if (!file_ops)
-		return;
-
 	for_each_event(call, start, end) {
 		__register_event(*call, mod);
-		__add_event_to_tracers(*call, file_ops);
+		__add_event_to_tracers(*call);
 	}
 }
 
 static void trace_module_remove_events(struct module *mod)
 {
-	struct ftrace_module_file_ops *file_ops;
 	struct ftrace_event_call *call, *p;
 	bool clear_trace = false;
 
@@ -1864,16 +1784,6 @@ static void trace_module_remove_events(struct module *mod)
 			__trace_remove_event_call(call);
 		}
 	}
-
-	/* Now free the file_operations */
-	list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
-		if (file_ops->mod == mod)
-			break;
-	}
-	if (&file_ops->list != &ftrace_module_file_list) {
-		list_del(&file_ops->list);
-		kfree(file_ops);
-	}
 	up_write(&trace_event_sem);
 
 	/*
@@ -1909,62 +1819,22 @@ static int trace_module_notify(struct notifier_block *self,
 	return 0;
 }
 
-static int
-__trace_add_new_mod_event(struct ftrace_event_call *call,
-			  struct trace_array *tr,
-			  struct ftrace_module_file_ops *file_ops)
-{
-	return __trace_add_new_event(call, tr,
-				     &file_ops->id, &file_ops->enable,
-				     &file_ops->filter, &file_ops->format);
-}
-
 #else
-static inline struct ftrace_module_file_ops *
-find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod)
-{
-	return NULL;
-}
 static inline int trace_module_notify(struct notifier_block *self,
 				      unsigned long val, void *data)
 {
 	return 0;
 }
-static inline int
-__trace_add_new_mod_event(struct ftrace_event_call *call,
-			  struct trace_array *tr,
-			  struct ftrace_module_file_ops *file_ops)
-{
-	return -ENODEV;
-}
 #endif /* CONFIG_MODULES */
 
 /* Create a new event directory structure for a trace directory. */
 static void
 __trace_add_event_dirs(struct trace_array *tr)
 {
-	struct ftrace_module_file_ops *file_ops = NULL;
 	struct ftrace_event_call *call;
 	int ret;
 
 	list_for_each_entry(call, &ftrace_events, list) {
-		if (call->mod) {
-			/*
-			 * Directories for events by modules need to
-			 * keep module ref counts when opened (as we don't
-			 * want the module to disappear when reading one
-			 * of these files). The file_ops keep account of
-			 * the module ref count.
-			 */
-			file_ops = find_ftrace_file_ops(file_ops, call->mod);
-			if (!file_ops)
-				continue; /* Warn? */
-			ret = __trace_add_new_mod_event(call, tr, file_ops);
-			if (ret < 0)
-				pr_warning("Could not create directory for event %s\n",
-					   call->name);
-			continue;
-		}
 		ret = __trace_add_new_event(call, tr,
 					    &ftrace_event_id_fops,
 					    &ftrace_enable_fops,
@@ -2322,21 +2192,16 @@ __trace_remove_event_dirs(struct trace_array *tr)
 		remove_event_file_dir(file);
 }
 
-static void
-__add_event_to_tracers(struct ftrace_event_call *call,
-		       struct ftrace_module_file_ops *file_ops)
+static void __add_event_to_tracers(struct ftrace_event_call *call)
 {
 	struct trace_array *tr;
 
 	list_for_each_entry(tr, &ftrace_trace_arrays, list) {
-		if (file_ops)
-			__trace_add_new_mod_event(call, tr, file_ops);
-		else
-			__trace_add_new_event(call, tr,
-					      &ftrace_event_id_fops,
-					      &ftrace_enable_fops,
-					      &ftrace_event_filter_fops,
-					      &ftrace_event_format_fops);
+		__trace_add_new_event(call, tr,
+				      &ftrace_event_id_fops,
+				      &ftrace_enable_fops,
+				      &ftrace_event_filter_fops,
+				      &ftrace_event_format_fops);
 	}
 }
 
-- 
1.5.5.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] tracing: Don't pass file_operations array to event_create_dir()
  2013-07-31 17:31 [PATCH 0/3] tracing: kill the no longer needed PITA code Oleg Nesterov
  2013-07-31 17:31 ` [PATCH 1/3] tracing: Kill trace_create_file_ops() and friends Oleg Nesterov
@ 2013-07-31 17:31 ` Oleg Nesterov
  2013-07-31 17:31 ` [PATCH 3/3] tracing: Kill the !CONFIG_MODULES code in trace_events.c Oleg Nesterov
  2013-07-31 17:48 ` [PATCH 0/3] tracing: kill the no longer needed PITA code Steven Rostedt
  3 siblings, 0 replies; 8+ messages in thread
From: Oleg Nesterov @ 2013-07-31 17:31 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Frederic Weisbecker, Ingo Molnar, zhangwei(Jovi), linux-kernel

Now that event_create_dir() and __trace_add_new_event() always
use the same file_operations we can kill these arguments and
simplify the code.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/trace/trace_events.c |   46 +++++++++++-------------------------------
 1 files changed, 12 insertions(+), 34 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 5fcd18b..77ef314 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1485,12 +1485,7 @@ event_subsystem_dir(struct trace_array *tr, const char *name,
 }
 
 static int
-event_create_dir(struct dentry *parent,
-		 struct ftrace_event_file *file,
-		 const struct file_operations *id,
-		 const struct file_operations *enable,
-		 const struct file_operations *filter,
-		 const struct file_operations *format)
+event_create_dir(struct dentry *parent, struct ftrace_event_file *file)
 {
 	struct ftrace_event_call *call = file->event_call;
 	struct trace_array *tr = file->tr;
@@ -1518,12 +1513,13 @@ event_create_dir(struct dentry *parent,
 
 	if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
 		trace_create_file("enable", 0644, file->dir, file,
-				  enable);
+				  &ftrace_enable_fops);
 
 #ifdef CONFIG_PERF_EVENTS
 	if (call->event.type && call->class->reg)
 		trace_create_file("id", 0444, file->dir,
-				  (void *)(long)call->event.type, id);
+				  (void *)(long)call->event.type,
+				  &ftrace_event_id_fops);
 #endif
 
 	/*
@@ -1540,10 +1536,10 @@ event_create_dir(struct dentry *parent,
 		}
 	}
 	trace_create_file("filter", 0644, file->dir, call,
-			  filter);
+			  &ftrace_event_filter_fops);
 
 	trace_create_file("format", 0444, file->dir, call,
-			  format);
+			  &ftrace_event_format_fops);
 
 	return 0;
 }
@@ -1644,12 +1640,7 @@ trace_create_new_event(struct ftrace_event_call *call,
 
 /* Add an event to a trace directory */
 static int
-__trace_add_new_event(struct ftrace_event_call *call,
-		      struct trace_array *tr,
-		      const struct file_operations *id,
-		      const struct file_operations *enable,
-		      const struct file_operations *filter,
-		      const struct file_operations *format)
+__trace_add_new_event(struct ftrace_event_call *call, struct trace_array *tr)
 {
 	struct ftrace_event_file *file;
 
@@ -1657,7 +1648,7 @@ __trace_add_new_event(struct ftrace_event_call *call,
 	if (!file)
 		return -ENOMEM;
 
-	return event_create_dir(tr->event_dir, file, id, enable, filter, format);
+	return event_create_dir(tr->event_dir, file);
 }
 
 /*
@@ -1835,11 +1826,7 @@ __trace_add_event_dirs(struct trace_array *tr)
 	int ret;
 
 	list_for_each_entry(call, &ftrace_events, list) {
-		ret = __trace_add_new_event(call, tr,
-					    &ftrace_event_id_fops,
-					    &ftrace_enable_fops,
-					    &ftrace_event_filter_fops,
-					    &ftrace_event_format_fops);
+		ret = __trace_add_new_event(call, tr);
 		if (ret < 0)
 			pr_warning("Could not create directory for event %s\n",
 				   call->name);
@@ -2147,11 +2134,7 @@ __trace_early_add_event_dirs(struct trace_array *tr)
 
 
 	list_for_each_entry(file, &tr->events, list) {
-		ret = event_create_dir(tr->event_dir, file,
-				       &ftrace_event_id_fops,
-				       &ftrace_enable_fops,
-				       &ftrace_event_filter_fops,
-				       &ftrace_event_format_fops);
+		ret = event_create_dir(tr->event_dir, file);
 		if (ret < 0)
 			pr_warning("Could not create directory for event %s\n",
 				   file->event_call->name);
@@ -2196,13 +2179,8 @@ static void __add_event_to_tracers(struct ftrace_event_call *call)
 {
 	struct trace_array *tr;
 
-	list_for_each_entry(tr, &ftrace_trace_arrays, list) {
-		__trace_add_new_event(call, tr,
-				      &ftrace_event_id_fops,
-				      &ftrace_enable_fops,
-				      &ftrace_event_filter_fops,
-				      &ftrace_event_format_fops);
-	}
+	list_for_each_entry(tr, &ftrace_trace_arrays, list)
+		__trace_add_new_event(call, tr);
 }
 
 static struct notifier_block trace_module_nb = {
-- 
1.5.5.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] tracing: Kill the !CONFIG_MODULES code in trace_events.c
  2013-07-31 17:31 [PATCH 0/3] tracing: kill the no longer needed PITA code Oleg Nesterov
  2013-07-31 17:31 ` [PATCH 1/3] tracing: Kill trace_create_file_ops() and friends Oleg Nesterov
  2013-07-31 17:31 ` [PATCH 2/3] tracing: Don't pass file_operations array to event_create_dir() Oleg Nesterov
@ 2013-07-31 17:31 ` Oleg Nesterov
  2013-07-31 17:48 ` [PATCH 0/3] tracing: kill the no longer needed PITA code Steven Rostedt
  3 siblings, 0 replies; 8+ messages in thread
From: Oleg Nesterov @ 2013-07-31 17:31 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Frederic Weisbecker, Ingo Molnar, zhangwei(Jovi), linux-kernel

Move trace_module_nb under CONFIG_MODULES and kill the dummy
trace_module_notify(). Imho it doesn't make sense to define
"struct notifier_block" and its .notifier_call just to avoid
"ifdef" in event_trace_init(), and all other !CONFIG_MODULES
code has already gone away.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/trace/trace_events.c |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 77ef314..6695970 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1810,12 +1810,10 @@ static int trace_module_notify(struct notifier_block *self,
 	return 0;
 }
 
-#else
-static inline int trace_module_notify(struct notifier_block *self,
-				      unsigned long val, void *data)
-{
-	return 0;
-}
+static struct notifier_block trace_module_nb = {
+	.notifier_call = trace_module_notify,
+	.priority = 0,
+};
 #endif /* CONFIG_MODULES */
 
 /* Create a new event directory structure for a trace directory. */
@@ -2183,11 +2181,6 @@ static void __add_event_to_tracers(struct ftrace_event_call *call)
 		__trace_add_new_event(call, tr);
 }
 
-static struct notifier_block trace_module_nb = {
-	.notifier_call = trace_module_notify,
-	.priority = 0,
-};
-
 extern struct ftrace_event_call *__start_ftrace_events[];
 extern struct ftrace_event_call *__stop_ftrace_events[];
 
@@ -2392,10 +2385,11 @@ static __init int event_trace_init(void)
 	if (ret)
 		return ret;
 
+#ifdef CONFIG_MODULES
 	ret = register_module_notifier(&trace_module_nb);
 	if (ret)
 		pr_warning("Failed to register trace events module notifier\n");
-
+#endif
 	return 0;
 }
 early_initcall(event_trace_memsetup);
-- 
1.5.5.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] tracing: kill the no longer needed PITA code
  2013-07-31 17:31 [PATCH 0/3] tracing: kill the no longer needed PITA code Oleg Nesterov
                   ` (2 preceding siblings ...)
  2013-07-31 17:31 ` [PATCH 3/3] tracing: Kill the !CONFIG_MODULES code in trace_events.c Oleg Nesterov
@ 2013-07-31 17:48 ` Steven Rostedt
  2013-08-11 17:49   ` Oleg Nesterov
  3 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2013-07-31 17:48 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Masami Hiramatsu, Frederic Weisbecker, Ingo Molnar,
	zhangwei(Jovi), linux-kernel

On Wed, 2013-07-31 at 19:31 +0200, Oleg Nesterov wrote:
> Hello.
> 
> Simple cleanups on top of the recent (already applied)
> id/filter/format/enable changes.
> 
> f_op->owner == mod is no longer needed and can go away.
> 

This patch set is not needed for 3.11. I'll be holding off my review
until I have all the 3.11 patches settled.

Thanks,

-- Steve



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] tracing: kill the no longer needed PITA code
  2013-07-31 17:48 ` [PATCH 0/3] tracing: kill the no longer needed PITA code Steven Rostedt
@ 2013-08-11 17:49   ` Oleg Nesterov
  2013-08-12  0:20     ` Steven Rostedt
  0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2013-08-11 17:49 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Masami Hiramatsu, Frederic Weisbecker, Ingo Molnar,
	zhangwei(Jovi), linux-kernel

On 07/31, Steven Rostedt wrote:
>
> On Wed, 2013-07-31 at 19:31 +0200, Oleg Nesterov wrote:
> > Hello.
> >
> > Simple cleanups on top of the recent (already applied)
> > id/filter/format/enable changes.
> >
> > f_op->owner == mod is no longer needed and can go away.
> >
>
> This patch set is not needed for 3.11. I'll be holding off my review
> until I have all the 3.11 patches settled.

It seems that you have no more 3.11 patches.

Should I resend this series?

Oleg.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] tracing: kill the no longer needed PITA code
  2013-08-11 17:49   ` Oleg Nesterov
@ 2013-08-12  0:20     ` Steven Rostedt
  2013-08-12 17:16       ` Oleg Nesterov
  0 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2013-08-12  0:20 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Masami Hiramatsu, Frederic Weisbecker, Ingo Molnar,
	zhangwei(Jovi), linux-kernel

On Sun, 11 Aug 2013 19:49:29 +0200
Oleg Nesterov <oleg@redhat.com> wrote:


> It seems that you have no more 3.11 patches.
> 
> Should I resend this series?

Only if it changed. I'll be looking into 3.12 patches come Monday.

-- Steve


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] tracing: kill the no longer needed PITA code
  2013-08-12  0:20     ` Steven Rostedt
@ 2013-08-12 17:16       ` Oleg Nesterov
  0 siblings, 0 replies; 8+ messages in thread
From: Oleg Nesterov @ 2013-08-12 17:16 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Masami Hiramatsu, Frederic Weisbecker, Ingo Molnar,
	zhangwei(Jovi), linux-kernel

On 08/11, Steven Rostedt wrote:
>
> On Sun, 11 Aug 2013 19:49:29 +0200
> Oleg Nesterov <oleg@redhat.com> wrote:
>
> > It seems that you have no more 3.11 patches.
> >
> > Should I resend this series?
>
> Only if it changed.

No, they still apply cleanly, just the offsets differ a bit.

> I'll be looking into 3.12 patches come Monday.

Great, thanks.

Oleg.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-08-12 17:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-31 17:31 [PATCH 0/3] tracing: kill the no longer needed PITA code Oleg Nesterov
2013-07-31 17:31 ` [PATCH 1/3] tracing: Kill trace_create_file_ops() and friends Oleg Nesterov
2013-07-31 17:31 ` [PATCH 2/3] tracing: Don't pass file_operations array to event_create_dir() Oleg Nesterov
2013-07-31 17:31 ` [PATCH 3/3] tracing: Kill the !CONFIG_MODULES code in trace_events.c Oleg Nesterov
2013-07-31 17:48 ` [PATCH 0/3] tracing: kill the no longer needed PITA code Steven Rostedt
2013-08-11 17:49   ` Oleg Nesterov
2013-08-12  0:20     ` Steven Rostedt
2013-08-12 17:16       ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox