From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6331 invoked by alias); 14 Feb 2006 08:57:49 -0000 Received: (qmail 6323 invoked by uid 22791); 14 Feb 2006 08:57:48 -0000 X-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from fmr19.intel.com (HELO orsfmr004.jf.intel.com) (134.134.136.18) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 14 Feb 2006 08:57:46 +0000 Received: from orsfmr101.jf.intel.com (orsfmr101.jf.intel.com [10.7.209.17]) by orsfmr004.jf.intel.com (8.12.10/8.12.10/d: major-outer.mc,v 1.1 2004/09/17 17:50:56 root Exp $) with ESMTP id k1E8vcWG024667; Tue, 14 Feb 2006 08:57:38 GMT Received: from pdsmsxvs01.pd.intel.com (pdsmsxvs01.pd.intel.com [172.16.12.122]) by orsfmr101.jf.intel.com (8.12.10/8.12.10/d: major-inner.mc,v 1.2 2004/09/17 18:05:01 root Exp $) with SMTP id k1E8vJTH003111; Tue, 14 Feb 2006 08:57:37 GMT Received: from pdsmsx331.ccr.corp.intel.com ([172.16.12.58]) by pdsmsxvs01.pd.intel.com (SAVSMTP 3.1.7.47) with SMTP id M2006021416573508884 ; Tue, 14 Feb 2006 16:57:35 +0800 Received: from pdsmsx405.ccr.corp.intel.com ([172.16.12.95]) by pdsmsx331.ccr.corp.intel.com with Microsoft SMTPSVC(6.0.3790.211); Tue, 14 Feb 2006 16:57:36 +0800 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: [PATCH] kretprobe instance recyled by parent process Date: Tue, 14 Feb 2006 08:57:00 -0000 Message-ID: <9FBCE015AF479F46B3B410499F3AE05B0898E1@pdsmsx405> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH] kretprobe instance recyled by parent process Thread-Index: AcYxRLMXpIXdNYj9SpCVskIak3zezw== From: "Mao, Bibo" To: , Cc: "SystemTAP" , "Keshavamurthy, Anil S" , "Zhang, Yanmin" X-OriginalArrivalTime: 14 Feb 2006 08:57:36.0169 (UTC) FILETIME=[B3430990:01C63144] X-Scanned-By: MIMEDefang 2.52 on 10.7.209.17 X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2006-q1/txt/msg00511.txt.bz2 When kretprobe probe schedule() function, if probed process exit then schedule() function will never return, so some kretprobe instance will never be recycled. By this patch the parent process will recycle kretprobe instance of probed function, there will be no memory leak of kretprobe instance. This patch is based on 2.6.16-rc3. Signed-off-by: bibo mao arch/i386/kernel/process.c | 8 -------- arch/ia64/kernel/process.c | 8 -------- arch/powerpc/kernel/process.c | 2 -- arch/x86_64/kernel/process.c | 8 -------- kernel/kprobes.c | 10 +++++----- kernel/sched.c | 9 ++++++++- 6 files changed, 13 insertions(+), 32 deletions(-) diff -Nruap linux-2.6.16-rc3.org/arch/i386/kernel/process.c linux-2.6.16-rc3/arch/i386/kernel/process.c --- linux-2.6.16-rc3.org/arch/i386/kernel/process.c 2006-02-14 05:46:38.000000000 +0800 +++ linux-2.6.16-rc3/arch/i386/kernel/process.c 2006-02-14 05:48:06.000000000 +0800 @@ -38,7 +38,6 @@ #include #include #include -#include =20 #include #include @@ -364,13 +363,6 @@ void exit_thread(void) struct task_struct *tsk =3D current; struct thread_struct *t =3D &tsk->thread; =20 - /* - * Remove function-return probe instances associated with this task - * and put them back on the free list. Do not insert an exit probe for - * this function, it will be disabled by kprobe_flush_task if you do. - */ - kprobe_flush_task(tsk); - /* The process may have allocated an io port bitmap... nuke it. */ if (unlikely(NULL !=3D t->io_bitmap_ptr)) { int cpu =3D get_cpu(); diff -Nruap linux-2.6.16-rc3.org/arch/ia64/kernel/process.c linux-2.6.16-rc3/arch/ia64/kernel/process.c --- linux-2.6.16-rc3.org/arch/ia64/kernel/process.c 2006-02-14 05:46:38.000000000 +0800 +++ linux-2.6.16-rc3/arch/ia64/kernel/process.c 2006-02-14 05:48:40.000000000 +0800 @@ -30,7 +30,6 @@ #include #include #include -#include =20 #include #include @@ -738,13 +737,6 @@ void exit_thread (void) { =20 - /* - * Remove function-return probe instances associated with this task - * and put them back on the free list. Do not insert an exit probe for - * this function, it will be disabled by kprobe_flush_task if you do. - */ - kprobe_flush_task(current); - ia64_drop_fpu(current); #ifdef CONFIG_PERFMON /* if needed, stop monitoring and flush state to perfmon context */ diff -Nruap linux-2.6.16-rc3.org/arch/powerpc/kernel/process.c linux-2.6.16-rc3/arch/powerpc/kernel/process.c --- linux-2.6.16-rc3.org/arch/powerpc/kernel/process.c 2006-02-14 05:46:38.000000000 +0800 +++ linux-2.6.16-rc3/arch/powerpc/kernel/process.c 2006-02-14 05:49:33.000000000 +0800 @@ -37,7 +37,6 @@ #include #include #include -#include =20 #include #include @@ -457,7 +456,6 @@ void show_regs(struct pt_regs * regs) =20 void exit_thread(void) { - kprobe_flush_task(current); discard_lazy_cpu_state(); } =20 diff -Nruap linux-2.6.16-rc3.org/arch/x86_64/kernel/process.c linux-2.6.16-rc3/arch/x86_64/kernel/process.c --- linux-2.6.16-rc3.org/arch/x86_64/kernel/process.c 2006-02-14 05:46:38.000000000 +0800 +++ linux-2.6.16-rc3/arch/x86_64/kernel/process.c 2006-02-14 05:50:02.000000000 +0800 @@ -35,7 +35,6 @@ #include #include #include -#include #include =20 #include @@ -353,13 +352,6 @@ void exit_thread(void) struct task_struct *me =3D current; struct thread_struct *t =3D &me->thread; =20 - /* - * Remove function-return probe instances associated with this task - * and put them back on the free list. Do not insert an exit probe for - * this function, it will be disabled by kprobe_flush_task if you do. - */ - kprobe_flush_task(me); - if (me->thread.io_bitmap_ptr) {=20 struct tss_struct *tss =3D &per_cpu(init_tss, get_cpu()); =20 diff -Nruap linux-2.6.16-rc3.org/kernel/kprobes.c linux-2.6.16-rc3/kernel/kprobes.c --- linux-2.6.16-rc3.org/kernel/kprobes.c 2006-02-14 05:46:38.000000000 +0800 +++ linux-2.6.16-rc3/kernel/kprobes.c 2006-02-14 08:16:55.000000000 +0800 @@ -323,10 +323,10 @@ struct hlist_head __kprobes *kretprobe_i } =20 /* - * This function is called from exit_thread or flush_thread when task tk's - * stack is being recycled so that we can recycle any function-return probe - * instances associated with this task. These left over instances represent - * probed functions that have been called but will never return. + * This function is called from finish_task_switch when task tk becomes dead, + * so that we can recycle any function-return probe instances associated=20 + * with this task. These left over instances represent probed functions + * that have been called but will never return. */ void __kprobes kprobe_flush_task(struct task_struct *tk) { @@ -336,7 +336,7 @@ void __kprobes kprobe_flush_task(struct=20 unsigned long flags =3D 0; =20 spin_lock_irqsave(&kretprobe_lock, flags); - head =3D kretprobe_inst_table_head(current); + head =3D kretprobe_inst_table_head(tk); hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { if (ri->task =3D=3D tk) recycle_rp_inst(ri); diff -Nruap linux-2.6.16-rc3.org/kernel/sched.c linux-2.6.16-rc3/kernel/sched.c --- linux-2.6.16-rc3.org/kernel/sched.c 2006-02-14 05:46:38.000000000 +0800 +++ linux-2.6.16-rc3/kernel/sched.c 2006-02-14 06:11:57.000000000 +0800 @@ -49,6 +49,7 @@ #include #include #include +#include #include =20 #include @@ -1566,8 +1567,14 @@ static inline void finish_task_switch(ru finish_lock_switch(rq, prev); if (mm) mmdrop(mm); - if (unlikely(prev_task_flags & PF_DEAD)) + if (unlikely(prev_task_flags & PF_DEAD)){ + /* + * Remove function-return probe instances associated with this task + * and put them back on the free list. + */ + kprobe_flush_task(prev); put_task_struct(prev); + } } =20 /**