From: Ingo Molnar <mingo@elte.hu>
To: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Christoph Hellwig <hch@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Anton Arapov <anton@redhat.com>,
Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
Jim Keniston <jkenisto@linux.vnet.ibm.com>,
Jiri Olsa <jolsa@redhat.com>, Josh Stone <jistone@redhat.com>
Subject: Re: [PATCH] uprobes/core: handle breakpoint and signal step exception.
Date: Tue, 28 Feb 2012 14:52:51 +0100 [thread overview]
Message-ID: <20120228135251.GA8279@elte.hu> (raw)
In-Reply-To: <20120228132601.GC32211@linux.vnet.ibm.com>
* Srikar Dronamraju <srikar@linux.vnet.ibm.com> wrote:
> > > Where possible, we check and skip singlestepping the
> > > breakpointed instructions. For now we skip single byte as
> > > well as few multibyte nop instructions. However this can
> > > be extended to other instructions too.
> >
> > Is this an optimization - allowing a NOP to be inserted for
> > easy probe insertion?
>
> Yes, Its an optimization by which we avoid singlestep
> exception.
That would be nice to comment in the code - nowhere in the
'skip' logic is this fact mentioned, and it's really useful
information to pretty much anyone reading the code.
It's also a nice optimization, there's no need to obfuscate its
existence.
> > > + case DIE_INT3:
> > > + /* Run your handler here */
> > > + if (uprobe_bkpt_notifier(regs))
> > > + ret = NOTIFY_STOP;
> >
> > This comment looks somewhat out of place.
> >
> > Also, I have not noticed this in the first patch, but 'bkpt' is
> > not a standard way to refer to breakpoints: we either use
> > 'breakpoint' or 'bp'.
>
> This is again one of those things that I changed from bp to
> bkpt based on LKML feedback. I am okay to go back to bp.
:-/ I can understand it somewhat, 'bp' also means other things.
'hwbp' is a common name - you could use 'swbp' which would pair
with that nicely?
> > > +bool arch_uprobe_skip_sstep(struct pt_regs *regs, struct arch_uprobe *auprobe)
> > > +{
> > > + int i;
> > > +
> > > + for (i = 0; i < MAX_UINSN_BYTES; i++) {
> > > + if ((auprobe->insn[i] == 0x66))
> > > + continue;
> > > +
> > > + if (auprobe->insn[i] == 0x90)
> > > + return true;
> > > +
> > > + if (i == (MAX_UINSN_BYTES - 1))
> > > + break;
> >
> > Looks like the loop could run from 0 to MAX_UINSN_BYTES-2 and
> > then this break would be superfluous.
> >
>
> Even if we were to run from 0 to MAX_UINSN_BYTES - 2, we would
> have to add extra code to handle 0x66* 0x90 (where 0x90 is
> stored at index i == MAX_UINSN_BYTES - 1. So I would like to
> keep this code as is.
Ok.
> > > +/*
> > > + * uprobe_task: Metadata of a task while it singlesteps.
> > > + */
> > > +struct uprobe_task {
> > > + unsigned long xol_vaddr;
> > > + unsigned long vaddr;
> >
> > These two fields are never actually used outside of architecture
> > code.
> >
> > Unless there's a good reason to keep them outside I'd
> > suggest to move them into struct arch_uprobe_task. This has
> > another benefit: we can pass struct arch_uprobe_task to the
> > architecture methods, instead of struct uprobe_task. This
> > would allow the moving of the struct uprobe_task into
> > uprobes.c - no code outside uprobes.c needs to know its
> > structure.
>
> The Xol layer(which is the next patch) uses them in arch
> agnostic way. Also vaddr/xol_vaddr are populated/used in arch
> agnostic way. We could still move them to arch_uprobe_task but
> we will then have to ensure that every other arch defines them
> the way uprobes understands.
Correct - and that still isolates the arch code from the core
uprobes code.
We could also introduce 'struct generic_arch_uprobe_task' and
embedd that inside arch_uprobe via a short field name, to make
it easy to access: ->gen.field or so.
You can also leave it as-is for now, I'll reconsider how things
look like with the patch following these bits and then make a
new suggestion if I see a better way.
> > > +static inline unsigned long get_uprobe_bkpt_addr(struct pt_regs *regs)
> > > +{
> > > + return 0;
> > > +}
> >
> > Please use the standard uprobe method naming pattern for
> > get_uprobe_bkpt_addr().
>
> do you mean uprobe_get_bp_addr ?
Yeah, that sounds good.
> > > +/*
> > > + * There could be threads that have hit the breakpoint and are entering the
> > > + * notifier code and trying to acquire the uprobes_treelock. The thread
> > > + * calling delete_uprobe() that is removing the uprobe from the rb_tree can
> > > + * race with these threads and might acquire the uprobes_treelock compared
> > > + * to some of the breakpoint hit threads. In such a case, the breakpoint hit
> > > + * threads will not find the uprobe. Hence wait till the current breakpoint
> > > + * hit threads acquire the uprobes_treelock before the uprobe is removed
> > > + * from the rbtree.
> >
> > Hm, the last sentence does not parse for me. (even if it's
> > correct English it might make sense to rephrase it to be clearer
> > what is meant.)
> >
>
> Would this be okay with you.
>
> The current unregistering thread waits till all other threads
> that have hit a breakpoint to acquire the uprobes_treelock
> before the uprobe is removed from the rbtree.
s/is removed/are removed
?
If yes then indeed this reads better.
> [...]
>
> If the thread was not in the middle of a uprobe hit then we go
> through the regular signal handling.
>
> Since there is no way this thread can hit a uprobe once a
> thread has entered get_signal_to_deliver(kernel code), I dont
> see a reason to move it under relock:
Ok, fair enough.
Thanks,
Ingo
next prev parent reply other threads:[~2012-02-28 13:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-23 11:02 [PATCH] uprobes/core: handle breakpoint and signal step exception Srikar Dronamraju
2012-02-23 12:18 ` Anton Arapov
2012-02-24 5:31 ` Srikar Dronamraju
2012-02-27 9:12 ` Ingo Molnar
2012-02-28 13:26 ` Srikar Dronamraju
2012-02-28 13:52 ` Ingo Molnar [this message]
2012-02-28 14:17 ` Srikar Dronamraju
2012-02-28 14:27 ` Ingo Molnar
2012-03-08 13:18 ` Srikar Dronamraju
2012-03-08 13:48 ` Ingo Molnar
2012-03-09 6:28 ` Srikar Dronamraju
2012-03-09 7:33 ` Ingo Molnar
2012-03-13 5:20 ` Ingo Molnar
2012-03-13 5:42 ` Ingo Molnar
2012-03-13 5:47 ` Ingo Molnar
2012-03-13 9:24 ` Srikar Dronamraju
2012-03-13 9:38 ` Ingo Molnar
2012-02-27 9:24 ` 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=20120228135251.GA8279@elte.hu \
--to=mingo@elte.hu \
--cc=ananth@in.ibm.com \
--cc=anton@redhat.com \
--cc=hch@infradead.org \
--cc=hpa@zytor.com \
--cc=jistone@redhat.com \
--cc=jkenisto@linux.vnet.ibm.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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 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.