From: Alan Stern <stern@rowland.harvard.edu>
To: "K.Prasad" <prasad@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Benjamin Herrenschmidt <benh@au1.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
<maneesh@linux.vnet.ibm.com>, Roland McGrath <roland@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [Patch 00/11] Hardware Breakpoint interfaces
Date: Thu, 9 Apr 2009 16:50:31 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.44L0.0904091634150.4094-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <20090407082224.GA22500@in.ibm.com>
On Tue, 7 Apr 2009, K.Prasad wrote:
> A slight change though...writes to DR0-DR3 may fail if the address is
> invalid. This behaviour is true even in existing implementation of
> ptrace_set_debugreg().
That's okay.
> > >
> > > /* Lazy debug register switching */
> > > if (per_cpu(last_debugged_task, get_cpu()) != current) {
> > > switch_to_none_hw_breakpoint();
> > > put_cpu_no_resched();
> > > }
> >
> > I just noticed that the lines saving DR7 and setting it to 0 need to
> > come here. Otherwise switch_to_none_hw_breakpoint() might set DR7 back
> > to a nonzero value, and it might not match the value stored in dr7.
> >
>
> arch_uninstall_thread_hw_breakpoint()<--switch_to_none_hw_breakpoint()
> will store 'kdr7' (which contains all kernel-space breakpoints in
> encoded format) to DR7 physical register. Given that the current()
> process should not have TIF_DEBUG() set (if it were set,
> switch_to_thread_hw_breakpoint() would have been invoked to set
> last_debugged_task), we will wipe out all user-space breakpoints and
> store only kdr7.
No, you don't understand. The code looks like this:
> + get_debugreg(dr7, 7);
> +
> + /* Disable breakpoints during exception handling */
> + set_debugreg(0UL, 7);
...
> + /* Lazy debug register switching */
> + if (per_cpu(last_debugged_task, get_cpu()) != current) {
> + switch_to_none_hw_breakpoint();
> + put_cpu_no_resched();
> + }
...
> + set_debugreg(dr7, 7);
> + return rc;
The first few lines will set dr7 to a value which includes the user
breakpoints and will set DR7 to 0. The next few lines will set DR7 to
kdr7, which might be non-zero. This is wrong; we need DR7 to be 0.
Then the second-to-last line will set DR7 back to dr7, which is also
wrong -- it should be set to kdr7.
> > For each breakpoint where we decide it's a case of lazy DR switching or
> > we invoke a "triggered" callback, the corresponding bit in dr6 should
> > be cleared. This is a way of indicating to do_debug() that the handler
> > has taken care of these causes of the exception.
> >
> > Similarly, the kprobe routine should clear the single-step bit in dr6
> > when it handles a single-step exception. When the notifier chain
> > completes, the only bits remaining in dr6 should be for events that
> > still need to be handled.
> >
> > Alan Stern
> >
>
> This does sound like good design, but unfortunately there are pieces in
> do_debug() which rely upon bits in dr6 being set even after the actual
> breakpoint is handled (the get_si_code() is one such example).
If necessary, do_debug() can keep two copies of dr6: the original
version read from DR6 and the version modified by the notification
handlers.
> Do we go about changing them to use thread->debugreg6 instead of dr6? If
> yes, wouldn't that be better done outside the HW Breakpoint patches as a
> part of some cleanup initiative?
Should they use thread->debugreg6? If they should, then change them.
And no, the change should not be in a separate patch; it should be part
of your series. Otherwise there would be intermediate kernels that
behaved incorrectly.
Alan Stern
next prev parent reply other threads:[~2009-04-09 20:50 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-24 15:24 [Patch 00/11] Hardware Breakpoint interfaces K.Prasad
2009-03-25 19:48 ` Alan Stern
2009-03-27 22:06 ` K.Prasad
2009-04-01 16:16 ` Alan Stern
2009-04-07 8:22 ` K.Prasad
2009-04-09 20:50 ` Alan Stern [this message]
2009-03-28 8:46 ` K.Prasad
2009-04-01 16:22 ` Alan Stern
2009-04-07 8:22 ` K.Prasad
-- strict thread matches above, loose matches on Subject: below --
2009-04-07 6:34 K.Prasad
2009-04-16 21:19 ` Alan Stern
2009-04-17 3:12 ` K.Prasad
2009-04-17 14:37 ` Alan Stern
2009-04-24 5:56 ` K.Prasad
2009-04-24 14:16 ` Alan Stern
2009-04-24 15:57 ` K.Prasad
2009-04-24 16:16 ` Alan Stern
2009-03-07 5:04 [Patch 00/11] Hardware Breakpoint Interfaces prasad
2009-03-05 4:37 [patch 00/11] Hardware Breakpoint interfaces prasad
2009-03-10 13:46 ` Ingo Molnar
2009-03-11 12:11 ` K.Prasad
2009-03-11 16:34 ` Alan Stern
2009-03-11 17:25 ` K.Prasad
2009-03-11 17:30 ` Ingo Molnar
2009-03-10 13:51 ` Ingo Molnar
2009-03-10 14:24 ` Alan Stern
2009-03-10 14:54 ` 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=Pine.LNX.4.44L0.0904091634150.4094-100000@iolanthe.rowland.org \
--to=stern@rowland.harvard.edu \
--cc=akpm@linux-foundation.org \
--cc=benh@au1.ibm.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maneesh@linux.vnet.ibm.com \
--cc=mingo@elte.hu \
--cc=prasad@linux.vnet.ibm.com \
--cc=roland@redhat.com \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).