On 10/14/19 4:29 PM, Miroslav Benes wrote:
> Livepatch uses ftrace for redirection to new patched functions. It means
> that if ftrace is disabled, all live patched functions are disabled as
> well. Toggling global 'ftrace_enabled' sysctl thus affect it directly.
> It is not a problem per se, because only administrator can set sysctl
> values, but it still may be surprising.
> 
> Introduce PERMANENT ftrace_ops flag to amend this. If the
> FTRACE_OPS_FL_PERMANENT is set on any ftrace ops, the tracing cannot be
> disabled by disabling ftrace_enabled. Equally, a callback with the flag
> set cannot be registered if ftrace_enabled is disabled.
> 
> Signed-off-by: Miroslav Benes <mbe...@suse.cz>

The patch looks good to me. A minor typo in flag description below.

Reviewed-by: Kamalesh Babulal <kamal...@linux.vnet.ibm.com>

[...]
> diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
> index 8a8cb3c401b2..c2cad29dc557 100644
> --- a/include/linux/ftrace.h
> +++ b/include/linux/ftrace.h
> @@ -142,6 +142,8 @@ ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
>   * PID     - Is affected by set_ftrace_pid (allows filtering on those pids)
>   * RCU     - Set when the ops can only be called when RCU is watching.
>   * TRACE_ARRAY - The ops->private points to a trace_array descriptor.
> + * PERMAMENT - Set when the ops is permanent and should not be affected by
> + *             ftrace_enabled.
>   */

s/PERMAMENT/PERMANENT

> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 62a50bf399d6..d2992ea29fe1 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -6752,12 +6764,19 @@ ftrace_enable_sysctl(struct ctl_table *table, int 
> write,
>               ftrace_startup_sysctl();
> 
>       } else {
> +             if (is_permanent_ops_registered()) {
> +                     ftrace_enabled = last_ftrace_enabled;
> +                     ret = -EBUSY;
> +                     goto out;
> +             }
> +
>               /* stopping ftrace calls (just send to ftrace_stub) */
>               ftrace_trace_function = ftrace_stub;
> 
>               ftrace_shutdown_sysctl();
>       }
> 
> +     last_ftrace_enabled = !!ftrace_enabled;

No strong feelings on last_ftrace_enabled placement, leaving it to
your preference. 

>   out:
>       mutex_unlock(&ftrace_lock);
>       return ret;
> 


-- 
Kamalesh

Reply via email to