All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Jessica Yu <jeyu@redhat.com>
Cc: Seth Jennings <sjenning@redhat.com>,
	Jiri Kosina <jikos@kernel.org>, Vojtech Pavlik <vojtech@suse.com>,
	Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 3/4] ftrace/module: remove ftrace module notifier
Date: Tue, 9 Feb 2016 09:45:26 -0600	[thread overview]
Message-ID: <20160209154526.GC10270@treble.redhat.com> (raw)
In-Reply-To: <1454993424-31031-4-git-send-email-jeyu@redhat.com>

On Mon, Feb 08, 2016 at 11:50:23PM -0500, Jessica Yu wrote:
> Remove the ftrace module notifier in favor of directly calling
> ftrace_module_enable() and ftrace_release_mod() in the module loader.
> Hard-coding the function calls directly in the module loader removes
> dependence on the module notifier call chain and provides better
> visibility and control over what gets called when, which is important
> to kernel utilities such as livepatch.
> 
> This fixes a notifier ordering issue in which the ftrace module notifier
> (and hence ftrace_module_enable()) for coming modules was being called
> after klp_module_notify(), which caused livepatch modules to initialize
> incorrectly. This patch removes dependence on the module notifier call
> chain in favor of hard coding the corresponding function calls in the
> module loader. This ensures that ftrace and livepatch code get called in
> the correct order on patch module load and unload.
> 
> Fixes: 5156dca34a3e ("ftrace: Fix the race between ftrace and insmod")
> Signed-off-by: Jessica Yu <jeyu@redhat.com>
> Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
> Reviewed-by: Petr Mladek <pmladek@suse.cz>
> Acked-by: Rusty Russell <rusty@rustcorp.com.au>

Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>

