mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Petr Mladek <pmladek@suse.cz>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Jiri Kosina <jkosina@suse.cz>,
	linux-kernel@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH 5/6] x86: patch all traced function calls using the int3-based framework
Date: Fri, 18 Oct 2013 12:39:55 -0400	[thread overview]
Message-ID: <20131018123955.2e301b97@gandalf.local.home> (raw)
In-Reply-To: <1382106445-31468-6-git-send-email-pmladek@suse.cz>

On Fri, 18 Oct 2013 16:27:24 +0200
Petr Mladek <pmladek@suse.cz> wrote:


>  void ftrace_replace_code(int enable)
>  {
>  	struct ftrace_rec_iter *iter;
>  	struct dyn_ftrace *rec;
> -	const char *report = "adding breakpoints";
> -	int count = 0;
> -	int ret;
> +	unsigned long *addr = NULL;
> +	void *opcode = NULL, *op = NULL;
> +	const unsigned char *new;
> +	size_t count = 0;
>  
>  	for_ftrace_rec_iter(iter) {
>  		rec = ftrace_rec_iter_record(iter);
> -
> -		ret = add_breakpoints(rec, enable);
> -		if (ret)
> -			goto remove_breakpoints;
> -		count++;
> -	}
> -
> -	run_sync();
> -
> -	report = "updating code";
> -
> -	for_ftrace_rec_iter(iter) {
> -		rec = ftrace_rec_iter_record(iter);
> -
> -		ret = add_update(rec, enable);
> -		if (ret)
> -			goto remove_breakpoints;
> +		new = ftrace_new_code(rec, enable);
> +
> +		/* check next record if there is no new code for this one */
> +		if (!new)
> +			continue;
> +
> +		/* allocate buffers only when there will be a change */
> +		if (unlikely(!addr)) {
> +			if (ftrace_allocate_replace_buffers(&addr, &opcode))
> +				goto out;
> +			op = opcode;
> +			count = 0;
> +		}
> +
> +		/* fill buffers */
> +		addr[count++] = rec->ip;
> +		memcpy(op, new, MCOUNT_INSN_SIZE);
> +		op += MCOUNT_INSN_SIZE;
> +
> +		/* write buffers if they are full */
> +		if (count == FTRACE_MAX_RECS_PATCH) {
> +			text_poke_bp((void **)addr, opcode,
> +				     MCOUNT_INSN_SIZE, count, NULL);
> +			op = opcode;
> +			count = 0;
> +		}
>  	}
>  
> -	run_sync();
> -
> -	report = "removing breakpoints";
> -
> -	for_ftrace_rec_iter(iter) {
> -		rec = ftrace_rec_iter_record(iter);
> +	if (count)
> +		text_poke_bp((void **)addr, opcode,
> +			     MCOUNT_INSN_SIZE, count, NULL);
>  
> -		ret = finish_update(rec, enable);
> -		if (ret)
> -			goto remove_breakpoints;
> -	}
> -
> -	run_sync();
> -
> -	return;
> -
> - remove_breakpoints:
> -	ftrace_bug(ret, rec ? rec->ip : 0);
> -	printk(KERN_WARNING "Failed on %s (%d):\n", report, count);
> -	for_ftrace_rec_iter(iter) {
> -		rec = ftrace_rec_iter_record(iter);
> -		remove_breakpoint(rec);

Also you must keep the ftrace_bug() functionality. I notice there's no
error check for text_poke_bp(). Not only do we need to check the error
status, but if an error does happen, we must know the following:

 1) What record it failed on
 2) Did in fail on the read, compare, or write?

If it failed on the read:     -EFAULT is returned
If it failed on the compare:  -EINVAL is returned
If it failed on the write:    -EPERM is returned

Look at "ftrace_bug()", and then you can also do a google search on
"ftrace faulted" or "ftrace failed to modify", and see that this is an
extremely useful debugging tool, and not something I will allow to be
removed.

-- Steve


> -	}
> +out:
> +	kfree(addr);
> +	kfree(opcode);
>  }
>  


      parent reply	other threads:[~2013-10-18 16:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-18 14:27 Petr Mladek
2013-10-18 14:55 ` Steven Rostedt
2013-10-18 15:01   ` Steven Rostedt
2013-10-18 16:39 ` Steven Rostedt [this message]

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=20131018123955.2e301b97@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=fweisbec@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=pmladek@suse.cz \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®