public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "K.Prasad" <prasad@linux.vnet.ibm.com>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>,
	Li Zefan <lizf@cn.fujitsu.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Jan Kiszka <jan.kiszka@web.de>, Jiri Slaby <jirislaby@gmail.com>,
	Avi Kivity <avi@redhat.com>, Paul Mackerras <paulus@samba.org>,
	Mike Galbraith <efault@gmx.de>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	Paul Mundt <lethal@linux-sh.org>,
	Arjan van de Ven <arjan@linux.intel.com>
Subject: Re: [PATCH 5/7 v6] hw-breakpoints: Rewrite the hw-breakpoints layer on top of perf events
Date: Wed, 11 Nov 2009 18:32:07 +0530	[thread overview]
Message-ID: <20091111130207.GA5676@in.ibm.com> (raw)
In-Reply-To: <1257694141-5670-6-git-send-email-fweisbec@gmail.com>

On Sun, Nov 08, 2009 at 04:28:59PM +0100, Frederic Weisbecker wrote:

There were a few comments that I posted against version 6 of your
patchset (which happened to cross your version 7 posting...) regarding
the breakpoint interfaces, reservation of register for unpinned events
and such...

By the way, I'm looking at refs/heads/perfevents/hw-breakpoint branch in
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
and hope that's correct/latest?

Some more comments about the ptrace implementation here...


static int ptrace_set_breakpoint_addr(struct task_struct *tsk, int nr,
				      unsigned long addr)
{
	struct perf_event *bp;
	struct thread_struct *t = &tsk->thread;

	if (!t->ptrace_bps[nr]) {
		/*
		 * Put stub len and type to register (reserve) an inactive but
		 * correct bp
		 */
		bp = register_user_hw_breakpoint(addr, HW_BREAKPOINT_LEN_1,
						 HW_BREAKPOINT_W,
						 ptrace_triggered, tsk,
						 false);
..
...
}

Given that a register_user_hw_breakpoint() is done at the time of a
write to DR0-DR3, it would needlessly hold onto the debug register until
the corresponding DR7 bit is allocated while using up one 'pinned' debug
slot. It would be prudent to postpone the breakpoint registration till
DR7 is changed to activate it.

static int ptrace_write_dr7(struct task_struct *tsk, unsigned long data)
{
..
...
		/*
		 * We shoud have at least an inactive breakpoint at this
		 * slot. It means the user is writing dr7 without having
		 * written the address register first
		 */
		if (!bp) {
			rc = -EINVAL;
			break;
		}

I was just about confused...thinking that the above condition would
become true during second_pass, but alas it turns out that you restore 
"thread->ptrace_bps[i] = bp" again later.

		rc = arch_bp_generic_fields(len, type, &gen_len, &gen_type);
		if (rc)
			break;

		/*
		 * This is a temporary thing as bp is unregistered/registered
		 * to simulate modification
		 */
		bp = modify_user_hw_breakpoint(bp, bp->attr.bp_addr, gen_len,
					       gen_type, bp->callback,
					       tsk, true);

modify_user_hw_breakpoint() is called twice (once per pass) and in its
current implementation, it would leave open a window for register
grabbing on two occasions. Another reason to change its implementation
soon...

		thread->ptrace_bps[i] = NULL;

Why not remove this line from here...

		if (!bp) { /* incorrect bp, or we have a bug in bp API */
			rc = -EINVAL;
			break;
		}
		if (IS_ERR(bp)) {
			rc = PTR_ERR(bp);
			bp = NULL;
			break;
		}
		thread->ptrace_bps[i] = bp;

...and put it here inside a condition "if (second_pass)"?

	}
	/*
	 * Make a second pass to free the remaining unused breakpoints
	 * or to restore the original breakpoints if an error occurred.
	 */
	if (!second_pass) {
		second_pass = 1;
		if (rc < 0) {
			orig_ret = rc;
			data = old_dr7;
		}
		goto restore;
	}
	return ((orig_ret < 0) ? orig_ret : rc);
}

Thanks,
K.Prasad


  parent reply	other threads:[~2009-11-11 13:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-08 15:28 [GIT PULL v6] hw-breakpoints: Rewrite on top of perf events v6 Frederic Weisbecker
2009-11-08 15:28 ` [PATCH 1/7 v6] perf/core: Provide a kernel-internal interface to get to performance counters Frederic Weisbecker
2009-11-08 15:28 ` [PATCH 2/7 v6] x86/hw-breakpoints: Actually flush thread breakpoints in flush_thread() Frederic Weisbecker
2009-11-08 15:28 ` [PATCH 3/7 v6] perf/core: Add a callback to perf events Frederic Weisbecker
2009-11-17 11:28   ` Peter Zijlstra
2009-11-18  0:18     ` Frederic Weisbecker
2009-11-18  9:31       ` Peter Zijlstra
2009-11-19 15:43         ` Frederic Weisbecker
2009-11-19 22:40           ` Peter Zijlstra
2009-11-08 15:28 ` [PATCH 4/7 v6] hw-breakpoint: Move asm-generic/hw_breakpoint.h to linux/hw_breakpoint.h Frederic Weisbecker
2009-11-08 15:28 ` [PATCH 5/7 v6] hw-breakpoints: Rewrite the hw-breakpoints layer on top of perf events Frederic Weisbecker
2009-11-08 17:24   ` Jan Kiszka
2009-11-12 14:32     ` Frederic Weisbecker
2009-11-11 13:02   ` K.Prasad [this message]
2009-11-12  4:25     ` K.Prasad
2009-11-17  1:36       ` Frederic Weisbecker
2009-11-17  1:31     ` Frederic Weisbecker
2009-11-17 11:30   ` Peter Zijlstra
2009-11-18  0:19     ` Frederic Weisbecker
2009-11-08 15:29 ` [PATCH 6/7 v6] hw-breakpoints: Arbitrate access to pmu following registers constraints Frederic Weisbecker
2009-11-08 15:29 ` [PATCH 7/7 v6] ksym_tracer: Remove KSYM_SELFTEST_ENTRY Frederic Weisbecker
2009-11-08 17:03 ` [GIT PULL v6] hw-breakpoints: Rewrite on top of perf events v6 Ingo Molnar
2009-11-24  9:44 ` K.Prasad
2009-11-24 10:13   ` Ingo Molnar
2009-11-24 13:21     ` K.Prasad
2009-11-26  5:59       ` Frederic Weisbecker
2009-11-27 19:07         ` K.Prasad
2009-12-01  6:43           ` Frederic Weisbecker
2009-11-26  5:47     ` Frederic Weisbecker
2009-11-26  9:01       ` Ingo Molnar

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=20091111130207.GA5676@in.ibm.com \
    --to=prasad@linux.vnet.ibm.com \
    --cc=acme@redhat.com \
    --cc=arjan@linux.intel.com \
    --cc=avi@redhat.com \
    --cc=efault@gmx.de \
    --cc=fweisbec@gmail.com \
    --cc=jan.kiszka@web.de \
    --cc=jirislaby@gmail.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stern@rowland.harvard.edu \
    /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