> ---
>  include/linux/ftrace.h |  6 ++++--
>  kernel/module.c        |  5 +++++
>  kernel/trace/ftrace.c  | 36 +-----------------------------------
>  3 files changed, 10 insertions(+), 37 deletions(-)
> 
> diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
> index 81de712..c2b340e 100644
> --- a/include/linux/ftrace.h
> +++ b/include/linux/ftrace.h
> @@ -603,6 +603,7 @@ extern int ftrace_arch_read_dyn_info(char *buf, int size);
>  
>  extern int skip_trace(unsigned long ip);
>  extern void ftrace_module_init(struct module *mod);
> +extern void ftrace_module_enable(struct module *mod);
>  extern void ftrace_release_mod(struct module *mod);
>  
>  extern void ftrace_disable_daemon(void);
> @@ -612,8 +613,9 @@ static inline int skip_trace(unsigned long ip) { return 0; }
>  static inline int ftrace_force_update(void) { return 0; }
>  static inline void ftrace_disable_daemon(void) { }
>  static inline void ftrace_enable_daemon(void) { }
> -static inline void ftrace_release_mod(struct module *mod) {}
> -static inline void ftrace_module_init(struct module *mod) {}
> +static inline void ftrace_module_init(struct module *mod) { }
> +static inline void ftrace_module_enable(struct module *mod) { }
> +static inline void ftrace_release_mod(struct module *mod) { }
>  static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
>  {
>  	return -EINVAL;
> diff --git a/kernel/module.c b/kernel/module.c
> index 77f6791..0bd0077 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -984,6 +984,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
>  		mod->exit();
>  	blocking_notifier_call_chain(&module_notify_list,
>  				     MODULE_STATE_GOING, mod);
> +	ftrace_release_mod(mod);
> +
>  	async_synchronize_full();
>  
>  	/* Store the name of the last unloaded module for diagnostic purposes */
> @@ -3313,6 +3315,7 @@ fail:
>  	module_put(mod);
>  	blocking_notifier_call_chain(&module_notify_list,
>  				     MODULE_STATE_GOING, mod);
> +	ftrace_release_mod(mod);
>  	free_module(mod);
>  	wake_up_all(&module_wq);
>  	return ret;
> @@ -3369,6 +3372,8 @@ out_unlocked:
>  static int prepare_coming_module(struct module *mod)
>  {
>  
> +	ftrace_module_enable(mod);
> +
>  	blocking_notifier_call_chain(&module_notify_list,
>  				     MODULE_STATE_COMING, mod);
>  	return 0;
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index eca592f..57a6eea 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -4961,7 +4961,7 @@ void ftrace_release_mod(struct module *mod)
>  	mutex_unlock(&ftrace_lock);
>  }
>  
> -static void ftrace_module_enable(struct module *mod)
> +void ftrace_module_enable(struct module *mod)
>  {
>  	struct dyn_ftrace *rec;
>  	struct ftrace_page *pg;
> @@ -5038,38 +5038,8 @@ void ftrace_module_init(struct module *mod)
>  	ftrace_process_locs(mod, mod->ftrace_callsites,
>  			    mod->ftrace_callsites + mod->num_ftrace_callsites);
>  }
> -
> -static int ftrace_module_notify(struct notifier_block *self,
> -				unsigned long val, void *data)
> -{
> -	struct module *mod = data;
> -
> -	switch (val) {
> -	case MODULE_STATE_COMING:
> -		ftrace_module_enable(mod);
> -		break;
> -	case MODULE_STATE_GOING:
> -		ftrace_release_mod(mod);
> -		break;
> -	default:
> -		break;
> -	}
> -
> -	return 0;
> -}
> -#else
> -static int ftrace_module_notify(struct notifier_block *self,
> -				unsigned long val, void *data)
> -{
> -	return 0;
> -}
>  #endif /* CONFIG_MODULES */
>  
> -struct notifier_block ftrace_module_nb = {
> -	.notifier_call = ftrace_module_notify,
> -	.priority = INT_MIN,	/* Run after anything that can remove kprobes */
> -};
> -
>  void __init ftrace_init(void)
>  {
>  	extern unsigned long __start_mcount_loc[];
> @@ -5098,10 +5068,6 @@ void __init ftrace_init(void)
>  				  __start_mcount_loc,
>  				  __stop_mcount_loc);
>  
> -	ret = register_module_notifier(&ftrace_module_nb);
> -	if (ret)
> -		pr_warning("Failed to register trace ftrace module exit notifier\n");
> -
>  	set_ftrace_early_filters();
>  
>  	return;
> -- 
> 2.4.3
> 

-- 
Josh

  reply	other threads:[~2016-02-09 15:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-09  4:50 [PATCH v4 0/4] Fix ordering of ftrace/livepatch calls on module load and unload Jessica Yu
2016-02-09  4:50 ` [PATCH v4 1/4] modules: split part of complete_formation() into prepare_coming_module() Jessica Yu
2016-02-09 15:41   ` Josh Poimboeuf
2016-02-10 10:13   ` Miroslav Benes
2016-02-10 12:16   ` Petr Mladek
2016-02-09  4:50 ` [PATCH v4 2/4] modules: set mod->state to MODULE_STATE_GOING before going notifiers are called Jessica Yu
2016-02-09 15:45   ` Josh Poimboeuf
2016-02-10 10:20   ` Miroslav Benes
2016-02-10 12:37   ` Petr Mladek
2016-02-09  4:50 ` [PATCH v4 3/4] ftrace/module: remove ftrace module notifier Jessica Yu
2016-02-09 15:45   ` Josh Poimboeuf [this message]
2016-02-10 10:27   ` Miroslav Benes
2016-02-09  4:50 ` [PATCH v4 4/4] livepatch/module: remove livepatch " Jessica Yu
2016-02-09 15:45   ` Josh Poimboeuf
2016-02-09 23:43   ` Rusty Russell
2016-02-10 10:18     ` Jiri Kosina
2016-02-14 22:59       ` Jiri Kosina
2016-02-15 23:27         ` Josh Poimboeuf
2016-02-15 23:42           ` Jiri Kosina
2016-02-16  0:48             ` Jessica Yu
2016-02-16  8:41               ` Miroslav Benes
2016-02-16 19:51                 ` Jessica Yu
2016-03-29  2:03             ` [PATCH v4 4/4] " Steven Rostedt
2016-02-29  0:30       ` Rusty Russell
2016-03-01  3:00         ` Jessica Yu
2016-02-10 10:34   ` [PATCH v4 4/4] " Miroslav Benes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160209154526.GC10270@treble.redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=jeyu@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mingo@redhat.com \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    --cc=sjenning@redhat.com \
    --cc=vojtech@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.