mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maneesh Soni <maneesh@in.ibm.com>
To: Manfred Spraul <manfred@colorfullife.com>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@digeo.com>,
	Dipankar Sarma <dipankar@in.ibm.com>
Subject: Re: Deadlock between tasklist_lock and dcache_lock
Date: Mon, 24 Mar 2003 19:11:35 +0530	[thread overview]
Message-ID: <20030324134134.GB2026@in.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0303231818530.3908-100000@dbl.q-ag.de>

On Sun, Mar 23, 2003 at 05:30:39PM +0000, Manfred Spraul wrote:
> __unhash_process acquires the dcache_lock while holding the tasklist_lock 
> for writing. AFAICS this can deadlock:
> 
> CPU1:
> 	[ in release_task() ]
> 	write_lock_irq(&tasklist_lock);
> 	__unhash_process()
> 	
> CPU2:
> 	spin_lock(&dcache_lock);
> 	<interrupt>
> 	read_lock(&tasklist_lock);, // e.g. for signal delivery
> 	** spins, lock held by cpu 1 for writing.
> 
> CPU1:
> 	[ within __unhash_process() ]
> 	spin_lock(&dcache_lock);
> 	** spins, lock held by CPU2
> 
> Probably the callers of __unhash_process must acquire the dcache_lock 
> before write_lock_irq(&tasklist_lock).
> 
> Any other ideas how to fix the deadlock?
> --
> 	Manfred

Hello Manfred, Andrew

How is the patch below?.. just some re-arrangement of code. I don't think
we need task_list lock while cleaning up the proc_dentry.

Same problem is there in fs/exec.c:de_thread(). So this is a common solution.

The patch does following things:
0. brings cleaning up of proc_dentry outside tasklist_lock protection.
1. gets rid of code duplication in __unhash_process() and clean_proc_dentry()
2. combines clean_proc_dentry() and put_proc_dentry()
3. makes clean_proc_dentry() extern

fs/exec.c               |   31 +++++++++++++------------------
include/linux/proc_fs.h |    1 +
kernel/exit.c           |   28 ++++++++--------------------
3 files changed, 22 insertions(+), 38 deletions(-)

diff -urN linux-2.5.65-base/fs/exec.c linux-2.5.65-unhash_process/fs/exec.c
--- linux-2.5.65-base/fs/exec.c	2003-03-18 03:14:03.000000000 +0530
+++ linux-2.5.65-unhash_process/fs/exec.c	2003-03-24 16:49:30.000000000 +0530
@@ -529,27 +529,20 @@
 	return 0;
 }
 
-static struct dentry *clean_proc_dentry(struct task_struct *p)
+void clean_proc_dentry(struct dentry * proc_dentry)
 {
-	struct dentry *proc_dentry = p->proc_dentry;
 
 	if (proc_dentry) {
 		spin_lock(&dcache_lock);
 		if (!d_unhashed(proc_dentry)) {
 			dget_locked(proc_dentry);
 			__d_drop(proc_dentry);
-		} else
-			proc_dentry = NULL;
-		spin_unlock(&dcache_lock);
-	}
-	return proc_dentry;
-}
-
-static inline void put_proc_dentry(struct dentry *dentry)
-{
-	if (dentry) {
-		shrink_dcache_parent(dentry);
-		dput(dentry);
+			spin_unlock(&dcache_lock);
+			shrink_dcache_parent(proc_dentry);
+			dput(proc_dentry);
+		}
+		else
+			spin_unlock(&dcache_lock);
 	}
 }
 
@@ -661,8 +654,8 @@
 			yield();
 
 		write_lock_irq(&tasklist_lock);
-		proc_dentry1 = clean_proc_dentry(current);
-		proc_dentry2 = clean_proc_dentry(leader);
+		proc_dentry1 = current->proc_dentry;
+		proc_dentry2 = leader->proc_dentry;
 
 		if (leader->tgid != current->tgid)
 			BUG();
