public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@elte.hu>,
	        Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	        lkml <linux-kernel@vger.kernel.org>,
	        systemtap <systemtap@sources.redhat.com>,
	        DLE <dle-develop@lists.sourceforge.net>,
	        Jim Keniston <jkenisto@us.ibm.com>,
	        Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	        Christoph Hellwig <hch@infradead.org>,
	        Frederic Weisbecker <fweisbec@gmail.com>,
	        "H. Peter Anvin" <hpa@zytor.com>,
	Anders Kaseorg <andersk@ksplice.com>,
	        Tim Abbott <tabbott@ksplice.com>
Subject: Re: [RFC][ PATCH -tip v2 2/7] kprobes: introducing generic insn_slot   framework
Date: Mon, 29 Jun 2009 21:06:00 -0000	[thread overview]
Message-ID: <4A492D86.5040604@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.00.0906271558140.12592@gandalf.stny.rr.com>

Thank you for reviewing.

Steven Rostedt wrote:
> Hi Masami,
> 
> I'm currently traveling so my responses are very slow this week.
> 
> 
> On Mon, 22 Jun 2009, Masami Hiramatsu wrote:
> 
>> Make insn_slot framework support various size slots.
>> Current insn_slot just supports one-size instruction buffer slot. However,
>> kprobes jump optimization needs larger size buffers.
>>
>> Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
>> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
>> Cc: Ingo Molnar <mingo@elte.hu>
>> Cc: Jim Keniston <jkenisto@us.ibm.com>
>> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
>> Cc: Christoph Hellwig <hch@infradead.org>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Cc: Frederic Weisbecker <fweisbec@gmail.com>
>> Cc: H. Peter Anvin <hpa@zytor.com>
>> Cc: Anders Kaseorg <andersk@ksplice.com>
>> Cc: Tim Abbott <tabbott@ksplice.com>
>> ---
>>
>>  kernel/kprobes.c |   96 +++++++++++++++++++++++++++++++++---------------------
>>  1 files changed, 58 insertions(+), 38 deletions(-)
>>
>> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
>> index 0b68fdc..bc9cfd0 100644
>> --- a/kernel/kprobes.c
>> +++ b/kernel/kprobes.c
>> @@ -100,26 +100,38 @@ static struct kprobe_blackpoint kprobe_blacklist[] = {
>>   * stepping on the instruction on a vmalloced/kmalloced/data page
>>   * is a recipe for disaster
>>   */
>> -#define INSNS_PER_PAGE	(PAGE_SIZE/(MAX_INSN_SIZE * sizeof(kprobe_opcode_t)))
>> -
>>  struct kprobe_insn_page {
>>  	struct list_head list;
>>  	kprobe_opcode_t *insns;		/* Page of instruction slots */
>> -	char slot_used[INSNS_PER_PAGE];
>>  	int nused;
>>  	int ngarbage;
>> +	char slot_used[1];
> 
> I would recommend using [] instead of [1], that would help other 
> developers know that it is a variable array.

Sure.

[...]
>> -	list_for_each_entry(kip, &kprobe_insn_pages, list) {
>> -		if (kip->nused < INSNS_PER_PAGE) {
>> +	list_for_each_entry(kip, &c->pages, list) {
>> +		if (kip->nused < slots_per_page(c)) {
>>  			int i;
>> -			for (i = 0; i < INSNS_PER_PAGE; i++) {
>> +			for (i = 0; i < slots_per_page(c); i++) {
>>  				if (kip->slot_used[i] == SLOT_CLEAN) {
>>  					kip->slot_used[i] = SLOT_USED;
>>  					kip->nused++;
>> -					return kip->insns + (i * MAX_INSN_SIZE);
>> +					return kip->insns + (i * c->insn_size);
>>  				}
>>  			}
>> -			/* Surprise!  No unused slots.  Fix kip->nused. */
>> -			kip->nused = INSNS_PER_PAGE;
>> +			/* kip->nused is broken. */
>> +			BUG();
> 
> Does this deserve a bug, or can we get away with a WARN and find a way to 
> fail nicely? Is it already too late to recover?

No, WARN() is enough here.

> 
>>  		}
>>  	}
>>  
>>  	/* If there are any garbage slots, collect it and try again. */
>> -	if (kprobe_garbage_slots && collect_garbage_slots() == 0) {
>> +	if (c->nr_garbage && collect_garbage_slots(c) == 0)
>>  		goto retry;
>> -	}
>> +
>>  	/* All out of space.  Need to allocate a new page. Use slot 0. */
>> -	kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL);
>> +	kip = kmalloc(sizeof(struct kprobe_insn_page) + slots_per_page(c) - 1,
> 
> Why the '- 1'?  Is it because of the char [1] above?
> 
> Would be better to make the size of the kprobe_insn_page a macro:
> 
> #define KPROBE_INSN_SIZE offsetof(struct kbrobe_insn_page, slot_used)
> 
> and then you can do the following:
> 
> 	kip = kmalloc(KPROBE_INSN_SIZE + slots_per_page(c));

Good idea!

Thanks


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

  reply	other threads:[~2009-06-29 21:06 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22 21:20 [RFC][ PATCH -tip v2 0/7] kprobes: Kprobes jump optimization support Masami Hiramatsu
2009-06-22 21:20 ` [RFC][ PATCH -tip v2 6/7] kprobes: x86: support kprobes jump optimization on x86 Masami Hiramatsu
2009-06-22 21:20 ` [RFC][ PATCH -tip v2 1/7] kprobes: use list instead of hlist for insn_pages Masami Hiramatsu
2009-06-22 21:20 ` [RFC][ PATCH -tip v2 2/7] kprobes: introducing generic insn_slot framework Masami Hiramatsu
2009-06-27 20:09   ` Steven Rostedt
2009-06-29 21:06     ` Masami Hiramatsu [this message]
2009-06-22 21:20 ` [RFC][ PATCH -tip v2 3/7] Kbuild: disable gcc crossjumping Masami Hiramatsu
2009-06-27 20:13   ` Steven Rostedt
2009-07-17 20:28     ` Sam Ravnborg
2009-07-17 21:12       ` Masami Hiramatsu
2009-07-17 21:14         ` Masami Hiramatsu
2009-07-17 21:19         ` Sam Ravnborg
2009-06-22 21:20 ` [RFC][ PATCH -tip v2 7/7] kprobes: add documents of jump optimization Masami Hiramatsu
2009-06-22 21:47 ` [RFC][ PATCH -tip v2 4/7] kprobes: kprobes jump optimization core Masami Hiramatsu
2009-06-23 12:58   ` Srikar Dronamraju
2009-06-23 13:10     ` Masami Hiramatsu
2009-06-22 21:47 ` [RFC][ PATCH -tip v2 5/7] kprobes: x86: cleanup save/restore registers Masami Hiramatsu
2009-06-23 11:43 ` [RFC][ PATCH -tip v2 0/7] kprobes: Kprobes jump optimization support Ingo Molnar
2009-06-23 14:05   ` Masami Hiramatsu
2009-06-23 19:40     ` Ingo Molnar
2009-06-23 21:52       ` Masami Hiramatsu
2009-06-23 22:05         ` Masami Hiramatsu
2009-06-23 12:09 ` Andi Kleen
2009-06-23 13:49   ` Masami Hiramatsu
2009-06-23 16:35     ` Andi Kleen
2009-06-23 17:26       ` Masami Hiramatsu
2009-06-23 20:37         ` Andi Kleen
2009-06-23 20:46           ` Masami Hiramatsu
2009-06-26 23:17           ` Masami Hiramatsu

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=4A492D86.5040604@redhat.com \
    --to=mhiramat@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=andersk@ksplice.com \
    --cc=dle-develop@lists.sourceforge.net \
    --cc=fweisbec@gmail.com \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jkenisto@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=systemtap@sources.redhat.com \
    --cc=tabbott@ksplice.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).