From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752811Ab3ACJE4 (ORCPT ); Thu, 3 Jan 2013 04:04:56 -0500 Received: from e9.ny.us.ibm.com ([32.97.182.139]:39282 "EHLO e9.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750915Ab3ACJEw (ORCPT ); Thu, 3 Jan 2013 04:04:52 -0500 Date: Thu, 3 Jan 2013 14:34:39 +0530 From: Srikar Dronamraju To: Oleg Nesterov Cc: Ingo Molnar , Peter Zijlstra , Ananth N Mavinakayanahalli , Anton Arapov , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] uprobes: Introduce uprobe_is_active() Message-ID: <20130103090439.GA8140@linux.vnet.ibm.com> Reply-To: Srikar Dronamraju References: <20121125223331.GA24788@redhat.com> <20121125223347.GA24808@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20121125223347.GA24808@redhat.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13010309-7182-0000-0000-0000042A4F17 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Oleg Nesterov [2012-11-25 23:33:47]: > The lifetime of uprobe->rb_node and uprobe->inode is not refcounted, > delete_uprobe() is called when we detect that uprobe has no consumers, > and it would be deadly wrong to do this twice. > > Change delete_uprobe() to WARN() if it was already called. We use > RB_CLEAR_NODE() to mark uprobe "inactive", then RB_EMPTY_NODE() can > be used to detect this case. > > RB_EMPTY_NODE() is not used directly, we add the trivial helper for > the next change. > > Signed-off-by: Oleg Nesterov Acked-by: Srikar Dronamraju > --- > kernel/events/uprobes.c | 8 ++++++++ > 1 files changed, 8 insertions(+), 0 deletions(-) > > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c > index 53dc2eb..2886c82 100644 > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -669,6 +669,10 @@ remove_breakpoint(struct uprobe *uprobe, struct mm_struct *mm, unsigned long vad > return set_orig_insn(&uprobe->arch, mm, vaddr); > } > > +static inline bool uprobe_is_active(struct uprobe *uprobe) > +{ > + return !RB_EMPTY_NODE(&uprobe->rb_node); > +} > /* > * There could be threads that have already hit the breakpoint. They > * will recheck the current insn and restart if find_uprobe() fails. > @@ -676,9 +680,13 @@ remove_breakpoint(struct uprobe *uprobe, struct mm_struct *mm, unsigned long vad > */ > static void delete_uprobe(struct uprobe *uprobe) > { > + if (WARN_ON(!uprobe_is_active(uprobe))) > + return; > + > spin_lock(&uprobes_treelock); > rb_erase(&uprobe->rb_node, &uprobes_tree); > spin_unlock(&uprobes_treelock); > + RB_CLEAR_NODE(&uprobe->rb_node); /* for uprobe_is_active() */ > iput(uprobe->inode); > put_uprobe(uprobe); > } > -- > 1.5.5.1 >