@@ -703,8 +696,10 @@
 
 		write_unlock_irq(&tasklist_lock);
 
-		put_proc_dentry(proc_dentry1);
-		put_proc_dentry(proc_dentry2);
+		if (proc_dentry1)
+			clean_proc_dentry(proc_dentry1);
+		if (proc_dentry2)
+			clean_proc_dentry(proc_dentry2);
 
 		if (state != TASK_ZOMBIE)
 			BUG();
diff -urN linux-2.5.65-base/include/linux/proc_fs.h linux-2.5.65-unhash_process/include/linux/proc_fs.h
--- linux-2.5.65-base/include/linux/proc_fs.h	2003-03-18 03:13:37.000000000 +0530
+++ linux-2.5.65-unhash_process/include/linux/proc_fs.h	2003-03-24 16:47:10.000000000 +0530
@@ -224,4 +224,5 @@
 	return PROC_I(inode)->pde;
 }
 
+extern void clean_proc_dentry(struct dentry *proc_dentry);
 #endif /* _LINUX_PROC_FS_H */
diff -urN linux-2.5.65-base/kernel/exit.c linux-2.5.65-unhash_process/kernel/exit.c
--- linux-2.5.65-base/kernel/exit.c	2003-03-18 03:14:43.000000000 +0530
+++ linux-2.5.65-unhash_process/kernel/exit.c	2003-03-24 16:46:40.000000000 +0530
@@ -21,6 +21,7 @@
 #include <linux/ptrace.h>
 #include <linux/profile.h>
 #include <linux/mount.h>
+#include <linux/proc_fs.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -33,7 +34,6 @@
 
 static struct dentry * __unhash_process(struct task_struct *p)
 {
-	struct dentry *proc_dentry;
 
 	nr_threads--;
 	detach_pid(p, PIDTYPE_PID);
@@ -46,17 +46,8 @@
 	}
 
 	REMOVE_LINKS(p);
-	proc_dentry = p->proc_dentry;
-	if (unlikely(proc_dentry != NULL)) {
-		spin_lock(&dcache_lock);
-		if (!d_unhashed(proc_dentry)) {
-			dget_locked(proc_dentry);
-			__d_drop(proc_dentry);
-		} else
-			proc_dentry = NULL;
-		spin_unlock(&dcache_lock);
-	}
-	return proc_dentry;
+
+	return p->proc_dentry;
 }
 
 void release_task(struct task_struct * p)
@@ -93,10 +84,9 @@
 	sched_exit(p);
 	write_unlock_irq(&tasklist_lock);
 
-	if (unlikely(proc_dentry != NULL)) {
-		shrink_dcache_parent(proc_dentry);
-		dput(proc_dentry);
-	}
+	if (unlikely(proc_dentry != NULL))
+		clean_proc_dentry(proc_dentry);
+
 	release_thread(p);
 	put_task_struct(p);
 }
@@ -111,10 +101,8 @@
 	proc_dentry = __unhash_process(p);
 	write_unlock_irq(&tasklist_lock);
 
-	if (unlikely(proc_dentry != NULL)) {
-		shrink_dcache_parent(proc_dentry);
-		dput(proc_dentry);
-	}
+	if (unlikely(proc_dentry != NULL)) 
+		clean_proc_dentry(proc_dentry);
 }
 
 /*

-- 
Maneesh Soni
IBM Linux Technology Center, 
IBM India Software Lab, Bangalore.
Phone: +91-80-5044999 email: maneesh@in.ibm.com
http://lse.sourceforge.net/

      reply	other threads:[~2003-03-24 13:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-23 17:28 Manfred Spraul
2003-03-24 13:41 ` Maneesh Soni [this message]

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=20030324134134.GB2026@in.ibm.com \
    --to=maneesh@in.ibm.com \
    --cc=akpm@digeo.com \
    --cc=dipankar@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.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

all inboxes | Powered by JetHome®