From: David Howells <dhowells@redhat.com>
To: David Howells <dhowells@redhat.com>
Cc: Manfred Spraul <manfred@colorfullife.com>,
Andrea Arcangeli <andrea@suse.de>,
Linus Torvalds <torvalds@transmeta.com>,
Ulrich.Weigand@de.ibm.com, linux-kernel@vger.kernel.org
Subject: Re: Deadlock on the mm->mmap_sem
Date: Tue, 18 Sep 2001 16:11:44 +0100 [thread overview]
Message-ID: <6401.1000825904@warthog.cambridge.redhat.com> (raw)
In-Reply-To: Message from David Howells <dhowells@redhat.com> of "Tue, 18 Sep 2001 15:13:45 BST." <5552.1000822425@warthog.cambridge.redhat.com>
Okay tested patch to cure coredumping of the need to hold the mm semaphore:
- kernel/fork.c: function to partially copy an mm_struct and attach it
to the task_struct in place of the old.
- include/linux/mm.h: declaration for above function
- fs/exec.c: have do_coredump() call this function and not get the
read lock around the binfmt coredumper
It works, and you can core dump without oopsing.
David
diff -uNr -x TAGS linux-2.4.10-pre11/fs/exec.c linux-rwsem/fs/exec.c
--- linux-2.4.10-pre11/fs/exec.c Tue Sep 18 13:57:06 2001
+++ linux-rwsem/fs/exec.c Tue Sep 18 15:01:56 2001
@@ -947,6 +947,14 @@
if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
goto fail;
+ /* make sure the attached VM has a single ref (this process) to make
+ * sure only do_exit() will change the VMA list, so we don't have to
+ * lock the mm->sem around the binfmt coredumper
+ */
+ retval = copy_mm_for_coredump(current);
+ if (retval<0)
+ goto fail;
+
memcpy(corename,"core.", 5);
corename[4] = '\0';
if (core_uses_pid || atomic_read(¤t->mm->mm_users) != 1)
@@ -969,9 +977,7 @@
if (do_truncate(file->f_dentry, 0) != 0)
goto close_fail;
- down_read(¤t->mm->mmap_sem);
retval = binfmt->core_dump(signr, regs, file);
- up_read(¤t->mm->mmap_sem);
close_fail:
filp_close(file, NULL);
diff -uNr -x TAGS linux-2.4.10-pre11/include/linux/mm.h linux-rwsem/include/linux/mm.h
--- linux-2.4.10-pre11/include/linux/mm.h Tue Sep 18 13:57:09 2001
+++ linux-rwsem/include/linux/mm.h Tue Sep 18 15:27:48 2001
@@ -615,6 +615,7 @@
}
extern struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr);
+extern int copy_mm_for_coredump(struct task_struct *tsk);
#endif /* __KERNEL__ */
diff -uNr -x TAGS linux-2.4.10-pre11/kernel/fork.c linux-rwsem/kernel/fork.c
--- linux-2.4.10-pre11/kernel/fork.c Tue Sep 18 13:57:10 2001
+++ linux-rwsem/kernel/fork.c Tue Sep 18 15:28:50 2001
@@ -359,6 +359,55 @@
return retval;
}
+int copy_mm_for_coredump(struct task_struct * tsk)
+{
+ struct mm_struct *mm, *old_mm;
+ int retval;
+
+ /* don't bother copying if there's only one user anyway */
+ if (atomic_read(&tsk->mm->mm_users)==1)
+ return 0;
+
+ old_mm = tsk->mm;
+
+ retval = -ENOMEM;
+ mm = allocate_mm();
+ if (!mm)
+ goto fail_nomem;
+
+ /* Copy the current MM stuff.. */
+ memcpy(mm, tsk->mm, sizeof(*mm));
+ if (!mm_init(mm))
+ goto fail_nomem;
+
+ down_write(&tsk->mm->mmap_sem);
+ retval = dup_mmap(mm);
+ up_write(&tsk->mm->mmap_sem);
+
+ if (retval)
+ goto free_pt;
+
+ /* no LDT now */
+ mm->context.segments = NULL;
+
+ if (init_new_context(tsk,mm))
+ goto free_pt;
+
+ /* swap to new MM */
+ task_lock(tsk);
+ tsk->mm = mm;
+ tsk->active_mm = mm;
+ task_unlock(tsk);
+ mmput(old_mm);
+
+ return 0;
+
+free_pt:
+ mmput(mm);
+fail_nomem:
+ return retval;
+}
+
static inline struct fs_struct *__copy_fs_struct(struct fs_struct *old)
{
struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
next prev parent reply other threads:[~2001-09-18 15:11 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-17 21:50 Deadlock on the mm->mmap_sem Manfred Spraul
2001-09-17 23:39 ` Linus Torvalds
[not found] ` <200109172339.f8HNd5W13244@penguin.transmeta.com>
2001-09-18 0:01 ` Andrea Arcangeli
2001-09-18 7:31 ` Manfred Spraul
2001-09-18 7:55 ` Andrea Arcangeli
2001-09-18 8:18 ` David Howells
2001-09-18 9:32 ` David Howells
2001-09-18 9:37 ` Manfred Spraul
2001-09-18 9:49 ` Arjan van de Ven
2001-09-18 12:53 ` Manfred Spraul
2001-09-18 14:13 ` David Howells
2001-09-18 14:49 ` Alan Cox
2001-09-18 15:26 ` David Howells
2001-09-18 15:46 ` Alan Cox
2001-09-18 15:11 ` David Howells [this message]
2001-09-18 16:49 ` Linus Torvalds
2001-09-19 9:51 ` David Howells
2001-09-19 12:49 ` Andrea Arcangeli
2001-09-19 14:08 ` Manfred Spraul
2001-09-19 14:51 ` David Howells
2001-09-19 15:18 ` Manfred Spraul
2001-09-19 14:53 ` David Howells
2001-09-19 18:03 ` Andrea Arcangeli
2001-09-19 18:16 ` Benjamin LaHaise
2001-09-19 18:27 ` David Howells
2001-09-19 18:48 ` Andrea Arcangeli
2001-09-19 18:45 ` Andrea Arcangeli
2001-09-19 21:14 ` Benjamin LaHaise
2001-09-19 22:07 ` Andrea Arcangeli
2001-09-19 18:19 ` Manfred Spraul
2001-09-20 2:07 ` Andrea Arcangeli
2001-09-20 4:37 ` Andrea Arcangeli
2001-09-20 7:05 ` David Howells
2001-09-20 7:19 ` Andrea Arcangeli
2001-09-20 8:01 ` David Howells
2001-09-20 8:09 ` Andrea Arcangeli
2001-09-19 18:26 ` David Howells
2001-09-19 18:47 ` Andrea Arcangeli
2001-09-19 23:25 ` David Howells
2001-09-19 23:34 ` Andrea Arcangeli
2001-09-19 23:46 ` Andrea Arcangeli
2001-09-19 23:24 ` [PATCH] attempt #2 (Re: Deadlock on the mm->mmap_sem) David Howells
2001-09-19 14:58 ` Deadlock on the mm->mmap_sem David Howells
[not found] <masp0008@stud.uni-sb.de>
2001-09-20 10:57 ` Studierende der Universitaet des Saarlandes
2001-09-20 12:40 ` David Howells
2001-09-20 18:24 ` Andrea Arcangeli
2001-09-20 21:43 ` Manfred Spraul
2001-09-22 21:06 ` Manfred Spraul
-- strict thread matches above, loose matches on Subject: below --
2001-09-18 13:22 Ulrich Weigand
2001-09-17 20:57 Ulrich Weigand
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=6401.1000825904@warthog.cambridge.redhat.com \
--to=dhowells@redhat.com \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=andrea@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=torvalds@transmeta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.