Re: [PATCH v2 11/27] ftrace: Allow subops filtering to be modified
From: Google
Date: Sun Jun 02 2024 - 22:37:41 EST
On Sat, 01 Jun 2024 23:37:55 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
[...]
>
> +static int ftrace_hash_move_and_update_subops(struct ftrace_ops *subops,
> + struct ftrace_hash **orig_subhash,
> + struct ftrace_hash *hash,
> + int enable)
> +{
> + struct ftrace_ops *ops = subops->managed;
> + struct ftrace_hash **orig_hash;
> + struct ftrace_hash *save_hash;
> + struct ftrace_hash *new_hash;
> + int ret;
> +
> + /* Manager ops can not be subops (yet) */
> + if (WARN_ON_ONCE(!ops || ops->flags & FTRACE_OPS_FL_SUBOP))
> + return -EINVAL;
This does return if ops->flags & FTRACE_OPS_FL_SUBOP, but --> (1)
> +
> + /* Move the new hash over to the subops hash */
> + save_hash = *orig_subhash;
> + *orig_subhash = __ftrace_hash_move(hash);
> + if (!*orig_subhash) {
> + *orig_subhash = save_hash;
> + return -ENOMEM;
> + }
> +
> + /* Create a new_hash to hold the ops new functions */
> + if (enable) {
> + orig_hash = &ops->func_hash->filter_hash;
> + new_hash = append_hashes(ops);
> + } else {
> + orig_hash = &ops->func_hash->notrace_hash;
> + new_hash = intersect_hashes(ops);
> + }
> +
> + /* Move the hash over to the new hash */
> + ret = ftrace_hash_move_and_update_ops(ops, orig_hash, new_hash, enable);
This also a bit wired to me. maybe we need simple version like
`__ftrace_hash_move_and_update_ops()`
And call it from ftrace_hash_move_and_update_ops() and here?
> +
> + free_ftrace_hash(new_hash);
> +
> + if (ret) {
> + /* Put back the original hash */
> + free_ftrace_hash_rcu(*orig_subhash);
> + *orig_subhash = save_hash;
> + } else {
> + free_ftrace_hash_rcu(save_hash);
> + }
> + return ret;
> +}
> +
> +
> static u64 ftrace_update_time;
> unsigned long ftrace_update_tot_cnt;
> unsigned long ftrace_number_of_pages;
> @@ -4770,8 +4823,33 @@ static int ftrace_hash_move_and_update_ops(struct ftrace_ops *ops,
> {
> struct ftrace_ops_hash old_hash_ops;
> struct ftrace_hash *old_hash;
> + struct ftrace_ops *op;
> int ret;
>
> + if (ops->flags & FTRACE_OPS_FL_SUBOP)
> + return ftrace_hash_move_and_update_subops(ops, orig_hash, hash, enable);
(1) This calls ftrace_hash_move_and_update_subops() if ops->flags & FTRACE_OPS_FL_SUBOP ?
Thank you,
> +
> + /*
> + * If this ops is not enabled, it could be sharing its filters
> + * with a subop. If that's the case, update the subop instead of
> + * this ops. Shared filters are only allowed to have one ops set
> + * at a time, and if we update the ops that is not enabled,
> + * it will not affect subops that share it.
> + */
> + if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) {
> + /* Check if any other manager subops maps to this hash */
> + do_for_each_ftrace_op(op, ftrace_ops_list) {
> + struct ftrace_ops *subops;
> +
> + list_for_each_entry(subops, &op->subop_list, list) {
> + if ((subops->flags & FTRACE_OPS_FL_ENABLED) &&
> + subops->func_hash == ops->func_hash) {
> + return ftrace_hash_move_and_update_subops(subops, orig_hash, hash, enable);
> + }
> + }
> + } while_for_each_ftrace_op(op);
> + }
> +
> old_hash = *orig_hash;
> old_hash_ops.filter_hash = ops->func_hash->filter_hash;
> old_hash_ops.notrace_hash = ops->func_hash->notrace_hash;
> --
> 2.43.0
>
>
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>