All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chengming Zhou <zhouchengming@bytedance.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, songmuchun@bytedance.com
Subject: Re: [External] Re: [PATCH 2/2] ftrace: setup correct flags before replace code of module rec
Date: Wed, 29 Jul 2020 01:29:28 +0800	[thread overview]
Message-ID: <b5b242eb-f7d8-0367-f95e-e8db8cc1a083@bytedance.com> (raw)
In-Reply-To: <20200728090211.4c94a14d@oasis.local.home>


在 2020/7/28 下午9:02, Steven Rostedt 写道:
> On Tue, 28 Jul 2020 18:27:20 +0800
> Chengming Zhou <zhouchengming@bytedance.com> wrote:
>
>> When module loaded and enabled, we will use __ftrace_replace_code
>> for module if any ftrace_ops referenced it found. But we will get
>> wrong ftrace_addr for module rec in ftrace_get_addr_new, because
>> rec->flags has not been setup correctly.
>> So setup correct rec->flags when we call referenced_filters to find
>> ftrace_ops references it.
> This is somewhat correct ;-)
>
>> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
>> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
>> ---
>>  kernel/trace/ftrace.c | 16 +++++++++++++---
>>  1 file changed, 13 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
>> index fca01a168ae5..00087dea0174 100644
>> --- a/kernel/trace/ftrace.c
>> +++ b/kernel/trace/ftrace.c
>> @@ -6190,8 +6190,17 @@ static int referenced_filters(struct dyn_ftrace *rec)
>>  	int cnt = 0;
>>  
>>  	for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {
>> -		if (ops_references_rec(ops, rec))
>> -		    cnt++;
>> +		if (ops_references_rec(ops, rec)) {
>> +			cnt++;
>> +			if (ops->flags & FTRACE_OPS_FL_DIRECT)
>> +				rec->flags |= FTRACE_FL_DIRECT;
> The above should be:
>
> 			if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_DIRECT))
> 				continue;
> 			cnt++;
>
> The direct flag is *very* special, and should not be set automatically
> like this.
>
> Probably should add the same kind of warning and skip for
> FTRACE_OPS_FL_IPMODIFY.
Ok, I think it's fine to warn and skip these ops.
>> +			if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
>> +				rec->flags |= FTRACE_FL_REGS;
> The above is definitely a bug fix. I'm thinking this patch should be
> broken up into two. One with just this update (and the clear below),
> and the rest later. As this should be backported to stable.

Yes, this bug cause a kernel crash on our server...

So I will send a bugfix patch just including this update and the clear
below.

>> +			if (cnt == 1 && ops->trampoline)
>> +				rec->flags |= FTRACE_FL_TRAMP;
>> +			else
>> +				rec->flags &= ~FTRACE_FL_TRAMP;
> The above is correct, but not critical that it would need to be
> backported.

I will put the rest in the second patch later.

Thanks!

>
> Thanks!
>
> -- Steve
>
>> +		}
>>  	}
>>  
>>  	return cnt;
>> @@ -6373,7 +6382,8 @@ void ftrace_module_enable(struct module *mod)
>>  			cnt += referenced_filters(rec);
>>  
>>  		/* This clears FTRACE_FL_DISABLED */
>> -		rec->flags = cnt;
>> +		rec->flags &= ~FTRACE_FL_DISABLED;
>> +		rec->flags += cnt;
>>  
>>  		if (ftrace_start_up && cnt) {
>>  			int failed = __ftrace_replace_code(rec, 1);

  reply	other threads:[~2020-07-28 17:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28 10:27 [PATCH 1/2] ftrace: clear module from hash of all ftrace ops Chengming Zhou
2020-07-28 10:27 ` [PATCH 2/2] ftrace: setup correct flags before replace code of module rec Chengming Zhou
2020-07-28 13:02   ` Steven Rostedt
2020-07-28 17:29     ` Chengming Zhou [this message]
2020-07-28 12:53 ` [PATCH 1/2] ftrace: clear module from hash of all ftrace ops Steven Rostedt
2020-07-28 16:59   ` [External] " Chengming Zhou
2020-07-28 17:26     ` Steven Rostedt
2020-07-31  4:00       ` Chengming Zhou
2020-08-10  2:54 ` [ftrace] a89282bc45: WARNING:possible_circular_locking_dependency_detected kernel test robot
2020-08-10  2:54   ` kernel test robot

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=b5b242eb-f7d8-0367-f95e-e8db8cc1a083@bytedance.com \
    --to=zhouchengming@bytedance.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=songmuchun@bytedance.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.