lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110315173041.GB24254@linux.vnet.ibm.com>
Date:	Tue, 15 Mar 2011 23:00:41 +0530
From:	Srikar Dronamraju <srikar@...ux.vnet.ibm.com>
To:	Thomas Gleixner <tglx@...utronix.de>
Cc:	Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...e.hu>,
	Steven Rostedt <rostedt@...dmis.org>,
	Linux-mm <linux-mm@...ck.org>,
	Arnaldo Carvalho de Melo <acme@...radead.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
	Christoph Hellwig <hch@...radead.org>,
	Ananth N Mavinakayanahalli <ananth@...ibm.com>,
	Andi Kleen <andi@...stfloor.org>,
	Oleg Nesterov <oleg@...hat.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Jim Keniston <jkenisto@...ux.vnet.ibm.com>,
	Roland McGrath <roland@...k.frob.com>,
	SystemTap <systemtap@...rces.redhat.com>,
	LKML <linux-kernel@...r.kernel.org>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Subject: Re: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a
 uprobe in a rb tree.

* Thomas Gleixner <tglx@...utronix.de> [2011-03-15 14:38:33]:

> On Mon, 14 Mar 2011, Srikar Dronamraju wrote:
> >  
> > +static int valid_vma(struct vm_area_struct *vma)
> 
>   bool perpaps ?

Okay, 

> 
> > +{
> > +	if (!vma->vm_file)
> > +		return 0;
> > +
> > +	if ((vma->vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)) ==
> > +						(VM_READ|VM_EXEC))
> 
> Looks more correct than the code it replaces :)

Yes, Steven Rostedt has already pointed this out.

> 
> > +		return 1;
> > +
> > +	return 0;
> > +}
> > +
> 
> > +static struct rb_root uprobes_tree = RB_ROOT;
> > +static DEFINE_MUTEX(uprobes_mutex);
> > +static DEFINE_SPINLOCK(treelock);
> 
> Why do you need a mutex and a spinlock ? Also the mutex is not
> referenced.

We can move the mutex to the next patch, (i.e register/unregister
patch), where it gets used. mutex for now serializes
register_uprobe/unregister_uprobe/mmap_uprobe.
This mutex is the one that guards mm->uprobes_list. 

> 
> > +/*
> > + * Find a uprobe corresponding to a given inode:offset
> > + * Acquires treelock
> > + */
> > +static struct uprobe *find_uprobe(struct inode * inode, loff_t offset)
> > +{
> > +	struct uprobe *uprobe;
> > +	unsigned long flags;
> > +
> > +	spin_lock_irqsave(&treelock, flags);
> > +	uprobe = __find_uprobe(inode, offset, NULL);
> > +	spin_unlock_irqrestore(&treelock, flags);
> 
> What's the calling context ? Do we really need a spinlock here for
> walking the rb tree ?
> 

find_uprobe() gets called from unregister_uprobe and on probe hit from
uprobe_notify_resume. I am not sure if its a good idea to walk the tree
as and when the tree is changing either because of a insertion or
deletion of a probe.

> > +
> > +/* Should be called lock-less */
> 
> -ENOPARSE
> 
> > +static void put_uprobe(struct uprobe *uprobe)
> > +{
> > +	if (atomic_dec_and_test(&uprobe->ref))
> > +		kfree(uprobe);
> > +}
> > +
> > +static struct uprobe *uprobes_add(struct inode *inode, loff_t offset)
> > +{
> > +	struct uprobe *uprobe, *cur_uprobe;
> > +
> > +	__iget(inode);
> > +	uprobe = kzalloc(sizeof(struct uprobe), GFP_KERNEL);
> > +
> > +	if (!uprobe) {
> > +		iput(inode);
> > +		return NULL;
> > +	}
> 
> Please move the __iget() after the kzalloc()

Okay.

> 
> > +	uprobe->inode = inode;
> > +	uprobe->offset = offset;
> > +
> > +	/* add to uprobes_tree, sorted on inode:offset */
> > +	cur_uprobe = insert_uprobe(uprobe);
> > +
> > +	/* a uprobe exists for this inode:offset combination*/
> > +	if (cur_uprobe) {
> > +		kfree(uprobe);
> > +		uprobe = cur_uprobe;
> > +		iput(inode);
> > +	} else
> > +		init_rwsem(&uprobe->consumer_rwsem);
> 
> Please init stuff _before_ inserting not afterwards.

Okay. 

> 
> > +
> > +	return uprobe;
> > +}
> > +
> > +/* Acquires uprobe->consumer_rwsem */
> > +static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
> > +{
> > +	struct uprobe_consumer *consumer;
> > +
> > +	down_read(&uprobe->consumer_rwsem);
> > +	consumer = uprobe->consumers;
> > +	while (consumer) {
> > +		if (!consumer->filter || consumer->filter(consumer, current))
> > +			consumer->handler(consumer, regs);
> > +
> > +		consumer = consumer->next;
> > +	}
> > +	up_read(&uprobe->consumer_rwsem);
> > +}
> > +
> > +/* Acquires uprobe->consumer_rwsem */
> > +static void add_consumer(struct uprobe *uprobe,
> > +				struct uprobe_consumer *consumer)
> > +{
> > +	down_write(&uprobe->consumer_rwsem);
> > +	consumer->next = uprobe->consumers;
> > +	uprobe->consumers = consumer;
> > +	up_write(&uprobe->consumer_rwsem);
> > +	return;
> 
>   pointless return

Okay,

> 
> > +}
> > +
> > +/* Acquires uprobe->consumer_rwsem */
> 
> I'd prefer a comment about the return code over this redundant
> information.
> 

Okay, 

> > +static int del_consumer(struct uprobe *uprobe,
> > +				struct uprobe_consumer *consumer)
> > +{
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